Skip to content

Commit

Permalink
GRIDEDIT-1611 changed UInt to uint8_t in size arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior committed Feb 4, 2025
1 parent 65e8339 commit 636cf91
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 33 deletions.
16 changes: 11 additions & 5 deletions libs/MeshKernel/include/MeshKernel/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//------------------------------------------------------------------------------

#pragma once
#include <cstdint>
#include <memory>

#include "MeshKernel/BoundingBox.hpp"
Expand Down Expand Up @@ -160,15 +161,20 @@ namespace meshkernel
/// @return The number of valid edges
[[nodiscard]] UInt GetNumValidEdges() const;

/// @brief Get the number of edges for a node
/// @param[in] nodeIndex The node index
/// @return The number of valid nodes
[[nodiscard]] UInt GetNumNodesEdges(UInt nodeIndex) const { return m_nodesNumEdges[nodeIndex]; }

/// @brief Get the number of edges for a face
/// @param[in] faceIndex The face index
/// @return The number of valid faces
[[nodiscard]] auto GetNumFaceEdges(UInt faceIndex) const { return m_numFacesNodes[faceIndex]; }
[[nodiscard]] UInt GetNumFaceEdges(UInt faceIndex) const { return m_numFacesNodes[faceIndex]; }

/// @brief Get the number of faces an edges shares
/// @param[in] edgeIndex The edge index
/// @return The number of faces an edges shares
[[nodiscard]] auto GetNumEdgesFaces(UInt edgeIndex) const { return m_edgesNumFaces[edgeIndex]; }
[[nodiscard]] UInt GetNumEdgesFaces(UInt edgeIndex) const { return m_edgesNumFaces[edgeIndex]; }

/// @brief Get the local edge number for an element edge.
// TODO add unit test and with all failing cases
Expand Down Expand Up @@ -468,18 +474,18 @@ namespace meshkernel

// nodes
std::vector<std::vector<UInt>> m_nodesEdges; ///< For each node, the indices of connected edges (nod%lin)
std::vector<UInt> m_nodesNumEdges; ///< For each node, the number of connected edges (nmk)
std::vector<std::uint8_t> m_nodesNumEdges; ///< For each node, the number of connected edges (nmk)
std::vector<int> m_nodesTypes; ///< The node types (nb)

// edges
std::vector<std::array<UInt, 2>> m_edgesFaces; ///< For each edge, the shared face index (lne)
std::vector<UInt> m_edgesNumFaces; ///< For each edge, the number of shared faces(lnn)
std::vector<std::uint8_t> m_edgesNumFaces; ///< For each edge, the number of shared faces(lnn)
std::vector<double> m_edgeLengths; ///< The edge lengths
std::vector<Point> m_edgesCenters; ///< The edges centers

// faces
std::vector<std::vector<UInt>> m_facesNodes; ///< The nodes composing the faces, in ccw order (netcell%Nod)
std::vector<UInt> m_numFacesNodes; ///< The number of nodes composing the face (netcell%N)
std::vector<std::uint8_t> m_numFacesNodes; ///< The number of nodes composing the face (netcell%N)
std::vector<std::vector<UInt>> m_facesEdges; ///< The edge indices composing the face (netcell%lin)
std::vector<Point> m_facesCircumcenters; ///< The face circumcenters the face circumcenter (xz, yz)
std::vector<Point> m_facesMassCenters; ///< The faces centers of mass (xzw, yzw)
Expand Down
6 changes: 3 additions & 3 deletions libs/MeshKernel/include/MeshKernel/Mesh2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace meshkernel
Mesh2D(const std::vector<Edge>& edges,
const std::vector<Point>& nodes,
const std::vector<std::vector<UInt>>& faceNodes,
const std::vector<UInt>& numFaceNodes,
const std::vector<std::uint8_t>& numFaceNodes,
Projection projection);

/// @brief Create triangular grid from nodes (triangulatesamplestonetwork)
Expand All @@ -132,7 +132,7 @@ namespace meshkernel
/// @param[in] faceNodes The input face nodes
/// @param[in] numFaceNodes For each face, the number of nodes
void FindFacesGivenFaceNodesMapping(const std::vector<std::vector<UInt>>& faceNodes,
const std::vector<UInt>& numFaceNodes);
const std::vector<std::uint8_t>& numFaceNodes);

