Reference documentation for deal.II version GIT d77e5ebb0a 2023-01-27 22:35:02+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\}}\)
grid_generator_from_name.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 - 2022 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
17 
19 
21 
22 namespace GridGenerator
23 {
24  namespace
25  {
32  template <int dim, int spacedim, class... Arguments>
33  void
34  parse_and_create(void (*generator)(Triangulation<dim, spacedim> &,
35  Arguments...),
36  const std::string & arguments,
38  {
39  std::function<void(Arguments...)> wrapper =
40  [&tria, &generator](Arguments... args) { generator(tria, args...); };
41  auto bound_function = Utilities::mutable_bind(wrapper);
42  bound_function.parse_arguments(arguments);
43  bound_function();
44  }
45 
46 
52  template <int dim, int spacedim>
53  std::enable_if_t<dim != spacedim, bool>
54  generate_codimension_zero_grid(const std::string &,
55  const std::string &,
57  {
58  return false;
59  }
60 
66  template <int dim>
67  bool
68  generate_codimension_zero_grid(const std::string & name,
69  const std::string & arguments,
71  {
72  if (name == "simplex")
73  parse_and_create<dim, dim, const std::vector<Point<dim>> &>(simplex,
74  arguments,
75  tria);
76  else if (name == "subdivided_hyper_rectangle")
77  {
78  // subdivided_hyper_rectangle is polymorphic, and can be called with
79  // different sets of arguments. We support two of these function
80  // calls. We try the first one, and if parsing fails, we go to the
81  // second one.
82  try
83  {
84  parse_and_create<dim,
85  dim,
86  const std::vector<unsigned int> &,
87  const Point<dim> &,
88  const Point<dim> &,
90  arguments,
91  tria);
92  }
94  {
95  parse_and_create<dim,
96  dim,
97  const std::vector<std::vector<double>> &,
98  const Point<dim> &,
99  const Point<dim> &,
101  arguments,
102  tria);
103  }
104  }
105  else if (name == "plate_with_a_hole")
106  parse_and_create<dim,
107  dim,
108  double,
109  double,
110  double,
111  double,
112  double,
113  double,
114  const Point<dim> &,
117  double,
118  unsigned int,
119  bool>(plate_with_a_hole, arguments, tria);
120  else if (name == "channel_with_cylinder")
121  parse_and_create<dim, dim, double, unsigned int, double, bool>(
122  channel_with_cylinder, arguments, tria);
123 
124  else if (name == "enclosed_hyper_cube")
125  parse_and_create<dim, dim, double, double, double, bool>(
126  enclosed_hyper_cube, arguments, tria);
127 
128  else if (name == "hyper_ball")
129  parse_and_create<dim, dim, const Point<dim> &, double, bool>(hyper_ball,
130  arguments,
131  tria);
132  else if (name == "hyper_ball_balanced")
133  parse_and_create<dim, dim, const Point<dim> &, double>(
134  hyper_ball_balanced, arguments, tria);
135 
136  else if (name == "quarter_hyper_ball")
137  parse_and_create<dim, dim, const Point<dim> &, double>(
138  quarter_hyper_ball, arguments, tria);
139 
140  else if (name == "half_hyper_ball")
141  parse_and_create<dim, dim, const Point<dim> &, double>(half_hyper_ball,
142  arguments,
143  tria);
144 
145  else if (name == "cylinder")
146  parse_and_create<dim, dim, double, double>(cylinder, arguments, tria);
147 
148  else if (name == "subdivided_cylinder")
149  parse_and_create<dim, dim, unsigned int, double, double>(
150  subdivided_cylinder, arguments, tria);
151 
152  else if (name == "truncated_cone")
153  parse_and_create<dim, dim, double, double, double>(truncated_cone,
154  arguments,
155  tria);
156 
157  else if (name == "pipe_junction")
158  parse_and_create<dim,
159  dim,
160  const std::vector<std::pair<Point<dim>, double>> &,
161  const std::pair<Point<dim>, double> &,
162  double>(pipe_junction, arguments, tria);
163 
164  else if (name == "hyper_L")
165  parse_and_create<dim, dim, double, double, bool>(hyper_L,
166  arguments,
167  tria);
168 
169  else if (name == "hyper_cube_slit")
170  parse_and_create<dim, dim, double, double, bool>(hyper_cube_slit,
171  arguments,
172  tria);
173 
174  else if (name == "hyper_shell")
175  parse_and_create<dim,
176  dim,
177  const Point<dim> &,
178  double,
179  double,
180  unsigned int,
181  bool>(hyper_shell, arguments, tria);
182 
183  else if (name == "half_hyper_shell")
184  parse_and_create<dim,
185  dim,
186  const Point<dim> &,
187  double,
188  double,
189  unsigned int,
190  bool>(half_hyper_shell, arguments, tria);
191 
192  else if (name == "quarter_hyper_shell")
193  parse_and_create<dim,
194  dim,
195  const Point<dim> &,
196  double,
197  double,
198  unsigned int,
199  bool>(quarter_hyper_shell, arguments, tria);
200 
201  else if (name == "eccentric_hyper_shell")
202  parse_and_create<dim,
203  dim,
204  const Point<dim> &,
205  const Point<dim> &,
206  double,
207  double,
208  unsigned int>(eccentric_hyper_shell, arguments, tria);
209 
210  else if (name == "cylinder_shell")
211  parse_and_create<dim,
212  dim,
213  double,
214  double,
215  double,
216  unsigned int,
217  unsigned int>(cylinder_shell, arguments, tria);
218 
219  else if (name == "hyper_cube_with_cylindrical_hole")
220  parse_and_create<dim, dim, double, double, double, unsigned int, bool>(
222 
223  else if (name == "concentric_hyper_shells")
224  parse_and_create<dim,
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  else
234  return false;
235 
236  return true;
237  }
238 
239 
245  template <int dim, int spacedim>
246  std::enable_if_t<dim != spacedim - 1, bool>
247  generate_codimension_one_grid(const std::string &,
248  const std::string &,
250  {
251  return false;
252  }
253 
259  template <int dim>
260  bool
261  generate_codimension_one_grid(const std::string & name,
262  const std::string & arguments,
264  {
265  if (name == "hyper_sphere")
266  parse_and_create<dim, dim + 1, const Point<dim + 1> &, double>(
267  hyper_sphere, arguments, tria);
268  else
269  return false;
270  return true;
271  }
272 
278  template <int dim, int spacedim>
279  bool
280  generate_special(const std::string &,
281  const std::string &,
283  {
284  return false;
285  }
286 
292  bool
293  generate_special(const std::string & name,
294  const std::string & arguments,
296  {
297  if (name == "moebius")
298  parse_and_create<3, 3, unsigned int, unsigned int, double, double>(
299  moebius, arguments, tria);
300  else if (name == "torus")
301  parse_and_create<3, 3, double, double, unsigned int, double>(torus,
302  arguments,
303  tria);
304  else
305  {
306  return false;
307  }
308  return true;
309  }
310 
316  bool
317  generate_special(const std::string & name,
318  const std::string & arguments,
320  {
321  if (name == "torus")
322  parse_and_create<2, 3, double, double, unsigned int, double>(torus,
323  arguments,
324  tria);
325  else
326  {
327  return false;
328  }
329  return true;
330  }
331  } // namespace
332 
333 
334 
335  template <int dim, int spacedim>
336  void
338  const std::string & name,
339  const std::string & arguments)
340  {
341  // We begin with all function calls that are implemented for all
342  // combinations of dim and spacedim.
343  if (name == "hyper_cube")
344  parse_and_create<dim, spacedim, double, double, bool>(hyper_cube,
345  arguments,
346  tria);
347  else if (name == "subdivided_hyper_cube")
348  parse_and_create<dim, spacedim, unsigned int, double, double, bool>(
349  subdivided_hyper_cube, arguments, tria);
350  else if (name == "hyper_rectangle")
351  parse_and_create<dim,
352  spacedim,
353  const Point<dim> &,
354  const Point<dim> &,
355  bool>(hyper_rectangle, arguments, tria);
356  else if (name == "cheese")
357  parse_and_create<dim, spacedim, const std::vector<unsigned int> &>(
358  cheese, arguments, tria);
359  else if (name == "general_cell")
360  parse_and_create<dim,
361  spacedim,
362  const std::vector<Point<spacedim>> &,
363  bool>(general_cell, arguments, tria);
364  else if (name == "hyper_cross")
365  parse_and_create<dim, spacedim, const std::vector<unsigned int> &, bool>(
366  hyper_cross, arguments, tria);
367  // If none of the above worked, than we try with more specific function
368  // calls. First we try to call functions that are only implemented when
369  // dim == spacedim, then when dim == spacedim-1, and lastly, we try to see
370  // if the name, dim, and spacedim match some of the very special grid
371  // generator functions, like torus, moebius, etc.
372  //
373  // If one of the function call succeeds, we skip the rest and return.
374  else if (generate_codimension_zero_grid(name, arguments, tria))
375  {}
376  else if (generate_codimension_one_grid(name, arguments, tria))
377  {}
378  else if (generate_special(name, arguments, tria))
379  {}
380  else
381  // If we got here, we really have no idea what grid the user wants to
382  // generate.
383  AssertThrow(false,
384  ExcMessage(name + "(" + arguments + ") not implemented"));
385  }
386 } // namespace GridGenerator
387 
388 #include "grid_generator_from_name.inst"
389 
Definition: point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:461
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:462
static ::ExceptionBase & ExcNoMatch(std::string arg1, std::string arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:1619
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_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 general_cell(Triangulation< dim, spacedim > &tria, const std::vector< Point< spacedim >> &vertices, const bool colorize=false)
void enclosed_hyper_cube(Triangulation< dim > &tria, const double left=0., const double right=1., const double thickness=1., 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_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 hyper_ball(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1., const bool attach_spherical_manifold_on_boundary_cells=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 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 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 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)
void cheese(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &holes)
Rectangular domain with rectangular pattern of holes.
void simplex(Triangulation< dim, dim > &tria, const std::vector< Point< dim >> &vertices)
void torus(Triangulation< dim, spacedim > &tria, const double R, const double r, const unsigned int n_cells_toroidal=6, const double phi=2.0 *numbers::PI)
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 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 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 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 hyper_shell(Triangulation< dim > &tria, const Point< dim > &center, const double inner_radius, const double outer_radius, const unsigned int n_cells=0, bool colorize=false)
void hyper_cube_with_cylindrical_hole(Triangulation< dim > &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 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.)
MutableBind< ReturnType, FunctionArgs... > mutable_bind(ReturnType(*function)(FunctionArgs...), typename identity< FunctionArgs >::type &&...arguments)
unsigned int manifold_id
Definition: types.h:146
const ::Triangulation< dim, spacedim > & tria