LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
lf::refinement::MeshHierarchy Class Reference

A hierarchy of nested 2D hybrid meshes created by refinement. More...

#include <lf/refinement/mesh_hierarchy.h>

Public Member Functions

 MeshHierarchy (const std::shared_ptr< mesh::Mesh > &base_mesh, std::unique_ptr< mesh::MeshFactory > mesh_factory)
 Initialize mesh hierarchy with an existing coarsest mesh.
 
 MeshHierarchy (const MeshHierarchy &)=delete
 
MeshHierarchyoperator= (const MeshHierarchy &)=delete
 
 MeshHierarchy (MeshHierarchy &&)=delete
 
MeshHierarchyoperator= (MeshHierarchy &&)=delete
 
size_type NumLevels () const
 number of meshes contained in the hierarchy, 1 for a single mesh
 
std::shared_ptr< const mesh::MeshgetMesh (size_type level) const
 access the mesh on a particular level
 
std::shared_ptr< mesh::MeshgetMesh (size_type level)
 access the mesh on a particular level
 
std::vector< std::shared_ptr< const mesh::Mesh > > getMeshes () const
 Provides array of shared pointers to meshes contained in the hierarchy.
 
const std::vector< PointChildInfo > & PointChildInfos (size_type level) const
 Obtain refinement information for all points.
 
const std::vector< EdgeChildInfo > & EdgeChildInfos (size_type level) const
 Obtain refinement information for all edges.
 
const std::vector< CellChildInfo > & CellChildInfos (size_type level) const
 Obtain refinement information for all.
 
const std::vector< ParentInfo > & ParentInfos (size_type level, dim_t codim) const
 Fetch information about parents.
 
const std::vector< sub_idx_t > & RefinementEdges (size_type level) const
 Access refinement edge indices.
 
void RefineRegular (RefPat ref_pat=RefPat::rp_regular)
 Perform regular or barycentric uniform refinement of the finest mesh in the hierarchy.
 
template<typename Marker >
void MarkEdges (Marker &&marker)
 Mark the edges of a mesh based on a predicate.
 
void RefineMarked ()
 Conduct local refinement of the mesh splitting all marked edges.
 
void Coarsen ()
 Destroy the mesh on the finest level unless it is the base mesh
 
const lf::geometry::GeometryGeometryInParent (size_type level, const lf::mesh::Entity &e) const
 shape of child entity in parent's reference coordinates
 
const lf::mesh::EntityParentEntity (size_type level, const lf::mesh::Entity &e) const
 Retrieve the parent of an entity contained in a mesh of a refinement hierarchy.
 
std::ostream & PrintInfo (std::ostream &o, unsigned ctrl=0) const
 Output of information about the mesh hierarchy.
 
virtual ~MeshHierarchy ()=default
 

Static Public Member Functions

static std::shared_ptr< spdlog::logger > & Logger ()
 Is used by MeshHierarchy to log additional information for debugging purposes.
 

Private Member Functions

void PerformRefinement ()
 Create new mesh according to refinement pattern provided for entities.
 
void initGeometryInParent ()
 Initialization of rel_ref_geo fields of ParentInfo structures.
 

Static Private Member Functions

static sub_idx_t LongestEdge (const lf::mesh::Entity &T)
 Finds the index of the longest edge of a triangle.
 

Private Attributes

std::vector< std::shared_ptr< mesh::Mesh > > meshes_
 the meshes managed by the MeshHierarchy object
 
std::unique_ptr< mesh::MeshFactorymesh_factory_
 The mesh factory to be used to creating a new mesh.
 
std::vector< std::vector< PointChildInfo > > point_child_infos_
 information about children of nodes for each level
 
std::vector< std::vector< EdgeChildInfo > > edge_child_infos_
 information about children of edges for each level
 
std::vector< std::vector< CellChildInfo > > cell_child_infos_
 information about children of cells for each level
 
std::vector< std::array< std::vector< ParentInfo >, 3 > > parent_infos_
 information about parent entities on each level
 
std::vector< std::vector< bool > > edge_marked_
 Information about marked edges.
 
