Skip to content

Commit

Permalink
GRIDEDIT-1516 Fixed bug in node classification and updated unit test
Browse files Browse the repository at this point in the history
Also added file missing in previous Jira item
This file was not required for normal execution of mesh kernel only help
in debugging
  • Loading branch information
BillSenior committed Nov 11, 2024
1 parent 0a58be0 commit 8853b6a
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 46 deletions.
1 change: 1 addition & 0 deletions libs/MeshKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ target_sources(
PRIVATE
${SRC_LIST}
${UNDO_SRC_LIST}
${UTILITIES_SRC_LIST}
${AVERAGING_STRATEGIES_SRC_LIST}
${CURVILINEAR_GRID_SRC_LIST}
${CURVILINEAR_GRID_UNDO_ACTION_SRC_LIST}
Expand Down
9 changes: 7 additions & 2 deletions libs/MeshKernel/src/Mesh2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ void Mesh2D::ClassifyNodes()
const auto firstNode = m_edges[e].first;
const auto secondNode = m_edges[e].second;

if (firstNode == constants::missing::uintValue || secondNode == constants::missing::uintValue)
if (firstNode == constants::missing::uintValue || secondNode == constants::missing::uintValue) [[unlikely]]
{
continue;
}
Expand All @@ -696,6 +696,11 @@ void Mesh2D::ClassifyNodes()

for (UInt n = 0; n < GetNumNodes(); n++)
{
if (!Node(n).IsValid()) [[unlikely]]
{
continue;
}

if (m_nodesTypes[n] == 1 || m_nodesTypes[n] == 2)
{
if (m_nodesNumEdges[n] == 2)
Expand All @@ -714,7 +719,7 @@ void Mesh2D::ClassifyNodes()
{
continue;
}
if (firstNode == 0)
if (firstNode == constants::missing::uintValue)
{
firstNode = OtherNodeOfEdge(m_edges[edgeIndex], n);
}
Expand Down
92 changes: 92 additions & 0 deletions libs/MeshKernel/src/Utilities/Utilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: delft3d.support@deltares.nl
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#include "MeshKernel/Utilities/Utilities.hpp"
#include "MeshKernel/Exceptions.hpp"

void meshkernel::Print(const std::vector<Point>& nodes, const std::vector<Edge>& edges, std::ostream& out)
{
out << "nullId = " << constants::missing::uintValue << ";" << std::endl;
out << "nullValue = " << constants::missing::doubleValue << ";" << std::endl;
out << "nodex = zeros ( " << nodes.size() << ", 1);" << std::endl;
out << "nodey = zeros ( " << nodes.size() << ", 1);" << std::endl;
out << "edges = zeros ( " << edges.size() << ", 2);" << std::endl;

for (UInt i = 0; i < nodes.size(); ++i)
{
out << "nodex (" << i + 1 << " ) = " << nodes[i].x << ";" << std::endl;
}

for (UInt i = 0; i < nodes.size(); ++i)
{
out << "nodey (" << i + 1 << " ) = " << nodes[i].y << ";" << std::endl;
}

out << "edges = zeros ( " << edges.size() << ", 2 );" << std::endl;

for (UInt i = 0; i < edges.size(); ++i)
{
out << "edges ( " << i + 1 << ", 1 ) = " << edges[i].first + 1 << ";" << std::endl;
out << "edges ( " << i + 1 << ", 2 ) = " << edges[i].second + 1 << ";" << std::endl;
}
}

void meshkernel::Print(const std::vector<double>& xNodes,
const std::vector<double>& yNodes,
const std::vector<int>& edges,
std::ostream& out)
{
// xNodes and yNodes should be the same size
if (xNodes.size() != yNodes.size())
{
throw ConstraintError("x-node and y-nodes are not the same size, {} /= {}", xNodes.size(), yNodes.size());
}

out << "nullId = " << constants::missing::uintValue << ";" << std::endl;
out << "nullValue = " << constants::missing::doubleValue << ";" << std::endl;
out << "nodex = zeros ( " << xNodes.size() << ", 1);" << std::endl;
out << "nodey = zeros ( " << xNodes.size() << ", 1);" << std::endl;
out << "edges = zeros ( " << edges.size() << ", 2);" << std::endl;

for (UInt i = 0; i < xNodes.size(); ++i)
{
out << "nodex (" << i + 1 << " ) = " << xNodes[i] << ";" << std::endl;
}

for (UInt i = 0; i < xNodes.size(); ++i)
{
out << "nodey (" << i + 1 << " ) = " << yNodes[i] << ";" << std::endl;
}

out << "edges = zeros ( " << edges.size() / 2 << ", 2 );" << std::endl;

for (UInt i = 0; i < edges.size() / 2; ++i)
{
out << "edges ( " << i + 1 << ", 1 ) = " << edges[2 * i] + 1 << ";" << std::endl;
out << "edges ( " << i + 1 << ", 2 ) = " << edges[2 * i + 1] + 1 << ";" << std::endl;
}
}
89 changes: 45 additions & 44 deletions libs/MeshKernel/tests/src/OrthogonalizationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <MeshKernel/Polygons.hpp>
#include <MeshKernel/Smoother.hpp>
#include <MeshKernel/UndoActions/UndoAction.hpp>
#include <MeshKernel/Utilities/Utilities.hpp>
#include <TestUtils/Definitions.hpp>
#include <TestUtils/MakeMeshes.hpp>

Expand Down Expand Up @@ -797,54 +798,54 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationWithGapsInNodeAndEdgeLists)
projectToLandBoundaryOption,
orthogonalizationParameters);

const std::vector<double> expectedX{28.197593689053271,
45.122094904304319,
67.434041291301682,
91.65019268878028,
121.18012351239659,
const std::vector<double> expectedX{25.0800705723722,
42.317662650388,
65.4076069697485,
90.1058019292434,
120.558686253752,
150.0,
121.65514995517655,
96.144810647136211,
73.392601318383058,
49.383970314068847,
27.985698958218652,
9.2519807557372626,
-13.113266174727251,
8.0469903108904433,
18.108865376000267,
30.057404995092867,
81.572189207388078,
100.72370484044434,
44.08035834002014,
62.494201377406981,
56.221541072263449,
80.952825997664704,
39.468493116531533,
121.059743084289,
95.1726727500558,
72.1931604613651,
47.4190144307411,
25.2372847856225,
5.68099647107239,
-20,
4.58504074822491,
14.9038474210351,
27.1345108996488,
80.0992228898113,
99.6419675416531,
41.6528740558509,
60.6207362548768,
54.0359431801395,
79.4201977834984,
36.6509101374463,
-999.0};

const std::vector<double> expectedY{5.6395187378106542,
9.0244189808608635,
13.486808258260337,
18.330038537756057,
32.708074107437959,
const std::vector<double> expectedY{5.01601411447445,
8.4635325300776,
13.0815213939497,
18.0211603858487,
32.3352117522512,
50.0,
59.448283348274487,
67.951729784287934,
74.238600624497238,
62.866091201401034,
52.730067927577252,
43.856201410612385,
33.262137075129196,
1.6093980621780888,
22.269932674539941,
35.917300713638298,
51.865232389386854,
45.127820397816109,
43.164232704286427,
48.110596487644287,
28.375434217690007,
34.073083926222459,
23.663968978263402,
59.6467523052371,
68.2757757499814,
73.6704444290677,
61.9353226250879,
51.4281875300317,
42.164682538929,
30.0,
0.917008149644981,
21.0550841422499,
34.910733978114,
51.5236060545154,
44.9951979924611,
42.223424366405,
47.4725501580611,
27.7287089020759,
33.7364202545338,
22.785807215113,
-999.0};

const std::vector<meshkernel::UInt> edgeFirst{13, 14, 12, 13, 0, 22, 0, 0, 20, 18, 22, 15,
Expand Down

0 comments on commit 8853b6a

Please sign in to comment.