Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRIDEDIT-1502 Reduce cyclomatic complexity #380

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6efca9b
GRIDEDIT-1502 Refactored several Casulli de-refinement functions, red…
BillSenior Oct 24, 2024
f0b9a7a
GRIDEDIT-1502 Fixed doxygen warning
BillSenior Oct 24, 2024
a0d4df5
GRIDEDIT-1502 Refactored several Casulli refinement functions, reduci…
BillSenior Oct 24, 2024
7c3cc7b
GRIDEDIT-1502 Refactoring several function in CurvilinearGrid and Cur…
BillSenior Oct 28, 2024
e1b1438
GRIDEDIT-1502 Refactored several CLG from splines functions, reducing…
BillSenior Oct 28, 2024
d03ca48
GRIDEDIT-1502 Refactored several CLG from splines transfinite functio…
BillSenior Oct 28, 2024
46c4071
GRIDEDIT-1502 Refactored several Mesh2D functions, reducing cyclomati…
BillSenior Oct 28, 2024
942e59d
GRIDEDIT-1502 Refactored several MeshRefinement functions, reducing c…
BillSenior Oct 28, 2024
1ef4ddc
GRIDEDIT-1502 Refactored several Polygon functions, reducing cyclomat…
BillSenior Oct 29, 2024
dd9935d
GRIDEDIT-1502 Removed several sonac cloud warnings
BillSenior Oct 29, 2024
6599067
GRIDEDIT-1481 Correct several sonarcloud warnings
BillSenior Oct 29, 2024
331a866
GRIDEDIT-1481 Removed some commented out code
BillSenior Oct 29, 2024
6506ab5
GRIDEDIT-1481 Added explicit to constructors needing it, according to…
BillSenior Oct 29, 2024
3a7946b
GRIDEDIT-1502 Refactored function reducing cyclomatic complexity
BillSenior Oct 29, 2024
6ca4cea
GRIDEDIT-1502 Fixed clang- formatting warning
BillSenior Oct 29, 2024
c0c7fbf
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Curviline…
BillSenior Oct 30, 2024
f37302f
GRIDEDIT-1502 Added doxygen comments for new functions in Curvilinear…
BillSenior Oct 30, 2024
333f3d1
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Curviline…
BillSenior Oct 30, 2024
732009b
GRIDEDIT-1502 First last commit for CurvilinearGridFromSplinesTransfi…
BillSenior Oct 30, 2024
448ca8d
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Curviline…
BillSenior Oct 30, 2024
8249ea1
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Curviline…
BillSenior Oct 30, 2024
e3dafed
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Curviline…
BillSenior Oct 30, 2024
8996567
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in FlipEdges…
BillSenior Oct 31, 2024
b28e917
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in LandBound…
BillSenior Oct 31, 2024
a4f8e1a
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Mesh2D
BillSenior Oct 31, 2024
2f8587f
GRIDEDIT-1502 Doxygen comments to newly added functions
BillSenior Oct 31, 2024
218e921
GRIDEDIT-1502 Correct spelling in comments
BillSenior Oct 31, 2024
f322557
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Smoother
BillSenior Oct 31, 2024
6eac807
GRIDEDIT-1502 Corrected and added missing doxygen comments
BillSenior Oct 31, 2024
d40cb25
GRIDEDIT-1502 Corrected doxygen comment
BillSenior Oct 31, 2024
f986634
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Operations
BillSenior Nov 4, 2024
0774f21
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Orthogona…
BillSenior Nov 4, 2024
1a2b0c6
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in Smoother
BillSenior Nov 4, 2024
088e0db
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in MeshRefin…
BillSenior Nov 4, 2024
6238762
GRIDEDIT-1502 Reduced cyclomatic complexity of functions in MeshRefin…
BillSenior Nov 4, 2024
ca15010
GRIDEDIT-1502 Fixed error in last commit
BillSenior Nov 4, 2024
5d3f1c3
GRIDEDIT-1502 Fixed several other SC warnings
BillSenior Nov 4, 2024
cb5c724
GRIDEDIT-1502 Changes after code review
BillSenior Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace meshkernel::averaging
/// @brief Construct a new ClosestAveragingStrategy.
/// @param[in] interpolationPoint The point for which the average should be calculated.
/// @param[in] projection The projection used to calculate distances with.
ClosestAveragingStrategy(Projection projection);
explicit ClosestAveragingStrategy(Projection projection);

