deal.II version 9.7.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
grid_generator_from_name.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
16
18
20
21namespace GridGenerator
22{
23 namespace
24 {
31 template <int dim, int spacedim, class... Arguments>
32 void
33 parse_and_create(void (*generator)(Triangulation<dim, spacedim> &,
34 Arguments...),
35 const std::string &arguments,
36 Triangulation<dim, spacedim> &tria)
37 {
38 std::function<void(Arguments...)> wrapper =
39 [&tria, &generator](Arguments... args) { generator(tria, args...); };
40 auto bound_function = Utilities::mutable_bind(wrapper);
41 bound_function.parse_arguments(arguments);
42 bound_function();
43 }
44
45
51 template <int dim, int spacedim>
52 std::enable_if_t<dim != spacedim, bool>
53 generate_codimension_zero_grid(const std::string &,
54 const std::string &,
55 Triangulation<dim, spacedim> &)
56 {
57 return false;
58 }
59
65 template <int dim>
66 bool
67 generate_codimension_zero_grid(const std::string &name,
68 const std::string &arguments,
69 Triangulation<dim> &tria)
70 {
71 if (name == "simplex")
72 parse_and_create<dim, dim, const std::vector<Point<dim>> &>(simplex,
73 arguments,
74 tria);
75 else if (name == "subdivided_hyper_rectangle")
76 {
77 // subdivided_hyper_rectangle is polymorphic, and can be called with
78 // different sets of arguments. We support two of these function
79 // calls. We try the first one, and if parsing fails, we go to the
80 // second one.
81 try
82 {
83 parse_and_create<dim,
84 dim,
85 const std::vector<unsigned int> &,
86 const Point<dim> &,
87 const Point<dim> &,
89 arguments,
90 tria);
91 }
93 {
94 parse_and_create<dim,
95 dim,
96 const std::vector<std::vector<double>> &,
97 const Point<dim> &,
98 const Point<dim> &,
100 arguments,
101 tria);
102 }
103 }
104 else if (name == "plate_with_a_hole")
105 parse_and_create<dim,
106 dim,
107 double,
108 double,
109 double,
110 double,
111 double,
112 double,
113 const Point<dim> &,
116 double,
117 unsigned int,
118 bool>(plate_with_a_hole, arguments, tria);
119 else if (name == "channel_with_cylinder")
120 parse_and_create<dim, dim, double, unsigned int, double, bool>(
121 channel_with_cylinder, arguments, tria);
122 else if (name == "uniform_channel_with_cylinder")
123 parse_and_create<dim,
124 dim,
125 const std::vector<unsigned int> &,
126 double,
127 unsigned int,
128 double,
129 unsigned int,
130 double,
131 bool,
132 bool>(uniform_channel_with_cylinder, arguments, tria);
133 else if (name == "enclosed_hyper_cube")
134 parse_and_create<dim, dim, double, double, double, bool>(
135 enclosed_hyper_cube, arguments, tria);
136
137 else if (name == "hyper_ball")
138 parse_and_create<dim, dim, const Point<dim> &, double, bool>(hyper_ball,
139 arguments,
140 tria);
141 else if (name == "hyper_ball_balanced")
142 parse_and_create<dim, dim, const Point<dim> &, double>(
143 hyper_ball_balanced, arguments, tria);
144
145 else if (name == "quarter_hyper_ball")
146 parse_and_create<dim, dim, const Point<dim> &, double>(
147 quarter_hyper_ball, arguments, tria);
148
149 else if (name == "half_hyper_ball")
150 parse_and_create<dim, dim, const Point<dim> &, double>(half_hyper_ball,
151 arguments,
152 tria);
153
154 else if (name == "cylinder")
155 parse_and_create<dim, dim, double, double>(cylinder, arguments, tria);
156
157 else if (name == "subdivided_cylinder")
158 parse_and_create<dim, dim, unsigned int, double, double>(
159 subdivided_cylinder, arguments, tria);
160
161 else if (name == "truncated_cone")
162 parse_and_create<dim, dim, double, double, double>(truncated_cone,
163 arguments,
164 tria);
165
166 else if (name == "pipe_junction")
167 parse_and_create<dim,
168 dim,
169 const std::vector<std::pair<Point<dim>, double>> &,
170 const std::pair<Point<dim>, double> &,
171 double>(pipe_junction, arguments, tria);
172
173 else if (name == "hyper_L")
174 parse_and_create<dim, dim, double, double, bool>(hyper_L,
175 arguments,
176 tria);
177
178 else if (name == "hyper_cube_slit")
179 parse_and_create<dim, dim, double, double, bool>(hyper_cube_slit,
180 arguments,
181 tria);
182
183 else if (name == "hyper_shell")
184 parse_and_create<dim,
185 dim,
186 const Point<dim> &,
187 double,
188 double,
189 unsigned int,
190 bool>(hyper_shell, arguments, tria);
191
192 else if (name == "half_hyper_shell")
193 parse_and_create<dim,
194 dim,
195 const Point<dim> &,
196 double,
197 double,
198 unsigned int,
199 bool>(half_hyper_shell, arguments, tria);
200
201 else if (name == "quarter_hyper_shell")
202 parse_and_create<dim,
203 dim,
204 const Point<dim> &,
205 double,
206 double,
207 unsigned int,
208 bool>(quarter_hyper_shell, arguments, tria);
209
210 else if (name == "eccentric_hyper_shell")
211 parse_and_create<dim,
212 dim,
213 const Point<dim> &,
214 const Point<dim> &,
215 double,
216 double,
217 unsigned int>(eccentric_hyper_shell, arguments, tria);
218
219 else if (name == "cylinder_shell")
220 parse_and_create<dim,
221 dim,
222 double,
223 double,
224 double,
225 unsigned int,
226 unsigned int,
227 bool>(cylinder_shell, arguments, tria);
228
229 else if (name == "hyper_cube_with_cylindrical_hole")
230 parse_and_create<dim, dim, double, double, double, unsigned int, bool>(
231 hyper_cube_with_cylindrical_hole, arguments, tria);
232
233 else if (name == "concentric_hyper_shells")
234 parse_and_create<dim,
235 dim,
236 const Point<dim> &,
237 double,
238 double,
239 unsigned int,
240 double,
241 unsigned int,
242 bool>(concentric_hyper_shells, arguments, tria);
243
244 else if (name == "subdivided_hyper_cube_with_simplices")
245 parse_and_create<dim, dim, unsigned int, double, double, bool>(
246 subdivided_hyper_cube_with_simplices, arguments, tria);
247
248 else if (name == "subdivided_hyper_rectangle_with_simplices")
249 parse_and_create<dim,
250 dim,
251 const std::vector<unsigned int> &,
252 const Point<dim> &,
253 const Point<dim> &,
255 arguments,
256 tria);
257
258 else if (name == "subdivided_hyper_L")
259 parse_and_create<dim,
260 dim,
261 const std::vector<unsigned int> &,
262 const Point<dim> &,
263 const Point<dim> &,
264 const std::vector<int> &>(subdivided_hyper_L,
265 arguments,
266 tria);
267
268 else
269 return false;
270
271 return true;
272 }
273
274
280 template <int dim, int spacedim>
281 std::enable_if_t<dim != spacedim - 1, bool>
282 generate_codimension_one_grid(const std::string &,
283 const std::string &,
284 Triangulation<dim, spacedim> &)
285 {
286 return false;
287 }
288
294 template <int dim>
295 bool
296 generate_codimension_one_grid(const std::string &name,
297 const std::string &arguments,
298 Triangulation<dim, dim + 1> &tria)
299 {
300 if (name == "hyper_sphere")
301 parse_and_create<dim, dim + 1, const Point<dim + 1> &, double>(
302 hyper_sphere, arguments, tria);
303 else
304 return false;
305 return true;
306 }
307
313 template <int dim, int spacedim>
314 bool
315 generate_special(const std::string &,
316 const std::string &,
317 Triangulation<dim, spacedim> &)
318 {
319 return false;
320 }
321
327 bool
328 generate_special(const std::string &name,
329 const std::string &arguments,
330 Triangulation<3, 3> &tria)
331 {
332 if (name == "moebius")
333 parse_and_create<3, 3, unsigned int, unsigned int, double, double>(
334 moebius, arguments, tria);
335 else if (name == "torus")
336 parse_and_create<3, 3, double, double, unsigned int, double>(torus,
337 arguments,
338 tria);
339 else
340 {
341 return false;
342 }
343 return true;
344 }
345
351 bool
352 generate_special(const std::string &name,
353 const std::string &arguments,
354 Triangulation<2, 3> &tria)
355 {
356 if (name == "torus")
357 parse_and_create<2, 3, double, double, unsigned int, double>(torus,
358 arguments,
359 tria);
360 else
361 {
362 return false;
363 }
364 return true;
365 }
366 } // namespace
367
368
369
370 template <int dim, int spacedim>
371 void
373 const std::string &name,
374 const std::string &arguments)
375 {
376 // We begin with all function calls that are implemented for all
377 // combinations of dim and spacedim.
378 if (name == "hyper_cube")
379 parse_and_create<dim, spacedim, double, double, bool>(hyper_cube,
380 arguments,
381 tria);
382 else if (name == "subdivided_hyper_cube")
383 parse_and_create<dim, spacedim, unsigned int, double, double, bool>(
384 subdivided_hyper_cube, arguments, tria);
385 else if (name == "hyper_rectangle")
386 parse_and_create<dim,
387 spacedim,
388 const Point<dim> &,
389 const Point<dim> &,
390 bool>(hyper_rectangle, arguments, tria);
391 else if (name == "cheese")
392 parse_and_create<dim, spacedim, const std::vector<unsigned int> &>(
393 cheese, arguments, tria);
394 else if (name == "general_cell")
395 parse_and_create<dim,
396 spacedim,
397 const std::vector<Point<spacedim>> &,
398 bool>(general_cell, arguments, tria);
399 else if (name == "hyper_cross")
400 parse_and_create<dim, spacedim, const std::vector<unsigned int> &, bool>(
401 hyper_cross, arguments, tria);
402 // If none of the above worked, than we try with more specific function
403 // calls. First we try to call functions that are only implemented when
404 // dim == spacedim, then when dim == spacedim-1, and lastly, we try to see
405 // if the name, dim, and spacedim match some of the very special grid
406 // generator functions, like torus, moebius, etc.
407 //
408 // If one of the function call succeeds, we skip the rest and return.
409 else if (generate_codimension_zero_grid(name, arguments, tria))
410 {
411 }
412 else if (generate_codimension_one_grid(name, arguments, tria))
413 {
414 }
415 else if (generate_special(name, arguments, tria))
416 {
417 }
418 else
419 // If we got here, we really have no idea what grid the user wants to
420 // generate.
421 AssertThrow(false,
422 ExcMessage(name + "(" + arguments + ") not implemented"));
423 }
424} // namespace GridGenerator
425
426#include "grid/grid_generator_from_name.inst"
427
Definition point.h:113
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
static ::ExceptionBase & ExcNoMatch(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void subdivided_hyper_cube_with_simplices(Triangulation< dim, spacedim > &tria, const unsigned int repetitions, const double p1=0.0, const double p2=1.0, const bool colorize=false)
void hyper_cross(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &sizes, const bool colorize_cells=false)
A center cell with stacks of cell protruding from each surface.
void hyper_cube_with_cylindrical_hole(Triangulation< dim, spacedim > &triangulation, const double inner_radius=.25, const double outer_radius=.5, const double L=.5, const unsigned int repetitions=1, const bool colorize=false)
void hyper_ball_balanced(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
void plate_with_a_hole(Triangulation< dim > &tria, const double inner_radius=0.4, const double outer_radius=1., const double pad_bottom=2., const double pad_top=2., const double pad_left=1., const double pad_right=1., const Point< dim > &center=Point< dim >(), const types::manifold_id polar_manifold_id=0, const types::manifold_id tfi_manifold_id=1, const double L=1., const unsigned int n_slices=2, const bool colorize=false)
Rectangular plate with an (offset) cylindrical hole.
void generate_from_name_and_arguments(Triangulation< dim, spacedim > &tria, const std::string &grid_generator_function_name, const std::string &grid_generator_function_arguments)
void enclosed_hyper_cube(Triangulation< dim > &tria, const double left=0., const double right=1., const double thickness=1., const bool colorize=false)
void general_cell(Triangulation< dim, spacedim > &tria, const std::vector< Point< spacedim > > &vertices, const bool colorize=false)
void subdivided_hyper_cube(Triangulation< dim, spacedim > &tria, const unsigned int repetitions, const double left=0., const double right=1., const bool colorize=false)
void hyper_shell(Triangulation< dim, spacedim > &tria, const Point< spacedim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, bool colorize=false)
void hyper_L(Triangulation< dim > &tria, const double left=-1., const double right=1., const bool colorize=false)
void hyper_cube_slit(Triangulation< dim > &tria, const double left=0., const double right=1., const bool colorize=false)
void eccentric_hyper_shell(Triangulation< dim > &triangulation, const Point< dim > &inner_center, const Point< dim > &outer_center, const double inner_radius, const double outer_radius, const unsigned int n_cells)
void hyper_rectangle(Triangulation< dim, spacedim > &tria, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void uniform_channel_with_cylinder(Triangulation< dim > &tria, const std::vector< unsigned int > &lengths_and_heights, const double depth=1, const unsigned int depth_division=1, const double shell_region_radius=0.75, const unsigned int n_shells=2, const double skewness=2.0, const bool use_transfinite_region=false, const bool colorize=false)
void cylinder(Triangulation< dim > &tria, const double radius=1., const double half_length=1.)
void moebius(Triangulation< 3, 3 > &tria, const unsigned int n_cells, const unsigned int n_rotations, const double R, const double r)
void pipe_junction(Triangulation< dim, spacedim > &tria, const std::vector< std::pair< Point< spacedim >, double > > &openings, const std::pair< Point< spacedim >, double > &bifurcation, const double aspect_ratio=0.5)
void half_hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, const bool colorize=false)
void quarter_hyper_ball(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
void cheese(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &holes)
Rectangular domain with rectangular pattern of holes.
void hyper_ball(Triangulation< dim, spacedim > &tria, const Point< spacedim > &center={}, const double radius=1., const bool attach_spherical_manifold_on_boundary_cells=false)
void subdivided_hyper_rectangle_with_simplices(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void subdivided_cylinder(Triangulation< dim > &tria, const unsigned int x_subdivisions, const double radius=1., const double half_length=1.)
void channel_with_cylinder(Triangulation< dim > &tria, const double shell_region_width=0.03, const unsigned int n_shells=2, const double skewness=2.0, const bool colorize=false)
void subdivided_hyper_L(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &bottom_left, const Point< dim > &top_right, const std::vector< int > &n_cells_to_remove)
void hyper_sphere(Triangulation< spacedim - 1, spacedim > &tria, const Point< spacedim > &center=Point< spacedim >(), const double radius=1.)
void concentric_hyper_shells(Triangulation< dim > &triangulation, const Point< dim > &center, const double inner_radius=0.125, const double outer_radius=0.25, const unsigned int n_shells=1, const double skewness=0.1, const unsigned int n_cells_per_shell=0, const bool colorize=false)
void subdivided_hyper_rectangle(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &repetitions, const Point< dim > &p1, const Point< dim > &p2, const bool colorize=false)
void quarter_hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, const bool colorize=false)
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
void torus(Triangulation< dim, spacedim > &tria, const double centerline_radius, const double inner_radius, const unsigned int n_cells_toroidal=6, const double phi=2.0 *numbers::PI)
void simplex(Triangulation< dim, dim > &tria, const std::vector< Point< dim > > &vertices)
void truncated_cone(Triangulation< dim > &tria, const double radius_0=1.0, const double radius_1=0.5, const double half_length=1.0)
void half_hyper_ball(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
void cylinder_shell(Triangulation< dim > &tria, const double length, const double inner_radius, const double outer_radius, const unsigned int n_radial_cells=0, const unsigned int n_axial_cells=0, const bool colorize=false)
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), std_cxx20::type_identity_t< FunctionArgs > &&...arguments)
unsigned int manifold_id
Definition types.h:173