Skip to content

Commit ffb9eed

Browse files
committed
GRIDEDIT-1699 Small refactoring, making the new circumcentre algo the only one available
1 parent 2c06fdd commit ffb9eed

File tree

8 files changed

+61
-37
lines changed

8 files changed

+61
-37
lines changed

libs/MeshKernel/include/MeshKernel/Constants.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,21 @@ namespace meshkernel
8181
// geometric constants
8282
namespace geometric
8383
{
84-
constexpr double earth_radius = 6378137.0; ///< Earth radius(m)
85-
constexpr double inverse_earth_radius = 1.0 / earth_radius; ///< One over constants::geometric::earth_radius(m-1);
86-
constexpr double absLatitudeAtPoles = 0.0001; ///< Pole tolerance in degrees
87-
constexpr double refinementTolerance = 1.0e-2; ///< Relative size of refinement.
88-
constexpr double circumcentreTolerance = 1.0e-3; ///< Tolerance used when computing the circumcentre of an element
89-
constexpr UInt numNodesInQuadrilateral = 4; ///< Number of nodes in a quadrilateral
90-
constexpr UInt numNodesInTriangle = 3; ///< Number of nodes in a triangle
91-
constexpr UInt numNodesInPentagon = 5; ///< Number of nodes in a pentagon
92-
constexpr UInt numNodesInHexagon = 6; ///< Number of nodes in a hexagon
93-
constexpr UInt maximumNumberOfEdgesPerNode = 16; ///< Maximum number of edges per node
94-
constexpr UInt maximumNumberOfEdgesPerFace = 6; ///< Maximum number of edges per face
95-
constexpr UInt maximumNumberOfNodesPerFace = 6; ///< Maximum number of nodes per face
96-
constexpr UInt maximumNumberOfConnectedNodes = maximumNumberOfEdgesPerNode * 4; ///< Maximum number of connected nodes
97-
constexpr double circumCentreWeight = 1.0; ///< Weighting factor for circumcentre calculations
98-
constexpr CircumCentreMethod defaultCircumCentreMethod = CircumCentreMethod::InternalNetlinksEdge; ///< Default circum centre calculation method
84+
constexpr double earth_radius = 6378137.0; ///< Earth radius(m)
85+
constexpr double inverse_earth_radius = 1.0 / earth_radius; ///< One over constants::geometric::earth_radius(m-1);
86+
constexpr double absLatitudeAtPoles = 0.0001; ///< Pole tolerance in degrees
87+
constexpr double refinementTolerance = 1.0e-2; ///< Relative size of refinement.
88+
constexpr double circumcentreTolerance = 1.0e-3; ///< Tolerance used when computing the circumcentre of an element
89+
constexpr UInt numNodesInQuadrilateral = 4; ///< Number of nodes in a quadrilateral
90+
constexpr UInt numNodesInTriangle = 3; ///< Number of nodes in a triangle
91+
constexpr UInt numNodesInPentagon = 5; ///< Number of nodes in a pentagon
92+
constexpr UInt numNodesInHexagon = 6; ///< Number of nodes in a hexagon
93+
constexpr UInt maximumNumberOfEdgesPerNode = 16; ///< Maximum number of edges per node
94+
constexpr UInt maximumNumberOfEdgesPerFace = 6; ///< Maximum number of edges per face
95+
constexpr UInt maximumNumberOfNodesPerFace = 6; ///< Maximum number of nodes per face
96+
constexpr UInt maximumNumberOfConnectedNodes = maximumNumberOfEdgesPerNode * 4; ///< Maximum number of connected nodes
97+
constexpr double circumCentreWeight = 1.0; ///< Weighting factor for circumcentre calculations
98+
constexpr CircumCentreMethod defaultCircumCentreMethod = CircumCentreMethod::AllNetlinksLoop; ///< Default circum centre calculation method
9999

100100
} // namespace geometric
101101

libs/MeshKernel/include/MeshKernel/Mesh.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <memory>
3131