/// @brief Calculates the average value based on the sample values.
/// @param[in] interpolationPoint The point for which the average should be calculated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace meshkernel::averaging
public:
/// @brief Constructor taking the minimum amount of points parameter
/// @param minNumSamples[in] The minimum amount of samples for a valid interpolation
SimpleAveragingStrategy(size_t minNumSamples);
explicit SimpleAveragingStrategy(size_t minNumSamples);

/// @brief Calculates the average value based on the sample values.
/// @param[in] interpolationPoint The point for which the average should be calculated.
Expand Down
66 changes: 65 additions & 1 deletion libs/MeshKernel/include/MeshKernel/CasulliDeRefinement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace meshkernel
{
/// @brief Compute the Casulli de-refinement for a mesh.
/// @brief Compute the Casulli de-refinement for a mesh (derefine_mesh).
class CasulliDeRefinement
{
public:
Expand Down Expand Up @@ -78,6 +78,14 @@ namespace meshkernel
Unassigned = 0 //< not assigned a value 0
};

/// @brief Indicates what should happen
enum class ResultIndicator
{
ReturnFromFunction, //< Return (false) from the current function
BreakInnerLoop, //< Break the inner loop
ContinueInnerLoop //< Continue in the inner loop
};

/// @brief Indicate if the element can be a seed element or not.
static bool ElementIsSeed(const Mesh2D& mesh,
const std::vector<int>& nodeTypes,
Expand All @@ -98,6 +106,16 @@ namespace meshkernel
const std::vector<UInt>& directlyConnected,
std::vector<UInt>& indirectlyConnected);

/// @brief Assign directly connected element indices
static void AssignDirectlyConnected(const std::vector<UInt>& directlyConnected,
std::array<int, 2>& kne,
UInt& neighbouringElementId);

/// @brief Assign indirectly connected element indices
static void AssignIndirectlyConnected(const std::vector<UInt>& indirectlyConnected,
std::array<int, 2>& kne,
const UInt neighbouringElementId);

/// @brief Find element id's
static void FindAdjacentCells(const Mesh2D& mesh,
const std::vector<UInt>& directlyConnected,
Expand All @@ -111,6 +129,32 @@ namespace meshkernel
std::vector<UInt>& indirectlyConnected,
std::vector<std::array<int, 2>>& kne);

/// @brief Update cell mask for directly connected elements
static void UpdateCellMaskDirectlyConnectedNodeFirst(const std::vector<UInt>& directlyConnected,
const Mesh2D& mesh,
const std::vector<UInt>& frontIndex,
std::vector<UInt>& frontIndexCopy,
std::vector<ElementType>& cellMask);

/// @brief Update cell mask for indirectly connected elements
static void UpdateCellMaskIndirectlyConnectedNodeFirst(const std::vector<UInt>& directlyConnected,
BillSenior marked this conversation as resolved.
Show resolved Hide resolved
const Mesh2D& mesh,
std::vector<ElementType>& cellMask);

/// @brief Update cell mask for directly connected elements
static void UpdateCellMaskDirectlyConnectedEdgeFirst(const std::vector<UInt>& directlyConnected,
const Mesh2D& mesh,
const std::vector<UInt>& frontIndex,
std::vector<UInt>& frontIndexCopy,
std::vector<ElementType>& cellMask);

/// @brief Update cell mask for indirectly connected elements
static void UpdateCellMaskIndirectlyConnectedEdgeFirst(const std::vector<UInt>& indirectlyConnected,
const Mesh2D& mesh,
const std::vector<UInt>& frontIndex,
std::vector<UInt>& frontIndexCopy,
std::vector<ElementType>& cellMask);

/// @brief Initialise the element mask.
static std::vector<ElementType> InitialiseElementType(const Mesh2D& mesh,
const std::vector<int>& nodeTypes);
Expand All @@ -126,6 +170,16 @@ namespace meshkernel
const std::vector<int>& nodeTypes,
const UInt nodeId);

