LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Related Symbols | List of all members
lf::mesh::Mesh Class Referenceabstract

Abstract interface for objects representing a single mesh. More...

#include <lf/mesh/mesh_interface.h>

Inheritance diagram for lf::mesh::Mesh:
lf::mesh::hybrid2d::Mesh

Public Types

using size_type = lf::base::size_type
 
using dim_t = lf::base::dim_t
 

Public Member Functions

virtual unsigned DimMesh () const =0
 The dimension of the manifold described by the mesh, or equivalently the maximum dimension of the reference elements present in the mesh.
 
virtual unsigned DimWorld () const =0
 The dimension of the Euclidean space in which the mesh is embedded.
 
virtual std::span< const Entity *const > Entities (unsigned codim) const =0
 All entities of a given codimension.
 
virtual size_type NumEntities (unsigned codim) const =0
 The number of Entities that have the given codimension.
 
virtual size_type NumEntities (lf::base::RefEl ref_el_type) const =0
 Tells number of entities of a particular topological/geometric type.
 
virtual size_type Index (const Entity &e) const =0
 Acess to the index of a mesh entity of any co-dimension.
 
virtual const mesh::EntityEntityByIndex (dim_t codim, base::glb_idx_t index) const =0
 Method for accessing an entity through its index.
 
virtual bool Contains (const Entity &e) const =0
 Check if the given entity is a part of this mesh.
 
virtual ~Mesh ()=default
 virtual destructor
 

Protected Member Functions

 Mesh ()=default
 
 Mesh (const Mesh &)=default
 
 Mesh (Mesh &&)=default
 
Meshoperator= (const Mesh &)=default
 
Meshoperator= (Mesh &&)=default
 

Related Symbols

(Note that these are not member symbols.)

void PrintInfo (std::ostream &o, const lf::mesh::Mesh &mesh, int ctrl=11)
 Diagnostic output operator. Prints info about a mesh.
 

Detailed Description

Abstract interface for objects representing a single mesh.

This abstract base class describes the basic functionality of objects that manage single-level conforming finite element meshes. These objects essentially boil down to containers for mesh entities of different co-dimensions. Thus they allow sequential traversal of these entities.

Another important functionality concerns the management of entity indices, which have to provide a consecutive numbering of entities of a specific co-dimension starting from zero.

Mesh object variables

Mesh objects are usually accessed through C++ shared pointers; declare and initialize variable for a mesh as follows (second line optional)

std::shared_ptr<lf::mesh::Mesh> mesh_p = .... ;
lf::mesh::Mesh &mesh(*mesh_p);
Abstract interface for objects representing a single mesh.

In most contexts mesh objects will be 'read-only' (immutable). Then the declaration should look like

std::shared_ptr<const lf::mesh::Mesh> mesh_p = .... ;
const lf::mesh::Mesh &mesh(*mesh_p);

Why do we use shared pointers? Usually in a finite element code a mesh object is allocated dynamically in the beginning and disposed only before the code terminates. Many other objects rely on information about the mesh. If the mesh was destroyed before all the objects depending on it, those would be plunged into an undefined state. Shared pointers ensure that a mesh object is destroyed only after every object holding a pointer to it has been destroyed.

Creating a mesh object

The standard ways to create a Mesh object are:

  1. Direct generation via the mesh::MeshFactory::Build() method. (This method is mainly used internally by LehrFEM++)
  2. Calling LehrFEM++'s generator of test meshes lf::mesh::test_utils::GenerateHybrid2DTestMesh().
  3. Reading a mesh from file, see lf::io::GmshReader, and invoking lf::io::GmshReader::mesh().
  4. Refining an existing mesh, see lf::refinement::MeshHierarchy.

Use case

The following function demonstrates the use of all pertinent methods of the class Entity. In particular is shows how to loop over all entities of a mesh.

// dimension of meshed manifold
const lf::base::dim_t dim_mesh = mesh.DimMesh();
// Now run over all co-dimensions to check indexing
for (lf::base::dim_t co_dim = 0; co_dim <= dim_mesh; ++co_dim) {
// Number of entities of current co-dimension. For a 2D hybrid mesh:
// codim == 0: cells, codim == 1: edges, codim == 2: nodes
const lf::base::size_type no_of_entities = mesh.NumEntities(co_dim);
// counting array for occurrences of an index
std::vector<int> idx_use(no_of_entities, 0);
// Traverse all entities of a given co-dimension. Note that the loop
// variable is a pointer!
for (const lf::mesh::Entity* entity_p : mesh.Entities(co_dim)) {
// Fetch index of current entity
const lf::base::glb_idx_t current_idx = mesh.Index(*entity_p);
// Check whether index is in range and, if so, count it
if (current_idx < no_of_entities)
idx_use[current_idx]++;
else
return false;
// Check consistency of indexing
const lf::mesh::Entity* e_ptr = mesh.EntityByIndex(co_dim, current_idx);
if ((e_ptr == nullptr) || (entity_p != e_ptr) ||
(current_idx != mesh.Index(*e_ptr)))
return false;
} // end loop over entities
// Indices should occur only once. This means that the counting array
// should contain 1 in every component.
for (lf::base::size_type idx_cnt = 0; idx_cnt < no_of_entities; ++idx_cnt) {
if (idx_use[idx_cnt] != 1) return false;
}
} // end for
return true;
} // end checkEntityIndexing()

