Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRIDEDIT-893: make curvilinear grid indexing consistent #297

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d728bb6
NumM and NumN made private
andreasbuykx Jan 31, 2024
ae644ad
Fix method comments
andreasbuykx Jan 31, 2024
9d82248
Additional access methods
andreasbuykx Jan 31, 2024
ff11ccf
Using access methods for m,n indexing
andreasbuykx Jan 31, 2024
99a1acb
Use new methods to get row and column vectors
andreasbuykx Jan 31, 2024
c103df9
Using access methods for m,n indexing (2)
andreasbuykx Jan 31, 2024
b38b616
Renamed method to clarify that node validity is tested
andreasbuykx Jan 31, 2024
19761e9
Added access method for face mask
andreasbuykx Jan 31, 2024
ffe1b08
Using numM, numN
andreasbuykx Jan 31, 2024
e9b686d
Grid faces mask matrix made private
andreasbuykx Jan 31, 2024
b27fc0e
Added grid node type access method, storage matrix made private
andreasbuykx Jan 31, 2024
d6ec13d
Gridindices matrix made private
andreasbuykx Jan 31, 2024
273bee1
Use GetNodes() access method
andreasbuykx Feb 1, 2024
2b73525
Using GetNode access method
andreasbuykx Feb 1, 2024
d7fac5b
Added asserts for the increasing number of rows/cols
andreasbuykx Feb 1, 2024
799f951
Use last row/column index consistently
andreasbuykx Feb 1, 2024
4c98e81
Use matrix dimensions for NumM and NumN
andreasbuykx Feb 1, 2024
0cfc139
Use NumM and NumN methods for grid dimensions
andreasbuykx Feb 1, 2024
dff3f54
Use NumM and NumN methods for grid dimensions
andreasbuykx Feb 1, 2024
b8bd3f3
Make gridnodes member private
andreasbuykx Feb 1, 2024
a6dc73e
Using NumM and NumN for dimensions
andreasbuykx Feb 1, 2024
9729fcd
Adjusted documentation of NumN and NumM
andreasbuykx Feb 5, 2024
0a73429
Adjusted comment of GetNodes
andreasbuykx Feb 5, 2024
f0bbda8
Renamed and fixed documentation for getters of row/column vectors
andreasbuykx Feb 5, 2024
d2fb82d
Renamed parameters and updated documentation
andreasbuykx Feb 5, 2024
59018dc
Made parameter comments consistent
andreasbuykx Feb 5, 2024
de7c6a2
Document row/column to m/n correspondence
andreasbuykx Feb 5, 2024
7e16ef7
Documented behavior of SetFlatCopies and ConvertCurvilinearToNodesAnd…
andreasbuykx Feb 5, 2024
1e17f03
Added node serialization test
andreasbuykx Feb 5, 2024
cc11b8e
Added node serialization test with invalid node
andreasbuykx Feb 5, 2024
9f2581b
Added edge serialization test
andreasbuykx Feb 5, 2024
0fce458
Added edge serialization test with invalid node
andreasbuykx Feb 5, 2024
fd3fb27
Removed tests that always evaluate to true
andreasbuykx Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ namespace meshkernel
explicit CurvilinearGrid(Projection projection);

/// @brief Lvalue constructor. Creates a new curvilinear grid from a given set of points
/// @details The matrix row index corresponds to the CurvilinearGrid m index, the matrix column index corresponds to the CurvilinearGrid n index
/// @param[in] grid The input grid points
/// @param[in] projection The projection to use
CurvilinearGrid(lin_alg::Matrix<Point> const& grid, Projection projection);

/// @brief Set the grid nodes of a curvilinear grid instance
/// @details The matrix row index corresponds to the CurvilinearGrid m index, the matrix column index corresponds to the CurvilinearGrid n index
/// @param[in] gridNodes The input grid points
void SetGridNodes(const lin_alg::Matrix<Point>& gridNodes);

Expand All @@ -99,21 +101,30 @@ namespace meshkernel
[[nodiscard]] bool IsValid() const;

/// @brief Converting a curvilinear mesh to a set of nodes, edges and returns the original mapping (gridtonet)
/// @details Nodes and grid indices from the matrix are serialized in row-major order (n runs fastest).
/// Edges are serialized as follows: first all m-oriented edges ((m,n)-(m+1,n)) in row-major order, then all
/// n-oriented edges ((m,n)-(m,n+1)), in row-major order.
/// @note Also invalid nodes are serialized to points, edges and grid indices
/// @returns The nodes, the edges, and the original mapping (m and n indices for each node)
[[nodiscard]] std::tuple<std::vector<Point>, std::vector<Edge>, std::vector<CurvilinearGridNodeIndices>> ConvertCurvilinearToNodesAndEdges() const;

/// @brief Set internal flat copies of nodes and edges, so the pointer to the first entry is communicated with the front-end
/// @details The Mesh nodes and edges arrays, and the grid node indices array are populated by the result of ConvertCurvilinearToNodesAndEdges.
void SetFlatCopies();

/// @brief Get the m and n indices of the node closest to the point
/// @param[in] point The input grid points
[[nodiscard]] CurvilinearGridNodeIndices GetNodeIndices(Point point);