std::vector< std::vector< sub_idx_t > > refinement_edges_
 Information about local refinement edges of triangles.
 

Detailed Description

A hierarchy of nested 2D hybrid meshes created by refinement.

This is the fundamental class for managing sequences of meshes that have been created by successive local or global refinement of an initial coarsest mesh. Objects of this class store comprehensive information about the relationship of the meshes in the sequence: parent-child relationships of mesh cells and local refinement patterns.

sample usage

// Generate test mesh
std::shared_ptr<lf::mesh::Mesh> mesh_p =
// Construction of a mesh hierarchy requires a factory object
std::unique_ptr<lf::mesh::hybrid2d::MeshFactory> mesh_factory_ptr =
std::make_unique<lf::mesh::hybrid2d::MeshFactory>(2);
// Initialize still flat MESH HIERARCHY containing a single mesh
lf::refinement::MeshHierarchy multi_mesh(mesh_p, std::move(mesh_factory_ptr));
// Perform a first step of regular refinement: adds a mesh
multi_mesh.RefineRegular();
// For demonstration purposes: Mark edges whose center lies inside a square
// type: std::function<bool(const lf::mesh::Mesh &, const lf::mesh::Entity
// &edge)>, but 'auto' faster.
auto marker = [](const lf::mesh::Mesh &mesh,
const lf::mesh::Entity &edge) -> bool {
Eigen::MatrixXd ref_c = (Eigen::MatrixXd(1, 1) << 0.5).finished();
Eigen::VectorXd c(edge.Geometry()->Global(ref_c));
return ((c[0] > 1.0) && (c[0] < 2.0) && (c[1] > 1.0) && (c[1] < 2.0));
};
// mark edges for which predicate returns true
multi_mesh.MarkEdges(marker);
// Refine current finest mesh locally: adds another mesh to the hierarchy
multi_mesh.RefineMarked();
// Finally obtain pointer to finest mesh in the hierarchy with three meshes
std::shared_ptr<const mesh::Mesh> fine_mesh = multi_mesh.getMesh(2);

In the context of studying convergence of finite elemment method objects of type MeshHierarchy can be employed to hold sequencies of uniformly refine meshes, see MeshHierarchy::RefineRegular().

Definition at line 116 of file mesh_hierarchy.h.

Constructor & Destructor Documentation

◆ MeshHierarchy() [1/3]

lf::refinement::MeshHierarchy::MeshHierarchy ( const std::shared_ptr< mesh::Mesh > & base_mesh,
std::unique_ptr< mesh::MeshFactory > mesh_factory )

Initialize mesh hierarchy with an existing coarsest mesh.

Parameters
base_meshvalid pointer to non-const coarsest mesh
mesh_factoryfactory object creating new meshes during refinement
  • Stores shared pointer to coarsest mesh.
  • Sets refinement edges of all cells according to the longest-edge criterion.
  • Initializes ChildInfo data structures of all entities to indicate absence of children, since no refinement has been done yet.
  • Fills void ParentInfo data structure, since the mesh has not been created by refinement.
  • Unmarks all edges, see RefineMarked().

Definition at line 34 of file mesh_hierarchy.cc.

References cell_child_infos_, edge_child_infos_, edge_marked_, lf::refinement::idx_nil, lf::base::RefEl::kTria(), LongestEdge(), meshes_, parent_infos_, point_child_infos_, and refinement_edges_.

◆ MeshHierarchy() [2/3]

lf::refinement::MeshHierarchy::MeshHierarchy ( const MeshHierarchy & )
delete

◆ MeshHierarchy() [3/3]

lf::refinement::MeshHierarchy::MeshHierarchy ( MeshHierarchy && )
delete

◆ ~MeshHierarchy()

virtual lf::refinement::MeshHierarchy::~MeshHierarchy ( )
virtualdefault

Member Function Documentation

◆ CellChildInfos()

const std::vector< CellChildInfo > & lf::refinement::MeshHierarchy::CellChildInfos ( size_type level) const
inline

Obtain refinement information for all.

Parameters
levelrefinement level to be queried
Returns
vector for CellChildInfo record for every node
See also
CellChildInfo

