deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\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: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2019 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
14
16
18
19namespace GridGenerator
20{
21 namespace
22 {
29 template <int dim, int spacedim, class... Arguments>
30 void
31 parse_and_create(void (*generator)(Triangulation<dim, spacedim> &,
32 Arguments...),
33 const std::string &arguments,
35 {
36 std::function<void(Arguments...)> wrapper =
37 [&tria, &generator](Arguments... args) { generator(tria, args...); };
38 auto bound_function = Utilities::mutable_bind(wrapper);
39 bound_function.parse_arguments(arguments);
40 bound_function();
41 }
42
43
49 template <int dim, int spacedim>
50 std::enable_if_t<dim != spacedim, bool>
51 generate_codimension_zero_grid(const std::string &,
52 const std::string &,
54 {
55 return false;
56 }
57
63 template <int dim>
64 bool
65 generate_codimension_zero_grid(const std::string &name,
66 const std::string &arguments,
68 {
69 if (name == "simplex")
70 parse_and_create<dim, dim, const std::vector<Point<dim>> &>(simplex,
71 arguments,
72 tria);
73 else if (name == "subdivided_hyper_rectangle")
74 {
75 // subdivided_hyper_rectangle is polymorphic, and can be called with
76 // different sets of arguments. We support two of these function
77 // calls. We try the first one, and if parsing fails, we go to the
78 // second one.
79 try
80 {
81 parse_and_create<dim,
82 dim,
83 const std::vector<unsigned int> &,
84 const Point<dim> &,
85 const Point<dim> &,
87 arguments,
88 tria);
89 }
91 {
92 parse_and_create<dim,
93 dim,
94 const std::vector<std::vector<double>> &,
95 const Point<dim> &,
96 const Point<dim> &,
98 arguments,
99 tria);
100 }
101 }
102 else if (name == "plate_with_a_hole")
103 parse_and_create<dim,
104 dim,
105 double,
106 double,
107 double,
108 double,
109 double,
110 double,
111 const Point<dim> &,
114 double,
115 unsigned int,
116 bool>(plate_with_a_hole, arguments, tria);
117 else if (name == "channel_with_cylinder")
118 parse_and_create<dim, dim, double, unsigned int, double, bool>(
119 channel_with_cylinder, arguments, tria);
120 else if (name == "uniform_channel_with_cylinder")
121 parse_and_create<dim,
122 dim,
123 const std::vector<unsigned int> &,
124 double,
125 unsigned int,
126 double,
127 unsigned int,
128 double,
129 bool,
130 bool>(uniform_channel_with_cylinder, arguments, tria);
131 else if (name == "uniform_channel_with_sphere")
132 parse_and_create<dim,
133 dim,
134 const std::vector<unsigned int> &,
135 const double,
136 const double,
137 const bool,
138 const bool>(uniform_channel_with_sphere,
139 arguments,
140 tria);
141 else if (name == "hyper_cube_with_spherical_hole")
142 parse_and_create<dim, dim, const double, const double, const bool>(
143 hyper_cube_with_spherical_hole, arguments, tria);
144 else if (name == "enclosed_hyper_cube")
145 parse_and_create<dim, dim, double, double, double, bool>(
146 enclosed_hyper_cube, arguments, tria);
147
148 else if (name == "hyper_ball")
149 parse_and_create<dim, dim, const Point<dim> &, double, bool>(hyper_ball,
150 arguments,
151 tria);
152 else if (name == "hyper_ball_balanced")
153 parse_and_create<dim, dim, const Point<dim> &, double>(
154 hyper_ball_balanced, arguments, tria);
155
156 else if (name == "quarter_hyper_ball")
157 parse_and_create<dim, dim, const Point<dim> &, double>(
158 quarter_hyper_ball, arguments, tria);
159
160 else if (name == "half_hyper_ball")
161 parse_and_create<dim, dim, const Point<dim> &, double>(half_hyper_ball,
162 arguments,
163 tria);
164
165 else if (name == "cylinder")
166 parse_and_create<dim, dim, double, double>(cylinder, arguments, tria);
167
168 else if (name == "subdivided_cylinder")
169 parse_and_create<dim, dim, unsigned int, double, double>(
170 subdivided_cylinder, arguments, tria);
171
172 else if (name == "truncated_cone")
173 parse_and_create<dim, dim, double, double, double>(truncated_cone,
174 arguments,
175 tria);
176
177 else if (name == "pipe_junction")
178 parse_and_create<dim,
179 dim,
180 const std::vector<std::pair<Point<dim>, double>> &,
181 const std::pair<Point<dim>, double> &,
182 double>(pipe_junction, arguments, tria);
183
184 else if (name == "hyper_L")
185 parse_and_create<dim, dim, double, double, bool>(hyper_L,
186 arguments,
187 tria);
188
189 else if (name == "hyper_cube_slit")
190 parse_and_create<dim, dim, double, double, bool>(hyper_cube_slit,
191 arguments,
192 tria);
193
194 else if (name == "hyper_shell")
195 parse_and_create<dim,
196 dim,
197 const Point<dim> &,
198 double,
199 double,
200 unsigned int,
201 bool>(hyper_shell, arguments, tria);
202
203 else if (name == "half_hyper_shell")
204 parse_and_create<dim,
205 dim,
206 const Point<dim> &,
207 double,
208 double,
209 unsigned int,
210 bool>(half_hyper_shell, arguments, tria);
211
212 else if (name == "quarter_hyper_shell")
213 parse_and_create<dim,
214 dim,
215 const Point<dim> &,
216 double,
217 double,
218 unsigned int,
219 bool>(quarter_hyper_shell, arguments, tria);
220
221 else if (name == "eccentric_hyper_shell")
222 parse_and_create<dim,
223 dim,
224 const Point<dim> &,
225 const Point<dim> &,
226 double,
227 double,
228 unsigned int>(eccentric_hyper_shell, arguments, tria);
229
230 else if (name == "cylinder_shell")
231 parse_and_create<dim,
232 dim,
233 double,
234 double,
235 double,
236 unsigned int,
237 unsigned int,
238 bool>(cylinder_shell, arguments, tria);
239
240 else if (name == "hyper_cube_with_cylindrical_hole")
241 parse_and_create<dim, dim, double, double, double, unsigned int, bool>(
242 hyper_cube_with_cylindrical_hole, arguments, tria);
243
244 else if (name == "concentric_hyper_shells")
245 parse_and_create<dim,
246 dim,
247 const Point<dim> &,
248 double,
249 double,
250 unsigned int,
251 double,
252 unsigned int,
253 bool>(concentric_hyper_shells, arguments, tria);
254
255 else if (name == "subdivided_hyper_cube_with_simplices")
256 parse_and_create<dim, dim, unsigned int, double, double, bool>(
257 subdivided_hyper_cube_with_simplices, arguments, tria);
258
259 else if (name == "subdivided_hyper_rectangle_with_simplices")
260 parse_and_create<dim,
261 dim,
262 const std::vector<unsigned int> &,
263 const Point<dim> &,
264 const Point<dim> &,
266 arguments,
267 tria);
268
269 else if (name == "subdivided_hyper_L")
270 parse_and_create<dim,
271 dim,
272 const std::vector<unsigned int> &,
273 const Point<dim> &,
274 const Point<dim> &,
275 const std::vector<int> &>(subdivided_hyper_L,
276 arguments,
277 tria);
278
279 else
280 return false;
281
282 return true;
283 }
284
285
291 template <int dim, int spacedim>
292 std::enable_if_t<dim != spacedim - 1, bool>
293 generate_codimension_one_grid(const std::string &,
294 const std::string &,
296 {
297 return false;
298 }
299
305 template <int dim>
306 bool
307 generate_codimension_one_grid(const std::string &name,
308 const std::string &arguments,
310 {
311 if (name == "hyper_sphere")
312 parse_and_create<dim, dim + 1, const Point<dim + 1> &, double>(
313 hyper_sphere, arguments, tria);
314 else
315 return false;
316 return true;
317 }
318
324 template <int dim, int spacedim>
325 bool
326 generate_special(const std::string &,
327 const std::string &,
329 {
330 return false;
331 }
332
338 bool
339 generate_special(const std::string &name,
340 const std::string &arguments,
342 {
343 if (name == "moebius")
344 parse_and_create<3, 3, unsigned int, unsigned int, double, double>(
345 moebius, arguments, tria);
346 else if (name == "torus")
347 parse_and_create<3, 3, double, double, unsigned int, double>(torus,
348 arguments,
349 tria);
350 else
351 {
352 return false;
353 }
354 return true;
355 }
356
362 bool
363 generate_special(const std::string &name,
364 const std::string &arguments,
366 {
367 if (name == "torus")
368 parse_and_create<2, 3, double, double, unsigned int, double>(torus,
369 arguments,
370 tria);
371 else
372 {
373 return false;
374 }
375 return true;
376 }
377 } // namespace
378
379
380
381 template <int dim, int spacedim>
382 void
384 const std::string &name,
385 const std::string &arguments)
386 {
387 // We begin with all function calls that are implemented for all
388 // combinations of dim and spacedim.
389 if (name == "hyper_cube")
390 parse_and_create<dim, spacedim, double, double, bool>(hyper_cube,
391 arguments,
392 tria);
393 else if (name == "subdivided_hyper_cube")
394 parse_and_create<dim, spacedim, unsigned int, double, double, bool>(
395 subdivided_hyper_cube, arguments, tria);
396 else if (name == "hyper_rectangle")
397 parse_and_create<dim,
398 spacedim,
399 const Point<dim> &,
400 const Point<dim> &,
401 bool>(hyper_rectangle, arguments, tria);
402 else if (name == "cheese")
403 parse_and_create<dim, spacedim, const std::vector<unsigned int> &>(
404 cheese, arguments, tria);
405 else if (name == "general_cell")
406 parse_and_create<dim,
407 spacedim,
408 const std::vector<Point<spacedim>> &,
409 bool>(general_cell, arguments, tria);
410 else if (name == "hyper_cross")
411 parse_and_create<dim, spacedim, const std::vector<unsigned int> &, bool>(
412 hyper_cross, arguments, tria);
413 // If none of the above worked, than we try with more specific function
414 // calls. First we try to call functions that are only implemented when
415 // dim == spacedim, then when dim == spacedim-1, and lastly, we try to see
416 // if the name, dim, and spacedim match some of the very special grid
417 // generator functions, like torus, moebius, etc.
418 //
419 // If one of the function call succeeds, we skip the rest and return.
420 else if (generate_codimension_zero_grid(name, arguments, tria))
421 {
422 }
423 else if (generate_codimension_one_grid(name, arguments, tria))
424 {
425 }
426 else if (generate_special(name, arguments, tria))
427 {
428 }
429 else
430 // If we got here, we really have no idea what grid the user wants to
431 // generate.
432 AssertThrow(false,
433 ExcMessage(name + "(" + arguments + ") not implemented"));
434 }
435} // namespace GridGenerator
436
437#include "grid/grid_generator_from_name.inst"
438
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcNoMatch(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
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 uniform_channel_with_sphere(Triangulation< dim > &tria, const std::vector< unsigned int > &lengths_heights_widths, const double inner_radius, const double outer_radius, const bool use_transfinite_region=false, 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 subdivided_hyper_cube_with_simplices(Triangulation< dim, spacedim > &tria, const unsigned int repetitions, const double left=0.0, const double right=1.0, const bool colorize=false)
void hyper_cube_slit(Triangulation< dim > &tria, const double left=0., const double right=1., const bool colorize=false)
void hyper_cube_with_spherical_hole(Triangulation< dim > &tria, const double inner_radius=0.25, const double outer_radius=0.5, 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:171