31 #include "MeshKernel/CurvilinearGrid/CurvilinearGrid.hpp"
32 #include "MeshKernel/Definitions.hpp"
33 #include "MeshKernel/Mesh2D.hpp"
34 #include "MeshKernel/Point.hpp"
35 #include "Utilities/LinearAlgebra.hpp"
37 using namespace meshkernel::constants;
52 std::unique_ptr<CurvilinearGrid> Compute(
const Point& point);
57 class MatrixWithNegativeIndices
64 int getValue(
int j,
int i)
const
66 const auto jIndex = j - m_minJ;
67 const auto iIndex = i - m_minI;
68 const auto value = m_matrix(jIndex, iIndex);
75 void setValue(
int j,
int i,
int value)
77 const auto jIndex = j - m_minJ;
78 const auto iIndex = i - m_minI;
79 m_matrix(jIndex, iIndex) = value;
86 bool IsValid(
int j,
int i)
const
88 const auto jIndex = j - m_minJ;
89 const auto iIndex = i - m_minI;
90 return m_matrix(jIndex, iIndex) != missing::intValue;
95 [[nodiscard]]
int rows()
const
97 return static_cast<int>(m_matrix.rows());
102 [[nodiscard]]
int cols()
const
104 return static_cast<int>(m_matrix.cols());
109 [[nodiscard]]
int minCol()
const
116 [[nodiscard]]
int maxCol()
const
123 [[nodiscard]]
int minRow()
const
130 [[nodiscard]]
int maxRow()
const
140 void resize(
int minJ,
int minI,
int maxJ,
int maxI)
143 const int extraRowsTop = std::max(m_minJ - minJ, 0);
144 const int extraRowsBottom = std::max(maxJ - m_maxJ, 0);
145 const int extraColsLeft = std::max(m_minI - minI, 0);
146 const int extraColsRight = std::max(maxI - m_maxI, 0);
148 if (extraRowsTop == 0 && extraRowsBottom == 0 && extraColsLeft == 0 && extraColsRight == 0)
154 const auto newRows =
static_cast<int>(m_matrix.rows()) + extraRowsTop + extraRowsBottom;
155 const auto newCols =
static_cast<int>(m_matrix.cols()) + extraColsLeft + extraColsRight;
156 lin_alg::Matrix<int> newMatrix(newRows, newCols);
157 newMatrix.setConstant(missing::intValue);
160 newMatrix.block(extraRowsTop, extraColsLeft, m_matrix.rows(), m_matrix.cols()) = m_matrix;
163 m_matrix.swap(newMatrix);
164 m_minI = std::min(m_minI, minI);
165 m_minJ = std::min(m_minJ, minJ);
166 m_maxI = std::max(m_maxI, maxI);
167 m_maxJ = std::max(m_maxJ, maxJ);
171 lin_alg::Matrix<int> m_matrix = lin_alg::Matrix<int>(1, 1);
179 [[nodiscard]] Eigen::Matrix<UInt, 2, 2> ComputeLocalNodeMapping(
UInt face)
const;
182 [[nodiscard]]
UInt ComputeNeighbouringFaceNodes(
const UInt face,
183 const Eigen::Matrix<UInt, 2, 2>& localNodeMapping,
185 const std::vector<bool>& visitedFace);
188 [[nodiscard]]
bool CheckGridLine(
const UInt validNode,
const UInt candidateNode)
const;
191 bool IsConnectionValid(
const UInt candidateNode,
const int iCandidate,
const int jCandidate);
194 [[nodiscard]] lin_alg::Matrix<Point> ComputeCurvilinearMatrix();
197 std::vector<int> m_i;
198 std::vector<int> m_j;
200 const std::array<std::array<int, 2>, 4> m_nodeFrom = {{{0, 0},
205 const std::array<std::array<int, 2>, 4> m_nodeTo = {{{0, 1},
210 const std::array<std::array<int, 2>, 4> m_directionsDeltas = {{{-1, 0},
215 const int n_maxNumRowsColumns = 1000000;
217 MatrixWithNegativeIndices m_mapping;