Definition at line 211 of file mesh_hierarchy.h.

References cell_child_infos_, and NumLevels().

◆ Coarsen()

void lf::refinement::MeshHierarchy::Coarsen ( )

Destroy the mesh on the finest level unless it is the base mesh

Note
the use of shared pointers prevents destruction if the finest mesh is still in use somewhere else in the code.

◆ EdgeChildInfos()

const std::vector< EdgeChildInfo > & lf::refinement::MeshHierarchy::EdgeChildInfos ( size_type level) const
inline

Obtain refinement information for all edges.

Parameters
levelrefinement level to be queried
Returns
vector for EdgeChildInfo record for every node
See also
EdgeChildInfo

Definition at line 198 of file mesh_hierarchy.h.

References edge_child_infos_, and NumLevels().

◆ GeometryInParent()

const lf::geometry::Geometry * lf::refinement::MeshHierarchy::GeometryInParent ( size_type level,
const lf::mesh::Entity & e ) const

shape of child entity in parent's reference coordinates

Parameters
levellevel of the fine mesh in the mesh hierarchy
ereference to entity object of the fine mesh
Returns
pointer to geometry description of entity of fine mesh with respect to reference coordinate system of its parent entity.

We consider the shape of the reference entity of the parent entity of e as a triangulated domain, if the parent entity has a positive dimension, that is, if it is not a point. The entities of that triangulation correspond to the reference shapes of the child entities on the fine mesh. This method returns the shape of an entity of that triangulation.

Example: The case of a quadrilateral split into four child entities, corresponding to rp_threeedge as defined in lf::refinement::RefPat, lf::refinement::Hybrid2DRefinementPattern::ChildPolygons(). The following image gives the local child numbers in pink.

The geometries of the child entities are as follows:

  • Child 0: quadrilateral with corners

    \[ \left[\begin{array}{cccc} 1 & 0 & 0 & 1 \\ 1 & 1 & 0.5 & 0.5 \end{array}\right] \]

  • Child 1: triangle with corners

    \[ \left[\begin{array}{ccc} 0 & 0.5 & 0 \\ 0 & 0 & 0.5 \end{array} \right] \]

  • Child 2: triangle with corners

    \[ \left[\begin{array}{ccc} 1 & 0.5 & 1 \\ 0.5 & 0 & 0 \end{array} \right] \]

  • Child 3: triangle with corners

    \[ \left[\begin{array}{ccc} 0.5 & 1 & 0 \\ 0 & 0.5 & 0.5 \end{array} \right] \]

One of the displayed matrices is returned if the entity e corresponds to that child of a quadrilateral.

Definition at line 1860 of file mesh_hierarchy.cc.

Referenced by lf::refinement::MeshFunctionTransfer< MF >::operator()().

◆ getMesh() [1/2]

std::shared_ptr< mesh::Mesh > lf::refinement::MeshHierarchy::getMesh ( size_type level)
inline

access the mesh on a particular level

Parameters
levelspecifies level of interest, 0 stands for coarsest level
Returns
shared pointer to mesh on specified level

Definition at line 160 of file mesh_hierarchy.h.

References meshes_.

◆ getMesh() [2/2]

std::shared_ptr< const mesh::Mesh > lf::refinement::MeshHierarchy::getMesh ( size_type level) const
inline

access the mesh on a particular level

Parameters
levelspecifies level of interest, 0 stands for coarsest level
Returns
shared pointer to mesh on specified level

Definition at line 151 of file mesh_hierarchy.h.

References meshes_.

Referenced by lf::refinement::MeshFunctionTransfer< MF >::getMesh(), lf::refinement::MeshFunctionTransfer< MF >::MeshFunctionTransfer(), lf::refinement::WriteMatlab(), and lf::refinement::WriteMatlabLevel().

◆ getMeshes()

std::vector< std::shared_ptr< const mesh::Mesh > > lf::refinement::MeshHierarchy::getMeshes ( ) const
inline

Provides array of shared pointers to meshes contained in the hierarchy.

Returns
vector of shared pointers to lf::mesh:Mesh objects

Definition at line 172 of file mesh_hierarchy.h.

