Skip to content

Commit

Permalink
Delete curvilinear block exterior (#239| GRIDEDIT-704)
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior authored Nov 2, 2023
1 parent 4f35f33 commit 9725675
Show file tree
Hide file tree
Showing 42 changed files with 2,214 additions and 1,715 deletions.
4 changes: 4 additions & 0 deletions libs/MeshKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ set(
CURVILINEAR_GRID_SRC_LIST
${CURVILINEAR_GRID_SRC_DIR}/CurvilinearGrid.cpp
${CURVILINEAR_GRID_SRC_DIR}/CurvilinearGridAlgorithm.cpp
${CURVILINEAR_GRID_SRC_DIR}/CurvilinearGridDeleteInterior.cpp
${CURVILINEAR_GRID_SRC_DIR}/CurvilinearGridDeleteExterior.cpp
${CURVILINEAR_GRID_SRC_DIR}/CurvilinearGridDeRefinement.cpp
${CURVILINEAR_GRID_SRC_DIR}/CurvilinearGridFromPolygon.cpp
${CURVILINEAR_GRID_SRC_DIR}/CurvilinearGridFromSplines.cpp
Expand Down Expand Up @@ -149,6 +151,8 @@ set(
CURVILINEAR_GRID_INC_LIST
${CURVILINEAR_GRID_INC_DIR}/CurvilinearGrid.hpp
${CURVILINEAR_GRID_INC_DIR}/CurvilinearGridAlgorithm.hpp
${CURVILINEAR_GRID_INC_DIR}/CurvilinearGridDeleteInterior.hpp
${CURVILINEAR_GRID_INC_DIR}/CurvilinearGridDeleteExterior.hpp
${CURVILINEAR_GRID_INC_DIR}/CurvilinearGridDeRefinement.hpp
${CURVILINEAR_GRID_INC_DIR}/CurvilinearGridFromPolygon.hpp
${CURVILINEAR_GRID_INC_DIR}/CurvilinearGridFromSplines.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ namespace meshkernel
/// @param[in] projection The projection to use
CurvilinearGrid(lin_alg::Matrix<Point> const& grid, Projection projection);

/// @brief Set the grid nodes of a curvilinear grid instance
/// @param[in] gridNodes The input grid points
void SetGridNodes(lin_alg::Matrix<Point> gridNodes);

/// @brief Deletes a curvilinear grid inside a polygon
/// @param[in] polygons The polygons
/// @param[in] polygonIndex The index of the polygon to use for deletion
Expand Down Expand Up @@ -153,7 +157,7 @@ namespace meshkernel
/// @param[in] firstNode The node indices of the first node
/// @param[in] secondNode The node indices of the second node
/// @return The upper left and lower right of the box defined by the two points
[[nodiscard]] std::tuple<CurvilinearGridNodeIndices, CurvilinearGridNodeIndices> ComputeBlockFromCornerPoints(const CurvilinearGridNodeIndices& firstNode, const CurvilinearGridNodeIndices& secondNode) const;
std::tuple<CurvilinearGridNodeIndices, CurvilinearGridNodeIndices> ComputeBlockFromCornerPoints(const CurvilinearGridNodeIndices& firstNode, const CurvilinearGridNodeIndices& secondNode) const;

/// @brief From two points expressed in cartesian coordinates, get the two corner nodes defining a block in m and n coordinates
/// @param[in] firstCornerPoint The first corner point
Expand Down Expand Up @@ -186,10 +190,6 @@ namespace meshkernel
/// @return The new displacement
[[nodiscard]] Point TransformDisplacement(Point const& displacement, CurvilinearGridNodeIndices const& node, bool isLocal) const;

/// @brief Clones the curvilinear grid instance
/// @return A pointer to a deep copy of current curvilinear grid instance
[[nodiscard]] CurvilinearGrid CloneCurvilinearGrid() const;

/// @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 All @@ -206,10 +206,6 @@ namespace meshkernel
/// @param[in] point The input point coordinate. The closest grid node will be deleted.
void DeleteNode(Point const& point);

/// @brief Set all the nodes interior to the block to be invalid.
/// @note If any index is the null value or is out of range a ConstraintError will be thrown
void DeleteInterior(const CurvilinearGridNodeIndices& firstNode, const CurvilinearGridNodeIndices& secondNode);

/// @brief Moves a node from one position to another
/// @param[in] fromPoint The input position, the closest node will be used
/// @param[in] toPoint The coordinates of the new position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@

#pragma once

#include <memory>

#include <MeshKernel/CurvilinearGrid/CurvilinearGrid.hpp>
#include <MeshKernel/CurvilinearGrid/CurvilinearGridLine.hpp>
#include <MeshKernel/Entities.hpp>
#include <MeshKernel/Splines.hpp>

namespace meshkernel
Expand All @@ -44,10 +41,10 @@ namespace meshkernel
public:
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
CurvilinearGridAlgorithm(std::shared_ptr<CurvilinearGrid> grid);
explicit CurvilinearGridAlgorithm(CurvilinearGrid& grid);

/// @brief Executes the algorithm
virtual CurvilinearGrid Compute() = 0;
virtual void Compute() = 0;

/// @brief Sets a block where the algorithm should execute
/// @param[in] firstCornerPoint The first point defining the bounding box
Expand All @@ -63,7 +60,7 @@ namespace meshkernel
/// @brief Virtual destructor
virtual ~CurvilinearGridAlgorithm() = default;

CurvilinearGrid m_grid; ///< A deep copy of the original grid, modified by the algorithms
CurvilinearGrid& m_grid; ///< A reference of the grid, modified by the algorithms
std::vector<CurvilinearGridLine> m_lines; ///< Selected grid lines
CurvilinearGridNodeIndices m_lowerLeft; ///< The lower left corner of the block
CurvilinearGridNodeIndices m_upperRight; ///< The upper right corner of the block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace meshkernel
public:
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
CurvilinearGridDeRefinement(std::shared_ptr<CurvilinearGrid> grid);
CurvilinearGridDeRefinement(CurvilinearGrid& grid);

/// @brief Refine the curvilinear grid
CurvilinearGrid Compute() override;
void Compute() override;
};
} // namespace meshkernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2021.
//
// 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: [email protected]
// 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.
//
//------------------------------------------------------------------------------

#pragma once

#include "CurvilinearGridAlgorithm.hpp"

namespace meshkernel
{

/// @brief A class implementing the curvilinear grid delete exterior algorithm.
class CurvilinearGridDeleteExterior : public CurvilinearGridAlgorithm
{
public:
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
explicit CurvilinearGridDeleteExterior(CurvilinearGrid& grid);

/// @brief Set all the nodes outside of the block to be invalid.
/// @note If any index is the null value or is out of range a ConstraintError will be thrown
void Compute() override;
};
} // namespace meshkernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2021.
//
// 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: [email protected]
// 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.
//
//------------------------------------------------------------------------------

#pragma once

#include "CurvilinearGridAlgorithm.hpp"

namespace meshkernel
{

/// @brief A class implementing the curvilinear grid delete interior algorithm.
class CurvilinearGridDeleteInterior : public CurvilinearGridAlgorithm
{
public:
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
explicit CurvilinearGridDeleteInterior(CurvilinearGrid& grid);

/// @brief Set all the nodes interior to the block to be invalid.
/// @note If any index is the null value or is out of range a ConstraintError will be thrown
void Compute() override;
};
} // namespace meshkernel
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ namespace meshkernel
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
/// @param[in] attractionFactor The input attraction/repulsion factor (positive attracts lines/negative repulses lines)
CurvilinearGridLineAttractionRepulsion(std::shared_ptr<CurvilinearGrid> grid, double attractionFactor);
CurvilinearGridLineAttractionRepulsion(CurvilinearGrid& grid, double attractionFactor);

/// @brief Computes a new curvilinear grid with line attracted towards \ref m_lines[0]
/// @return The shifted curvilinear grid
CurvilinearGrid Compute() override;
void Compute() override;

private:
std::shared_ptr<CurvilinearGrid> m_originalGrid; ///< A pointer to the original grid, used for computation of quantities
double m_attractionFactor; ///< The attraction factor. If 0.0 no line will be attracted to m_lines[0]
CurvilinearGrid m_originalGrid; ///< A pointer to the original grid, used for computation of quantities
double m_attractionFactor; ///< The attraction factor. If 0.0 no line will be attracted to m_lines[0]
};
} // namespace meshkernel
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ namespace meshkernel
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
/// @param[in] mirroringFactor The mirroringFactor factor
CurvilinearGridLineMirror(std::shared_ptr<CurvilinearGrid> grid, double mirroringFactor);
CurvilinearGridLineMirror(CurvilinearGrid& grid, double mirroringFactor);

