Fluid structure interaction suite
ParsedTools::GridGenerator< dim, spacedim > Class Template Reference

GridGenerator class. More...

#include <grid_generator.h>

Inheritance diagram for ParsedTools::GridGenerator< dim, spacedim >:
[legend]

Public Member Functions

 GridGenerator (const std::string &prm_section_path="", const std::string &grid_generator_function="hyper_cube", const std::string &grid_generator_arguments="0: 1: false", const std::string &output_file_name="", const bool transform_to_simplex_grid=false, const unsigned int initial_grid_refinement=0)
 Constructor. More...
 
void generate (Triangulation< dim, spacedim > &tria) const
 Fill a triangulation according to the parsed parameters. More...
 
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 file name. More...
 
- Public Member Functions inherited from ParameterAcceptor
 ParameterAcceptor (const std::string &section_name="")
 
unsigned int get_acceptor_id () const
 
virtual ~ParameterAcceptor () override
 
virtual void declare_parameters (ParameterHandler &prm)
 
virtual void parse_parameters (ParameterHandler &prm)
 
std::string get_section_name () const
 
std::vector< std::string > get_section_path () const
 
void add_parameter (const std::string &entry, ParameterType &parameter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern())
 
void enter_subsection (const std::string &subsection)
 
void leave_subsection ()
 
void enter_my_subsection (ParameterHandler &prm)
 
void leave_my_subsection (ParameterHandler &prm)
 
void serialize (Archive &ar, const unsigned int version)
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&) noexcept
 
void serialize (Archive &ar, const unsigned int version)
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 
void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 

Private Attributes

std::string grid_generator_function
 Name of the grid to generate. More...
 
std::string grid_generator_arguments
 Arguments to the grid generator function. More...
 
std::string output_file_name
 Name of the output file. More...
 
bool transform_to_simplex_grid
 Transform quad and hex grids to simplex grids. More...
 
unsigned int initial_grid_refinement
 Initial global refinement of the grid. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ParameterAcceptor
static void initialize (const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle)
 
static void initialize (std::istream &input_stream, ParameterHandler &prm=ParameterAcceptor::prm)
 
static void clear ()
 
static void parse_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm)
 
static void declare_all_parameters (ParameterHandler &prm=ParameterAcceptor::prm)
 
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 
- Static Public Member Functions inherited from Subscriptor
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 
- Public Attributes inherited from ParameterAcceptor
boost::signals2::signal< void()> declare_parameters_call_back
 
boost::signals2::signal< void()> parse_parameters_call_back
 
- Static Public Attributes inherited from ParameterAcceptor
static ParameterHandler prm
 
- Protected Attributes inherited from ParameterAcceptor
const std::string section_name
 
std::vector< std::string > subsections
 

Detailed Description

template<int dim, int spacedim = dim>
class ParsedTools::GridGenerator< dim, spacedim >

GridGenerator class.

This is an interface, derived from ParameterAcceptor, for the deal.II function GridGenerator::generate_from_name_and_arguments(), for the classes GridIn and GridOut, and for the OpenCASCADE ArclengthProjectionLineManifold, NormalToMeshProjectionManifold, and NURBSPatchManifold classes.

Example usage:

GridGenerator<dim, spacedim> pgg("/Grid");
pgg.generate(tria);
pgg.write(tria);
static void initialize(const std::string &filename="", const std::string &output_filename="", const ParameterHandler::OutputStyle output_style_for_output_filename=ParameterHandler::Short, ParameterHandler &prm=ParameterAcceptor::prm, const ParameterHandler::OutputStyle output_style_for_filename=ParameterHandler::DefaultStyle)

This class follows the design of the ParameterAcceptor class to handle parameter files and section names.

The default set of parameters usad to drive this class is given by:

set Input name = hyper_cube
set Arguments = 0: 1: false
set Initial grid refinement = 1
set Output name = grid_out.msh
set Transform to simplex grid = false