References meshes_.

◆ initGeometryInParent()

void lf::refinement::MeshHierarchy::initGeometryInParent ( )
private

Initialization of rel_ref_geo fields of ParentInfo structures.

This method created geometry::Geometry type objects describing the shape of a child entity in the reference coordinates of its parent.

Note
This method assumes that the parent-child connections of the mesh hierarchy have been initialized completely already. Therefore this method is invoked at the end of PerformRefinement().

Definition at line 1605 of file mesh_hierarchy.cc.

Referenced by RefineMarked(), and RefineRegular().

◆ Logger()

std::shared_ptr< spdlog::logger > & lf::refinement::MeshHierarchy::Logger ( )
static

Is used by MeshHierarchy to log additional information for debugging purposes.

Definition at line 27 of file mesh_hierarchy.cc.

References lf::base::InitLogger().

Referenced by PerformRefinement().

◆ LongestEdge()

sub_idx_t lf::refinement::MeshHierarchy::LongestEdge ( const lf::mesh::Entity & T)
staticprivate

Finds the index of the longest edge of a triangle.

This method is used for setting refinement edges on coarsest meshes. Called in the constructor of MeshHierarchy.

Definition at line 1839 of file mesh_hierarchy.cc.

Referenced by MeshHierarchy().

◆ MarkEdges()

template<typename Marker >
void lf::refinement::MeshHierarchy::MarkEdges ( Marker && marker)

Mark the edges of a mesh based on a predicate.

Parameters
markerthis should be functor of type std::function<bool(const Mesh &,const Entity &)> returning true if the passed edge is to be marked.

The marker object also takes a reference to a mesh, because marking makes sense only for the finest level. The mesh on the finest level is provided to the marker object by the MeshHierarchy.

Of course, marking will always affect the finest mesh in hierarchy.

Definition at line 455 of file mesh_hierarchy.h.

References edge_marked_, lf::mesh::Mesh::Entities(), lf::mesh::Mesh::Index(), meshes_, and lf::mesh::Mesh::NumEntities().

◆ NumLevels()

size_type lf::refinement::MeshHierarchy::NumLevels ( ) const
inline

◆ operator=() [1/2]

MeshHierarchy & lf::refinement::MeshHierarchy::operator= ( const MeshHierarchy & )
delete

◆ operator=() [2/2]

MeshHierarchy & lf::refinement::MeshHierarchy::operator= ( MeshHierarchy && )
delete

◆ ParentEntity()

const lf::mesh::Entity * lf::refinement::MeshHierarchy::ParentEntity ( size_type level,
const lf::mesh::Entity & e ) const

Retrieve the parent of an entity contained in a mesh of a refinement hierarchy.

Parameters
levelrefinement level > 0 of the fine mesh
epointer to (potential) child entity, must be contained in mesh on the specified level.
Returns
pointer to parent entity
Note
to be used in combination with geometry::Geometry::GeometryInParent()

Definition at line 1878 of file mesh_hierarchy.cc.

Referenced by lf::refinement::MeshFunctionTransfer< MF >::operator()().

◆ ParentInfos()

const std::vector< ParentInfo > & lf::refinement::MeshHierarchy::ParentInfos ( size_type level,
dim_t codim ) const
inline

Fetch information about parents.

Parameters
levelrefinement level of interest
codimco-dimension of entities to be queried
Returns
vector for ParentInfo record for every entity
See also
ParentInfo

Definition at line 225 of file mesh_hierarchy.h.

References NumLevels(), and parent_infos_.

Referenced by lf::refinement::WriteMatlabLevel().

◆ PerformRefinement()

void lf::refinement::MeshHierarchy::PerformRefinement ( )
private

Create new mesh according to refinement pattern provided for entities.

This function expects that the refinement patterns stored in the vectors point_child_infos_, edge_child_infos_ and cell_child_infos_ have been initialized consistently for the finest mesh. According to this information, refinement is carried out using the object pointed to by mesh_factory_ to created new entities by calling lf::mesh::MeshFactory::Build().

The vectors point_child_infos_, edge_child_infos_ and cell_child_infos_ will be augmented with information about the indices of the child entities contained in the newly created finest mesh.