/// @brief Get the element index
static UInt GetElementIndex(const std::array<int, 2>& kne,
const UInt index);

/// @brief Find a common edge between elements
static std::tuple<UInt, UInt> FindCommonEdge(Mesh2D& mesh,
const UInt leftElementId,
const UInt rightElementId,
const UInt connectedElementId);

/// @brief Update the mesh members for the mesh description and connectivity.
[[nodiscard]] static bool UpdateDirectlyConnectedElements(Mesh2D& mesh,
const UInt elementId,
Expand Down Expand Up @@ -165,6 +219,16 @@ namespace meshkernel
const UInt nodeId,
const std::vector<UInt>& indirectlyConnected);

/// @brief Remove a boundary node or edge
static ResultIndicator RemoveBoundaryNodeAndEdge(Mesh2D& mesh,
const Polygons& polygon,
const std::vector<int>& nodeTypes,
const UInt faceNodeIndex,
const UInt connectedElementId,
const UInt edgeId,
const UInt previousEdgeId,
const UInt nodeId);

/// @brief Removes nodes from the boundary that will not be part of the de-refined mesh.
[[nodiscard]] static bool RemoveUnwantedBoundaryNodes(Mesh2D& mesh,
const std::vector<int>& nodeTypes,
Expand Down
15 changes: 15 additions & 0 deletions libs/MeshKernel/include/MeshKernel/CasulliRefinement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ namespace meshkernel
/// @param [in] numEdges Number of edges in original mesh, before refinement.
static void ConnectNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numEdges);

/// @brief Get list of node-ids that should be connected to the nodeIndex
static std::vector<UInt> GetNodesToConnect(const Mesh2D& mesh,
const std::vector<NodeMask>& nodeMask,
const std::vector<UInt>& newEdges,
const std::vector<EdgeNodes>& newNodes,
const UInt edgeCount,
const UInt nodeIndex);

/// @brief Connect nodes to nodeIndex.
static void ConnectNodes(Mesh2D& mesh,
const NodeMask nodeMask,
const std::vector<UInt>& nodesToConnect,
const UInt edgeCount,
const UInt nodeIndex);

/// @brief Compute new edges required for refinement
///
/// @param [in, out] mesh The mesh being refined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ namespace meshkernel
/// @return The new displacement
[[nodiscard]] Point TransformDisplacement(Point const& displacement, CurvilinearGridNodeIndices const& node, bool isLocal) const;

UndoActionPtr AddGridLineAtBottom(const CurvilinearGridNodeIndices& firstNode,
const CurvilinearGridNodeIndices& secondNode);

UndoActionPtr AddGridLineAtTop(const CurvilinearGridNodeIndices& firstNode,
const CurvilinearGridNodeIndices& secondNode);

UndoActionPtr AddGridLineAtLeft(const CurvilinearGridNodeIndices& firstNode,
const CurvilinearGridNodeIndices& secondNode);

UndoActionPtr AddGridLineAtRight(const CurvilinearGridNodeIndices& firstNode,
const CurvilinearGridNodeIndices& secondNode);

/// @brief Allocates a new grid line at the boundary of the curvilinear grid if needed.
/// @param firstNode The first node of the boundary grid line.
/// @param secondNode The second node of the boundary grid line.
Expand Down Expand Up @@ -451,6 +463,23 @@ namespace meshkernel
void CommitAction(const ResetCurvilinearNodeAction& undoAction);