The above example allows you to generate() a hypercube with side 1, lower left corner at the origin, and with all boundary ids set to zero by default. See GridGenerator::hyper_cube() for an explanation of all the arguments.

Input name

This class understands two types of Input name arguments:

  1. the name of one of the functions in the GridGenerator namespace of the deal.II library, as understood by the GridGenerator::generate_from_name_and_arguments() function;
  2. A file name, which is understood by the GridIn class of the deal.II library. In this case, the format of the name is deduced by the file extension. If everything else fails, GridIn::read_assimp() is used as a last resort.
Warning
If you have defined DEAL_II_WITH_MSH, and DEAL_II_GMSH_WITH_API, the preferred way to read .msh files will be through the api version, which supports the writing of both boundary ids, material ids and manifold ids.

Arguments

When the Input name argument is a function in the deal.II library, the Arguments parameter is interpreted as a list of arguments to be passed to the function itself, and it will be passed, together with the Input name parameter to the GridGenerator::generate_from_name_and_arguments() function.

If the argument is a filename, then the Arguments parameter is interpreted as a map from manifold ids to CAD file names (IGES, STEP, and STL formats are supported) that you can use to specify the Geometrical description of your domain (see [1] for more details of how this works in the deal.II library).

Warning
When writing your CAD files, make sure that each CAD file contains a single shape or compound for each of the topological entities you want to describe. This class uses the following interpretation:
  1. wires/edges and lines are fed to an ArclengthProjectionLineManifold, and can be used as manifolds for edges, both in two and three dimensions;
  2. surfaces and faces when spacedim is equal to two are fed to a NURBSPatchManifold, and can be used as a manifold for cell in two dimensions;
  3. surfaces and faces when spacedim is equal to three are fed to a NormalToMeshProjectionManifold, and can be used as a manifold for faces or edges in three dimensions;

Output name

The Output name argument is interpreted as a file name. If the extension is understood by GridOut, then the coarse triangulation is written to this file as soon as it is generated, before any refinement occurs.

Warning
The newly generated grid is written within the generate() function, before any refinement occurs. This allows you to write a grid to file, and then use the same file to read it back in as a coarse mesh, irrespective of the Initial grid refinement parameter. If you want to output explicitly the refined version of the grid, you should call the write() method with the grid you want to output.

Transform to simplex grid

If this is set to true, the class assumes you have read or generated a hex grid, and want to transform it to a simplex grid, i.e. the GridGenerator::convert_hypercube_to_simplex_mesh() is called with the grid that has been generated using Input name and Arguments.

Examples

In the following examples we assume that the class was instantiated with section name equal to "/". We report the example input parameter file, and show a plot of the resulting grid after refinement, i.e., we call the write() method ourselves. In order to regenerate the following examples, just place this somwhere in your code:

GridGenerator<dim, spacedim> pgg("/");
pgg.generate(tria);
pgg.write(tria);

Hyper shell

Parameter file :

set Arguments = 0,0: .5: 1: 5: true
set Initial grid refinement = 4
set Input name = hyper_shell
set Output name = hyper_shell.vtk
set Transform to simplex grid = false

This will generate a hyper shell with center in the point 0,0, inner radius .5, outer radius 1, and with 5 cells the angular direction, colorizing the boundary ids to 0 and 1. The output grid will look like the following:

and the coarse grid (before any refinement takes place) will also be written to hyper_shell.vtk as soon as the grid is generated.

If you later call again the write() method with another Triangulation as input parameter, then the argument of the write() method will overwrite the hyper_shell.vtk file (or the file you specified in the parameters) with the content of the grid.

Definition at line 175 of file grid_generator.h.

Constructor & Destructor Documentation

◆ GridGenerator()

template<int dim, int spacedim>
ParsedTools::GridGenerator< dim, spacedim >::GridGenerator ( const std::string &  prm_section_path = "",
const std::string &  grid_generator_function = "hyper_cube",
const std::string &  grid_generator_arguments = "0: 1: false",
const std::string &  output_file_name = "",
const bool  transform_to_simplex_grid = false,
const unsigned int  initial_grid_refinement = 0 
)