This method relies on lf::geometry::Geometry::ChildGeometry() to obtain information about the shape of child entities in the form of lf::geometry::Geometry objects.

The method also initializes the data vectors in _parent_infos_ for the newly created finest mesh.

Definition at line 368 of file mesh_hierarchy.cc.

References lf::refinement::EdgeChildInfo::child_edge_idx, lf::refinement::EdgeChildInfo::child_point_idx, lf::geometry::Geometry::ChildGeometry(), edge_child_infos_, lf::mesh::Mesh::Entities(), lf::mesh::Mesh::Index(), lf::base::RefEl::kPoint(), Logger(), mesh_factory_, meshes_, point_child_infos_, lf::refinement::EdgeChildInfo::ref_pat_, lf::refinement::rp_copy, lf::refinement::rp_nil, and lf::refinement::rp_split.

Referenced by RefineMarked(), and RefineRegular().

◆ PointChildInfos()

const std::vector< PointChildInfo > & lf::refinement::MeshHierarchy::PointChildInfos ( size_type level) const
inline

Obtain refinement information for all points.

Parameters
levelrefinement level to be queried
Returns
vector for PointChildInfo record for every node
See also
PointChildInfo

Definition at line 185 of file mesh_hierarchy.h.

References NumLevels(), and point_child_infos_.

◆ PrintInfo()

std::ostream & lf::refinement::MeshHierarchy::PrintInfo ( std::ostream & o,
unsigned ctrl = 0 ) const

Output of information about the mesh hierarchy.

Parameters
ooutput stream, can be std::cout or similar
ctrlcontrols the level of detail of the generated output.
Returns
output stream

The type of output is controlled by the ctrl static control variable. If its second bit is set, the output function of the mesh class is used.

This is a rudimentary implementation and should be extended.

Definition at line 1896 of file mesh_hierarchy.cc.

◆ RefineMarked()

void lf::refinement::MeshHierarchy::RefineMarked ( )

Conduct local refinement of the mesh splitting all marked edges.

This method creates a new mesh by selectively (locally) refining entities of the current finest mesh in the hierarchy. Refinement is controlled by the boolean vector edge_marked_ that indicates, which edges must be refined (= split) in the course of refinement.

Algorithm

  • First all marked edges are labelled as "to be split".
  • REPEAT

    • Set refinement pattern of all cells to accommodate edges to be split
    • Add "to be split" tag to edges according to local refinement pattern for cells

    UNTIL no extra edges had to be tagged as "to be split"

For details please consult the comments in mesh_hierarchy.cc

This algorithm ends with a set of local refinement patterns for every entity that is compatible with a conforming finite element mesh, that is, hanging nodes are avoided.

Definition at line 116 of file mesh_hierarchy.cc.

References cell_child_infos_, edge_child_infos_, edge_marked_, lf::mesh::Mesh::Entities(), lf::mesh::Mesh::Index(), initGeometryInParent(), lf::base::RefEl::kQuad(), lf::base::RefEl::kSegment(), lf::base::RefEl::kTria(), meshes_, lf::mesh::Mesh::NumEntities(), PerformRefinement(), point_child_infos_, lf::refinement::PointChildInfo::ref_pat, lf::refinement::EdgeChildInfo::ref_pat_, refinement_edges_, lf::refinement::rp_bisect, lf::refinement::rp_copy, lf::refinement::rp_nil, lf::refinement::rp_quadsect, lf::refinement::rp_regular, lf::refinement::rp_split, lf::refinement::rp_threeedge, lf::refinement::rp_trisect, and lf::refinement::rp_trisect_left.

◆ RefinementEdges()

const std::vector< sub_idx_t > & lf::refinement::MeshHierarchy::RefinementEdges ( size_type level) const
inline

Access refinement edge indices.

Parameters
levelrefinement level of interest
Returns
vector of (local) sub-entity index of refinement edge for every cell

Definition at line 238 of file mesh_hierarchy.h.

References NumLevels(), and refinement_edges_.

Referenced by lf::refinement::WriteMatlabLevel().

◆ RefineRegular()

