Skip to content

Commit

Permalink
More replacemenmts in CurvilinearGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-el-sayed committed Jul 18, 2023
1 parent 6d997fb commit 998dfd0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace meshkernel
UInt m_numN = 0; ///< The number of n coordinates (horizontal lines)
std::vector<std::vector<Point>> m_gridNodes; ///< Member variable storing the grid
lin_alg::MatrixRowMajor<bool> m_gridFacesMask; ///< The mask of the grid faces (true/false)
std::vector<std::vector<NodeType>> m_gridNodesTypes; ///< The grid node types
lin_alg::MatrixRowMajor<NodeType> m_gridNodesTypes; ///< The grid node types
std::vector<CurvilinearGridNodeIndices> m_gridIndices; ///< The original mapping of the flatten nodes in the curvilinear grid

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "MeshKernel/Definitions.hpp"

// Not allowed, must be signed!
// #define EIGEN_DEFAULT_DENSE_INDEX_TYPE UInt
#include <Eigen/Core>

namespace meshkernel
Expand All @@ -29,7 +27,7 @@ namespace meshkernel
/// @param[in] preserve Optional parameter that determines if the existing elements in
/// the matrix should be presrved or overwritten by the provided
/// or deflault (if not provided) fill value
/// @param[in] fill_value The otional the fill value (defaults to the template class constructor)
/// @param[in] fill_value The optional the fill value (defaults to the template class constructor)
template <class T>
inline static void ResizeAndFillMatrix(MatrixRowMajor<T>& matrix,
UInt rows,
Expand Down
65 changes: 33 additions & 32 deletions libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <MeshKernel/CurvilinearGrid/CurvilinearGrid.hpp>
#include <MeshKernel/CurvilinearGrid/CurvilinearGridLine.hpp>
#include <MeshKernel/Exceptions.hpp>
#include <MeshKernel/Operations.hpp>
#include <MeshKernel/Polygons.hpp>

Expand Down Expand Up @@ -358,7 +359,7 @@ namespace meshkernel
void CurvilinearGrid::ComputeGridNodeTypes()
{
RemoveInvalidNodes(true);
ResizeAndFill2DVector(m_gridNodesTypes, m_numM, m_numN, true, NodeType::Invalid);
lin_alg::ResizeAndFillMatrix(m_gridNodesTypes, m_numM, m_numN, true, NodeType::Invalid);

// Flag faces based on boundaries
for (UInt m = 0; m < m_numM; ++m)
Expand All @@ -374,85 +375,85 @@ namespace meshkernel
// Left side
if (m == 0 && n == 0)
{
m_gridNodesTypes[m][n] = NodeType::BottomLeft;
m_gridNodesTypes(m, n) = NodeType::BottomLeft;
continue;
}
if (m == 0 && n == m_numN - 1)
{
m_gridNodesTypes[m][n] = NodeType::UpperLeft;
m_gridNodesTypes(m, n) = NodeType::UpperLeft;
continue;
}
if (m == 0 && !m_gridNodes[m][n - 1].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::BottomLeft;
m_gridNodesTypes(m, n) = NodeType::BottomLeft;
continue;
}
if (m == 0 && !m_gridNodes[m][n + 1].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::UpperLeft;
m_gridNodesTypes(m, n) = NodeType::UpperLeft;
continue;
}
if (m == 0)
{
m_gridNodesTypes[m][n] = NodeType::Left;
m_gridNodesTypes(m, n) = NodeType::Left;
continue;
}
// Right side
if (m == m_numM - 1 && n == 0)
{
m_gridNodesTypes[m][n] = NodeType::BottomRight;
m_gridNodesTypes(m, n) = NodeType::BottomRight;
continue;
}
if (m == m_numM - 1 && n == m_numN - 1)
{
m_gridNodesTypes[m][n] = NodeType::UpperRight;
m_gridNodesTypes(m, n) = NodeType::UpperRight;
continue;
}
if (m == m_numM - 1 && !m_gridNodes[m][n - 1].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::BottomRight;
m_gridNodesTypes(m, n) = NodeType::BottomRight;
continue;
}
if (m == m_numM - 1 && !m_gridNodes[m][n + 1].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::UpperRight;
m_gridNodesTypes(m, n) = NodeType::UpperRight;
continue;
}
if (m == m_numM - 1)
{
m_gridNodesTypes[m][n] = NodeType::Right;
m_gridNodesTypes(m, n) = NodeType::Right;
continue;
}
// Bottom side
if (n == 0 && !m_gridNodes[m - 1][n].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::BottomLeft;
m_gridNodesTypes(m, n) = NodeType::BottomLeft;
continue;
}
if (n == 0 && !m_gridNodes[m + 1][n].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::BottomRight;
m_gridNodesTypes(m, n) = NodeType::BottomRight;
continue;
}
if (n == 0)
{
m_gridNodesTypes[m][n] = NodeType::Bottom;
m_gridNodesTypes(m, n) = NodeType::Bottom;
continue;
}
// Upper side
if (n == m_numN - 1 && !m_gridNodes[m - 1][n].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::UpperLeft;
m_gridNodesTypes(m, n) = NodeType::UpperLeft;
continue;
}
if (n == m_numN - 1 && !m_gridNodes[m + 1][n].IsValid())
{
m_gridNodesTypes[m][n] = NodeType::UpperRight;
m_gridNodesTypes(m, n) = NodeType::UpperRight;
continue;
}
if (n == m_numN - 1)
{
m_gridNodesTypes[m][n] = NodeType::Up;
m_gridNodesTypes(m, n) = NodeType::Up;
continue;
}

Expand All @@ -466,39 +467,39 @@ namespace meshkernel
isBottomLeftFaceValid &&
isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::InternalValid;
m_gridNodesTypes(m, n) = NodeType::InternalValid;
continue;
}
if (!isTopRightFaceValid &&
isTopLeftFaceValid &&
isBottomLeftFaceValid &&
isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::BottomLeft;
m_gridNodesTypes(m, n) = NodeType::BottomLeft;
continue;
}
if (isTopRightFaceValid &&
!isTopLeftFaceValid &&
isBottomLeftFaceValid &&
isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::BottomRight;
m_gridNodesTypes(m, n) = NodeType::BottomRight;
continue;
}
if (isTopRightFaceValid &&
isTopLeftFaceValid &&
!isBottomLeftFaceValid &&
isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::UpperRight;
m_gridNodesTypes(m, n) = NodeType::UpperRight;
continue;
}
if (isTopRightFaceValid &&
isTopLeftFaceValid &&
isBottomLeftFaceValid &&
!isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::UpperLeft;
m_gridNodesTypes(m, n) = NodeType::UpperLeft;
continue;
}

Expand All @@ -507,15 +508,15 @@ namespace meshkernel
!isBottomLeftFaceValid &&
!isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::Bottom;
m_gridNodesTypes(m, n) = NodeType::Bottom;
continue;
}
if (isTopRightFaceValid &&
!isTopLeftFaceValid &&
!isBottomLeftFaceValid &&
isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::Left;
m_gridNodesTypes(m, n) = NodeType::Left;
continue;
}