Constructor.

Initialize all parameters, and make sure the class is ready to run.

Parameters
prm_section_pathName of the section to use in the parameter file.

Definition at line 40 of file grid_generator.cc.

References ParameterAcceptor::add_parameter().

Member Function Documentation

◆ generate()

template<int dim, int spacedim>
void ParsedTools::GridGenerator< dim, spacedim >::generate ( Triangulation< dim, spacedim > &  tria) const

Fill a triangulation according to the parsed parameters.

If the output_file_name variable is not empty, the coarse triangulation is also saved to disk in the format specified by the the output_file_format.

Notice that the triangulation is written to disk before any initial refinement occurs. This allows you to store the Triangulation to a file, and then use the same input file you used here with the exception of the input/output grid names, and reproduce the same results.

If the triangulation would be refined before output, running the same program twice with input and output grid with the same name, would produce more and more refined grids. If you really want to output the same grid in the refined case, simply call the write() function again.

Definition at line 64 of file grid_generator.cc.

References AssertThrow, OpenCASCADE::count_elements(), deallog, StandardExceptions::ExcIO(), StandardExceptions::ExcNotImplemented(), GridGenerator::generate_from_name_and_arguments(), Triangulation< int dim, int spacedim >::load(), LogStream::pop(), LogStream::push(), GridIn< int dim, int spacedim >::read(), GridIn< int dim, int spacedim >::read_assimp(), OpenCASCADE::read_IGES(), GridIn< int dim, int spacedim >::read_msh(), OpenCASCADE::read_STEP(), OpenCASCADE::read_STL(), and Triangulation< int dim, int spacedim >::set_manifold().

Referenced by main().

◆ write()

template<int dim, int spacedim>
void ParsedTools::GridGenerator< dim, spacedim >::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 file name.

If no Output file name is given and filename is the empty string, this function does nothing. If an output file name is provided (either in the input file, or as an argument to this function), then this function will call the appropriate GridOut method according to the extension of the file name.

Definition at line 223 of file grid_generator.cc.

References Assert, AssertThrow, StandardExceptions::ExcIO(), StandardExceptions::ExcNotImplemented(), Triangulation< int dim, int spacedim >::save(), GridOut::set_flags(), GridOut::write_msh(), GridOut::write_ucd(), GridOut::write_vtk(), and GridOut::write_vtu().

Referenced by main().

Member Data Documentation

◆ grid_generator_function

template<int dim, int spacedim = dim>
std::string ParsedTools::GridGenerator< dim, spacedim >::grid_generator_function
private

Name of the grid to generate.

See the documentation of GridGenerator::generate_from_name_and_arguments() for a description of how to format the input string.

If the name does not coincide with a function in the GridGenerator namespace, the name is assumed to be a file name.

Definition at line 235 of file grid_generator.h.

◆ grid_generator_arguments

template<int dim, int spacedim = dim>
std::string ParsedTools::GridGenerator< dim, spacedim >::grid_generator_arguments
private

Arguments to the grid generator function.

See the documentation of GridGenerator::generate_from_name_and_arguments() for a description of how to format the input string.

Definition at line 242 of file grid_generator.h.

◆ output_file_name

template<int dim, int spacedim = dim>
std::string ParsedTools::GridGenerator< dim, spacedim >::output_file_name
private

Name of the output file.

Definition at line 245 of file grid_generator.h.

◆ transform_to_simplex_grid

template<int dim, int spacedim = dim>
bool ParsedTools::GridGenerator< dim, spacedim >::transform_to_simplex_grid
private

Transform quad and hex grids to simplex grids.

Definition at line 248 of file grid_generator.h.

◆ initial_grid_refinement

template<int dim, int spacedim = dim>
unsigned int ParsedTools::GridGenerator< dim, spacedim >::initial_grid_refinement
private

Initial global refinement of the grid.

Definition at line 251 of file grid_generator.h.


The documentation for this class was generated from the following files: