deal2lkit: A ToolKit library for Deal.II
parsed_grid_generator.cc
Go to the documentation of this file.
1 //-----------------------------------------------------------
2 //
3 // Copyright (C) 2015 by the deal2lkit authors
4 //
5 // This file is part of the deal2lkit library.
6 //
7 // The deal2lkit 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 at
12 // the top level of the deal2lkit distribution.
13 //
14 //-----------------------------------------------------------
15 
16 #include <deal.II/base/config.h>
18 #include <deal2lkit/utilities.h>
22 #include <deal.II/grid/grid_in.h>
23 #include <deal.II/grid/grid_out.h>
24 #include <boost/archive/text_oarchive.hpp>
25 #include <boost/archive/text_iarchive.hpp>
26 #include <boost/archive/binary_oarchive.hpp>
27 #include <boost/archive/binary_iarchive.hpp>
29 
32 
33 #include <fstream>
34 
35 
36 namespace
37 {
38  std::string extension(const std::string &filename)
39  {
40  std::string::size_type idx;
41  idx = filename.rfind('.');
42  if (idx != std::string::npos)
43  {
44  return filename.substr(idx+1);
45  }
46  else
47  {
48  return "";
49  }
50  }
51 }
52 
53 D2K_NAMESPACE_OPEN
54 
55 
56 template <int dim, int spacedim>
58  const std::string _grid_type,
59  const std::string _input_grid_file,
60  const std::string _point_1,
61  const std::string _point_2,
62  const std::string _colorize,
63  const std::string _double_1,
64  const std::string _double_2,
65  const std::string _double_3,
66  const std::string _int_1,
67  const std::string _int_2,
68  const std::string _vec_of_int,
69  const std::string _mesh_smoothing,
70  const std::string _output_grid_file,
71  const std::string _manifold_descriptors)
72  :
73  ParameterAcceptor(_section_name),
74  mesh_smoothing(_mesh_smoothing),
75  grid_name(_grid_type),
76  optional_manifold_descriptors(_manifold_descriptors),
77  create_default_manifolds(true),
78  copy_boundary_to_manifold_ids(false),
79  copy_material_to_manifold_ids(false),
80  input_grid_file_name(_input_grid_file),
81  output_grid_file_name(_output_grid_file),
82  str_point_1(_point_1),
83  str_point_2(_point_2),
84  str_colorize(_colorize),
85  str_double_1(_double_1),
86  str_double_2(_double_2),
87  str_double_3(_double_3),
88  str_un_int_1(_int_1),
89  str_un_int_2(_int_2),
90  str_vec_int(_vec_of_int)
91 {}
92 
93 
94 
95 template <int dim, int spacedim>
97 {
98  return "file|rectangle|hyper_ball|hyper_shell|hyper_sphere|hyper_L|half_hyper_ball|cylinder|truncated_cone|hyper_cross|hyper_cube_slit|half_hyper_shell|quarter_hyper_shell|cylinder_shell|torus|hyper_cube_with_cylindrical_hole|moebius|cheese";
99 }
100 
101 template <int dim, int spacedim>
103 {
104 
105  std::vector<unsigned int> dummy_vec_int(dim, 1);
106  std::vector<double> dummy_vec_double(spacedim);
107  Point<spacedim> dummy_point;
108  Point<spacedim> dummy_point_2;
109  for (unsigned int d=0; d<dim; ++d)
110  dummy_point_2[d]=1.0;
111 
112  std::string def_point, def_point_2, def_int, def_double;
113  def_point = print(dummy_point);
114  def_point_2 = print(dummy_point_2);
115  def_int = print(dummy_vec_int);
116  def_double = print(dummy_vec_double);
117 
118  add_parameter(prm, &grid_name,
119  "Grid to generate", grid_name,
121  "The grid to generate. You can choose among:\n"
122  "- file: read grid from a file using:\n"
123  " - Input grid filename : input filename\n\n"
124  "- rectangle: create a subdivided hyperrectangle using:\n"
125  " - Optional Point<spacedim> 1: lower-left corner\n"
126  " - Optional Point<spacedim> 2: upper-right corner\n"
127  " - Optional Vector of dim int: subdivisions on each direction\n"
128  " - Optional bool 1 : colorize grid\n"
129  "- hyper_sphere : generate an hyper sphere with center and radius prescribed:\n"
130  " - Optional Point<spacedim> : center\n"
131  " - Optional double : radius\n"
132  "- hyper_ball : initialize the given triangulation with a hyper_ball:\n\n"
133  " - Optional Point<spacedim> : center\n"
134  " - Optional double : radius\n"
135  "- hyper_shell : create a gird represented by the region between two spheres with fixed center:\n\n"
136  " - Optional Point<spacedim> : center\n"
137  " - Optional double : inner sphere radius\n"
138  " - Optional double : outer sphere radius\n"
139  " - Optional unsigned int : number of cells of the resulting triangulation (In 3d, only 6, 12, and 96 are allowed)\n"
140  " - Optional bool : colorize grid\n"
141  "- hyper_L : initialize the given triangulation with a hyper-L. It produces the hypercube with the interval [left,right] without the hypercube made out of the interval [(left+right)/2,right] for each coordinate."
142  " - Optional double : left\n"
143  " - Optional double : right\n"
144  "- half_hyper_ball : produce a half hyper-ball around center, which contains four elements in 2d and 6 in 3d. The cut plane is perpendicular to the x-axis: \n"
145  " - Optional Point<spacedim> : center\n"
146  " - Optional double : radius\n"
147  "- cylinder: create a cylinder around the x-axis. The cylinder extends from x=-half_length to x=+half_length and its projection into the yz-plane is a circle of radius radius: \n"
148  " - Optional double : radius\n"
149  " - Optional double : half length of the cylinder\n"
150  "- truncated_cone : create a cut cone around the x-axis. The cone extends from x=-half_length to x=half_length and its projection into the yz-plane is a circle of radius radius1 at x=-half_length and a circle of radius radius2 at x=+half_length :\n"
151  " - Optional double : radius 1\n"
152  " - Optional double : radius 2\n"
153  " - Optional double : half length\n"
154  "- hyper_cross : a center cell with stacks of cell protruding from each surface :\n"
155  " - Optional Vector of dim int: sizes\n"
156  " - Optional bool : colorize grid\n"
157  "- hyper_cube_slit : initialize the given Triangulation with a hypercube with a slit. In each coordinate direction, the hypercube extends from left to right :\n"
158  " - Optional double : left\n"
159  " - Optional double : right\n"
160  " - Optional bool : colorize grid\n"
161  "- half_hyper_shell : produce a half hyper-shell, i.e. the space between two circles in two space dimensions and the region between two spheres in 3d :\n"
162  " - Optional Point<spacedim> : center\n"
163  " - Optional double : inner radius\n"
164  " - Optional double : outer radius\n"
165  " - Optional unsigned int : number of cells\n"
166  " - Optional bool : colorize grid\n"
167  "- quarter_hyper_shell : Produce a domain that is the intersection between a hyper-shell with given inner and outer radius, i.e. the space between two circles in two space dimensions and the region between two spheres in 3d, and the positive quadrant (in 2d) or octant (in 3d). In 2d, this is indeed a quarter of the full annulus, while the function is a misnomer in 3d because there the domain is not a quarter but one eighth of the full shell :\n"
168  " - Optional Point<spacedim> : center\n"
169  " - Optional double : inner radius\n"
170  " - Optional double : outer radius\n"
171  " - Optional unsigned int : number of cells\n"
172  " - Optional bool : colorize grid\n"
173  "- cylinder_shell : produce a domain that is the space between two cylinders in 3d, with given length, inner and outer radius and a given number of elements for this initial triangulation. If n_radial_cells is zero (as is the default), then it is computed adaptively such that the resulting elements have the least aspect ratio. The same holds for n_axial_cells :\n"
174  " - Optional double : lenght\n"
175  " - Optional double : inner radius\n"
176  " - Optional double : outer radius\n"
177  " - Optional unsigned int : n_radial_cells\n"
178  " - Optional unsigned int : n_axial_cells\n"
179  "- moebius : produce a ring of cells in 3d that is cut open, twisted and glued together again. This results in a kind of moebius-loop :\n"
180  " - Optional unsigned int : number of cells in the loop\n"
181  " - Optional unsigned int : number of rotations (Pi/2 each) to be performed before gluing the loop together\n"
182  " - Optional double : radius of the circle\n"
183  " - Optional double : radius of the cylinder bend together as loop\n"
184  "- hyper_cube_with_cylindrical_hole : produces a square in the xy-plane with a circular hole in the middle :\n"
185  " - Optional double : inner radius\n"
186  " - Optional double : outer radius\n"
187  " - Optional double : lenght\n"
188  " - Optional unsigned int : repetitions (number of subdivisions along the z-direction)\n"
189  " - Optional bool : colorize grid\n"
190  "- torus : produce the surface meshing of the torus :\n"
191  " - Optional double : radius of the circle which forms the middle line of the torus containing the loop of cells\n"
192  " - Optional double : inner radius of the torus\n"
193  "- cheese : domain itself is rectangular. The argument holes specifies how many square holes the domain should have in each coordinate direction :\n"
194  " - Optional Vector of dim int: number of holes on each direction\n"
195  );
196 
198  "Mesh smoothing alogrithm", mesh_smoothing,
200  "limit_level_difference_at_vertices|"
201  "eliminate_unrefined_islands|"
202  "patch_level_1|"
203  "coarsest_level_1|"
204  "allow_anisotropic_smoothing|"
205  "eliminate_refined_inner_islands|"
206  "eliminate_refined_boundary_islands|"
207  "do_not_produce_unrefined_islands|"
208  "smoothing_on_refinement|"
209  "smoothing_on_coarsening|"
210  "maximum_smoothing"));
211 
213  "Input grid file name", input_grid_file_name,
215  "Name of the input grid. All supported deal.II formats. "
216  "The extestion will be used to decide what "
217  "grid format to use.");
218 
220  "Optional double 1", str_double_1,
222  "First additional double to be used in the generation of the grid. "
223  "The use of it will depend on the specific grid.");
224 
226  "Optional double 2", str_double_2,
228  "Second additional double to be used in the generation of the grid. "
229  "The use of it will depend on the specific grid.");
230 
232  "Optional double 3", str_double_3,
234  "Second additional double to be used in the generation of the grid. "
235  "The use of it will depend on the specific grid.");
236 
238  "Optional Point<spacedim> 1", (str_point_1==""?def_point:str_point_1),
239  Patterns::List(Patterns::Double(), spacedim, spacedim),
240  "First additional Point<spacedim> to be used in the generation of the grid. "
241  "The use of it will depend on the specific grid.");
242 
244  "Optional Point<spacedim> 2", (str_point_2==""?def_point_2:str_point_2),
245  Patterns::List(Patterns::Double(), spacedim, spacedim),
246  "Second additional Point<spacedim> to be used in the generation of the grid. "
247  "The use of it will depend on the specific grid.");
248 
249 
251  "Optional int 1",str_un_int_1,
253  "Unsigned int to be used in the generation of the grid. "
254  "The use of it will depend on the specific grid.");
255 
257  "Optional int 2",str_un_int_2,
259  "Unsigned int to be used in the generation of the grid. "
260  "The use of it will depend on the specific grid.");
261 
263  "Optional vector of dim int", (str_vec_int==""?def_int:str_vec_int),
264  Patterns::List(Patterns::Integer(1), dim, dim),
265  "Vector of positive unsigned int to be used in the generation of the grid. "
266  "The use of it will depend on the specific grid.");
267 
268  add_parameter(prm, &colorize,
269  "Colorize",str_colorize,
270  Patterns::Bool(),
271  "Bool be used in the generation of the grid to set colorize. "
272  "The use of it will depend on the specific grid.");
273 
275  "Create default manifolds",
276  create_default_manifolds ? "true" : "false",
277  Patterns::Bool(),
278  "If set to true, boundary ids "
279  "will be copied over the manifold ids, and the "
280  "default manifolds for this triangulation will be"
281  "Generated.");
282 
283 
285  "Copy boundary to manifold ids",
286  copy_boundary_to_manifold_ids ? "true" : "false",
287  Patterns::Bool(),
288  "If set to true, boundary ids will be copied over "
289  "the manifold ids.");
290 
292  "Copy material to manifold ids",
293  copy_material_to_manifold_ids ? "true" : "false",
294  Patterns::Bool(),
295  "If set to true, material ids "
296  "will be copied over the manifold ids.");
297 
298 
300  "Manifold descriptors", optional_manifold_descriptors,
302  "Manifold descriptors.\n"
303  "Pattern to be used: \n"
304  "id followed by '=' manifold descriptor \n "
305  "each couple of id and manifold descriptor is separated by '%' "
306  "and those Manifold descriptors which require additional parameters "
307  "use the ones defined in this class.\n"
308  "Available manifold descriptor: \n"
309  "- HyperBallBoundary : boundary of a hyper_ball :\n"
310  " - Optional double : radius\n"
311  " - Optional Point<spacedim> 1: center\n"
312  "- CylinderBoundaryOnAxis : boundary of a cylinder, given radius and axis :\n"
313  " - Optional double : radius\n"
314  " - Optional int 1 : axis (0=x, 1=y, 2=z)\n"
315  "- GeneralCylinderBoundary : boundary of a cylinder, given radius, a point on the axis and a direction :\n"
316  " - Optional double : radius\n"
317  " - Optional int 1 : axis (0=x, 1=y, 2=z)\n"
318  " - Optional Point<spacedim> 1: point on axis\n"
319  " - Optional Point<spacedim> 2: direction\n"
320  "- ConeBoundary : boundary of a cone, given radii, and two points on the faces:\n"
321  " - Optional double 1 : radius 1\n"
322  " - Optional double 2 : radius 2\n"
323  " - Optional Point<spacedim> 1: point on first face\n"
324  " - Optional Point<spacedim> 2: point on second face\n"
325  "- TorusBoundary : boundary of a torus :\n"
326  " - Optional double 1 : radius 1\n"
327  " - Optional double 2 : radius 2\n"
328  "- ArclengthProjectionLineManifold:file.iges/step : interface to CAD file:\n"
329  " - Optional double 1 : scale to apply to input CAD file\n"
330  "- ArclengthProjectionLineManifold:file.iges/step : interface to CAD file:\n"
331  " - Optional double 1 : scale to apply to input CAD file\n"
332  "- DirectionalProjectionBoundary:file.iges/step : interface to CAD file:\n"
333  " - Optional double 1 : scale to apply to input CAD file\n"
334  " - Optional Point<spacedim> 1: direction of projection\n"
335  "- NormalProjectionBoundary:file.iges/step : interface to CAD file:\n"
336  " - Optional double 1 : scale to apply to input CAD file\n"
337  "- NormalToMeshProjectionBoundary:file.iges/step : interface to CAD file:\n"
338  " - Optional double 1 : scale to apply to input CAD file\n"
339  );
340 
342  "Output grid file name", output_grid_file_name,
344  "Name of the output grid. All supported deal.II formats. "
345  "The extestion will be used to decide what "
346  "grid format to use. If empty, no grid will be written.");
347 }
348 
349 #ifdef DEAL_II_WITH_MPI
350 #ifdef DEAL_II_WITH_P4EST
351 template <int dim, int spacedim>
354 {
357  (comm);//, get_smoothing());
358 
359  create(*tria);
360  return tria;
361 }
362 #endif
363 #endif
364 
365 
366 template <int dim, int spacedim>
369 {
372  create(*tria);
373  return tria;
374 }
375 
382 struct PGGHelper
383 {
389  template<int dim, int spacedim>
390  static void
393  {
394  if (p->grid_name == "rectangle")
395  {
396  Tensor<1,dim> initializer1;
397  Tensor<1,dim> initializer2;
398  for (unsigned int i=0; i<dim; ++i)
399  {
400  initializer1[i]=p->point_option_one(i);
401  initializer2[i]=p->point_option_two(i);
402  }
403  Point<dim> p1(initializer1);
404  Point<dim> p2(initializer2);
405 
408  p2,
409  p1,
410  p->colorize);
411  }
412  else if (p->grid_name == "file")
413  {
415  gi.attach_triangulation(tria);
416 
417  std::ifstream in(p->input_grid_file_name.c_str());
418  AssertThrow(in, ExcIO());
419 
420  std::string ext = extension(p->input_grid_file_name);
421  if (ext == "vtk")
422  gi.read_vtk(in);
423  else if (ext == "msh")
424  gi.read_msh(in);
425  else if (ext == "ucd" || ext == "inp")
426  gi.read_ucd(in);
427  else if (ext == "unv")
428  gi.read_unv(in);
429  else if (ext == "ar")
430  {
431  boost::archive::text_iarchive ia(in);
432  tria.load(ia, 0);
433  }
434  else if (ext == "bin")
435  {
436  boost::archive::binary_iarchive ia(in);
437  tria.load(ia, 0);
438  }
439  else
440  Assert(false, ExcNotImplemented());
441  }
442  else
443  AssertThrow(false, ExcMessage("Not implemented: " + p->grid_name));
444 
445  }
446 
450  template<int dim>
451  static void
454  typename std::enable_if<(dim<3), void **>::type=0)
455  {
456  if (p->grid_name == "hyper_sphere")
457  {
458  GridGenerator::hyper_sphere<dim,dim+1> ( tria,
459  p->point_option_one,
460  p->double_option_one);
462  tria.set_all_manifold_ids(0);
463  p->default_manifold_descriptors = "0=SphericalManifold";
464  }
465  else
466  {
468  }
469  }
470 
474  template<int dim>
475  static void
478  {
479  if (p->grid_name == "hyper_ball")
480  {
481 
483  p->point_option_one,
484  p->double_option_one);
485  p->default_manifold_descriptors = "0=HyperBallBoundary";
486  }
487  else if (p->grid_name == "hyper_L")
488  {
489  GridGenerator::hyper_L ( tria,
491  p->double_option_one );
492  }
493  else if (p->grid_name == "half_hyper_ball")
494  {
496  p->point_option_one,
497  p->double_option_one);
498  p->default_manifold_descriptors = "0=HalfHyperBallBoundary";
499  }
500  else if (p->grid_name == "cylinder")
501  {
504  p->double_option_two);
505  p->default_manifold_descriptors = "0=CylindricalManifoldOnAxis";
506  }
507  else if (p->grid_name == "truncated_cone")
508  {
513  p->default_manifold_descriptors = dim == 3 ? "0=ConeBoundary" : "";
514  }
515  else if (p->grid_name == "hyper_cross")
516  {
519  p->colorize);
520  }
521  else if (p->grid_name == "hyper_cube_slit")
522  {
526  p->colorize);
527  }
528  else if (p->grid_name == "half_hyper_shell")
529  {
531  p->point_option_one,
535  p->colorize);
537  "0=SphericalManifold % 1=SphericalManifold" :
538  "0=SphericalManifold";
539 
540  }
541  else if (p->grid_name == "quarter_hyper_shell")
542  {
544  p->point_option_one,
548  p->colorize);
550  "0=SphericalManifold % 1=SphericalManifold" :
551  "0=SphericalManifold";
552  }
553  else if (p->grid_name == "cylinder_shell")
554  {
560  p->un_int_option_two);
561  // This won't work, because of the differen meaning of the various
562  // options...
563 
564  // p->default_manifold_descriptors = "0=CylindricalManifoldOnAxis";
565  }
566  else if (p->grid_name == "hyper_cube_with_cylindrical_hole")
567  {
573  p->colorize);
574  }
575  else if (p->grid_name == "hyper_shell")
576  {
578  p->point_option_one,
582  p->colorize);
584  "0=SphericalManifold % 1=SphericalManifold" :
585  "0=SphericalManifold";
586  }
587  else if (p->grid_name == "cheese")
588  {
591  }
592  else
593  {
595  }
596  }
597 
601  static void
603  Triangulation<3,3> &tria)
604  {
605  if (p->grid_name == "moebius")
606  {
607  GridGenerator::moebius ( tria,
611  p->double_option_one );
612  }
613  else
614  {
615  PGGHelper::create_grid<3>( p, tria);
616  }
617  }
618 
622  static void
624  Triangulation<2,3> &tria)
625  {
626  if (p->grid_name == "torus")
627  {
628  GridGenerator::torus (tria,
630  p->double_option_two);
631 
632  p->default_manifold_descriptors = "0=TorusBoundary";
633  }
634 #ifdef DEAL_II_WITH_OPENCASCADE
635  else if (p->grid_name == "file")
636  {
637  std::string ext = extension(p->input_grid_file_name);
638  if (ext == "step" || ext == "stp" ||
639  ext == "iges" || ext == "igs")
640  {
641  TopoDS_Shape sh = PGGHelper::readOCC(p->input_grid_file_name,
642  p->double_option_one);
643 
644 
645  std::vector<TopoDS_Face> faces;
646  std::vector<TopoDS_Edge> edges;
647  std::vector<TopoDS_Vertex> vertices;
648 
649  OpenCASCADE::extract_geometrical_shapes(sh, faces, edges, vertices);
650 
651  AssertThrow(p->un_int_option_one < faces.size(),
652  ExcMessage("The optional unsigned int you specified ("
653  +std::to_string(p->un_int_option_one) + ") does not " +
654  "correspond to a valid face in the CAD file " + p->input_grid_file_name));
655 
657  }
658  else
659  {
660  PGGHelper::create_grid<2>(p, tria);
661  }
662  }
663 #endif
664 
665  else
666  PGGHelper::create_grid<2>(p, tria);
667  }
668 
673  static
674  shared_ptr<Manifold<3> > create_manifold(ParsedGridGenerator<3> *p,
675  const std::string &name)
676  {
677  if (name=="CylinderBoundaryOnAxis")
678  {
680  p->un_int_option_one));
681  }
682  else if (name=="GeneralCylinderBoundary")
683  {
685  p->point_option_one,
686  p->point_option_two));
687  }
688  else if (name=="ConeBoundary")
689  {
690  return SP(new ConeBoundary<3>(p->double_option_one,
692  p->point_option_one,
693  p->point_option_two));
694  }
695  else
696  {
697 #ifdef DEAL_II_WITH_OPENCASCADE
698  const int dim = 3;
699  const int spacedim = 3;
700  auto subnames = Utilities::split_string_list(name,':');
701 
702  if (subnames[0] == "ArclengthProjectionLineManifold")
703  {
704  AssertDimension(subnames.size(), 2);
706  (PGGHelper::readOCC(subnames[1],p->double_option_one)));
707  }
708  else if (subnames[0] == "DirectionalProjectionBoundary")
709  {
710  AssertDimension(subnames.size(), 2);
712  (PGGHelper::readOCC(subnames[1],p->double_option_one),
714  }
715  else if (subnames[0] == "NormalProjectionBoundary")
716  {
717  AssertDimension(subnames.size(), 2);
719  (PGGHelper::readOCC(subnames[1],p->double_option_one)));
720  }
721  else if (subnames[0] == "NormalToMeshProjectionBoundary")
722  {
723  AssertDimension(subnames.size(), 2);
725  (PGGHelper::readOCC(subnames[1],p->double_option_one)));
726  }
727 #endif
728 
729  return create_manifold<3>(p, name);
730  }
731  }
732 
733  static
734  shared_ptr<Manifold<2,3> > create_manifold(ParsedGridGenerator<2,3> *p,
735  const std::string &name)
736  {
737  if (name=="TorusBoundary")
738  {
740  p->double_option_two));
741  }
742  else
743  {
744 #ifdef DEAL_II_WITH_OPENCASCADE
745  const int dim = 2;
746  const int spacedim = 3;
747  auto subnames = Utilities::split_string_list(name,':');
748 
749  if (subnames[0] == "ArclengthProjectionLineManifold")
750  {
751  AssertDimension(subnames.size(), 2);
753  (PGGHelper::readOCC(subnames[1], p->double_option_one)));
754  }
755  else if (subnames[0] == "DirectionalProjectionBoundary")
756  {
757  AssertDimension(subnames.size(), 2);
759  (PGGHelper::readOCC(subnames[1],p->double_option_one),
761  }
762  else if (subnames[0] == "NormalProjectionBoundary")
763  {
764  AssertDimension(subnames.size(), 2);
766  (PGGHelper::readOCC(subnames[1],p->double_option_one)));
767  }
768  else if (subnames[0] == "NormalToMeshProjectionBoundary")
769  {
770  AssertDimension(subnames.size(), 2);
772  (PGGHelper::readOCC(subnames[1],p->double_option_one)));
773  }
774 #endif
775  return default_create_manifold(p, name);
776  }
777  }
778 
783  template<int dim>
784  static
785  shared_ptr<Manifold<dim> > create_manifold(ParsedGridGenerator<dim> *p,
786  const std::string &name)
787  {
788  if (name=="HalfHyperBallBoundary")
789  {
791  p->double_option_one));
792  }
793  else if (name == "HyperShellBoundary")
794  {
796  }
797  else if (name == "HalfHyperShellBoundary")
798  {
801  p->double_option_one));
802  }
803  else
804  return default_create_manifold(p, name);
805  }
806 
811  template<int dim>
812  static
813  shared_ptr<Manifold<dim,dim+1> > create_manifold(ParsedGridGenerator<dim, dim+1> *p,
814  const std::string &name,
815  typename std::enable_if<(dim<3), void **>::type=0)
816  {
817  return default_create_manifold(p, name);
818  }
819 
820 #ifdef DEAL_II_WITH_OPENCASCADE
821  static TopoDS_Shape readOCC(const std::string &name, const double &scale)
822  {
823  std::string ext = extension(name);
824  TopoDS_Shape shape;
825 
826  if (ext == "iges" || ext == "igs")
827  shape = OpenCASCADE::read_IGES(name, scale);
828  else if (ext == "step" || ext == "stp")
829  shape = OpenCASCADE::read_STEP(name, scale);
830  return shape;
831  }
832 #endif
833 
834 
838  template<int dim, int spacedim>
839  static
840  shared_ptr<Manifold<dim,spacedim> > default_create_manifold(ParsedGridGenerator<dim,spacedim> *p,
841  const std::string &name)
842  {
843  if (name=="HyperBallBoundary")
844  {
846  p->double_option_one));
847  }
848  else if (name=="SphericalManifold")
849  {
851  }
852  else if (name=="CylindricalManifoldOnAxis")
853  {
855  }
856  else if (name=="GeneralCylindricalManifold")
857  {
859  p->point_option_two));
860  }
861  else
862  {
863  // Try splitting the name at ":" and see if this is a more complicated
864  // object
865  auto subnames = Utilities::split_string_list(name,':');
866  if (subnames[0] == "FunctionManifold0")
867  {
868  AssertDimension(subnames.size(), 3);
869  return SP(new FunctionManifold<dim,spacedim,dim>(subnames[1], subnames[2]));
870  }
871  else if (subnames[0] == "FunctionManifold1")
872  {
873  AssertDimension(subnames.size(), 3);
874  return SP(new FunctionManifold<dim,spacedim,(dim > 1 ? dim-1: dim)>
875  (subnames[1], subnames[2]));
876  }
877  AssertThrow(false, ExcInternalError(name+" is not a valid manifold descriptor."))
878  }
879  return shared_ptr<Manifold<dim,spacedim> >();
880  }
881 };
882 
883 template <int dim, int spacedim>
885 {
887  PGGHelper::create_grid( this, tria);
888 
890 
893 
896 
899 
900  // Now attach the manifold descriptors
901  for (auto m: manifold_descriptors)
902  {
903  tria.set_manifold(m.first, *m.second);
904  }
905 
906 }
907 
908 
909 template <int dim, int spacedim>
910 void
911 ParsedGridGenerator<dim, spacedim>::parse_manifold_descriptors(const std::string &str_manifold_descriptors)
912 {
913  std::vector<std::string> idcomponents = Utilities::split_string_list(str_manifold_descriptors, '%');
914 
915  for (unsigned int i=0; i<idcomponents.size(); ++i)
916  {
917  std::vector<std::string> comp = Utilities::split_string_list(idcomponents[i], '=');
918  AssertDimension(comp.size(), 2);
919 
921  PGGHelper::create_manifold(this, comp[1]);
922  }
923 }
924 
925 
926 
927 template <int dim, int spacedim>
929  const std::string &filename) const
930 {
931  std::string my_filename = filename != "" ? filename : output_grid_file_name;
932  if (my_filename != "")
933  {
934  GridOut go;
935  std::ofstream out(my_filename.c_str());
936  AssertThrow(out, ExcIO());
937 
938  go.set_flags(GridOutFlags::Msh(true, true));
939  go.set_flags(GridOutFlags::Ucd(false,true, true));
940 
941  std::string ext = extension(my_filename);
942  if (ext == "vtk")
943  go.write_vtk(tria, out);
944  else if (ext == "msh")
945  go.write_msh(tria, out);
946  else if (ext == "ucd" || ext == "inp")
947  go.write_ucd(tria, out);
948  else if (ext == "vtu")
949  go.write_vtu(tria, out);
950  else if (ext == "ar")
951  {
952  boost::archive::text_oarchive oa(out);
953  tria.save(oa, 0);
954  }
955  else if (ext == "bin")
956  {
957  boost::archive::binary_oarchive oa(out);
958  tria.save(oa, 0);
959  }
960  else
961  Assert(false, ExcNotImplemented());
962  out.close();
963  }
964 }
965 
966 
967 namespace
968 {
969  template <int dim, int spacedim>
970  inline typename Triangulation<dim,spacedim>::MeshSmoothing operator|
973  {
974  return static_cast<typename Triangulation<dim,spacedim>::MeshSmoothing>
975  (static_cast<int>(a)|static_cast<int>(b));
976  }
977 }
978 
979 template <int dim, int spacedim>
982 {
983  int smoothing = 0;
984  std::vector<std::string> ss = Utilities::split_string_list(mesh_smoothing);
985  for (std::string s : ss)
986  {
987  if (s == "none")
988  smoothing = smoothing|(int)Triangulation<dim,spacedim>::none;
989  else if (s == "limit_level_difference_at_vertices")
991  else if (s == "eliminate_unrefined_islands")
993  else if (s == "patch_level_1")
994  smoothing = smoothing|(int)Triangulation<dim,spacedim>::patch_level_1;
995  else if (s == "coarsest_level_1")
996  smoothing = smoothing|(int)Triangulation<dim,spacedim>::coarsest_level_1;
997  else if (s == "allow_anisotropic_smoothing")
999  else if (s == "eliminate_refined_inner_islands")
1001  else if (s == "eliminate_refined_boundary_islands")
1003  else if (s == "do_not_produce_unrefined_islands")
1005  else if (s == "smoothing_on_refinement")
1006  smoothing = smoothing|(int)Triangulation<dim,spacedim>::smoothing_on_refinement;
1007  else if (s == "smoothing_on_coarsening")
1008  smoothing = smoothing|(int)Triangulation<dim,spacedim>::smoothing_on_coarsening;
1009  else if (s == "maximum_smoothing")
1010  smoothing = smoothing|(int)Triangulation<dim,spacedim>::maximum_smoothing;
1011  else
1012  Assert(false, ExcInternalError("Found a non supported smoothing. Should not happen:"+s))
1013  }
1014  return static_cast<typename Triangulation<dim,spacedim>::MeshSmoothing>(smoothing);
1015 }
1016 
1017 
1018 D2K_NAMESPACE_CLOSE
1019 
1020 template class deal2lkit::ParsedGridGenerator<1,1>;
1021 template class deal2lkit::ParsedGridGenerator<1,2>;
1022 //template class deal2lkit::ParsedGridGenerator<1,3>;
1023 template class deal2lkit::ParsedGridGenerator<2,2>;
1024 template class deal2lkit::ParsedGridGenerator<2,3>;
1025 template class deal2lkit::ParsedGridGenerator<3,3>;
1026 
void write_ucd(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
static void create_grid(ParsedGridGenerator< 2, 3 > *p, Triangulation< 2, 3 > &tria)
This function is used to generate grids when dim = 2 and spacedim = 3.
#define AssertDimension(dim1, dim2)
void copy_boundary_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool reset_boundary_ids=false)
TopoDS_Shape read_IGES(const std::string &filename, const double scale_factor=1e-3)
void torus(Triangulation< dim, spacedim > &tria, const double R, const double r)
A parameter acceptor base class.
static void create_grid(ParsedGridGenerator< 3 > *p, Triangulation< 3, 3 > &tria)
This function is used to generate grids when spacedim = dim = 3.
bool colorize
For all the internally generated meshes that support it, turn on colorizing.
unsigned int un_int_option_two
Optional int argument.
static ParameterHandler prm
Static parameter.
static::ExceptionBase & ExcIO()
std::string grid_name
The grid to generate.
TopoDS_Shape read_STEP(const std::string &filename, const double scale_factor=1e-3)
std::string output_grid_file_name
Output grid file name.
bool create_default_manifolds
Create default manifold descriptors.
bool copy_material_to_manifold_ids
Copy material ids to manifold ids.
void write_vtk(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
void scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
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 moebius(Triangulation< 3, 3 > &tria, const unsigned int n_cells, const unsigned int n_rotations, const double R, const double r)
std::string default_manifold_descriptors
Default Manifold descriptors.
static shared_ptr< Manifold< dim, spacedim > > default_create_manifold(ParsedGridGenerator< dim, spacedim > *p, const std::string &name)
Prototype function for creating new manifolds from a name and a pgg.
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)
std::string mesh_smoothing
Mesh smoothing to apply to the newly created Triangulation.
std::string optional_manifold_descriptors
Optional Manifold descriptors.
static std::string get_grid_names()
Return a list of implemented grids.
Parsed grid generator.
static::ExceptionBase & ExcNotInitialized()
#define AssertThrow(cond, exc)
shared_ptr< T > SP(T *t)
Construct a shared pointer to a non const class T.
Definition: utilities.h:483
Parsed Grid Generator Helper.
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)
double double_option_three
Optional double argument.
unsigned int un_int_option_one
Optional int argument.
static void create_grid(ParsedGridGenerator< dim, dim > *p, Triangulation< dim, dim > &tria)
This function is used to generate grids when spacedim = dim.
void read_vtk(std::istream &in)
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 hyper_cross(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &sizes, const bool colorize_cells=false)
void set_manifold(const types::manifold_id number, const Manifold< dim, spacedim > &manifold_object)
void hyper_L(Triangulation< dim > &tria, const double left=-1., const double right=1., const bool colorize=false)
void write_msh(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
void half_hyper_ball(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
static::ExceptionBase & ExcMessage(std::string arg1)
double double_option_two
Optional double argument.
static void default_create_grid(ParsedGridGenerator< dim, spacedim > *p, Triangulation< dim, spacedim > &tria)
This function is used to generate grids when there are no restriction on the template parameters...
void write_vtu(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
void cylinder(Triangulation< dim > &tria, const double radius=1., const double half_length=1.)
std::string type(const T &t)
Return a human readable name of the type passed as argument.
Definition: utilities.h:461
#define Assert(cond, exc)
Triangulation< dim, spacedim > * serial()
Return a pointer to a newly created serial Triangulation.
void load(Archive &ar, const unsigned int version)
void read_ucd(std::istream &in, const bool apply_all_indicators_to_manifolds=false)
virtual void declare_parameters(ParameterHandler &prm)
Declare all parameters of this class.
std::string input_grid_file_name
Input grid file name.
void parse_manifold_descriptors(const std::string &str_manifold_descriptors)
Take str_manifold_descriptors and fill manifold_descriptors with ids and manifolds.
double double_option_one
Optional double argument.
void copy_material_to_manifold_id(Triangulation< dim, spacedim > &tria, const bool compute_face_ids=false)
void hyper_cube_slit(Triangulation< dim > &tria, const double left=0., const double right=1., const bool colorize=false)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
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 read_msh(std::istream &in)
void cheese(Triangulation< dim, spacedim > &tria, const std::vector< unsigned int > &holes)
std::string print(const std::vector< Type > &list, const std::string sep=",")
Return a string containing the content of the vector, with elements separated by the @ sep parameter...
Definition: utilities.h:425
unsigned int manifold_id
Point< spacedim > point_option_one
Optional Point argument.
void save(Archive &ar, const unsigned int version) const
static shared_ptr< Manifold< 2, 3 > > create_manifold(ParsedGridGenerator< 2, 3 > *p, const std::string &name)
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)
ParsedGridGenerator(const std::string section_name="", const std::string grid_type="rectangle", const std::string input_grid_file="", const std::string opt_point_1="", const std::string opt_point_2="", const std::string opt_colorize="false", const std::string opt_double_1="1.0", const std::string opt_double_2="0.5", const std::string opt_double_3="1.5", const std::string opt_int_1="1", const std::string opt_int_2="2", const std::string opt_vec_of_int="", const std::string mesh_smoothing="none", const std::string output_grid_file="", const std::string opt_manifold_descriptors="")
Constructor.
void extract_geometrical_shapes(const TopoDS_Shape &shape, std::vector< TopoDS_Face > &faces, std::vector< TopoDS_Edge > &edges, std::vector< TopoDS_Vertex > &vertices)
static shared_ptr< Manifold< dim > > create_manifold(ParsedGridGenerator< dim > *p, const std::string &name)
Prototype function for creating new manifolds from a name and a pgg.
std::vector< std::string > split_string_list(const std::string &s, const char delimiter=',')
void read_unv(std::istream &in)
static shared_ptr< Manifold< 3 > > create_manifold(ParsedGridGenerator< 3 > *p, const std::string &name)
Prototype function for creating new manifolds from a name and a pgg.
int string_to_int(const std::string &s)
static::ExceptionBase & ExcNotImplemented()
Point< spacedim > point_option_two
Optional Point argument.
void write(const Triangulation< dim, spacedim > &tria, const std::string &filename="") const
Write the given Triangulation to the output file specified in Output file name, or in the optional fi...
Triangulation< dim, spacedim >::MeshSmoothing get_smoothing()
Mesh smoothing.
std::map< types::manifold_id, shared_ptr< Manifold< dim, spacedim > > > manifold_descriptors
A map of Manifold associated to the given manifold_ids.
void set_flags(const GridOutFlags::DX &flags)
static void create_grid(ParsedGridGenerator< dim, dim+1 > *p, Triangulation< dim, dim+1 > &tria, typename std::enable_if<(dim< 3), void **>::type=0)
This function is used to generate grids when spacedim = dim + 1.
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 hyper_ball(Triangulation< dim > &tria, const Point< dim > &center=Point< dim >(), const double radius=1.)
void attach_triangulation(Triangulation< dim, spacedim > &tria)
static shared_ptr< Manifold< dim, dim+1 > > create_manifold(ParsedGridGenerator< dim, dim+1 > *p, const std::string &name, typename std::enable_if<(dim< 3), void **>::type=0)
Prototype function for creating new manifolds from a name and a pgg.
void add_parameter(ParameterHandler &prm, T *parameter, const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
Add a parameter the given parameter list.
std::vector< unsigned int > un_int_vec_option_one
Optional vector of integers.
bool copy_boundary_to_manifold_ids
Copy boundary ids to manifold ids.
void create(Triangulation< dim, spacedim > &tria)
Generate the grid.
void create_triangulation(const TopoDS_Face &face, Triangulation< 2, 3 > &tria)
static::ExceptionBase & ExcInternalError()