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

Feature/gridedit 656 projection enum to string #227

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion libs/MeshKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ set(
${SRC_DIR}/BilinearInterpolationOnGriddedSamples.cpp
${SRC_DIR}/ConnectMeshes.cpp
${SRC_DIR}/Contacts.cpp
${SRC_DIR}/Definitions.cpp
${SRC_DIR}/Entities.cpp
${SRC_DIR}/FlipEdges.cpp
${SRC_DIR}/LandBoundaries.cpp
Expand Down Expand Up @@ -95,6 +94,7 @@ set(
set(
INC_LIST
${DOMAIN_INC_DIR}/AveragingInterpolation.hpp
${DOMAIN_INC_DIR}/AveragingInterpolationMethod.hpp
${DOMAIN_INC_DIR}/BilinearInterpolationOnGriddedSamples.hpp
${DOMAIN_INC_DIR}/BoundingBox.hpp
${DOMAIN_INC_DIR}/ConnectMeshes.hpp
Expand All @@ -111,7 +111,9 @@ set(
${DOMAIN_INC_DIR}/Mesh1D.hpp
${DOMAIN_INC_DIR}/Mesh2D.hpp
${DOMAIN_INC_DIR}/MeshInterpolation.hpp
${DOMAIN_INC_DIR}/MeshLocation.hpp
${DOMAIN_INC_DIR}/MeshRefinement.hpp
${DOMAIN_INC_DIR}/MeshRefinementType.hpp
${DOMAIN_INC_DIR}/Network1D.hpp
${DOMAIN_INC_DIR}/Operations.hpp
${DOMAIN_INC_DIR}/OrthogonalizationAndSmoothing.hpp
Expand All @@ -121,6 +123,8 @@ set(
${DOMAIN_INC_DIR}/Polygon.hpp
${DOMAIN_INC_DIR}/PolygonalEnclosure.hpp
${DOMAIN_INC_DIR}/Polygons.hpp
${DOMAIN_INC_DIR}/Projection.hpp
${DOMAIN_INC_DIR}/ProjectionToLandBoundary.hpp
${DOMAIN_INC_DIR}/RangeCheck.hpp
${DOMAIN_INC_DIR}/RemoveDisconnectedRegions.hpp
${DOMAIN_INC_DIR}/Smoother.hpp
Expand Down Expand Up @@ -168,6 +172,7 @@ set(
${UTILITIES_INC_DIR}/LinearAlgebra.hpp
${UTILITIES_INC_DIR}/NumericFunctions.hpp
${UTILITIES_INC_DIR}/RTree.hpp
${UTILITIES_INC_DIR}/UnderlyingType.hpp
)

set(
Expand Down
10 changes: 5 additions & 5 deletions libs/MeshKernel/benchmark/src/perf_curvilinear_uniform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void BM_CurvilinearUniform(benchmark::State& state)
{2.04861111111111, 4.5397633744856},
{2.21527777777778, 5.08143004115226}};

auto const polygons = std::make_shared<Polygons>(polygon_points, Projection::cartesian);
auto const polygons = std::make_shared<Polygons>(polygon_points, Projection::Cartesian);

double const dim_x = 10.0;
double const dim_y = 15.0;
Expand All @@ -50,7 +50,7 @@ static void BM_CurvilinearUniform(benchmark::State& state)
// resume the timers to begin benchmarking
state.ResumeTiming();

CurvilinearGridCreateUniform const curvilinear_grid_create_uniform(Projection::cartesian);
CurvilinearGridCreateUniform const curvilinear_grid_create_uniform(Projection::Cartesian);
const auto curvilinearGrid = std::make_shared<CurvilinearGrid>(
curvilinear_grid_create_uniform.Compute(make_grid_parameters.angle,
make_grid_parameters.block_size_x,
Expand Down Expand Up @@ -85,7 +85,7 @@ static void BM_CurvilinearUniform_add_faces_to_left_boundary(benchmark::State& s
const double blockSizeX = block_size;
const double blockSizeY = block_size;

CurvilinearGridCreateUniform const curvilinear_grid_create_uniform(Projection::cartesian);
CurvilinearGridCreateUniform const curvilinear_grid_create_uniform(Projection::Cartesian);
const auto curvilinearGrid = std::make_shared<CurvilinearGrid>(
curvilinear_grid_create_uniform.Compute(numColumns,
numRows,
Expand Down Expand Up @@ -121,7 +121,7 @@ static void BM_CurvilinearFromSplines(benchmark::State& state)
// that are irrelevant to the benchmark and should not be measured)
state.PauseTiming();

const auto splines = std::make_shared<Splines>(Projection::cartesian);
const auto splines = std::make_shared<Splines>(Projection::Cartesian);

const std::vector<Point>
firstSpline{
Expand Down Expand Up @@ -200,7 +200,7 @@ static void BM_CurvilinearFromSplinesTransfinite(benchmark::State& state)
const std::vector<Point> fourthSpline{{5.067361E+02, 6.034946E+02},
{7.475956E+02, 3.336055E+02}};

const auto splines = std::make_shared<Splines>(Projection::cartesian);
const auto splines = std::make_shared<Splines>(Projection::Cartesian);
splines->AddSpline(firstSpline);
splines->AddSpline(secondSpline);
splines->AddSpline(thirdSpline);
Expand Down
8 changes: 4 additions & 4 deletions libs/MeshKernel/benchmark/src/perf_mesh_refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void BM_MeshRefinementBasedOnSamples(benchmark::State& state)
static_cast<UInt>(state.range(1)),
10.0,
15.0,
Projection::cartesian);
Projection::Cartesian);

// sample points
std::vector<Sample> samples;
Expand All @@ -37,8 +37,8 @@ static void BM_MeshRefinementBasedOnSamples(benchmark::State& state)
auto const interpolator = std::make_shared<AveragingInterpolation>(
*mesh,
samples,
AveragingInterpolation::Method::MinAbsValue,
Mesh::Location::Faces,
AveragingInterpolationMethod::Method::MinAbsValue,
MeshLocation::Faces,
1.0,
false,
false,
Expand Down Expand Up @@ -84,7 +84,7 @@ static void BM_MeshRefinementBasedOnPolygons(benchmark::State& state)
static_cast<UInt>(state.range(1)),
10.0,
15.0,
Projection::cartesian);
Projection::Cartesian);

std::vector<meshkernel::Point> polygon_points{
{2.21527777777778, 5.08143004115226},
Expand Down
4 changes: 2 additions & 2 deletions libs/MeshKernel/benchmark/src/perf_orthogonalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void BM_Orthogonalization(benchmark::State& state)
m,
dim_x,
dim_y,
Projection::cartesian);
Projection::Cartesian);

// move nodes to skew the mesh
double const delta_x = dim_x / static_cast<double>(n - 1);
Expand Down Expand Up @@ -64,7 +64,7 @@ static void BM_Orthogonalization(benchmark::State& state)

mesh->AdministrateNodesEdges();

auto const project_to_land_Boundary = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary;
auto const project_to_land_Boundary = ProjectionToLandBoundary::None;
OrthogonalizationParameters orthogonalization_parameters;
orthogonalization_parameters.inner_iterations = 25;
orthogonalization_parameters.boundary_iterations = 25;
Expand Down
35 changes: 12 additions & 23 deletions libs/MeshKernel/include/MeshKernel/AveragingInterpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@

#include "MeshInterpolation.hpp"

#include <MeshKernel/AveragingInterpolationMethod.hpp>
#include <MeshKernel/AveragingStrategies/AveragingStrategy.hpp>
#include <MeshKernel/Constants.hpp>
#include <MeshKernel/Mesh2D.hpp>
#include <MeshKernel/MeshLocation.hpp>
#include <MeshKernel/Utilities/RTree.hpp>

namespace meshkernel
Expand All @@ -42,10 +44,11 @@ namespace meshkernel

/// @brief The class used to interpolate based on averaging
///
/// The averaging interpolation operates on three specific \ref Mesh::Location - Faces
/// (m_facesMassCenters), Nodes, and Edges(m_edgesCenters). The idea is to
/// The averaging interpolation operates on three specific \ref MeshLocation::Type
/// - Faces (m_facesMassCenters), Nodes, and Edges (m_edgesCenters). The idea is to
/// collect all samples close to the locations and perform a mathematical
/// operation on their values. The \ref Method enum describes available operations.
/// operation on their values. The \ref AveragingInterpolationMethod::Method enum
/// describes the available operations.
///
/// The algorithm operates as follow:
///
Expand All @@ -58,7 +61,7 @@ namespace meshkernel
/// (relativeSearchRadius > 1 increased, relativeSearchRadius < 1
/// decreased).
///
/// 2. For \ref Mesh::Location Nodes and \ref Mesh::Location Edges locations, the dual face around the node is
/// 2. For \ref MeshLocation Nodes and \ref MeshLocation Edges locations, the dual face around the node is
/// constructed by connecting the mid-points of all edges connected
/// to the node. As above, the resulting polygon can be
/// increased/decreased by the relativeSearchRadius parameter.
Expand All @@ -71,22 +74,11 @@ namespace meshkernel
///
/// - The operations described above are executed on the found samples.
///
/// - For the \ref Mesh::Location Edges location, the interpolated values at the node are
/// - For the \ref MeshLocation Edges location, the interpolated values at the node are
/// averaged.
class AveragingInterpolation : public MeshInterpolation
{
public:
/// @brief Averaging methods
enum class Method
{
SimpleAveraging = 1, ///< Computes a simple mean
Closest = 2, ///< Takes the value of the closest sample to the interpolation location
Max = 3, ///< Takes the maximum sample value
Min = 4, ///< Takes the minimum sample value
InverseWeightedDistance = 5, ///< Computes the inverse weighted sample mean
MinAbsValue = 6 ///< Computes the minimum absolute value
};

/// @brief Interpolation based on averaging
/// @param[in] mesh The input mesh
/// @param[in] samples The samples with x,y locations and values
Expand All @@ -98,8 +90,8 @@ namespace meshkernel
/// @param[in] minNumSamples The minimum a of samples used for certain interpolation algorithms
AveragingInterpolation(Mesh2D& mesh,
std::vector<Sample>& samples,
Method method,
Mesh::Location locationType,
AveragingInterpolationMethod::Method method,
MeshLocation::Type locationType,
double relativeSearchRadius,
bool useClosestSampleIfNoneAvailable,
bool subtractSampleValues,
Expand All @@ -116,9 +108,6 @@ namespace meshkernel
double ComputeOnPolygon(const std::vector<Point>& polygon,
const Point& interpolationPoint);

/// @brief Decreases the values of samples
void DecreaseValueOfSamples();

/// @brief Generate the search polygon from an input polygon
/// @param[in] polygon The input polygon
/// @param[in] interpolationPoint The interpolation point
Expand All @@ -145,8 +134,8 @@ namespace meshkernel

Mesh2D& m_mesh; ///< Pointer to the mesh
std::vector<Sample>& m_samples; ///< The samples
Method m_method; ///< The method to use for the interpolation
Mesh::Location m_interpolationLocation; ///< Interpolation location
AveragingInterpolationMethod::Method m_method; ///< The method to use for the interpolation
MeshLocation::Type m_interpolationLocation; ///< Interpolation location
double m_relativeSearchRadius; ///< Relative search radius
bool m_useClosestSampleIfNoneAvailable = false; ///< Whether to use the closest sample if there is none available
bool m_transformSamples = false; ///< Wheher to transform samples
Expand Down
114 changes: 114 additions & 0 deletions libs/MeshKernel/include/MeshKernel/AveragingInterpolationMethod.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//---- 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 <string>
#include <vector>

#include "MeshKernel/Definitions.hpp"

namespace meshkernel
{

/// @brief Projection::Type class
class AveragingInterpolationMethod
{
public:
/// @brief Class constructor
AveragingInterpolationMethod() = delete;

/// @enum Method
/// @brief Enumerator describing the averaging interpolation methods
enum Method
{
SimpleAveraging = 1, ///< Computes a simple mean
Closest = 2, ///< Takes the value of the closest sample to the interpolation location
Max = 3, ///< Takes the maximum sample value
Min = 4, ///< Takes the minimum sample value
InverseWeightedDistance = 5, ///< Computes the inverse weighted sample mean
MinAbsValue = 6, ///< Computes the minimum absolute value
Unknown = 7 ///> Unknown
};

/// @brief Returns the mesh location string
/// @param type The mesh location enumeration
/// @return The mesh lcoations string
inline static std::string ToString(Method const type)
{
switch (type)
{
case SimpleAveraging:
return "Simple averaging (mean)";
case Closest:
return "Closest";
case Max:
return "Max";
case Min:
return "Min";
case InverseWeightedDistance:
return "Inverse weighted distance";
case MinAbsValue:
return "Minimum absolute value";
case Unknown:
default:
return "Unknown";
}
}

/// @brief Returns the mesh location string
/// @param type The mesh location enumeration as an integer
/// @return The mesh lcoations string
inline static std::string ToString(int const type)
{
return ToString(static_cast<Method>(type));
}

/// @brief Gets vector of valid values (integers)
/// @return Vector of valid values
inline static std::vector<int> const& ValidValues() { return m_ValidValues; }

/// @brief Gets valid values as a string
/// @return String of valid values
inline static std::string const& ValidValuesString() { return m_ValidValuesString; }

private:
/// @brief Vector of valid values
inline static std::vector<int> const m_ValidValues = {
SimpleAveraging,
Closest,
Max,
Min,
InverseWeightedDistance,
MinAbsValue //
};

/// @brief String of valid values
inline static std::string const m_ValidValuesString = MakeValidValuesString<AveragingInterpolationMethod>();
};

} // namespace meshkernel
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <MeshKernel/AveragingInterpolation.hpp>
#include <MeshKernel/Entities.hpp>
#include <MeshKernel/Projection.hpp>

namespace meshkernel::averaging
{
Expand All @@ -41,9 +42,9 @@ namespace meshkernel::averaging
/// @param[in] interpolationPoint The interpolation point
/// @param[in] projection The projection to use
/// @return The interpolation strategy to use
[[nodiscard]] std::unique_ptr<AveragingStrategy> static GetAveragingStrategy(AveragingInterpolation::Method averagingMethod,
[[nodiscard]] std::unique_ptr<AveragingStrategy> static GetAveragingStrategy(AveragingInterpolationMethod::Method averagingMethod,
size_t minNumSamples,
Point const& interpolationPoint,
Projection projection);
Projection::Type projection);
};
} // namespace meshkernel::averaging
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <MeshKernel/AveragingStrategies/AveragingStrategy.hpp>
#include <MeshKernel/Entities.hpp>
#include <MeshKernel/Projection.hpp>

namespace meshkernel::averaging
{
Expand All @@ -40,7 +41,7 @@ namespace meshkernel::averaging
/// @param[in] interpolationPoint The point for which the average should be calculated.
/// @param[in] projection The projection used to calculate distances with.
ClosestAveragingStrategy(Point const& interpolationPoint,
Projection projection);
Projection::Type projection);

void Add(Point const& samplePoint, double sampleValue) override;
[[nodiscard]] double Calculate() const override;
Expand All @@ -56,6 +57,6 @@ namespace meshkernel::averaging
Point const& m_interpolationPoint;

/// @brief The projection used to calculate the squared distance.
Projection const m_projection;
Projection::Type const m_projection;
};
} // namespace meshkernel::averaging
Loading
Loading