MeshKernel
Parameters.hpp
1 //---- GPL ---------------------------------------------------------------------
2 //
3 // Copyright (C) Stichting Deltares, 2011-2021.
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation version 3.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // contact: delft3d.support@deltares.nl
18 // Stichting Deltares
19 // P.O. Box 177
20 // 2600 MH Delft, The Netherlands
21 //
22 // All indications and logos of, and references to, "Delft3D" and "Deltares"
23 // are registered trademarks of Stichting Deltares, and remain the property of
24 // Stichting Deltares. All rights reserved.
25 //
26 //------------------------------------------------------------------------------
27 
28 #pragma once
29 
30 #include "MeshKernel/RangeCheck.hpp"
31 
32 namespace meshkernel
33 {
38  {
40  int num_columns = 3;
41 
43  int num_rows = 3;
44 
46  double angle = 0.0;
47 
49  double origin_x = 0.0;
50 
52  double origin_y = 0.0;
53 
55  double block_size_x = 10.0;
56 
58  double block_size_y = 10.0;
59 
61  double upper_right_x = 0.0;
62 
64  double upper_right_y = 0.0;
65 
67  double radius_curvature = 0.0;
68 
72  double uniform_columns_fraction = 0.25;
73 
75  double uniform_rows_fraction = 0.25;
76 
79 
82  };
83 
84  inline static void CheckMakeGridParameters(MakeGridParameters const& parameters)
85  {
86  range_check::CheckGreater(parameters.num_columns, 0, "Number of columns");
87  range_check::CheckGreater(parameters.num_rows, 0, "Number of rows");
88  range_check::CheckInClosedInterval(parameters.angle, {-90.0, 90.0}, "Grid angle");
89  range_check::CheckGreater(parameters.block_size_x, 0.0, "X block size");
90  range_check::CheckGreater(parameters.block_size_y, 0.0, "Y block size");
91  range_check::CheckGreaterEqual(parameters.radius_curvature, 0.0, "Radius of curvature");
92  range_check::CheckGreaterEqual(parameters.uniform_columns_fraction, 0.0, "Uniform m-fraction");
93  range_check::CheckGreaterEqual(parameters.uniform_rows_fraction, 0.0, "Uniform n-fraction");
94  range_check::CheckGreaterEqual(parameters.maximum_uniform_size_columns, 0.0, "Maximum size / delta-x");
95  range_check::CheckGreaterEqual(parameters.maximum_uniform_size_rows, 0.0, "Maximum size / delta-y");
96 
97  auto isFinite = [](const double value)
98  { return std::isfinite(value); };
99 
100  range_check::CheckPrecondition(parameters.block_size_x, "X block size", "value is finite", isFinite);
101  range_check::CheckPrecondition(parameters.block_size_y, "Y block size", "value is finite", isFinite);
102  range_check::CheckPrecondition(parameters.radius_curvature, "Radius of curvature", "value is finite", isFinite);
103  range_check::CheckPrecondition(parameters.maximum_uniform_size_columns, "Maximum size / delta-x", "value is finite", isFinite);
104  range_check::CheckPrecondition(parameters.maximum_uniform_size_rows, "Maximum size / delta-y", "value is finite", isFinite);
105  range_check::CheckPrecondition(parameters.uniform_columns_fraction, "Uniform m-fraction", "value is finite", isFinite);
106  range_check::CheckPrecondition(parameters.uniform_rows_fraction, "Uniform n-fraction", "value is finite", isFinite);
107  }
108 
111  {
113  int m_refinement = 2000;
114 
116  int n_refinement = 40;
117 
120 
122  double smoothing_parameter = 0.5;
123 
125  double attraction_parameter = 0.0;
126  };
127 
128  inline static void CheckCurvilinearParameters(CurvilinearParameters const& parameters)
129  {
130  range_check::CheckGreater(parameters.m_refinement, 0, " M-refinement factor");
131  range_check::CheckGreater(parameters.n_refinement, 0, "N-refinement factor");
132  range_check::CheckGreater(parameters.smoothing_iterations, 0, "Smoothing iterations");
133  range_check::CheckInClosedInterval(parameters.smoothing_parameter, {0.0, 1.0}, "Smoothing parameter"); // CHECK ME
134  range_check::CheckGreaterEqual(parameters.attraction_parameter, 0.0, "Attraction parameter"); // CHECK ME
135  }
136 
139  {
141  double aspect_ratio = 0.1;
142 
145 
147  double average_width = 500.0;
148 
151 
154 
157 
160 
163 
166 
169  };
170 
171  inline static void CheckSplinesToCurvilinearParameters(SplinesToCurvilinearParameters const& parameters)
172  {
173  range_check::CheckGreater(parameters.aspect_ratio, 0.0, "Aspect ratio");
174  range_check::CheckGreater(parameters.aspect_ratio_grow_factor, 0.0, "Aspect ratio grow factor");
175  range_check::CheckGreater(parameters.average_width, 0.0, "Average width");
176  range_check::CheckOneOf(parameters.curvature_adapted_grid_spacing, {0, 1}, "Curvature adapted grid spacing");
177  range_check::CheckOneOf(parameters.grow_grid_outside, {0, 1}, "Grow grid outside");
178  range_check::CheckGreater(parameters.maximum_num_faces_in_uniform_part, 0, "Max number of faces in uniform part");
179  range_check::CheckGreater(parameters.nodes_on_top_of_each_other_tolerance, 0.0, "nodes on top of each other tolerance");
180  range_check::CheckGreater(parameters.min_cosine_crossing_angles, 0.0, "Min cosine crossing angles");
181  range_check::CheckOneOf(parameters.check_front_collisions, {0, 1}, "Check front collisions");
182  range_check::CheckOneOf(parameters.remove_skinny_triangles, {0, 1}, "Remove skinny triangles");
183  }
184 
187  {
190 
193 
196 
198  double min_edge_size = 0.5;
199 
202 
205 
208 
211 
213  double max_courant_time = 120.0;
214 
217  };
218 
219  inline static void CheckMeshRefinementParameters(MeshRefinementParameters const& parameters)
220  {
221  range_check::CheckGreater(parameters.max_num_refinement_iterations, 0, "Max num refinement iterations");
222  range_check::CheckOneOf(parameters.refine_intersected, {0, 1}, "Refine intersected");
223  range_check::CheckOneOf(parameters.use_mass_center_when_refining, {0, 1}, "Use mass center when refining");
224  range_check::CheckGreater(parameters.min_edge_size, 0.0, "Min edge size");
225  // Move enum meshkernel::MeshRefinement::RefinementType out of meshkernel::MeshRefinement
226  // then use the underlying type of the enums to define ValidMeshRefinementTypes
227  static std::vector<int> const ValidMeshRefinementTypes{1, 2, 3};
228  range_check::CheckOneOf(parameters.refinement_type, ValidMeshRefinementTypes, "Refinement type");
229  range_check::CheckOneOf(parameters.connect_hanging_nodes, {0, 1}, "Connect hanging nodes");
230  range_check::CheckOneOf(parameters.account_for_samples_outside, {0, 1}, "Account for samples outside");
231  range_check::CheckGreaterEqual(parameters.smoothing_iterations, 0, "Smoothing iterations");
232  range_check::CheckGreater(parameters.max_courant_time, 0.0, "Max courant time");
233  range_check::CheckOneOf(parameters.directional_refinement, {0, 1}, "Directional refinement");
234  }
235 
238  {
241 
244 
247 
250 
253 
256  };
257 
258  inline static void CheckOrthogonalizationParameters(OrthogonalizationParameters const& parameters)
259  {
260  range_check::CheckGreater(parameters.outer_iterations, 0, "Outer iterations");
261  range_check::CheckGreater(parameters.boundary_iterations, 0, "Boundary iterations");
262  range_check::CheckGreater(parameters.inner_iterations, 0, "Inner iterations");
263  range_check::CheckInClosedInterval(parameters.orthogonalization_to_smoothing_factor, {0.0, 1.0}, "Orthogonalization-to-smoothing_factor");
264  range_check::CheckInClosedInterval(parameters.orthogonalization_to_smoothing_factor_at_boundary, {0.0, 1.0}, "orthogonalization-to-smoothing factor at boundary");
265  range_check::CheckInClosedInterval(parameters.areal_to_angle_smoothing_factor, {0.0, 1.0}, "area to angle smoothing factor");
266  }
267 
268 } // namespace meshkernel
meshkernel::MakeGridParameters::num_columns
int num_columns
The number of columns in x direction.
Definition: Parameters.hpp:40
meshkernel::SplinesToCurvilinearParameters::average_width
double average_width
Average mesh width on center spline.
Definition: Parameters.hpp:147
meshkernel::MakeGridParameters::angle
double angle
The grid angle.
Definition: Parameters.hpp:46
meshkernel::MakeGridParameters::uniform_rows_fraction
double uniform_rows_fraction
Fraction of cells containing the default grid row size.
Definition: Parameters.hpp:75
meshkernel::OrthogonalizationParameters::boundary_iterations
int boundary_iterations
Number of boundary iterations in grid/net orthogonalization within itatp.
Definition: Parameters.hpp:243
meshkernel::SplinesToCurvilinearParameters::remove_skinny_triangles
int remove_skinny_triangles
Check for collisions with other parts of the front.
Definition: Parameters.hpp:168
meshkernel::OrthogonalizationParameters::areal_to_angle_smoothing_factor
double areal_to_angle_smoothing_factor
Factor between smoother 1d0 and area-homogenizer 0d0.
Definition: Parameters.hpp:255
meshkernel::SplinesToCurvilinearParameters::check_front_collisions
int check_front_collisions
Check for collisions with other parts of the front, 1 or not 0.
Definition: Parameters.hpp:165
meshkernel::OrthogonalizationParameters::inner_iterations
int inner_iterations
Number of inner iterations in grid/net orthogonalization within itbnd.
Definition: Parameters.hpp:246
meshkernel::SplinesToCurvilinearParameters
A struct used to describe the spline to curvilinear grid parameters in a C-compatible manner.
Definition: Parameters.hpp:138
meshkernel::MeshRefinementParameters::refinement_type
int refinement_type
Refinement criterion type.
Definition: Parameters.hpp:201
meshkernel::MakeGridParameters::block_size_y
double block_size_y
The grid block size in y dimension, used only for squared grids.
Definition: Parameters.hpp:58
meshkernel::MeshRefinementParameters::directional_refinement
int directional_refinement
Directional refinement, cannot be used when the number of smoothing iterations is larger than 0.
Definition: Parameters.hpp:216
meshkernel::MakeGridParameters::maximum_uniform_size_rows
double maximum_uniform_size_rows
Maximum element row size.
Definition: Parameters.hpp:81
meshkernel::CurvilinearParameters::smoothing_iterations
int smoothing_iterations
Nr. of inner iterations in regular grid smoothing.
Definition: Parameters.hpp:119
meshkernel::MakeGridParameters::origin_x
double origin_x
The x coordinate of the origin, located at the bottom left corner.
Definition: Parameters.hpp:49
meshkernel::MakeGridParameters::upper_right_x
double upper_right_x
The x coordinate of the upper right corner.
Definition: Parameters.hpp:61
meshkernel::OrthogonalizationParameters::orthogonalization_to_smoothing_factor_at_boundary
double orthogonalization_to_smoothing_factor_at_boundary
Minimum ATPF on the boundary.
Definition: Parameters.hpp:252
meshkernel::OrthogonalizationParameters::outer_iterations
int outer_iterations
Number of outer iterations in orthogonalization. Increase this parameter for complex grids.
Definition: Parameters.hpp:240
meshkernel::MakeGridParameters
This struct describes the necessary parameters to create a new curvilinear grid in a C-compatible man...
Definition: Parameters.hpp:37
meshkernel::MakeGridParameters::radius_curvature
double radius_curvature
Radius of curvature.
Definition: Parameters.hpp:67
meshkernel::SplinesToCurvilinearParameters::aspect_ratio
double aspect_ratio
Aspect ratio (mfacmax)
Definition: Parameters.hpp:141
meshkernel::CurvilinearParameters::smoothing_parameter
double smoothing_parameter
Smoothing parameter.
Definition: Parameters.hpp:122
meshkernel::CurvilinearParameters
A struct used to describe parameters for generating a curvilinear grid in a C-compatible manner.
Definition: Parameters.hpp:110
meshkernel::CurvilinearParameters::n_refinement
int n_refinement
N-refinement factor for regular grid generation (nfacmax)
Definition: Parameters.hpp:116
meshkernel::MakeGridParameters::maximum_uniform_size_columns
double maximum_uniform_size_columns
Maximum element column size.
Definition: Parameters.hpp:78
meshkernel::MeshRefinementParameters::min_edge_size
double min_edge_size
Minimum edge size in meters.
Definition: Parameters.hpp:198
meshkernel
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
meshkernel::CurvilinearParameters::attraction_parameter
double attraction_parameter
Attraction/repulsion parameter.
Definition: Parameters.hpp:125
meshkernel::OrthogonalizationParameters::orthogonalization_to_smoothing_factor
double orthogonalization_to_smoothing_factor
Factor from 0 to 1. between grid smoothing and grid orthogonality.
Definition: Parameters.hpp:249
meshkernel::SplinesToCurvilinearParameters::min_cosine_crossing_angles
double min_cosine_crossing_angles
Minimum allowed absolute value of crossing-angle cosine.
Definition: Parameters.hpp:162
meshkernel::CurvilinearParameters::m_refinement
int m_refinement
M-refinement factor for regular grid generation (mfacmax)
Definition: Parameters.hpp:113
meshkernel::MeshRefinementParameters
A struct used to describe the mesh refinement parameters in a C-compatible manner.
Definition: Parameters.hpp:186
meshkernel::MeshRefinementParameters::smoothing_iterations
int smoothing_iterations
The number of smoothing iterations.
Definition: Parameters.hpp:210
meshkernel::SplinesToCurvilinearParameters::aspect_ratio_grow_factor
double aspect_ratio_grow_factor
Grow factor of aspect ratio.
Definition: Parameters.hpp:144
meshkernel::SplinesToCurvilinearParameters::maximum_num_faces_in_uniform_part
int maximum_num_faces_in_uniform_part
Maximum number of layers in the uniform part.
Definition: Parameters.hpp:156
meshkernel::MeshRefinementParameters::connect_hanging_nodes
int connect_hanging_nodes
Connect hanging nodes at the end of the iteration, 1 yes or 0 no.
Definition: Parameters.hpp:204
meshkernel::MakeGridParameters::origin_y
double origin_y
The y coordinate of the origin, located at the bottom left corner.
Definition: Parameters.hpp:52
meshkernel::MakeGridParameters::upper_right_y
double upper_right_y
The y coordinate of the upper right corner.
Definition: Parameters.hpp:64
meshkernel::MeshRefinementParameters::refine_intersected
int refine_intersected
Whether to compute faces intersected by polygon (yes=1/no=0)
Definition: Parameters.hpp:192
meshkernel::MeshRefinementParameters::use_mass_center_when_refining
int use_mass_center_when_refining
Whether to use the mass center when splitting a face in the refinement process (yes=1/no=0)
Definition: Parameters.hpp:195
meshkernel::MakeGridParameters::uniform_columns_fraction
double uniform_columns_fraction
Fraction of cells containing the default grid column size.
Definition: Parameters.hpp:72
meshkernel::MeshRefinementParameters::max_num_refinement_iterations
int max_num_refinement_iterations
Maximum number of refinement iterations, set to 1 if only one refinement is wanted.
Definition: Parameters.hpp:189
meshkernel::MeshRefinementParameters::account_for_samples_outside
int account_for_samples_outside
Take samples outside face into account , 1 yes 0 no.
Definition: Parameters.hpp:207
meshkernel::MeshRefinementParameters::max_courant_time
double max_courant_time
Maximum courant time in seconds.
Definition: Parameters.hpp:213
meshkernel::MakeGridParameters::block_size_x
double block_size_x
The grid block size in x dimension, used only for squared grids.
Definition: Parameters.hpp:55
meshkernel::SplinesToCurvilinearParameters::nodes_on_top_of_each_other_tolerance
double nodes_on_top_of_each_other_tolerance
On-top-of-each-other tolerance.
Definition: Parameters.hpp:159
meshkernel::SplinesToCurvilinearParameters::grow_grid_outside
int grow_grid_outside
Grow the grid outside the prescribed grid height.
Definition: Parameters.hpp:153
meshkernel::MakeGridParameters::num_rows
int num_rows
The number of rows in y direction.
Definition: Parameters.hpp:43
meshkernel::OrthogonalizationParameters
A struct used to describe the orthogonalization parameters in a C-compatible manner.
Definition: Parameters.hpp:237
meshkernel::SplinesToCurvilinearParameters::curvature_adapted_grid_spacing
int curvature_adapted_grid_spacing
Curvature adapted grid spacing, 1 or not 0.
Definition: Parameters.hpp:150