3232
#include "MeshKernel/BoundingBox.hpp"
33+
#include "MeshKernel/Constants.hpp"
34+
#include "MeshKernel/Definitions.hpp"
3335
#include "MeshKernel/Entities.hpp"
3436
#include "MeshKernel/Exceptions.hpp"
3537
#include "MeshKernel/UndoActions/AddEdgeAction.hpp"
@@ -459,6 +461,15 @@ namespace meshkernel
459461
/// @param[in,out] polygonNodesCache The cache array to be filled with the nodes values
460462
void ComputeFaceClosedPolygon(UInt faceIndex, std::vector<Point>& polygonNodesCache) const;
461463

464+
/// @brief Get the circumecentre algorithm
465+
CircumCentreMethod GetCircumcentreMethod() const;
466+
467+
/// @brief Get the circumcentre-masscentre weighting factor.
468+
///
469+
/// This value should be in the range to 0 to 1
470+
/// \f$ c_{
471+
double GetCircumcentreWeight() const;
472+
462473
// nodes
463474
std::vector<std::vector<UInt>> m_nodesEdges; ///< For each node, the indices of connected edges (nod%lin)
464475
std::vector<std::uint8_t> m_nodesNumEdges; ///< For each node, the number of connected edges (nmk)
@@ -498,6 +509,10 @@ namespace meshkernel
498509
std::unordered_map<Location, std::unique_ptr<RTreeBase>> m_RTrees; ///< The RTrees to use
499510
BoundingBox m_boundingBoxCache; ///< Caches the last bounding box used for selecting the locations
500511

512+
// These two circumcentre related members are to be kept.
513+
const CircumCentreMethod m_circumcentreMethod = constants::geometric::defaultCircumCentreMethod; ///< The circum-centre method
514+
const double m_circumcentreWeight = constants::geometric::circumCentreWeight; ///< The circum centre--mass centre weighting factor
515+
501516
/// @brief Set nodes and edges that are not connected to be invalid.
502517
void SetUnConnectedNodesAndEdgesToInvalid(CompoundUndoAction* undoAction);
503518

@@ -579,3 +594,13 @@ inline bool meshkernel::Mesh::AdministrationRequired() const
579594
{
580595
return m_administrationRequired;
581596
}
597+
598+
inline meshkernel::CircumCentreMethod meshkernel::Mesh::GetCircumcentreMethod() const
599+
{
600+
return m_circumcentreMethod;
601+
}
602+
603+
inline double meshkernel::Mesh::GetCircumcentreWeight() const
604+
{
605+
return m_circumcentreWeight;
606+
}

libs/MeshKernel/include/MeshKernel/MeshFaceCenters.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,17 @@
3939
namespace meshkernel::algo
4040
{
4141
/// @brief Compute the circum-center point of each of the faces
42-
std::vector<Point> ComputeFaceCircumcenters(const Mesh& mesh, CircumCentreMethod circumcentreMethod = constants::geometric::defaultCircumCentreMethod,
43-
double circumCentreWeight = constants::geometric::circumCentreWeight);
42+
std::vector<Point> ComputeFaceCircumcenters(const Mesh& mesh);
4443

4544
/// @brief Compute the circum-center point of each of the faces overwriting the values in an array
46-
void ComputeFaceCircumcenters(const Mesh& mesh, std::span<Point> faceCenters,
47-
CircumCentreMethod circumcentreMethod = constants::geometric::defaultCircumCentreMethod,
48-
double circumCentreWeight = constants::geometric::circumCentreWeight);
45+
void ComputeFaceCircumcenters(const Mesh& mesh, std::span<Point> faceCenters);
4946

5047
/// @brief Compute the circumcenter of a polygon
5148
Point ComputeFaceCircumenter(std::vector<Point>& polygon,
5249
const std::vector<UInt>& edgesNumFaces,
5350
const Projection projection,
54-
double circumCentreWeight = constants::geometric::circumCentreWeight,
55-
CircumCentreMethod circumcentreMethod = constants::geometric::defaultCircumCentreMethod);
51+
double circumCentreWeight,
52+
CircumCentreMethod circumcentreMethod);
5653