Design and use of lf::mesh::Mesh functionality is also presented in Lecture Document Subsection 2.7.2.1

Definition at line 73 of file mesh_interface.h.

Member Typedef Documentation

◆ dim_t

Definition at line 84 of file mesh_interface.h.

◆ size_type

Auxiliary types

Definition at line 83 of file mesh_interface.h.

Constructor & Destructor Documentation

◆ Mesh() [1/3]

lf::mesh::Mesh::Mesh ( )
protecteddefault

◆ Mesh() [2/3]

lf::mesh::Mesh::Mesh ( const Mesh & )
protecteddefault

◆ Mesh() [3/3]

lf::mesh::Mesh::Mesh ( Mesh && )
protecteddefault

◆ ~Mesh()

virtual lf::mesh::Mesh::~Mesh ( )
virtualdefault

virtual destructor

Member Function Documentation

◆ Contains()

virtual bool lf::mesh::Mesh::Contains ( const Entity & e) const
pure virtual

Check if the given entity is a part of this mesh.

Parameters
eThe entity that should be checked.
Returns
true if the entity belongs to the mesh.

Implemented in lf::mesh::hybrid2d::Mesh.

◆ DimMesh()

virtual unsigned lf::mesh::Mesh::DimMesh ( ) const
pure virtual

The dimension of the manifold described by the mesh, or equivalently the maximum dimension of the reference elements present in the mesh.

See the code snippet showing the use of lf::mesh::Mesh

Implemented in lf::mesh::hybrid2d::Mesh.

Referenced by lf::mesh::test_utils::checkEntityIndexing(), lf::mesh::test_utils::checkMeshCompleteness(), lf::mesh::test_utils::isWatertightMesh(), PrintInfo(), lf::io::writeMatlab(), lf::io::writeMatplotlib(), and lf::io::writeTikZ().

◆ DimWorld()

virtual unsigned lf::mesh::Mesh::DimWorld ( ) const
pure virtual

The dimension of the Euclidean space in which the mesh is embedded.

Implemented in lf::mesh::hybrid2d::Mesh.

Referenced by PrintInfo().

◆ Entities()

virtual std::span< const Entity *const > lf::mesh::Mesh::Entities ( unsigned codim) const
pure virtual

All entities of a given codimension.

Parameters
codimThe codimension of the entities that should be returned.
Returns
A span of pointers to entities that enumerate all entities of the given codimension.
See also
Entity

Principal access method for entities distinguished only by their co-dimension. Hence, all cells of a mesh are covered by the range returned when giving co-dimension 0, regardless of their concrete shape.

The typical loop for entity traversal looks like this, where mesh is a variable containing a reference to a Mesh object.

for (const lf::mesh::Entity* entity : mesh.Entities(codim)) {
....
}
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
virtual std::span< const Entity *const > Entities(unsigned codim) const =0
All entities of a given codimension.

Inside the loop body the variable entity contains a pointer to an immutable object of type Entity whose co-dimension is codim.

Note
The pointer remains valid for as long as the mesh data structure remains valid.

Demonstration code

int traverseEntities(const lf::mesh::Mesh& mesh, lf::base::dim_t codim) {
// Typical loop for running through all entities of a specific co-dimension
for (const lf::mesh::Entity* entity : mesh.Entities(codim)) {
// Print entity information including its unique index
std::cout << cnt << ": Entity #" << mesh.Index(*entity) << ": " << *entity
<< std::endl;
cnt++;
}
return cnt;
}

Also see Lecture Document Example 2.7.2.6 or the code snippet showing the use of lf::mesh::Mesh

Implemented in lf::mesh::hybrid2d::Mesh.

Referenced by lf::mesh::test_utils::checkEntityIndexing(), lf::mesh::test_utils::checkMeshCompleteness(), lf::fe::InitEssentialConditionFromFunction(), lf::mesh::test_utils::isWatertightMesh(), lf::refinement::MeshHierarchy::MarkEdges(), lf::refinement::MeshHierarchy::PerformRefinement(), PrintInfo(), lf::refinement::MeshHierarchy::RefineMarked(), lf::refinement::MeshHierarchy::RefineRegular(), lf::io::writeMatlab(), lf::io::writeMatplotlib(), and lf::io::writeTikZ().

