deal.II version GIT relicensing-3356-g4636aadadd 2025-05-22 18:40:00+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: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2024 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
34 Arguments...),
35 const std::string &arguments,
37 {
38 std::function<void(Arguments...)> wrapper =
39 [&tria, &generator](Arguments... args) { generator(tria, args...); };
41 bound_function.parse_arguments(arguments);
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 &,
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,
70 {
71 if (name == "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 {
84 dim,
85 const std::vector<unsigned int> &,
86 const Point<dim> &,
87 const Point<dim> &,
89 arguments,
90 tria);
91 }
93 {
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")
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")
121 channel_with_cylinder, arguments, tria);
122
123 else if (name == "enclosed_hyper_cube")
125 enclosed_hyper_cube, arguments, tria);
126
127 else if (name == "hyper_ball")
129 arguments,
130 tria);
131 else if (name == "hyper_ball_balanced")
133 hyper_ball_balanced, arguments, tria);
134
135 else if (name == "quarter_hyper_ball")
137 quarter_hyper_ball, arguments, tria);
138
139 else if (name == "half_hyper_ball")
141 arguments,
142 tria);
143
144 else if (name == "cylinder")
146
147 else if (name == "subdivided_cylinder")
149 subdivided_cylinder, arguments, tria);
150
151 else if (name == "truncated_cone")
153 arguments,
154 tria);
155
156 else if (name == "pipe_junction")
158 dim,
159 const std::vector<std::pair<Point<dim>, double>> &,
160 const std::pair<Point<dim>, double> &,
161 double>(pipe_junction, arguments, tria);
162
163 else if (name == "hyper_L")
165 arguments,
166 tria);
167
168 else if (name == "hyper_cube_slit")
170 arguments,
171 tria);
172
173 else if (name == "hyper_shell")
175 dim,
176 const Point<dim> &,
177 double,
178 double,
179 unsigned int,
180 bool>(hyper_shell, arguments, tria);
181
182 else if (name == "half_hyper_shell")
184 dim,
185 const Point<dim> &,
186 double,
187 double,
188 unsigned int,
189 bool>(half_hyper_shell, arguments, tria);
190
191 else if (name == "quarter_hyper_shell")
193 dim,
194 const Point<dim> &,
195 double,
196 double,
197 unsigned int,
198 bool>(quarter_hyper_shell, arguments, tria);
199
200 else if (name == "eccentric_hyper_shell")
202 dim,
203 const Point<dim> &,
204 const Point<dim> &,
205 double,
206 double,
207 unsigned int>(eccentric_hyper_shell, arguments, tria);
208
209 else if (name == "cylinder_shell")
211 dim,
212 double,
213 double,
214 double,
215 unsigned int,
216 unsigned int,
217 bool>(cylinder_shell, arguments, tria);
218
219 else if (name == "hyper_cube_with_cylindrical_hole")
221 hyper_cube_with_cylindrical_hole, arguments, tria);
222
223 else if (name == "concentric_hyper_shells")
225 dim,
226 const Point<dim> &,
227 double,
228 double,
229 unsigned int,
230 double,
231 unsigned int,
232 bool>(concentric_hyper_shells, arguments, tria);
233
234 else if (name == "subdivided_hyper_cube_with_simplices")
236 subdivided_hyper_cube_with_simplices, arguments, tria);
237
238 else if (name == "subdivided_hyper_rectangle_with_simplices")
240 dim,
241 const std::vector<unsigned int> &,
242 const Point<dim> &,
243 const Point<dim> &,
244 bool,
246 arguments,
247 tria);
248
249 else if (name == "subdivided_hyper_L")
251 dim,
252 const std::vector<unsigned int> &,
253 const Point<dim> &,
254 const Point<dim> &,
255 const std::vector<int> &>(subdivided_hyper_L,
256 arguments,
257 tria);
258
259 else
260 return false;
261
262 return true;
263 }
264
265
271 template <int dim, int spacedim>
272 std::enable_if_t<dim != spacedim - 1, bool>
273 generate_codimension_one_grid(const std::string &,
274 const std::string &,
276 {
277 return false;
278 }
279
285 template <int dim>
286 bool
287 generate_codimension_one_grid(const std::string &name,
288 const std::string &arguments,
290 {
291 if (name == "hyper_sphere")
293 hyper_sphere, arguments, tria);
294 else
295 return false;
296 return true;
297 }
298
304 template <int dim, int spacedim>
305 bool
306 generate_special(const std::string &,
307 const std::string &,
309 {
310 return false;
311 }
312
318 bool
319 generate_special(const std::string &name,
320 const std::string &arguments,
322 {
323 if (name == "moebius")
325 moebius, arguments, tria);
326 else if (name == "torus")
328 arguments,
329 tria);
330 else
331 {
332 return false;
333 }
334 return true;
335 }
336
342 bool
343 generate_special(const std::string &name,
344 const std::string &arguments,
346 {
347 if (name == "torus")
349 arguments,
350 tria);
351 else
352 {
353 return false;
354 }
355 return true;
356 }
357 } // namespace
358
359
360
361 template <int dim, int spacedim>
362 void
364 const std::string &name,
365 const std::string &arguments)
366 {
367 // We begin with all function calls that are implemented for all
368 // combinations of dim and spacedim.
369 if (name == "hyper_cube")
371 arguments,
372 tria);
373 else if (name == "subdivided_hyper_cube")
375 subdivided_hyper_cube, arguments, tria);
376 else if (name == "hyper_rectangle")
378 spacedim,
379 const Point<dim> &,
380 const Point<dim> &,
381 bool>(hyper_rectangle, arguments, tria);
382 else if (name == "cheese")
384 cheese, arguments, tria);
385 else if (name == "general_cell")
387 spacedim,
388 const std::vector<Point<spacedim>> &,
389 bool>(general_cell, arguments, tria);
390 else if (name == "hyper_cross")
392 hyper_cross, arguments, tria);
393 // If none of the above worked, than we try with more specific function
394 // calls. First we try to call functions that are only implemented when
395 // dim == spacedim, then when dim == spacedim-1, and lastly, we try to see
396 // if the name, dim, and spacedim match some of the very special grid
397 // generator functions, like torus, moebius, etc.
398 //
399 // If one of the function call succeeds, we skip the rest and return.
400 else if (generate_codimension_zero_grid(name, arguments, tria))
401 {
402 }
403 else if (generate_codimension_one_grid(name, arguments, tria))
404 {
405 }
406 else if (generate_special(name, arguments, tria))
407 {
408 }
409 else
410 // If we got here, we really have no idea what grid the user wants to
411 // generate.
412 AssertThrow(false,
413 ExcMessage(name + "(" + arguments + ") not implemented"));
414 }
415} // namespace GridGenerator
416
417#include "grid/grid_generator_from_name.inst"
418
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:35
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:36
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 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 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, const bool periodic=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_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 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, const bool periodic=false)
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