/// @brief Computes a new curvilinear grid with the line shift
/// @return The shifted curvilinear grid
CurvilinearGrid Compute() override;
void Compute() override;

private:
CurvilinearGrid m_originalGrid; ///< The new grid, storing the new positions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ namespace meshkernel
public:
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
CurvilinearGridLineShift(std::shared_ptr<CurvilinearGrid> grid);
CurvilinearGridLineShift(CurvilinearGrid& grid);

/// @brief Computes a new curvilinear grid with the line shift
/// @return The shifted curvilinear grid
CurvilinearGrid Compute() override;
void Compute() override;

/// @brief Moves a node from one position to another
/// @param[in] fromPoint The input position, the closest node on the \ref m_grid grid will be used
Expand All @@ -68,6 +67,6 @@ namespace meshkernel
/// @return The new displacement
Point TransformDisplacement(Point const& displacement, CurvilinearGridNodeIndices const& node, bool toLocal) const;

std::shared_ptr<CurvilinearGrid> m_originalGrid; ///< A pointer to the original grid
CurvilinearGrid m_originalGrid; ///< A pointer to the original grid
};
} // namespace meshkernel
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ namespace meshkernel
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
/// @param[in] orthogonalizationParameters The orthogonalization parameters
CurvilinearGridOrthogonalization(std::shared_ptr<CurvilinearGrid> grid,
CurvilinearGridOrthogonalization(CurvilinearGrid& grid,
const OrthogonalizationParameters& orthogonalizationParameters);

/// @brief Orthogonalize the curvilinear grid (modifies the grid point by m_grid)
CurvilinearGrid Compute() override;
void Compute() override;

private:
/// @brief Solve one orthogonalization iteration, using the method of successive over-relaxation SOR (ORTSOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ namespace meshkernel
/// \p firstPoint and \p secondPoint must lie on the same gridline
/// @param[in] grid The input curvilinear grid
/// @param[in] refinement The number of refinement lines between the points set by SetBlock()
CurvilinearGridRefinement(const std::shared_ptr<CurvilinearGrid>& grid, UInt refinement);
CurvilinearGridRefinement(CurvilinearGrid& grid, UInt refinement);

/// @brief Refine the curvilinear grid
CurvilinearGrid Compute() override;
void Compute() override;

private:
UInt m_refinement; ///< The selected number of refinement lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

#include <MeshKernel/CurvilinearGrid/CurvilinearGrid.hpp>
#include <MeshKernel/CurvilinearGrid/CurvilinearGridAlgorithm.hpp>
#include <MeshKernel/Entities.hpp>

namespace meshkernel
{
Expand All @@ -43,11 +42,10 @@ namespace meshkernel
/// @brief Class constructor
/// @param[in] grid The input curvilinear grid
/// @param[in] smoothingIterations The number of smoothing iterations to perform
CurvilinearGridSmoothing(std::shared_ptr<CurvilinearGrid> grid, UInt smoothingIterations);
CurvilinearGridSmoothing(CurvilinearGrid& grid, UInt smoothingIterations);

/// @brief Compute curvilinear grid block smoothing (modifies the m_grid nodal values)
/// @return The smoothed grid
CurvilinearGrid Compute() override;
void Compute() override;

/// @brief Compute curvilinear grid line smoothing. The algorithm smooths the grid along the direction specified by the line.
/// The line must be an m or n grid line of the curvilinear grid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ namespace meshkernel
/// @param [in] grid The input curvilinear grid
/// @param [in] landBoundary The land boundary to which the grid is to be snapped.
/// @param [in] points The points used to control the snapping and smoothing.
CurvilinearGridSnapping(std::shared_ptr<CurvilinearGrid> grid,
CurvilinearGridSnapping(CurvilinearGrid& grid,
const LandBoundary& landBoundary,
const std::vector<Point>& points);

/// @brief Executes the snapping and smoothing algorithm
CurvilinearGrid Compute() override;
void Compute() override;

private:
/// @brief Tolerance to determine if point is on (close to) boundary
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace meshkernel
void Initialise();

/// @brief The grid to be smoothed
const CurvilinearGrid& m_originalGrid;
const CurvilinearGrid m_originalGrid;

/// @brief The land boundary to which the grid is to be snapped.
const LandBoundary& m_landBoundary;
Expand Down
Loading

0 comments on commit 9725675

Please sign in to comment.