Skip to content

Latest commit

 

History

History
416 lines (287 loc) · 13.4 KB

File metadata and controls

416 lines (287 loc) · 13.4 KB

Using computational meshes

Introduction

Feel++ provides some tools to manipulate meshes. Here is a basic example that shows how to generate a mesh for a square geometry

Excerpt from codes/mymesh.cpp
link:../../../../codes/03-mymesh.cpp[role=include]

As always, we initialize the {feelpp} environment (see section [FirstApp] ). The unitSquare() will generate a mesh for a square geometry. Feel++ provides several functions to automate the GMSH mesh generation for different topologies. These functions will create a geometry file .geo and a mesh file .msh. We can visualize them in {uri-gmsh-www}[Gmsh].

$ gmsh <entity_name>.msh

Finally we use the exporter() (see \ref Exporter) function to export the mesh for post processing. It will create by default a Paraview format file .sos and an Ensight format file .case.

$ paraview <app_name>.case

In this section, we present some of the mesh definition and manipulation tools provided by Feel++. For more information you can also read {uri-gmsh-manual}[the Gmsh manual].

Basic Meshes

There is a list of basic geometries you can automatically generate with Feel++ library.

Table 1. Table of function generation basic primitive mesh

Feel++ function

Dim

Description

unitSegment()

1

Build a mesh of the unit segment \$[0,1\$]

unitSquare()

2

Build a mesh of the unit square \$[0,1\$^2] using triangles

unitCircle()

2

Build a mesh of the unit circle using triangles

unitHypercube()

3

Build a mesh of the unit hypercube \$[0,1\$^3] using tetrahedrons

unitSphere()

3

Build a mesh of the unit sphere using tetrahedrons

Example
auto mesh = unitSquare();

Loading Meshes

loadMesh

You can use this function to load mesh from different formats

Note
in the case of a .geo file, {feelpp} automatically generate a mesh data structure on this geometrical structure.
Interface
mesh_ptrtype loadMesh(_mesh, _filename, _refine, _update, physical_are_elementary_regions);

Required Parameters:

  • _mesh a mesh data structure.

Optional Parameters:

Name Type Description Default Value Option

_hsize

double

characteristic size of the mesh. This option will edit the .geo file and change the variable h if defined

0.1

gmsh.hsize

_geo_variables_list

string

Set a list of variable that may be defined in a .geo file

""

gmsh.geo-variables-list

_filename

string

filename with extension

feel.geo

gmsh.filename

_depends

string

list of files (separated by , or ;) on which gmsh.filename depends

""

gmsh.depends

_refine

boolean

optionally refine with \p refine levels the mesh.

0.

gmsh.refine

_update

integer

update the mesh data structure (build internal faces and edges)

true

_physical_are_elementary_regions

boolean

to load specific meshes formats.

false.

gmsh.physical_are_elementary_regions

_straighten

boolean

in case of curvilinear elements, straighten the elements which are not touching with a face the boundary of the domain

true

gmsh.straighten

_partitioner

The file you want to load has to be in an appropriate repository. {feelpp} looks for the files in the following directories (in this order):

  • current path

  • paths that went through changeRepository(), it means that we look for example into the path from which the executable was run

  • localGeoRepository() which is usually "$HOME/feel/geo" (Environment )

  • systemGeoRepository() which is usually "$FEELPP_DIR/share/feel/geo" (Environment)

Examples

Load a mesh data structure from the file $HOME/feel/mymesh.msh.

auto mesh = loadMesh(_mesh=new mesh_type,
                     _filename="mymesh.msh");

Load a geometric structure from the file ./mygeo.geo and automatically create a mesh data structure.

auto mesh = loadMesh(_mesh=new mesh_type,
                     _filename="mygeo.geo");

Create a mesh data structure from the file ./feel.geo.

auto mesh = loadMesh(_mesh=new Mesh<Simplex< 2 > > );

loadGMSHMesh

In order to load only .msh file, you can also use the loadGMSHMesh.

Interface:

mesh_ptrtype loadGMSHMesh(_mesh, _filename, _refine, _update, _physical_are_elementary_regions);

Required Parameters:

  • _mesh a mesh data structure.

  • _filename filename with extension.

Optional Parameters:

  • _refine optionally refine with \p refine levels the mesh. - Default =0

  • _update update the mesh data structure (build internal faces and edges).

    • Default =true

  • _physical_are_elementary_regions to load specific meshes formats.

    • Default = false

The file you want to load has to be in an appropriate repository. See LoadMesh.

Examples

From doc/manual/heatns.cpp

 mesh_ptrtype mesh = loadGMSHMesh( _mesh=new mesh_type,
                                   _filename="piece.msh",
                                   _update=MESH_CHECK|MESH_UPDATE_FACES|MESH_UPDATE_EDGES|MESH_RENUMBER );

From applications/check/check.cpp

mesh = loadGMSHMesh( _mesh=new mesh_type,
                     _filename=soption("filename"),
                     _rebuild_partitions=(Environment::worldComm().size() > 1),
                     _update=MESH_RENUMBER|MESH_UPDATE_EDGES|MESH_UPDATE_FACES|MESH_CHECK );

Creating Meshes

createGMSHMesh

Interface
mesh_ptrtype createGMSHMesh(_mesh, _desc, _h, _order, _parametricnodes, _refine, _update, _force_rebuild, _physical_are_elementary_regions);

Required Parameters:

  • _mesh mesh data structure.

  • _desc descprition. See further.

Optional Parameters:

  • _h characteristic size.

    • Default = 0.1

  • _order order.

    • Default = 1

  • _parametricnodes

    • Default = 0

  • _refine optionally refine with \p refine levels the mesh.

    • Default =0

  • _update update the mesh data structure (build internal faces and edges).

    • Default =true

  • _force_rebuild rebuild mesh if already exists.

    • Default = false

  • _physical_are_elementary_regions to load specific meshes formats.

    • Default = false

To generate your mesh you need a description parameter. This one can be create by one the two following function.

geo

Use this function to create a description from a .geo file.

Interface
gmsh_ptrtype geo(_filename, _h, _dim, _order, _files_path);

Required Parameters:

  • filename: file to load.

Optional Parameters:

  • _h characteristic size of the mesh.

    • Default = 0.1.

  • _dim dimension.

    • Default = 3.

  • _order order.

    • Default = 1.

  • _files_path path to the file.

    • Default = localGeoRepository().

The file you want to load has to be in an appropriate repository. See LoadMesh.

Example

From doc/manual/heat/ground.cpp

mesh = createGMSHMesh( _mesh=new mesh_type,
                       _desc=geo( _filename="ground.geo",
                                  _dim=2,
                                  _order=1,
                                  _h=meshSize ) );
