Skip to content

Commit

Permalink
GRIDEDIT-953 Removed most goto's and some refactoring and tidying up
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior committed Jun 12, 2024
1 parent 958c9c4 commit fcb2c0b
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ namespace meshkernel
/// @brief Copy constructor taking only a curvilinear grid
CurvilinearGrid(const CurvilinearGrid& grid);

/// @brief Move constructor taking only a curvilinear grid
CurvilinearGrid(CurvilinearGrid&& grid);

/// @brief Constructor taking only a projection
explicit CurvilinearGrid(Projection projection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ namespace meshkernel
const CurvilinearParameters& curvilinearParameters,
CurvilinearGrid& grid) const;

// CurvilinearGrid Compute(const Splines& splines,
// const CurvilinearParameters& curvilinearParameters) const;

private:
/// @brief Maximum number of spline points allowed when doubling of the spline points.
static const UInt MaximumNumberOfSplinePoints = 10; // TODO make higher for production code

/// @brief The maximum number of
static const UInt MaximumCumulativeUnlabeledSplineCount = 1000;

//
#undef USE_EIGEN

Expand Down Expand Up @@ -77,10 +86,12 @@ namespace meshkernel

UInt longestSplineLength(const Splines& splines) const;

void sectr(Splines& splines,
EigenMatrix<double>& splineIntersections,
AnotherMatrix& mn12,
UInt& numMSplines) const;
/// @brief Double the number of spline support points for all splines.
void DoubleSplinePoints(Splines& splines) const;

void ComputeSplineIntersections(Splines& splines,
EigenMatrix<double>& splineIntersections,
UInt& numMSplines) const;

void splrgf(Splines& splines,
const EigenMatrix<double>& splineIntersections,
Expand All @@ -90,11 +101,11 @@ namespace meshkernel
const UInt mFac,
const UInt nFac) const;

void makespl(const Splines& splines,
const UInt whichSpline,
const UInt mFac,
std::vector<double>& intersectionPoints,
std::vector<Point>& gridPoints) const;
void GenerateGridPoints(const Splines& splines,
const UInt whichSpline,
const UInt mFac,
std::vector<double>& intersectionPoints,
std::vector<Point>& gridPoints) const;

void makessq(const std::vector<double>& fixedPoints,
const UInt mFac,
Expand All @@ -110,32 +121,62 @@ namespace meshkernel
double& tValue,
double& sValue) const;

bool checkSplines(const Splines& splines) const;
bool CheckSplines(const Splines& splines) const;

void OrderSplines(Splines& splines,
const UInt numMSplines,
EigenMatrix<double>& splineIntersections) const;

bool SortSplines(Splines& splines,
const UInt outerStartIndex,
const UInt outerEndIndex,
const UInt innerStartIndex,
const UInt innerEndIndex,
EigenMatrix<double>& splineIntersections,
bool& jaChange) const;

Point GetXy(const Splines& splines,
const UInt whichSpline,
const std::vector<double>& intersectionPoints,
const double ssq) const;

// great name
std::vector<double> paktij(const EigenMatrix<double>& splineIntersections,
const UInt whichRow) const;
// great name (paktij)
std::vector<double> CompressRow(const EigenMatrix<double>& splineIntersections,
const UInt whichRow) const;

void determineIntersection(Splines& splines,
const UInt i,
const UInt j,
const UInt splineI,
const UInt splineJ,
UInt& numberTimesCrossing,
double& crossProductOfIntersection,
double& firstNormalisedIntersectionLength,
double& secondNormalisedIntersectionLength) const;

void assignBoundaryPoint (const UInt loopIndex,
const UInt boundaryIndex,
const UInt mnFac,
std::vector<Point>& startBoundaryPoints,
std::vector<Point>& endBoundaryPoints,
const Point gridNode) const;
bool ComputeInteractions(Splines& splines,
std::vector<int>& splineType,
EigenMatrix<double>& splineIntersections) const;

/// @brief One or more splines remain unlabeled.
/// @return true if one or more splines is unlabeled, false if all splines have been labeled.
bool SplinesRemainUnlabeled(const std::vector<int>& splineType, UInt& unlabledSplineCount) const;