/// @brief Offset the x coordinates if m_projection is spherical
/// @param[in] minx
Expand Down Expand Up @@ -499,7 +499,7 @@ namespace meshkernel
/// @param[in] faceNodes The input face nodes
/// @param[in] numFaceNodes For each face, the number of nodes
void DoAdministrationGivenFaceNodesMapping(const std::vector<std::vector<UInt>>& faceNodes,
const std::vector<UInt>& numFaceNodes);
const std::vector<std::uint8_t>& numFaceNodes);

/// @brief Perform complete administration
/// @param[in,out] undoAction if not null then collect any undo actions generated during the administration.
Expand Down
8 changes: 4 additions & 4 deletions libs/MeshKernel/src/CasulliRefinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void meshkernel::CasulliRefinement::InitialiseFaceNodes(const Mesh2D& mesh, std:
nodeMask[i] = NodeMask::Unassigned;
}

if (elementCount < mesh.m_nodesNumEdges[i] - 1 && nodeMask[i] == NodeMask::BoundaryNode)
if (elementCount < mesh.m_nodesNumEdges[i] - 1u && nodeMask[i] == NodeMask::BoundaryNode)
{
nodeMask[i] = NodeMask::CornerNode;
}
Expand Down Expand Up @@ -359,14 +359,14 @@ void meshkernel::CasulliRefinement::ConnectFaceNodes(Mesh2D& mesh, const UInt cu
for (UInt j = 0; j < mesh.m_numFacesNodes[currentFace]; ++j)
{
const UInt previousIndex = (j == 0 ? (mesh.m_numFacesNodes[currentFace] - 1) : (j - 1));
const UInt nextIndex = (j == mesh.m_numFacesNodes[currentFace] - 1 ? 0 : (j + 1));
const UInt nextIndex = (j == mesh.m_numFacesNodes[currentFace] - 1u ? 0 : (j + 1));
UInt nextNextIndex;

if (j == mesh.m_numFacesNodes[currentFace] - 2)
if (j == mesh.m_numFacesNodes[currentFace] - 2u)
{
nextNextIndex = 0;
}
else if (j == mesh.m_numFacesNodes[currentFace] - 1)
else if (j == mesh.m_numFacesNodes[currentFace] - 1u)
{
nextNextIndex = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/MeshKernel/src/FlipEdges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void FlipEdges::DeleteEdgeFromNode(UInt edge, UInt firstNode) const
}

UInt count = 0;
for (UInt i = 0; i < m_mesh.m_nodesNumEdges[firstNode] + 1; i++)
for (UInt i = 0; i < m_mesh.m_nodesNumEdges[firstNode] + 1u; i++)
{
if (i + 1 <= kk || i > kk)
{
Expand Down
14 changes: 7 additions & 7 deletions libs/MeshKernel/src/Mesh2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Mesh2D::Mesh2D(const std::vector<Edge>& edges,
Mesh2D::Mesh2D(const std::vector<Edge>& edges,
const std::vector<Point>& nodes,
const std::vector<std::vector<UInt>>& faceNodes,
const std::vector<UInt>& numFaceNodes,
const std::vector<std::uint8_t>& numFaceNodes,
Projection projection)
: Mesh(edges, nodes, projection)
{
Expand Down Expand Up @@ -176,7 +176,7 @@ void Mesh2D::DoAdministration(CompoundUndoAction* undoAction)
}

void Mesh2D::DoAdministrationGivenFaceNodesMapping(const std::vector<std::vector<UInt>>& faceNodes,
const std::vector<UInt>& numFaceNodes)
const std::vector<std::uint8_t>& numFaceNodes)
{
AdministrateNodesEdges();

Expand Down Expand Up @@ -550,7 +550,7 @@ void Mesh2D::FindFaces()
}

void Mesh2D::FindFacesGivenFaceNodesMapping(const std::vector<std::vector<UInt>>& faceNodes,
const std::vector<UInt>& numFaceNodes)
const std::vector<std::uint8_t>& numFaceNodes)
{
m_facesNodes = faceNodes;
m_numFacesNodes = numFaceNodes;
Expand Down Expand Up @@ -1420,7 +1420,7 @@ std::unique_ptr<meshkernel::UndoAction> Mesh2D::TriangulateFaces()

for (UInt i = 0; i < GetNumFaces(); ++i)
{
const auto NumEdges = GetNumFaceEdges(i);
const UInt NumEdges = GetNumFaceEdges(i);

if (NumEdges < 4)
{
Expand Down Expand Up @@ -1805,7 +1805,7 @@ void Mesh2D::DeletedMeshNodesAndEdges(const std::function<bool(UInt)>& excludedF
std::vector<bool>& deleteNode,
CompoundUndoAction& deleteMeshAction)
{
std::vector<UInt> nodeEdgeCount(m_nodesNumEdges);
std::vector<std::uint8_t> nodeEdgeCount(m_nodesNumEdges);

for (UInt e = 0; e < GetNumEdges(); ++e)
{
Expand Down Expand Up @@ -2521,8 +2521,8 @@ void Mesh2D::FindFacesConnectedToNode(UInt nodeIndex, std::vector<UInt>& sharedF
}

// find the face shared by the two edges
const auto firstFace = std::max(std::min(m_edgesNumFaces[firstEdge], 2U), 1U) - 1U;
const auto secondFace = std::max(std::min(m_edgesNumFaces[secondEdge], static_cast<UInt>(2)), static_cast<UInt>(1)) - 1;
const auto firstFace = std::max(std::min<UInt>(m_edgesNumFaces[firstEdge], 2U), 1U) - 1U;
const auto secondFace = std::max(std::min<UInt>(m_edgesNumFaces[secondEdge], 2U), 1U) - 1U;

if (m_edgesFaces[firstEdge][0] != newFaceIndex &&
(m_edgesFaces[firstEdge][0] == m_edgesFaces[secondEdge][0] ||
Expand Down
12 changes: 6 additions & 6 deletions libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ std::unique_ptr<meshkernel::UndoAction> OrthogonalizationAndSmoothing::Initializ
m_localCoordinatesIndices[0] = 1;
for (UInt n = 0; n < m_mesh.GetNumNodes(); ++n)
{
m_localCoordinatesIndices[n + 1] = m_localCoordinatesIndices[n] + std::max(m_mesh.m_nodesNumEdges[n] + 1, m_smoother->GetNumConnectedNodes(n));
m_localCoordinatesIndices[n + 1] = m_localCoordinatesIndices[n] + std::max(m_mesh.GetNumNodesEdges(n) + 1u, m_smoother->GetNumConnectedNodes(n));
}

m_localCoordinates.resize(m_localCoordinatesIndices.back() - 1, {constants::missing::doubleValue, constants::missing::doubleValue});
Expand Down Expand Up @@ -169,7 +169,7 @@ void OrthogonalizationAndSmoothing::AllocateLinearSystem()
for (UInt n = 0; n < m_mesh.GetNumNodes(); n++)
{
m_compressedEndNodeIndex[n] = nodeCacheSize;
nodeCacheSize += std::max(m_mesh.m_nodesNumEdges[n] + 1, m_smoother->GetNumConnectedNodes(n));
nodeCacheSize += std::max(m_mesh.GetNumNodesEdges(n) + 1, m_smoother->GetNumConnectedNodes(n));
m_compressedStartNodeIndex[n] = nodeCacheSize;
}

Expand All @@ -194,7 +194,7 @@ void OrthogonalizationAndSmoothing::ComputeLinearSystemTerms()
#pragma omp parallel for
for (int n = 0; n < static_cast<int>(m_mesh.GetNumNodes()); n++)
{
if ((m_mesh.m_nodesTypes[n] != 1 && m_mesh.m_nodesTypes[n] != 2) || m_mesh.m_nodesNumEdges[n] < 2)
if ((m_mesh.m_nodesTypes[n] != 1 && m_mesh.m_nodesTypes[n] != 2) || m_mesh.GetNumNodesEdges(n) < 2)
{
continue;
}
Expand All @@ -218,7 +218,7 @@ void OrthogonalizationAndSmoothing::ComputeLinearSystemTerms()
}

// Orthogonalizer
if (nn < static_cast<int>(m_mesh.m_nodesNumEdges[n]) + 1)
if (nn < static_cast<int>(m_mesh.GetNumNodesEdges(n)) + 1)
{
wwx += atpfLoc * m_orthogonalizer->GetWeight(n, nn - 1);
wwy += atpfLoc * m_orthogonalizer->GetWeight(n, nn - 1);
Expand Down Expand Up @@ -267,7 +267,7 @@ void OrthogonalizationAndSmoothing::FindNeighbouringBoundaryNodes(const UInt nod
UInt& rightNode) const
{
UInt numNodes = 0;
const auto numEdges = m_mesh.m_nodesNumEdges[nearestPointIndex];
const auto numEdges = m_mesh.GetNumNodesEdges(nearestPointIndex);

leftNode = constants::missing::uintValue;
rightNode = constants::missing::uintValue;
Expand Down Expand Up @@ -310,7 +310,7 @@ void OrthogonalizationAndSmoothing::SnapMeshToOriginalMeshBoundary()
for (UInt n = 0; n < m_mesh.GetNumNodes(); n++)
{
const auto nearestPointIndex = nearestPoints[n];
if (m_mesh.m_nodesTypes[n] == 2 && m_mesh.m_nodesNumEdges[n] > 0 && m_mesh.m_nodesNumEdges[nearestPointIndex] > 0)
if (m_mesh.m_nodesTypes[n] == 2 && m_mesh.GetNumNodesEdges(n) > 0 && m_mesh.GetNumNodesEdges(nearestPointIndex) > 0)
{
Point firstPoint = m_mesh.Node(n);
if (!firstPoint.IsValid())
Expand Down
14 changes: 14 additions & 0 deletions libs/MeshKernel/tests/src/Mesh2DTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,3 +1533,17 @@ TEST(Mesh2D, Mesh2DComputeAspectRatio)
EXPECT_NEAR(aspectRatios[i], expectedAspectRatios[i], tolerance);
}
}


TEST(Mesh2D, WTF)
{
// Prepare
[[maybe_unused]] auto mesh = MakeRectangularMeshForTesting(4000,
4000,
10.0,
10.0,
meshkernel::Projection::cartesian);

[[maybe_unused]] int dummy;
std::cin >> dummy;
}
9 changes: 5 additions & 4 deletions libs/MeshKernelApi/src/MeshKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ namespace meshkernelapi

const auto face_nodes = meshkernel::ConvertToFaceNodesVector(mesh2d.num_faces, mesh2d.face_nodes, mesh2d.nodes_per_face);

std::vector<meshkernel::UInt> num_face_nodes;
std::vector<std::uint8_t> num_face_nodes;
num_face_nodes.reserve(mesh2d.num_faces);
for (auto n = 0; n < mesh2d.num_faces; n++)
{
num_face_nodes.emplace_back(static_cast<meshkernel::UInt>(mesh2d.nodes_per_face[n]));
num_face_nodes.emplace_back(static_cast<std::uint8_t>(mesh2d.nodes_per_face[n]));
}

// Do not change the pointer, just the object it is pointing to
Expand Down Expand Up @@ -668,11 +668,12 @@ namespace meshkernelapi
{
const auto face_nodes = meshkernel::ConvertToFaceNodesVector(mesh2d.num_faces, mesh2d.face_nodes, mesh2d.nodes_per_face);

std::vector<meshkernel::UInt> num_face_nodes;
std::vector<std::uint8_t> num_face_nodes;
num_face_nodes.reserve(mesh2d.num_faces);

for (auto n = 0; n < mesh2d.num_faces; n++)
{
num_face_nodes.emplace_back(static_cast<meshkernel::UInt>(mesh2d.nodes_per_face[n]));
num_face_nodes.emplace_back(static_cast<std::uint8_t>(mesh2d.nodes_per_face[n]));
}

undoAction = meshKernelState[meshKernelId].m_mesh2d->Join(meshkernel::Mesh2D(edges2d, nodes2d, face_nodes, num_face_nodes,
Expand Down
3 changes: 2 additions & 1 deletion tools/test_utils/include/TestUtils/MakeMeshes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//------------------------------------------------------------------------------

#pragma once
#include <cstdint>
#include <filesystem>
#include <memory>

Expand Down Expand Up @@ -134,5 +135,5 @@ MakeMeshWithFaceNodesForApiTesting();
std::tuple<std::vector<meshkernel::Point>,
std::vector<meshkernel::Edge>,
std::vector<std::vector<meshkernel::UInt>>,
std::vector<meshkernel::UInt>>
std::vector<std::uint8_t>>
MakeMeshWithFaceNodes();
4 changes: 2 additions & 2 deletions tools/test_utils/src/MakeMeshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ MakeMeshWithFaceNodesForApiTesting()
std::tuple<std::vector<meshkernel::Point>,
std::vector<meshkernel::Edge>,
std::vector<std::vector<meshkernel::UInt>>,
std::vector<meshkernel::UInt>>
std::vector<std::uint8_t>>
MakeMeshWithFaceNodes()
{

Expand Down Expand Up @@ -871,7 +871,7 @@ MakeMeshWithFaceNodes()
{9, 10, 14, 13},
{10, 11, 15, 14}};

std::vector<meshkernel::UInt> num_face_nodes{4, 4, 4, 4, 4, 4, 4, 4, 4};
std::vector<std::uint8_t> num_face_nodes{4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u, 4u};

return {nodes, edges, faceNodes, num_face_nodes};
}

0 comments on commit 636cf91

Please sign in to comment.