Excerpt from doc/manual/fd/penalisation.cpp
mesh = createGMSHMesh( _mesh=new mesh_type,
                       _desc=geo( _filename=File_Mesh,
                                  _dim=Dim,
                                  _h=doption(_name="gmsh.hsize"),
                                  _update=MESH_CHECK|MESH_UPDATE_FACES|MESH_UPDATE_EDGES|MESH_RENUMBER );

domain

Use this function to generate a simple geometrical domain from parameters.

Interface
gmsh_ptrtype domain(_name, _shape, _h, _dim, _order, _convex, \
                    _addmidpoint, _xmin, _xmax, _ymin, _ymax, _zmin, _zmax);

Required Parameters:

  • _name name of the file that will ge generated without extension.

  • _shape shape of the domain to be generated (simplex or hypercube).

Optional Parameters:

  • _h characteristic size of the mesh.

    • Default = 0.1

  • _dim dimension of the domain.

    • Default = 2

  • _order order of the geometry.

    • Default = 1

  • _convex type of convex used to mesh the domain.

    • Default = simplex

  • _addmidpoint add middle point.

    • Default = true

  • _xmin minimum x coordinate.

    • Default = 0

  • _xmax maximum x coordinate.

    • Default = 1

  • _ymin minimum y coordinate.

    • Default = 0

  • _ymax maximum y coordinate.

    • Default = 1.

  • _zmin minimum z coordinate.

    • Default = 0

  • _zmax maximum z coordinate.

    • Default = 1

Example

From doc/manual/laplacian/laplacian.ccp

mesh_ptrtype mesh = createGMSHMesh( _mesh=new mesh_type,
                                    _desc=domain( _name=( boost::format( "%1%-%2%" ) % shape % Dim ).str() ,
                                                  _usenames=true,
                                                  _shape=shape,
                                                  _h=meshSize,
                                                  _xmin=-1,
                                                  _ymin=-1 ) );

From doc/manual/stokes/stokes.cpp

mesh = createGMSHMesh( _mesh=new mesh_type,
                       _desc=domain( _name=(boost::format("%1%-%2%-%3%")%"hypercube"%convex_type().dimension()%1).str() ,
                                     _shape="hypercube",
                                     _dim=convex_type().dimension(),
                                     _h=meshSize ) );

From doc/manual/solid/beam.cpp

mesh_ptrtype mesh = createGMSHMesh( _mesh=new mesh_type,
                                    _update=MESH_UPDATE_EDGES|MESH_UPDATE_FACES|MESH_CHECK,
                                    _desc=domain( _name=( boost::format( "beam-%1%" ) % nDim ).str(),
                                                  _shape="hypercube",
                                                  _xmin=0., _xmax=0.351,
                                                  _ymin=0., _ymax=0.02,
                                                  _zmin=0., _zmax=0.02,
                                                  _h=meshSize ) );

Mesh Operations

straightenMesh

One of the optimisations that allows to have a huge gain in computational effort is to straighten all the high order elements except for the boundary faces of the computational mesh. This is achieved by moving all the nodes associated to the high order transformation to the position these nodes would have if a first order geometrical transformation were applied. This procedure can be formalized in the following operator

\$\mathbf{\eta}^{\mathrm{straightening}}_K(\mathbf{\varphi}^N_{K}(\mathbf{x}^*)) = \left(\mathbf{\varphi}^1_{K}(\mathbf{x}^*)-\mathbf{\varphi}^N_{K}(\mathbf{x}^*)\right) - {\left( \mathbf{\varphi}^1_{K \cap \Gamma}(\mathbf{x}^*)-\mathbf{\varphi}^N_{K \cap \Gamma}(\mathbf{x}^*)\right)}\$

where \$\mathbf{x}^*\$ is any point in \$K^*\$ and \$\mathbf{\varphi}^1_{K}(\mathbf{x}^*)\$ and \$\mathbf{\varphi}^N_{K}(\mathbf{x}^*)\$ its images by the geometrical transformation of order one and order \$N\$, respectively. On one hand, the first two terms ensure that for all \$K\$ not intersecting \$\Gamma\$, the order one and \$N\$ transformations produce the same image. On the other hand, the last two terms are 0 unless the image of \$\mathbf{x}^*\$ in on \$\Gamma\$ and, in this case, we don’t move the high order image of \$\mathbf{x}^*\$. This allows to have straight internal elements and elements touching the boundary to remain high order. When applying numerical integration, specific quadratures are considered when dealing with internal elements or elements sharing a face with the boundary. The performances, thanks to this transformation, are similar to the ones obtained with first order meshes. However, it needs to be used with care as it can generate folded meshes.

createSubmesh

In multiphysics applications or using advanced numerical methods e.g. involving Lagrange multipliers, it is often required to define Function Spaces on different meshes. Theses meshes are often related. Consider for example a heat transfer problem on a domain \$\Omega\$ coupled with fluid flow problem on a domain \$\Omega_f \subset \Omega\$ as in the {uri-benchmarks}heat[Heat Transfer benchmarks]. createSubmesh allows to extract \$\Omega_f\$ out of \$\Omega\$ while keeping information on the relation between the two meshes to be able to transfer data between these meshes very efficiently.

auto mesh=loadMesh(_mesh=new Mesh<Simplex<d>>); (1)
auto fluid_mesh = createSubmesh( mesh, markedelements(mesh,"Air") ); (2)
auto face_mesh = createSubmesh( mesh, faces(mesh) ); (3)
  1. create a mesh of simplices of dimension \$d\$

  2. extract a mesh subregion \$\Omega_f\$ marked Air from a mesh \$\Omega\$

  3. extract a \$d-1\$ mesh made of all the faces of the \$d\$ mesh