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"
50 std::unique_ptr<CurvilinearGrid>
Compute(
const Point& point);
55 class MatrixWithNegativeIndices
62 int getValue(
int j,
int i)
const
64 const auto jIndex = j - m_minJ;
65 const auto iIndex = i - m_minI;
66 const auto value = m_matrix(jIndex, iIndex);
73 void setValue(
int j,
int i,
int value)
75 const auto jIndex = j - m_minJ;
76 const auto iIndex = i - m_minI;
77 m_matrix(jIndex, iIndex) = value;
84 bool IsValid(
int j,
int i)
const
86 const auto jIndex = j - m_minJ;
87 const auto iIndex = i - m_minI;
88 return m_matrix(jIndex, iIndex) != constants::missing::intValue;
93 [[nodiscard]]
int rows()
const
95 return static_cast<int>(m_matrix.rows());
100 [[nodiscard]]
int cols()
const
102 return static_cast<int>(m_matrix.cols());
107 [[nodiscard]]
int minCol()
const
114 [[nodiscard]]
int maxCol()
const
121 [[nodiscard]]
int minRow()
const
128 [[nodiscard]]
int maxRow()
const
138 void resize(
int minJ,
int minI,
int maxJ,
int maxI)
141 const int extraRowsTop = std::max(m_minJ - minJ, 0);
142 const int extraRowsBottom = std::max(maxJ - m_maxJ, 0);
143 const int extraColsLeft = std::max(m_minI - minI, 0);
144 const int extraColsRight = std::max(maxI - m_maxI, 0);
146 if (extraRowsTop == 0 && extraRowsBottom == 0 && extraColsLeft == 0 && extraColsRight == 0)
152 const auto newRows =
static_cast<int>(m_matrix.rows()) + extraRowsTop + extraRowsBottom;
153 const auto newCols =
static_cast<int>(m_matrix.cols()) + extraColsLeft + extraColsRight;
154 lin_alg::Matrix<int> newMatrix(newRows, newCols);
155 newMatrix.setConstant(constants::missing::intValue);
158 newMatrix.block(extraRowsTop, extraColsLeft, m_matrix.rows(), m_matrix.cols()) = m_matrix;
161 m_matrix.swap(newMatrix);
162 m_minI = std::min(m_minI, minI);
163 m_minJ = std::min(m_minJ, minJ);
164 m_maxI = std::max(m_maxI, maxI);
165 m_maxJ = std::max(m_maxJ, maxJ);
169 lin_alg::Matrix<int> m_matrix = lin_alg::Matrix<int>(1, 1);
177 [[nodiscard]] Eigen::Matrix<UInt, 2, 2> ComputeLocalNodeMapping(
UInt face)
const;
180 [[nodiscard]]
UInt ComputeNeighbouringFaceNodes(
const UInt face,
181 const Eigen::Matrix<UInt, 2, 2>& localNodeMapping,
183 const std::vector<bool>& visitedFace);
186 [[nodiscard]]
bool CheckGridLine(
const UInt validNode,
const UInt candidateNode)
const;
189 bool IsConnectionValid(
const UInt candidateNode,
const int iCandidate,
const int jCandidate);
192 [[nodiscard]] lin_alg::Matrix<Point> ComputeCurvilinearMatrix();
195 std::vector<int> m_i;
196 std::vector<int> m_j;
198 const std::array<std::array<int, 2>, 4> m_nodeFrom = {{{0, 0},
203 const std::array<std::array<int, 2>, 4> m_nodeTo = {{{0, 1},
208 const std::array<std::array<int, 2>, 4> m_directionsDeltas = {{{-1, 0},
213 const int n_maxNumRowsColumns = 1000000;
215 MatrixWithNegativeIndices m_mapping;