private:
/// @brief One dimensional array of NodeType
using NodeTypeArray1D = std::array<meshkernel::NodeType, 2>;

/// @brief Two dimensional array of NodeType
using NodeTypeArray2D = std::array<NodeTypeArray1D, 2>;

/// @brief Three dimensional array of NodeType
using NodeTypeArray3D = std::array<NodeTypeArray2D, 2>;

/// @brief Four dimensional array of NodeType
/// Indices are (n, m), (n-1, m), (n-1, m-1), (n, m-1)
/// top-right, top-left, bottom-left, bottom-right,
using NodeTypeArray4D = std::array<NodeTypeArray3D, 2>;

/// @brief Get interior node type array
static NodeTypeArray4D InitialiseInteriorNodeType();

/// @brief Remove invalid nodes.
/// This function is recursive
/// @param[in] invalidNodesToRemove Whether there are still invalid nodes to remove
Expand Down Expand Up @@ -499,6 +528,21 @@ namespace meshkernel
/// @param[in] value The value of the flag
void SetFacesRTreeRequiresUpdate(bool value) { m_facesRTreeRequiresUpdate = value; }

/// @brief Get the node type of the bottom row of nodes, m = 0
NodeType GetBottomNodeType(const UInt n) const;

/// @brief Get the node type of the top row of nodes, m = NumM - 1
NodeType GetTopNodeType(const UInt n) const;

/// @brief Get the node type of the left row of nodes, n = 0
NodeType GetLeftNodeType(const UInt m) const;

/// @brief Get the node type of the right row of nodes, m = NumN - 1
NodeType GetRightNodeType(const UInt m) const;

/// @brief Get the node type of the interior nodes
NodeType GetInteriorNodeType(const UInt n, const UInt m) const;

Projection m_projection; ///< The curvilinear grid projection
lin_alg::Matrix<Point> m_gridNodes; ///< Member variable storing the grid
lin_alg::Matrix<bool> m_gridFacesMask; ///< The mask of the grid faces (true/false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace meshkernel
public:
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
CurvilinearGridDeRefinement(CurvilinearGrid& grid);
explicit CurvilinearGridDeRefinement(CurvilinearGrid& grid);