5754
/// @brief Compute the mass centre element.
5855
Point ComputeMassCentre(const std::vector<Point>& polygon);

libs/MeshKernel/include/MeshKernel/MeshOrthogonality.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <span>
3131
#include <vector>
3232

33-
#include "MeshKernel/Definitions.hpp"
3433
#include "MeshKernel/Mesh2D.hpp"
3534

3635
namespace meshkernel
@@ -40,10 +39,10 @@ namespace meshkernel
4039
{
4140
public:
4241
/// @brief Compute the orthogonality values returning values in a vector
43-
static std::vector<double> Compute(const Mesh2D& mesh, CircumCentreMethod circumcentreMethod = constants::geometric::defaultCircumCentreMethod);
42+
static std::vector<double> Compute(const Mesh2D& mesh);
4443

4544
/// @brief Compute the orthogonality values overwriting the values in an array
46-
static void Compute(const Mesh2D& mesh, std::span<double> orthogonality, CircumCentreMethod circumcentreMethod = constants::geometric::defaultCircumCentreMethod);
45+
static void Compute(const Mesh2D& mesh, std::span<double> orthogonality);
4746

4847
private:
4948
/// @brief Compute the orthogonality value for the edge

libs/MeshKernel/src/MeshFaceCenters.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ meshkernel::Point meshkernel::algo::ComputeFaceCircumenter(std::vector<Point>& p
166166
const double circumCentreWeight,
167167
const CircumCentreMethod circumcentreMethod)
168168
{
169+
// This variable is in the fortran code, but it does not seem to be able to be changed from its default value (dcenterinside)
169170
static constexpr double weightCircumCenter = 1.0; ///< Weight circum center
170171

171172
std::array<Point, constants::geometric::maximumNumberOfNodesPerFace> middlePoints;
@@ -213,15 +214,15 @@ meshkernel::Point meshkernel::algo::ComputeFaceCircumenter(std::vector<Point>& p
213214
return circumCentre;
214215
}
215216

216-
std::vector<meshkernel::Point> meshkernel::algo::ComputeFaceCircumcenters(const Mesh& mesh, const CircumCentreMethod circumcentreMethod, const double circumCentreWeight)
217+
std::vector<meshkernel::Point> meshkernel::algo::ComputeFaceCircumcenters(const Mesh& mesh)
217218
{
218219
std::vector<Point> faceCenters(mesh.GetNumFaces());
219-
ComputeFaceCircumcenters(mesh, faceCenters, circumcentreMethod, circumCentreWeight);
220+
ComputeFaceCircumcenters(mesh, faceCenters);
220221

221222
return faceCenters;
222223
}
223224

224-
void meshkernel::algo::ComputeFaceCircumcenters(const Mesh& mesh, std::span<Point> faceCenters, const CircumCentreMethod circumcentreMethod, const double circumCentreWeight)
225+
void meshkernel::algo::ComputeFaceCircumcenters(const Mesh& mesh, std::span<Point> faceCenters)
225226
{
226227
if (faceCenters.size() != mesh.GetNumFaces())
227228
{
@@ -265,7 +266,7 @@ void meshkernel::algo::ComputeFaceCircumcenters(const Mesh& mesh, std::span<Poin
265266
numEdgeFacesCache.emplace_back(mesh.m_edgesNumFaces[mesh.m_facesEdges[f][n]]);
266267
}
267268

268-
faceCenters[f] = algo::ComputeFaceCircumenter(polygonNodesCache, numEdgeFacesCache, mesh.m_projection, circumCentreWeight, circumcentreMethod);
269+
faceCenters[f] = algo::ComputeFaceCircumenter(polygonNodesCache, numEdgeFacesCache, mesh.m_projection, mesh.GetCircumcentreWeight(), mesh.GetCircumcentreMethod());
269270
}
270271
}
271272
}

libs/MeshKernel/src/MeshOrthogonality.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
#include "MeshKernel/MeshFaceCenters.hpp"
3232
#include "MeshKernel/Operations.hpp"
3333

34-
std::vector<double> meshkernel::MeshOrthogonality::Compute(const Mesh2D& mesh, const CircumCentreMethod circumcentreMethod)
34+
std::vector<double> meshkernel::MeshOrthogonality::Compute(const Mesh2D& mesh)
3535
{
3636
std::vector<double> orthogonality(mesh.GetNumEdges(), constants::missing::doubleValue);
37-
Compute(mesh, orthogonality, circumcentreMethod);
37+
Compute(mesh, orthogonality);
3838

3939
return orthogonality;
4040
}
@@ -77,14 +77,14 @@ double meshkernel::MeshOrthogonality::ComputeValue(const Mesh2D& mesh, const std
7777
return val;
7878
}
7979

80-
void meshkernel::MeshOrthogonality::Compute(const Mesh2D& mesh, std::span<double> orthogonality, const CircumCentreMethod circumcentreMethod)
80+
void meshkernel::MeshOrthogonality::Compute(const Mesh2D& mesh, std::span<double> orthogonality)
8181
{
8282
if (orthogonality.size() != mesh.GetNumEdges())
8383
{
8484
throw ConstraintError("array for orthogonality values is not the correct size");
8585
}
8686

87-
std::vector<Point> faceCircumcentres = algo::ComputeFaceCircumcenters(mesh, circumcentreMethod);
87+
std::vector<Point> faceCircumcentres = algo::ComputeFaceCircumcenters(mesh);
8888

8989
const auto numEdges = mesh.GetNumEdges();
9090

libs/MeshKernel/src/MeshRefinement.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,9 @@ void MeshRefinement::ComputeSplittingNode(const UInt faceId,
699699

700700
splittingNode = algo::ComputeFaceCircumenter(facePolygonWithoutHangingNodes,
701701
localEdgesNumFaces,
702-
m_mesh.m_projection);
702+
m_mesh.m_projection,
703+
m_mesh.GetCircumcentreWeight(),
704+
m_mesh.GetCircumcentreMethod());
703705

704706
if (m_mesh.m_projection == Projection::spherical)
705707
{

libs/MeshKernel/tests/src/Mesh2DTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,9 +1555,9 @@ TEST(Mesh2D, GetOrthogonality_OnTriangularMesh_ShouldGetOrthogonalityValues)
15551555
// Assert
15561556
const double tolerance = 1e-6;
15571557
ASSERT_NEAR(1.0566340037701503e-15, orthogonality[0], tolerance);
1558-
ASSERT_NEAR(0.052159566591519289, orthogonality[10], tolerance); // 0.0697870665979613
1558+
ASSERT_NEAR(0.052159566591519289, orthogonality[10], tolerance);
15591559
ASSERT_NEAR(1.0342915752434056e-15, orthogonality[20], tolerance);
1560-
ASSERT_NEAR(0.045878303256790140, orthogonality[30], tolerance); //0.20448535986258717
1560+
ASSERT_NEAR(0.045878303256790140, orthogonality[30], tolerance);
15611561
}
15621562

15631563
TEST(Mesh2D, MeshToCurvilinear_OnRealMesh_ShouldConvertCurvilinearPart)
@@ -1722,7 +1722,7 @@ TEST(Mesh2D, CircumcentreTest)
17221722
// This is required
17231723
mesh->ComputeFaceAreaAndMassCenters(true);
17241724

1725-
std::vector<meshkernel::Point> circumcentres(meshkernel::algo::ComputeFaceCircumcenters(*mesh, meshkernel::CircumCentreMethod::AllNetlinksLoop));
1725+
std::vector<meshkernel::Point> circumcentres(meshkernel::algo::ComputeFaceCircumcenters(*mesh));
17261726

17271727
std::vector<double> expectedCentresX{206.660451817758, 185.888995485133, 276.045461920919, 262.103773081694,
17281728
351.512547260357, 354.488336820198, 96.9057821605506, 74.139650060642,

0 commit comments

Comments
 (0)