void lf::refinement::MeshHierarchy::RefineRegular ( RefPat ref_pat = RefPat::rp_regular)

Perform regular or barycentric uniform refinement of the finest mesh in the hierarchy.

Parameters
ref_patselector for type of uniform refinement: default is rp_regular, rp_barycentric choses barycentric refinement.

This method carries out uniform refinement of all cells of a mesh according to the rp_regular or rp_barycentric refinement patterns.

A new mesh is added to the bottom of the hierarchy by regularly refining the finest mesh in the hierarchy. Regular refinement means that every node is copied, every edge is split and every cell is subdivided into four or six smaller ones of the same shape.

Internally, this method flags all nodes as to be copied, all edges as to be split and all cells as to be refined according to the passed refinement pattern. Then it calls PerformRefinement().

Definition at line 72 of file mesh_hierarchy.cc.

References cell_child_infos_, edge_child_infos_, lf::mesh::Mesh::Entities(), lf::mesh::Mesh::Index(), initGeometryInParent(), meshes_, lf::mesh::Mesh::NumEntities(), PerformRefinement(), point_child_infos_, lf::refinement::PointChildInfo::ref_pat, lf::refinement::EdgeChildInfo::ref_pat_, lf::refinement::CellChildInfo::ref_pat_, lf::refinement::rp_barycentric, lf::refinement::rp_copy, lf::refinement::rp_regular, and lf::refinement::rp_split.

Member Data Documentation

◆ cell_child_infos_

std::vector<std::vector<CellChildInfo> > lf::refinement::MeshHierarchy::cell_child_infos_
private

information about children of cells for each level

Definition at line 430 of file mesh_hierarchy.h.

Referenced by CellChildInfos(), MeshHierarchy(), RefineMarked(), and RefineRegular().

◆ edge_child_infos_

std::vector<std::vector<EdgeChildInfo> > lf::refinement::MeshHierarchy::edge_child_infos_
private

information about children of edges for each level

Definition at line 428 of file mesh_hierarchy.h.

Referenced by EdgeChildInfos(), MeshHierarchy(), PerformRefinement(), RefineMarked(), and RefineRegular().

◆ edge_marked_

std::vector<std::vector<bool> > lf::refinement::MeshHierarchy::edge_marked_
private

Information about marked edges.

Definition at line 434 of file mesh_hierarchy.h.

Referenced by MarkEdges(), MeshHierarchy(), and RefineMarked().

◆ mesh_factory_

std::unique_ptr<mesh::MeshFactory> lf::refinement::MeshHierarchy::mesh_factory_
private

The mesh factory to be used to creating a new mesh.

Definition at line 424 of file mesh_hierarchy.h.

Referenced by PerformRefinement().

◆ meshes_

std::vector<std::shared_ptr<mesh::Mesh> > lf::refinement::MeshHierarchy::meshes_
private

the meshes managed by the MeshHierarchy object

Definition at line 422 of file mesh_hierarchy.h.

Referenced by getMesh(), getMesh(), getMeshes(), MarkEdges(), MeshHierarchy(), NumLevels(), PerformRefinement(), RefineMarked(), and RefineRegular().

◆ parent_infos_

std::vector<std::array<std::vector<ParentInfo>, 3> > lf::refinement::MeshHierarchy::parent_infos_
private

information about parent entities on each level

Definition at line 432 of file mesh_hierarchy.h.

Referenced by MeshHierarchy(), and ParentInfos().

◆ point_child_infos_

std::vector<std::vector<PointChildInfo> > lf::refinement::MeshHierarchy::point_child_infos_
private

information about children of nodes for each level

Definition at line 426 of file mesh_hierarchy.h.

Referenced by MeshHierarchy(), PerformRefinement(), PointChildInfos(), RefineMarked(), and RefineRegular().

◆ refinement_edges_

std::vector<std::vector<sub_idx_t> > lf::refinement::MeshHierarchy::refinement_edges_
private

Information about local refinement edges of triangles.

Definition at line 436 of file mesh_hierarchy.h.

Referenced by MeshHierarchy(), RefineMarked(), and RefinementEdges().


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