/// @brief Refine the curvilinear grid
[[nodiscard]] UndoActionPtr Compute() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace meshkernel
{
public:
/// @param polygon The input polygon
CurvilinearGridFromPolygon(const Polygon& polygon);
explicit CurvilinearGridFromPolygon(const Polygon& polygon);

/// @brief Compute curvilinear in a polygon (pol2curvi)
/// @returns The computed curvilinear grid
Expand All @@ -52,6 +52,24 @@ namespace meshkernel
std::unique_ptr<CurvilinearGrid> Compute(UInt firstNode, UInt secondNode, UInt thirdNode) const;

private:
/// &brief Fill boundary coordinates
void AssignPolygonPointsToSegment(UInt nodeIndex,
UInt numPointsSide,
int direction,
std::vector<Point>& sideToFill) const;

void ComputeNumberOfMNodes(const UInt firstNode,
const UInt secondNode,
const UInt numPolygonNodes,
int& direction,
UInt& numMNodes) const;

void ComputeNumberOfNNodes(const UInt secondNode,
const UInt thirdNode,
const UInt numPolygonNodes,
const int direction,
UInt& numNNodes) const;

const Polygon& m_polygon; /// Reference to a polygon
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ namespace meshkernel
std::vector<double> ComputeMaximumEdgeGrowTime(const lin_alg::RowVector<Point>& coordinates,
const std::vector<Point>& velocities) const;

/// @brief Check corner nodes
bool CheckCornerNodes(const UInt p,
const lin_alg::RowVector<UInt>& indices,
const lin_alg::Matrix<UInt>& gridPointsIndices,
const bool increaseOffset) const;

/// @brief Copy growth velocities to the advancing front, add points at front corners corners (copy_vel_to_front)
/// @param[in] layerIndex The current grid layerIndex index
/// @param[in] previousFrontVelocities The previous front velocities
Expand Down Expand Up @@ -368,5 +374,33 @@ namespace meshkernel
std::vector<UInt> m_subLayerGridPoints; ///< Sublayer grid points
lin_alg::Matrix<UInt> m_numPerpendicularFacesOnSubintervalAndEdge; ///< Perpendicular faces on subinterval and edge
lin_alg::Matrix<double> m_growFactorOnSubintervalAndEdge; ///< Grow factor on subinterval and edge

/// @brief Move any grid nodes
/// @returns Number of grid nodes moved.
UInt MoveGridNodes(const UInt i, const UInt j, const UInt firstLeftIndex, const UInt firstRightIndex);

/// @brief Compute the end points of the spline crossing the main spline
std::tuple<Point, Point> GetCrossSplinePoints(const UInt s, const UInt i) const;

/// @brief Move active layer points.
///
/// The amount of displacement is determined by the time-step size and the velocity
void TranslateActiveLayerPoints(const std::vector<Point>& velocityVectorAtGridPoints,
const double localTimeStep,
lin_alg::RowVector<Point>& activeLayerPoints) const;

/// @brief Disable front nodes that do not satisfy the time-step requirements
void DisableValidFrontNodes(const std::vector<double>& otherTimeStepMax,
const double otherTimeStep,
const double localTimeStep,
std::vector<UInt>& newValidFrontNodes) const;

/// @brief Set active layer points to invalid is indicated by validFrontNodes
void InvalidateActiveLayerPoints(lin_alg::RowVector<Point>& activeLayerPoints) const;

/// @brief Invalidate grid nodes that exceed edge angle requirements
void InvalidateGridNodes(const UInt layerIndex,
lin_alg::RowVector<Point>& activeLayerPoints,
std::vector<UInt>& newValidFrontNodes);
};
} // namespace meshkernel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ namespace meshkernel
/// finds intersections and orders the splines
void CharacteriseSplines();

/// @brief Compute spline intersections in n-direction
void ComputeNDirectionIntersections();

/// @brief Compute spline intersections in m-direction
void ComputeMDirectionIntersections();

/// @brief Compute spline intersection start and end points
void ComputeSplineStartAndEnd(const UInt outerStart, const UInt outerEnd, const UInt innerStart, const UInt innerEnd);

/// @brief Label each spline and its intersection.
///
/// In which group does it lie (m or n), and spline crossing indices.
Expand Down Expand Up @@ -114,6 +123,21 @@ namespace meshkernel
const std::vector<double>& intersectionDistances,
std::vector<double>& distances) const;

/// @brief Fill side point arrays
void FillInterpolationPlaneBlock(const lin_alg::Matrix<Point>& gridNodes,
const UInt i,
const UInt j,
std::vector<Point>& bottomSide,
std::vector<Point>& upperSide,
std::vector<Point>& leftSide,
std::vector<Point>& rightSide) const;

/// @brief Assign interpolated points to the grid block
void AssignInterpolatedNodes(const UInt i,
const UInt j,
const lin_alg::Matrix<Point>& interpolationResult,
lin_alg::Matrix<Point>& gridNodes) const;

std::vector<int> m_splineType; ///< The spline types (1 horizontal, -1 vertical)
std::vector<std::vector<double>> m_splineIntersectionRatios; ///< For each spline, stores the intersections in terms of total spline length
std::vector<std::vector<UInt>> m_splineGroupIndexAndFromToIntersections; ///< For each spline: position in m or n group, from and to spline crossing indices (MN12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace meshkernel
public:
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
CurvilinearGridLineShift(CurvilinearGrid& grid);
explicit CurvilinearGridLineShift(CurvilinearGrid& grid);

/// @brief Computes a new curvilinear grid with the line shift
[[nodiscard]] UndoActionPtr Compute() override;
Expand Down
Loading
Loading