/// @brief Gets a constant reference to the grid node at the (i,j) location
[[nodiscard]] meshkernel::Point& GetNode(const UInt i, const UInt j) { return m_gridNodes(i, j); }
/// @brief Gets a reference to the grid node at the (m,n) location
/// @param[in] m The m-dimension index
/// @param[in] n The n-dimension index
[[nodiscard]] meshkernel::Point& GetNode(const UInt m, const UInt n) { return m_gridNodes(m, n); }

/// @brief Gets a reference to the grid node at the (i,j) location
[[nodiscard]] meshkernel::Point const& GetNode(const UInt i, const UInt j) const { return m_gridNodes(i, j); }
/// @brief Gets a constant reference to the grid node at the (m,n) location
/// @param[in] m The m-dimension index
/// @param[in] n The n-dimension index
[[nodiscard]] meshkernel::Point const& GetNode(const UInt m, const UInt n) const { return m_gridNodes(m, n); }

/// @brief Gets a reference to the grid node at the location specified by the index.
/// @note Exception will be raised for a non-valid index
Expand Down Expand Up @@ -147,12 +158,24 @@ namespace meshkernel
/// @brief Computes the grid nodes types and the faces masks
void ComputeGridNodeTypes();

/// @brief Determines if a face is valid.
/// @brief Determines the grid node type
/// @param[in] m The m-dimension index
/// @param[in] n The n-dimension index
/// @return the node type
NodeType GetNodeType(UInt m, UInt n) const { return m_gridNodesTypes(m, n); }

/// @brief Determines if all nodes of a face are valid.
/// A face is valid if all its nodes are valid.
/// @param[in] m The m coordinate
/// @param[in] n The n coordinate
/// @param[in] m The m-dimension index
/// @param[in] n The n-dimension index
/// @return True if the face is valid, false otherwise
[[nodiscard]] bool IsValidFace(UInt m, UInt n) const;
[[nodiscard]] bool AreFaceNodesValid(UInt m, UInt n) const;

/// @brief Determines if the face mask is true (valid face) or false (invalid face)
/// @param[in] m The m-dimension index
/// @param[in] n The n-dimension index
/// @return the face mask value (true/false)
[[nodiscard]] bool IsFaceMaskValid(UInt m, UInt n) const { return m_gridFacesMask(m, n); }

/// @brief Inserts a new face. The new face will be inserted on top of the closest edge.
/// @param[in] point The point used for finding the closest edge.
Expand Down Expand Up @@ -219,12 +242,32 @@ namespace meshkernel
/// @brief Get the mesh bounding box.
BoundingBox GetBoundingBox() const;

UInt m_numM = 0; ///< The number of m coordinates (vertical lines)
UInt m_numN = 0; ///< The number of n coordinates (horizontal lines)
lin_alg::Matrix<Point> m_gridNodes; ///< Member variable storing the grid
lin_alg::Matrix<bool> m_gridFacesMask; ///< The mask of the grid faces (true/false)
lin_alg::Matrix<NodeType> m_gridNodesTypes; ///< The grid node types
std::vector<CurvilinearGridNodeIndices> m_gridIndices; ///< The original mapping of the flatten nodes in the curvilinear grid
/// @brief The number of nodes M in the m dimension
/// @return A number >= 2 for a valid curvilinear grid
UInt NumM() const { return static_cast<UInt>(m_gridNodes.rows()); }

/// @brief The number of nodes N in the n dimension
/// @return A number >= 2 for a valid curvilinear grid
UInt NumN() const { return static_cast<UInt>(m_gridNodes.cols()); }

/// @brief Is the node matrix empty
/// @return true iff the node matrix is empty
bool IsEmpty() const { return lin_alg::MatrixIsEmpty(m_gridNodes); }

/// @brief Get a copy of the nodes matrix
/// @note:the m dimension is the first (or row) index, the n dimension is the second (or column) index
/// @return a copy of the matrix
lin_alg::Matrix<Point> GetNodes() const { return m_gridNodes; }

/// @brief Get the array of nodes at an m-dimension index
/// @param [in] m the m-dimension index
/// @return a vector of N nodes
std::vector<Point> GetNodeVectorAtM(UInt m) const { return lin_alg::MatrixRowToSTLVector(m_gridNodes, m); }

/// @brief Get the array of nodes at an n-dimension index
/// @param [in] n the n-dimension index
/// @return a vector of M nodes
std::vector<Point> GetNodeVectorAtN(UInt n) const { return lin_alg::MatrixColToSTLVector(m_gridNodes, n); }

private:
/// @brief Remove invalid nodes.
Expand All @@ -243,5 +286,10 @@ namespace meshkernel
/// @param[in] secondNode The indices of the second new node in the modified grid.
void AddEdge(CurvilinearGridNodeIndices const& firstNode,
CurvilinearGridNodeIndices const& secondNode);

lin_alg::Matrix<Point> m_gridNodes; ///< Member variable storing the grid
lin_alg::Matrix<bool> m_gridFacesMask; ///< The mask of the grid faces (true/false)
lin_alg::Matrix<NodeType> m_gridNodesTypes; ///< The grid node types
std::vector<CurvilinearGridNodeIndices> m_gridIndices; ///< The original mapping of the flatten nodes in the curvilinear grid
};
} // namespace meshkernel
Loading
Loading