Expand All @@ -524,7 +525,7 @@ namespace meshkernel
isBottomLeftFaceValid &&
isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::Up;
m_gridNodesTypes(m, n) = NodeType::Up;
continue;
}

Expand All @@ -533,7 +534,7 @@ namespace meshkernel
isBottomLeftFaceValid &&
!isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::Right;
m_gridNodesTypes(m, n) = NodeType::Right;
continue;
}

Expand All @@ -542,7 +543,7 @@ namespace meshkernel
!isBottomLeftFaceValid &&
!isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::BottomLeft;
m_gridNodesTypes(m, n) = NodeType::BottomLeft;
continue;
}

Expand All @@ -551,7 +552,7 @@ namespace meshkernel
!isBottomLeftFaceValid &&
!isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::BottomRight;
m_gridNodesTypes(m, n) = NodeType::BottomRight;
continue;
}

Expand All @@ -560,7 +561,7 @@ namespace meshkernel
isBottomLeftFaceValid &&
!isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::UpperRight;
m_gridNodesTypes(m, n) = NodeType::UpperRight;
continue;
}

Expand All @@ -569,7 +570,7 @@ namespace meshkernel
!isBottomLeftFaceValid &&
isBottomRightFaceValid)
{
m_gridNodesTypes[m][n] = NodeType::UpperLeft;
m_gridNodesTypes(m, n) = NodeType::UpperLeft;
}
}
}
Expand Down Expand Up @@ -641,8 +642,8 @@ namespace meshkernel