void SortInteractionsOnSplineType(Splines& splines,
std::vector<int>& splineType,
EigenMatrix<double>& splineIntersections) const;

UInt GetNumberOfSplinesInDirectionM(const std::vector<int>& splineType) const;

void ComputeSplineInteractions(const Splines& splines,
const UInt numMSplines,
const EigenMatrix<double>& splineIntersections,
AnotherMatrix& splineInteraction) const;

void assignBoundaryPoint(const UInt loopIndex,
const UInt boundaryIndex,
const UInt mnFac,
std::vector<Point>& startBoundaryPoints,
std::vector<Point>& endBoundaryPoints,
const Point gridNode) const;
};

} // namespace meshkernel
20 changes: 15 additions & 5 deletions libs/MeshKernel/include/MeshKernel/Splines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ namespace meshkernel
/// @param[in] splines The spline corner points
void AddSpline(const std::vector<Point>& splines);

/// @brief Replaces an existing spline
/// @param[in] splineIndex The index of the spline to be replaced
/// @param[in] splinePoints The spline points
void Replace(const UInt splineIndex, const std::vector<Point>& splinePoints);

/// @brief Swap all the data for two splines.
///
/// On exit the contents of the two splines will be swapped
Expand Down Expand Up @@ -158,6 +163,9 @@ namespace meshkernel
/// @return the size of the desired spline
UInt Size(const UInt whichSpline) const;

/// @brief Get the spline with the largest number of spline points.
UInt MaxSize() const;

std::vector<std::vector<Point>> m_splineNodes; ///< The spline corner points
std::vector<std::vector<Point>> m_splineDerivatives; ///< The spline derivatives at the corner points
std::vector<double> m_splinesLength; ///< The length of each spline
Expand All @@ -182,6 +190,9 @@ namespace meshkernel

/// @brief Allocate spline properties vectors
void AllocateSplinesProperties();

/// @brief Compute the second order derivative of the spline.
static std::vector<Point> ComputeSplineDerivative(const std::vector<Point>& splinesNodes);
};

/// @brief This structure is used to create a function for converting an adimensional distance on a spline to a dimensional one
Expand Down Expand Up @@ -211,11 +222,10 @@ namespace meshkernel
bool isSpacingCurvatureAdapted,
double h,
double distance) : m_spline(splines),
m_splineIndex(splineIndex),
m_isSpacingCurvatureAdapted(isSpacingCurvatureAdapted),
m_h(h),
m_DimensionalDistance(distance){}

m_splineIndex(splineIndex),
m_isSpacingCurvatureAdapted(isSpacingCurvatureAdapted),
m_h(h),
m_DimensionalDistance(distance) {}

/// @brief Set dimensional distance
/// @param[in] distance distance
Expand Down
9 changes: 9 additions & 0 deletions libs/MeshKernel/src/CurvilinearGrid/CurvilinearGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
//
//------------------------------------------------------------------------------

#include <utility>

#include "MeshKernel/CurvilinearGrid/CurvilinearGrid.hpp"
#include "MeshKernel/CurvilinearGrid/CurvilinearGridLine.hpp"
#include "MeshKernel/CurvilinearGrid/UndoActions/ResetCurvilinearNodeAction.hpp"
Expand All @@ -48,6 +50,13 @@ CurvilinearGrid::CurvilinearGrid(const CurvilinearGrid& grid) : m_projection(Pro
m_RTrees.emplace(Location::Faces, RTreeFactory::Create(m_projection));
}

CurvilinearGrid::CurvilinearGrid(CurvilinearGrid&& grid) : m_projection(Projection::cartesian),
m_gridNodes(std::move(grid.m_gridNodes)),
m_gridFacesMask(std::move(grid.m_gridFacesMask)),
m_gridNodesTypes(std::move(grid.m_gridNodesTypes)),
m_gridIndices(std::move(grid.m_gridIndices)),
m_RTrees(std::move(grid.m_RTrees)) {}

CurvilinearGrid::CurvilinearGrid(Projection projection) : m_projection(projection)
{
m_RTrees.emplace(Location::Nodes, RTreeFactory::Create(m_projection));
Expand Down
Loading

0 comments on commit fcb2c0b

Please sign in to comment.