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

irregular to regular #322

Merged
merged 11 commits into from
Apr 27, 2024
2 changes: 2 additions & 0 deletions libs/MeshKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(
${SRC_DIR}/Mesh2D.cpp
${SRC_DIR}/Mesh2DGenerateGlobal.cpp
${SRC_DIR}/Mesh2DIntersections.cpp
${SRC_DIR}/Mesh2DToCurvilinear.cpp
${SRC_DIR}/MeshRefinement.cpp
${SRC_DIR}/Network1D.cpp
${SRC_DIR}/Operations.cpp
Expand Down Expand Up @@ -147,6 +148,7 @@ set(
${DOMAIN_INC_DIR}/Mesh2D.hpp
${DOMAIN_INC_DIR}/Mesh2DGenerateGlobal.hpp
${DOMAIN_INC_DIR}/Mesh2DIntersections.hpp
${DOMAIN_INC_DIR}/Mesh2DToCurvilinear.hpp
${DOMAIN_INC_DIR}/MeshConversion.hpp
${DOMAIN_INC_DIR}/MeshInterpolation.hpp
${DOMAIN_INC_DIR}/MeshRefinement.hpp
Expand Down
89 changes: 89 additions & 0 deletions libs/MeshKernel/include/MeshKernel/Mesh2DToCurvilinear.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2023.
//
Comment on lines +2 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a year out of date

// 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 <memory>

#include "MeshKernel/CurvilinearGrid/CurvilinearGrid.hpp"
#include "MeshKernel/Definitions.hpp"
#include "MeshKernel/Mesh2D.hpp"
#include "MeshKernel/Point.hpp"
#include "Utilities/LinearAlgebra.hpp"

using namespace meshkernel::constants;

namespace meshkernel
{
/// @brief Construct a curvilinear grid from an unstructured mesh
class Mesh2DToCurvilinear
{
public:
/// @brief Constructor
/// @param[in] mesh The input unstructured mesh
explicit Mesh2DToCurvilinear(Mesh2D& mesh);

/// @brief Computes the curvilinear grid starting from a specific point
/// @param[in] point The point from which start growing the curvilinear mesh. The point must be inside a quadrangular face
/// @returns The curvilinear grid
std::unique_ptr<CurvilinearGrid> Compute(const Point& point);
lucacarniato marked this conversation as resolved.
Show resolved Hide resolved

private:
/// @brief Computes the local mapping of the nodes composing the face
[[nodiscard]] Eigen::Matrix<UInt, 2, 2> ComputeLocalNodeMapping(UInt face) const;

/// @brief Computes the node indices of the neighbouring faces
[[nodiscard]] UInt ComputeNeighbouringFaceNodes(const UInt face,
const Eigen::Matrix<UInt, 2, 2>& localNodeMapping,
const UInt d,
const std::vector<bool>& visitedFace);

/// @brief Computes the final curvilinear matrix
[[nodiscard]] lin_alg::Matrix<Point> ComputeCurvilinearMatrix();

Mesh2D& m_mesh; ///< The mesh to convert
std::vector<int> m_i; ///< The i indices of each node on the curvilinear grid
std::vector<int> m_j; ///< The j indices of each node on the curvilinear grid

std::array<std::array<int, 2>, 4> m_nodeFrom = {{{0, 0},
{0, 0},
{1, 0},
{1, 1}}}; ///< starting edge node indices for each direction in the local mapping

std::array<std::array<int, 2>, 4> m_nodeTo = {{{0, 1},
{1, 0},
{1, 1},
{0, 1}}}; ///< ending edge node indices for each direction in the local mapping

std::array<std::array<int, 2>, 4> m_directionsDeltas = {{{-1, 0},
{0, -1},
{1, 0},
{0, 1}}}; ///< increments for the new nodes depending on the node direction
lucacarniato marked this conversation as resolved.
Show resolved Hide resolved

const int n_maxNumRowsColumns = 1000000; ///< The maximum number of allowed rows or columns
};

} // namespace meshkernel
Loading
Loading