CurvilinearGrid::BoundaryGridLineType CurvilinearGrid::GetBoundaryGridLineType(CurvilinearGridNodeIndices const& firstNode, CurvilinearGridNodeIndices const& secondNode) const
{
auto const firstNodeType = m_gridNodesTypes[firstNode.m_m][firstNode.m_n];
auto const secondNodeType = m_gridNodesTypes[secondNode.m_m][secondNode.m_n];
auto const firstNodeType = m_gridNodesTypes(firstNode.m_m, firstNode.m_n);
auto const secondNodeType = m_gridNodesTypes(secondNode.m_m, secondNode.m_n);

if (firstNodeType == NodeType::InternalValid || firstNodeType == NodeType::Invalid ||
secondNodeType == NodeType::InternalValid || secondNodeType == NodeType::Invalid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void CurvilinearGridOrthogonalization::ProjectHorizontalBoundaryGridNodes()
int nextVertical = 0;
for (UInt m = 0; m < m_grid.m_numM; ++m)
{
const auto nodeType = m_grid.m_gridNodesTypes[m][n];
const auto nodeType = m_grid.m_gridNodesTypes(m, n);
if (nodeType == CurvilinearGrid::NodeType::BottomLeft || nodeType == CurvilinearGrid::NodeType::UpperLeft)
{
startM = m;
Expand Down Expand Up @@ -136,7 +136,7 @@ void CurvilinearGridOrthogonalization::ProjectHorizontalBoundaryGridNodes()
{
continue;
}
if (m_grid.m_gridNodesTypes[mm][n] == CurvilinearGrid::NodeType::Invalid)
if (m_grid.m_gridNodesTypes(mm, n) == CurvilinearGrid::NodeType::Invalid)
{
continue;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ void CurvilinearGridOrthogonalization::ProjectVerticalBoundariesGridNodes()
int nextHorizontal = 0;
for (UInt n = 0; n < m_grid.m_numN; ++n)
{
const auto nodeType = m_grid.m_gridNodesTypes[m][n];
const auto nodeType = m_grid.m_gridNodesTypes(m, n);
if (nodeType == CurvilinearGrid::NodeType::BottomLeft || nodeType == CurvilinearGrid::NodeType::BottomRight)
{
startN = n;
Expand Down Expand Up @@ -215,7 +215,7 @@ void CurvilinearGridOrthogonalization::ProjectVerticalBoundariesGridNodes()
{
continue;
}
if (m_grid.m_gridNodesTypes[m][nn] == CurvilinearGrid::NodeType::Invalid)
if (m_grid.m_gridNodesTypes(m, nn) == CurvilinearGrid::NodeType::Invalid)
{
continue;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ void CurvilinearGridOrthogonalization::Solve()
{
for (auto n = minNInternal; n < maxNInternal; ++n)
{
if (m_grid.m_gridNodesTypes[m][n] != CurvilinearGrid::NodeType::InternalValid)
if (m_grid.m_gridNodesTypes(m, n) != CurvilinearGrid::NodeType::InternalValid)
{
continue;
}
Expand Down Expand Up @@ -390,7 +390,7 @@ void CurvilinearGridOrthogonalization::ComputeCoefficients()
{
for (auto n = m_lowerLeft.m_n + 1; n < m_upperRight.m_n; ++n)
{
if (m_grid.m_gridNodesTypes[m][n] != CurvilinearGrid::NodeType::InternalValid)
if (m_grid.m_gridNodesTypes(m, n) != CurvilinearGrid::NodeType::InternalValid)
{
continue;
}
Expand Down Expand Up @@ -520,19 +520,19 @@ CurvilinearGridOrthogonalization::ComputeInvalidHorizontalBoundaryNodes() const
for (auto n = m_lowerLeft.m_n + 1; n < m_upperRight.m_n; ++n)
{
int step = 0;
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::BottomLeft)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::BottomLeft)
{
step = -1;
}
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::BottomRight)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::BottomRight)
{
step = 1;
}
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::UpperRight)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::UpperRight)
{
step = 1;
}
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::UpperLeft)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::UpperLeft)
{
step = -1;
}
Expand All @@ -544,7 +544,7 @@ CurvilinearGridOrthogonalization::ComputeInvalidHorizontalBoundaryNodes() const
auto lastValidM = m + step;
while (lastValidM > 0 &&
lastValidM < m_grid.m_numM &&
m_grid.m_gridNodesTypes[lastValidM][n] == CurvilinearGrid::NodeType::InternalValid)
m_grid.m_gridNodesTypes(lastValidM, n) == CurvilinearGrid::NodeType::InternalValid)
{
lastValidM += step;
}
Expand All @@ -569,19 +569,19 @@ CurvilinearGridOrthogonalization::ComputeInvalidVerticalBoundaryNodes() const
for (auto n = m_lowerLeft.m_n + 1; n < m_upperRight.m_n; ++n)
{
int step = 0;
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::BottomLeft)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::BottomLeft)
{
step = -1;
}
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::BottomRight)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::BottomRight)
{
step = -1;
}
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::UpperRight)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::UpperRight)
{
step = 1;
}
if (m_grid.m_gridNodesTypes[m][n] == CurvilinearGrid::NodeType::UpperLeft)
if (m_grid.m_gridNodesTypes(m, n) == CurvilinearGrid::NodeType::UpperLeft)
{
step = 1;
}
Expand All @@ -592,7 +592,7 @@ CurvilinearGridOrthogonalization::ComputeInvalidVerticalBoundaryNodes() const
auto lastValidN = n + step;
while (lastValidN > 0 &&
lastValidN < m_grid.m_numN &&
m_grid.m_gridNodesTypes[m][lastValidN] == CurvilinearGrid::NodeType::InternalValid)
m_grid.m_gridNodesTypes(m, lastValidN) == CurvilinearGrid::NodeType::InternalValid)
{
lastValidN += step;
}
Expand Down
Loading

0 comments on commit 998dfd0

Please sign in to comment.