◆ EntityByIndex()

virtual const mesh::Entity * lf::mesh::Mesh::EntityByIndex ( dim_t codim,
base::glb_idx_t index ) const
pure virtual

Method for accessing an entity through its index.

Parameters
codimcodimension of the entity. Remember that indices are supposed to be unique and contiguous for a given co-dimension
indexan integer between 0 and number of entities of the given co-dimension -1. It passes the index.
Returns
pointer to the entity object with the given index.

Based on the bijectition between entities of a given co-dimension and an integer range. The following expression should evaluate to true, if mesh is a reference to a Mesh object, and idx a valid index

((idx < mesh.NumEntities(codim)) &&
mesh.Index(*mesh.EntityByIndex(codim,idx)) == idx)
Note
O(1) access complexity due to table lookup.

Also see the code snippet showing the use of lf::mesh::Mesh

Implemented in lf::mesh::hybrid2d::Mesh.

Referenced by lf::mesh::test_utils::checkEntityIndexing().

◆ Index()

virtual size_type lf::mesh::Mesh::Index ( const Entity & e) const
pure virtual

Acess to the index of a mesh entity of any co-dimension.

Parameters
eEntity whose index is requested
Returns
index ranging from 0 to no. of entities of the same co-dimension-1

It is a strict convention in LehrFEM++ that all entities of the same co-dimension belonging to a mesh are endowed with an integer index. These indices are guaranteed to be contiguous and to range from 0 to Size(codim)-1, cf. Lecture Document Equation 2.7.2.5.

Note
The index of a mesh entity is NOT related to its position in the range returned by the Entities() method.

Also see the code snippet showing the use of lf::mesh::Mesh

The indexing of mesh entities is explained in Lecture Document Subsection 2.7.2.1

Implemented in lf::mesh::hybrid2d::Mesh.

Referenced by lf::mesh::test_utils::checkEntityIndexing(), lf::mesh::test_utils::checkMeshCompleteness(), lf::mesh::test_utils::isWatertightMesh(), lf::refinement::MeshHierarchy::MarkEdges(), lf::refinement::MeshHierarchy::PerformRefinement(), PrintInfo(), lf::refinement::MeshHierarchy::RefineMarked(), lf::refinement::MeshHierarchy::RefineRegular(), lf::io::writeMatlab(), lf::io::writeMatplotlib(), and lf::io::writeTikZ().

◆ NumEntities() [1/2]

virtual size_type lf::mesh::Mesh::NumEntities ( lf::base::RefEl ref_el_type) const
pure virtual

Tells number of entities of a particular topological/geometric type.

Parameters
ref_el_typetopological/geometric type
Returns
number of entities of that type

Implemented in lf::mesh::hybrid2d::Mesh.

◆ NumEntities() [2/2]

virtual size_type lf::mesh::Mesh::NumEntities ( unsigned codim) const
pure virtual

The number of Entities that have the given codimension.

Parameters
codimThe codimension of the entities that should be counted.
Returns
That number of entities that have the given codimension.

See the code snippet showing the use of lf::mesh::Mesh

Implemented in lf::mesh::hybrid2d::Mesh.

Referenced by lf::mesh::test_utils::checkEntityIndexing(), lf::mesh::test_utils::checkMeshCompleteness(), lf::refinement::MeshHierarchy::MarkEdges(), PrintInfo(), lf::refinement::MeshHierarchy::RefineMarked(), lf::refinement::MeshHierarchy::RefineRegular(), lf::io::writeMatlab(), and lf::io::writeTikZ().

◆ operator=() [1/2]

Mesh & lf::mesh::Mesh::operator= ( const Mesh & )
protecteddefault

◆ operator=() [2/2]

Mesh & lf::mesh::Mesh::operator= ( Mesh && )
protecteddefault

Friends And Related Symbol Documentation

◆ PrintInfo()

void PrintInfo ( std::ostream & o,
const lf::mesh::Mesh & mesh,
int ctrl = 11 )
related

Diagnostic output operator. Prints info about a mesh.

Parameters
meshThe mesh to print info about
ctrlcontrols the level of detail of the printed output (see below)
oThe stream to which this function should output

Output levels

  • > 10: also output entity information
  • > 90: also output subentity information

Definition at line 18 of file print_info.cc.

References lf::geometry::Geometry::DimLocal(), DimMesh(), DimWorld(), Entities(), lf::geometry::Geometry::Geometry(), lf::geometry::Geometry::Global(), Index(), lf::base::RefEl::NodeCoords(), NumEntities(), lf::geometry::Geometry::RefEl(), and lf::base::RefEl::RefEl().


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