PTEMS  0.1.0-dev+git.81fd0e4
PolyTopic Element Method Solver
ptems::FEMesh< DIM > Class Template Reference

A finite element mesh for a domain in the specified dimensions. More...

#include <ptems/mesh.hpp>

Inheritance diagram for ptems::FEMesh< DIM >:
Collaboration diagram for ptems::FEMesh< DIM >:

Classes

struct  MeshChangeListener
 A listener to be notified on mesh change. More...
 
struct  ModificationStep
 Defines a set of modifications of a mesh during refinement. More...
 

Public Types

typedef std::list< ModificationStepModifications
 Defines how a mesh was modified during refinement. More...
 
typedef std::vector< Vector< DIM > > VertexList
 Defines a list of vertices. More...
 
typedef std::vector< PElement< DIM > > ElementList
 Defines a list of elements. More...
 
typedef ElementList::const_iterator iterator
 Iterator type for iterating thorough the list of elements in the mesh. More...
 
typedef ElementList::const_iterator const_iterator
 Const iterator type for iterating thorough the list of elements in the mesh. More...
 
typedef ElementList::const_reverse_iterator reverse_iterator
 Iterator type for iterating thorough the list of elements in the mesh in reverse. More...
 
typedef ElementList::const_reverse_iterator const_reverse_iterator
 Const iterator type for iterating thorough the list of elements in the mesh in reverse. More...
 

Public Member Functions

const VertexListVertices () const
 Gets a immutable reference to the list of vertices in the mesh. More...
 
std::size_t VertexCount () const
 Gets the number of vertices in the mesh. More...
 
const Vector< DIM > & Vertex (std::size_t idx) const
 Gets the vertex at the specified index. More...
 
void AddVertex (const Vector< DIM > &vertex)
 Adds a vertex to the mesh. More...
 
template<typename... T>
const Vector< DIM > & AddVertex (double x, T... args)
 Adds a vertex to the mesh. More...
 
const ElementListElements () const
 Gets a immutable reference to the list of elements in the mesh. More...
 
std::size_t ElementCount () const
 Gets the number of elements in the mesh. More...
 
std::size_t size () const
 Gets the number of elements in the mesh. More...
 
const PElement< DIM > & Element (std::size_t idx) const
 Gets the element at the specified index. More...
 
const PElement< DIM > & operator[] (std::size_t idx) const
 Gets the element at the specified index. More...
 
bool IsStandard () const
 Returns if the mesh consists of only finite elements which map to standard reference elements; e.g, simplices, hypercubes, triangular prisms, square pyramids, ... More...
 
bool IsPolytopal () const
 Returns if the mesh contains general polytopal elements; i.e. More...
 
bool IsConforming () const
 Returns if the mesh is a conforming mesh of standard elements. More...
 
bool IsAgglomeration () const
 Returns if this mesh is an agglomerated mesh. More...
 
const std::shared_ptr< FEMesh< DIM > > & BaseMesh () const
 Returns the mesh that this mesh agglomerates. More...
 
iterator begin () const
 Begin iterator for iterating over the list of elements. More...
 
iterator end () const
 End iterator for iterating over the list of elements. More...
 
const_iterator cbegin () const
 Begin iterator for iterating over the list of elements. More...
 
const_iterator cend () const
 End iterator for iterating over the list of elements. More...
 
reverse_iterator rbegin () const
 Begin iterator for iterating over the list of elements in reverse order. More...
 
reverse_iterator rend () const
 End iterator for iterating over the list of elements in reverse order. More...
 
const_reverse_iterator crbegin () const
 Begin iterator for iterating over the list of elements in reverse order. More...
 
const_reverse_iterator crend () const
 End iterator for iterating over the list of elements in reverse order. More...
 
const PElement< DIM > & AddElement (const Polytope< DIM > &polytope)
 Adds an element to the mesh defined by a polytope. More...
 
template<typename... T>
const PElement< DIM > & AddElement (T... args)
 Adds an element to the mesh defined by a polytope. More...
 
std::shared_ptr< FEMesh< DIM > > Clone () const
 Returns a deep copy of this mesh, excluding refinement history. More...
 
template<typename... Vars>
std::ostreamSave (std::ostream &file, SaveFileOptions options, Vars... variables)
 Save the mesh to a file with specified options. More...
 
template<typename... Vars>
bool Save (const ParallelComm &mpi, const std::filesystem::path &file, SaveFileOptions options, Vars... variables)
 Save the mesh to a file with specified options. More...
 
template<typename... Vars>
bool Save (const ParallelComm &mpi, const char *file, SaveFileOptions options, Vars... variables)
 Save the mesh to a file with specified options. More...
 
template<typename... Vars>
bool Save (const ParallelComm &mpi, const std::string &file, SaveFileOptions options, Vars... variables)
 Save the mesh to a file with specified options. More...
 
template<typename... Vars>
std::ostreamSave (std::ostream &file, MeshFileFormat format, Vars... variables)
 Save the mesh to a file with default options. More...
 
template<typename... Vars>
bool Save (const ParallelComm &mpi, const std::filesystem::path &file, MeshFileFormat format, Vars... variables)
 Save the mesh to a file with default options. More...
 
template<typename... Vars>
bool Save (const ParallelComm &mpi, const char *file, MeshFileFormat format, Vars... variables)
 Save the mesh to a file with default options. More...
 
template<typename... Vars>
bool Save (const ParallelComm &mpi, const std::string &file, MeshFileFormat format, Vars... variables)
 Save the mesh to a file. More...
 
template<typename It >
std::shared_ptr< FEMesh< DIM > > Agglomerate (It begin, It end, std::size_t eleCountEstimate=0)
 Create a mesh of agglomerated elements. More...
 
template<typename Container >
std::shared_ptr< FEMesh< DIM > > Agglomerate (const Container &elements)
 Create a mesh of agglomerated elements. More...
 
std::shared_ptr< FEMesh< DIM > > Agglomerate (const std::initializer_list< std::initializer_list< std::size_t >> &elements)
 Create a mesh of agglomerated elements. More...
 
template<typename Func , typename = std::enable_if_t<std::is_same_v<decltype(std::declval<Func>()(std::declval<std::size_t>())), AdaptationType>>
Modifications Adapt (Func flagFunction, MeshSmoother smoother=MeshSmoother{})
 Performs refinement on the mesh using a function for deciding which elements to refine. More...
 
template<typename Container , typename = typename Container::value_type>
Modifications Adapt (const Container &flags, MeshSmoother smoother=MeshSmoother{})
 Performs refinement on the mesh using a container of flags indicating the refinement to perform. More...
 
template<typename Container >
Modifications Adapt (const Container &refine, const Container &coarsen, MeshSmoother smoother=MeshSmoother{})
 Performs refinement on the mesh using a set of elements to refine and coarsen. More...
 
void UniformRefine ()
 Performs uniform refinement of the mesh (refines every element). More...
 
void AddListener (const std::weak_ptr< MeshChangeListener > &listener)
 Adds a listener to be notified when the mesh is modified (refine/derefine) More...
 
shared_from_this (T... args)
 
weak_from_this (T... args)
 

Static Public Member Functions

static std::shared_ptr< FEMesh< DIM > > Create (std::size_t numVertices=0, std::size_t numElements=0)
 Creates an empty finite element mesh. More...
 

Static Public Attributes

static constexpr std::size_t Dimensions = DIM
 The dimension of the mesh. More...
 

Related Functions

(Note that these are not member functions.)

PFEMesh< 1 > CreateUniformMesh (const ParallelComm &mpi, double min, double max, std::size_t numElements)
 Create a 1 dimensional finite element mesh by uniform subdivision of the specified interval. More...
 
PFEMesh< 2 > CreateUniformMesh (const ParallelComm &mpi, const DomainDefinition2D &domain, std::size_t numElementsX, std::size_t numElementsY, UniformElementType2D elementType=UniformElementType2D::Square)
 Create a 2 dimensional finite element mesh by uniform subdivision of the specified domain. More...
 
PFEMesh< 2 > LoadMesh2D (const ParallelComm &mpi, std::istream &input, MeshFileFormat format=MeshFileFormat::Automatic)
 Loads 2 dimensional finite element mesh of elements from a input stream representing a mesh file. More...
 
PFEMesh< 2 > LoadMesh2D (const ParallelComm &mpi, const std::filesystem::path &path, MeshFileFormat format=MeshFileFormat::Automatic)
 Loads 2 dimensional finite element mesh of elements from a mesh file. More...
 

Detailed Description

template<std::size_t DIM>
class ptems::FEMesh< DIM >

A finite element mesh for a domain in the specified dimensions.

Template Parameters
DIMThe dimension of the mesh

Member Typedef Documentation

◆ const_iterator

template<std::size_t DIM>
typedef ElementList::const_iterator ptems::FEMesh< DIM >::const_iterator

Const iterator type for iterating thorough the list of elements in the mesh.

◆ const_reverse_iterator

template<std::size_t DIM>
typedef ElementList::const_reverse_iterator ptems::FEMesh< DIM >::const_reverse_iterator

Const iterator type for iterating thorough the list of elements in the mesh in reverse.

◆ ElementList

template<std::size_t DIM>
typedef std::vector<PElement<DIM> > ptems::FEMesh< DIM >::ElementList

Defines a list of elements.

◆ iterator

template<std::size_t DIM>
typedef ElementList::const_iterator ptems::FEMesh< DIM >::iterator

Iterator type for iterating thorough the list of elements in the mesh.

◆ Modifications

template<std::size_t DIM>
typedef std::list<ModificationStep> ptems::FEMesh< DIM >::Modifications

Defines how a mesh was modified during refinement.

Modifications are a list of ModificationStep items, where each step denotes one set of changes to a mesh. Essentially the steps denote a sequence of intermediate meshes that have been generated. For example, the list contains the following (in order)

  • Optional set of modifications to remove green refined elements
  • Set of actual mesh adaptations that were requested
  • Zero or more mesh smoothing steps
  • Optional set of modifications to insert green refinements to generate conforming mesh

Note, it is possible for two steps to essentially undo each other (for example, if an element was requested to be coarsened and then is refined by the smoother)

◆ reverse_iterator

template<std::size_t DIM>
typedef ElementList::const_reverse_iterator ptems::FEMesh< DIM >::reverse_iterator

Iterator type for iterating thorough the list of elements in the mesh in reverse.

◆ VertexList

template<std::size_t DIM>
typedef std::vector<Vector<DIM> > ptems::FEMesh< DIM >::VertexList

Defines a list of vertices.

Member Function Documentation

◆ Adapt() [1/3]

template<std::size_t DIM>
template<typename Container , typename = typename Container::value_type>
Modifications ptems::FEMesh< DIM >::Adapt ( const Container flags,
MeshSmoother  smoother = MeshSmoother{} 
)
inline

Performs refinement on the mesh using a container of flags indicating the refinement to perform.

A container of flags can be one of the following:

  • A random access container of AdaptationType (i.e., supports operator[] and size()) containing an AdaptationType for each element
  • An associative container (map/unordered_map etc) of element number (std::size_t) to AdaptationType containing an AdaptationType for SOME elements, all other elements are left unrefined
  • A container of element numbers to perform mesh refinement on, all other elements are left unrefined
Note
If the random access container size is less than the number of elements the remaining elements are left unrefined.
Attention
While the container of element numbers to refine can be ANY container type, it is strongly recommended to use a set-like container which can perform fast searching (e.g. std::set or std::unordered_set)
Template Parameters
ContainerContainer type containing AdaptationType or std::size_t, or map from std::size_t to AdaptationType
Parameters
flagsContainer of AdaptationType or std::size_t, or map from std::size_t to AdaptationType
smootherSpecifies the paramters for mesh smoothing
Returns
Structure denoting changes that occurred to the mesh
Warning
Green refinement (conforming meshes) is only supported for simplex and convex quadrilateral elements

◆ Adapt() [2/3]

template<std::size_t DIM>
template<typename Container >
Modifications ptems::FEMesh< DIM >::Adapt ( const Container refine,
const Container coarsen,
MeshSmoother  smoother = MeshSmoother{} 
)
inline

Performs refinement on the mesh using a set of elements to refine and coarsen.

Attention
While the container of element numbers to refine/coarsen can be ANY container time, it is strongly recommended to use a set-like container which can perform fast searching (e.g. std::set or std::unordered_set)
Parameters
refineContainer of indices of elements to refine
coarsenContainer of indices of elements to coarsen
smootherSpecifies the paramters for mesh smoothing
Returns
Structure denoting changes that occurred to the mesh
Warning
Green refinement (conforming meshes) is only supported for simplex and convex quadrilateral elements

◆ Adapt() [3/3]

template<std::size_t DIM>
template<typename Func , typename = std::enable_if_t<std::is_same_v<decltype(std::declval<Func>()(std::declval<std::size_t>())), AdaptationType>>
Modifications ptems::FEMesh< DIM >::Adapt ( Func  flagFunction,
MeshSmoother  smoother = MeshSmoother{} 
)
inline

Performs refinement on the mesh using a function for deciding which elements to refine.

Exceptions
std::logic_errorif an element cannot be refined for some reason (concave, METIS not available for agglomerated meshes, etc.).
Template Parameters
FuncA function type which takes a std::size_t, and returns an AdaptionType; e.g., of form AdaptionType operator()(std::size_t idx).
Parameters
flagFunctionFunction which takes an element index in range [0, ElementCount()), and returns an AdaptionType flag value indicating if the element should be refined, coarsened, or left 'as-is'
smootherSpecifies the parameters for mesh smoothing
Returns
Structure denoting changes that occurred to the mesh
Warning
Green refinement (conforming meshes) is only supported for simplex and convex quadrilateral elements

◆ AddElement() [1/2]

template<std::size_t DIM>
const PElement<DIM>& ptems::FEMesh< DIM >::AddElement ( const Polytope< DIM > &  polytope)
inline

Adds an element to the mesh defined by a polytope.

Warning
All vertices used by this element must have been inserted into the mesh before adding the element.
Parameters
polytopePolytope to define the element
Exceptions
std::invalid_argumentIf any of the vertex indices are not in the mesh vertex list or if the polytope is not "valid",
See also
Polytope<DIM>::Validate
Returns
The added element

◆ AddElement() [2/2]

template<std::size_t DIM>
template<typename... T>
const PElement<DIM>& ptems::FEMesh< DIM >::AddElement ( T...  args)
inline

Adds an element to the mesh defined by a polytope.

Warning
All vertices used by this element must have been inserted into the mesh before adding the element.
Template Parameters
TTypes of the arguments to pass to the Polytope<DIM> constructor
Parameters
argsArguments to pass to the Polytope<DIM> constructor to define the element
Exceptions
std::invalid_argumentIf any of the vertex indices are not in the mesh vertex list or if the polytope is not "valid",
See also
Polytope<DIM>::Validate
Returns
The added element

◆ AddListener()

template<std::size_t DIM>
void ptems::FEMesh< DIM >::AddListener ( const std::weak_ptr< MeshChangeListener > &  listener)
inline

Adds a listener to be notified when the mesh is modified (refine/derefine)

Attention
This method is primarily for use by implementations of DiscreteFunctionSpace. In general, it should not be used in client code.
Parameters
listenerThe listener to be modified on mesh changes

◆ AddVertex() [1/2]

template<std::size_t DIM>
void ptems::FEMesh< DIM >::AddVertex ( const Vector< DIM > &  vertex)
inline

Adds a vertex to the mesh.

Parameters
vertexVertex to add.

◆ AddVertex() [2/2]

template<std::size_t DIM>
template<typename... T>
const Vector<DIM>& ptems::FEMesh< DIM >::AddVertex ( double  x,
T...  args 
)
inline

Adds a vertex to the mesh.

Must be called with exactly DIM arguments.

Template Parameters
TMust be convertible to double
Parameters
xThe first component of the vertex.
argsThe rest of the components (must be DIM-1) arguments.
Returns
The added vertex.

◆ Agglomerate() [1/3]

template<std::size_t DIM>
template<typename Container >
std::shared_ptr<FEMesh<DIM> > ptems::FEMesh< DIM >::Agglomerate ( const Container elements)
inline

Create a mesh of agglomerated elements.

Exceptions
std::out_of_rangeIf any index in the containers of agglomerations is greater or equal to VertexCount()
std::invalid_argumentIf any element is contained within two agglomerated elements
std::invalid_argumentIf any agglomerated element is disjoint
Warning
Any element index not included in the agglomerated element list is treated as if it is an agglomerate of one element.
Template Parameters
ContainerType of a container (in the STL-sense) containing a container of (convertible to) std::size_t elements
Parameters
elementsContainer containing one entry for each agglomerated element, where each entry is a list of the indices of the elements to agglomerate to construct the agglomerated element
Returns
The agglomerated mesh

◆ Agglomerate() [2/3]

template<std::size_t DIM>
std::shared_ptr<FEMesh<DIM> > ptems::FEMesh< DIM >::Agglomerate ( const std::initializer_list< std::initializer_list< std::size_t >> &  elements)
inline

Create a mesh of agglomerated elements.

Exceptions
std::out_of_rangeIf any index in the containers of agglomerations is greater or equal to VertexCount()
std::invalid_argumentIf any element is contained within two agglomerated elements
std::invalid_argumentIf any agglomerated element is disjoint
Warning
Any element index not included in the agglomerated element list is treated as if it is an agglomerate of one element.
Parameters
elementsContainer containing one entry for each agglomerated element, where each entry is a list of the indices of the elements to agglomerate to construct the agglomerated element
Returns
The agglomerated mesh

◆ Agglomerate() [3/3]

template<std::size_t DIM>
template<typename It >
std::shared_ptr<FEMesh<DIM> > ptems::FEMesh< DIM >::Agglomerate ( It  begin,
It  end,
std::size_t  eleCountEstimate = 0 
)
inline

Create a mesh of agglomerated elements.

Exceptions
std::out_of_rangeIf any index in the containers of agglomerations is greater or equal to VertexCount()
std::invalid_argumentIf any element is contained within two agglomerated elements
std::invalid_argumentIf any agglomerated element is disjoint
Warning
Any element index not included in the agglomerated element list is treated as if it is an agglomerate of one element.
Note
eleCountEstimate is an estimate used to initialise storage vectors. More or less elements than this can be added by the algorithm without issue. If the iterators are random access (more accurately implement operator- for computing distance between them), than the estimate can be zero and the estimate is computed by iterator distance. If the iterator DOESN'T support this distance measure (without iterating) then passing the size MAY improve performance and memory allocation. For example, if the iterators come from std::vector, then no need to pass the estimate; whereas, if they come from std::list passing the value of std::list::size() would help.
Template Parameters
ItIterator type for a container (in the STL-sense) containing a container of (convertible to) std::size_t elements
Parameters
beginBegin iterator for a container containing one entry for each agglomerated element, where each entry is a list of the indices of the elements to agglomerate to constructed the agglomerated element
endEnd element to the container
eleCountEstimateEstimate of the number of elements the mesh will contain (Default=0).
Returns
The agglomerated mesh

◆ BaseMesh()

template<std::size_t DIM>
const std::shared_ptr<FEMesh<DIM> >& ptems::FEMesh< DIM >::BaseMesh ( ) const
inline

Returns the mesh that this mesh agglomerates.

Returns
The mesh that this mesh agglomerates, or null if this mesh is not an agglomeration

◆ begin()

template<std::size_t DIM>
iterator ptems::FEMesh< DIM >::begin ( ) const
inline

Begin iterator for iterating over the list of elements.

◆ cbegin()

template<std::size_t DIM>
const_iterator ptems::FEMesh< DIM >::cbegin ( ) const
inline

Begin iterator for iterating over the list of elements.

◆ cend()

template<std::size_t DIM>
const_iterator ptems::FEMesh< DIM >::cend ( ) const
inline

End iterator for iterating over the list of elements.

◆ Clone()

template<std::size_t DIM>
std::shared_ptr<FEMesh<DIM> > ptems::FEMesh< DIM >::Clone ( ) const
inline

Returns a deep copy of this mesh, excluding refinement history.

Warning
The cloned mesh does not have a record of the mesh refinement tree; therefore, it is not possible to derefine the cloned mesh.
Todo:
Add cloning of refinement tree?
Returns
Copy of the mesh

◆ crbegin()

template<std::size_t DIM>
const_reverse_iterator ptems::FEMesh< DIM >::crbegin ( ) const
inline

Begin iterator for iterating over the list of elements in reverse order.

◆ Create()

template<std::size_t DIM>
static std::shared_ptr<FEMesh<DIM> > ptems::FEMesh< DIM >::Create ( std::size_t  numVertices = 0,
std::size_t  numElements = 0 
)
inlinestatic

Creates an empty finite element mesh.

It is necessary to call AddVertex and AddElement to fully initialise the mesh.

Note
numVertices and numElements are estimates used to initialised storage vectors. More or less element/vertices than these numbers can be added to the mesh without issue.
Parameters
numVerticesEstimate of the number of vertices the mesh will contain (Default=0).
numElementsEstimate of the number of elements the mesh will contain (Default=0).
Returns
Shared pointer to the newly constructed (empty) mesh.

◆ crend()

template<std::size_t DIM>
const_reverse_iterator ptems::FEMesh< DIM >::crend ( ) const
inline

End iterator for iterating over the list of elements in reverse order.

◆ Element()

template<std::size_t DIM>
const PElement<DIM>& ptems::FEMesh< DIM >::Element ( std::size_t  idx) const
inline

Gets the element at the specified index.

Parameters
idxIndex of the element to get
Returns
The element at the specified index

◆ ElementCount()

template<std::size_t DIM>
std::size_t ptems::FEMesh< DIM >::ElementCount ( ) const
inline

Gets the number of elements in the mesh.

Returns
Number of elements in mesh.

◆ Elements()

template<std::size_t DIM>
const ElementList& ptems::FEMesh< DIM >::Elements ( ) const
inline

Gets a immutable reference to the list of elements in the mesh.

Returns
The element list

◆ end()

template<std::size_t DIM>
iterator ptems::FEMesh< DIM >::end ( ) const
inline

End iterator for iterating over the list of elements.

◆ IsAgglomeration()

template<std::size_t DIM>
bool ptems::FEMesh< DIM >::IsAgglomeration ( ) const
inline

Returns if this mesh is an agglomerated mesh.

Returns
true if agglomerated mesh, false otherwise

◆ IsConforming()

template<std::size_t DIM>
bool ptems::FEMesh< DIM >::IsConforming ( ) const
inline

Returns if the mesh is a conforming mesh of standard elements.

Returns
true if IsStandard() is true and no hanging nodes; false otherwise

◆ IsPolytopal()

template<std::size_t DIM>
bool ptems::FEMesh< DIM >::IsPolytopal ( ) const
inline

Returns if the mesh contains general polytopal elements; i.e.

no standard elements.

Returns
!IsStandard()
See also
IsStandard()

◆ IsStandard()

template<std::size_t DIM>
bool ptems::FEMesh< DIM >::IsStandard ( ) const
inline

Returns if the mesh consists of only finite elements which map to standard reference elements; e.g, simplices, hypercubes, triangular prisms, square pyramids, ...

Returns
true if mesh only consists of standard elements; false otherwise

◆ operator[]()

template<std::size_t DIM>
const PElement<DIM>& ptems::FEMesh< DIM >::operator[] ( std::size_t  idx) const
inline

Gets the element at the specified index.

Parameters
idxIndex of the element to get
Returns
The element at the specified index

◆ rbegin()

template<std::size_t DIM>
reverse_iterator ptems::FEMesh< DIM >::rbegin ( ) const
inline

Begin iterator for iterating over the list of elements in reverse order.

◆ rend()

template<std::size_t DIM>
reverse_iterator ptems::FEMesh< DIM >::rend ( ) const
inline

End iterator for iterating over the list of elements in reverse order.

◆ Save() [1/8]

template<std::size_t DIM>
template<typename... Vars>
bool ptems::FEMesh< DIM >::Save ( const ParallelComm mpi,
const char *  file,
MeshFileFormat  format,
Vars...  variables 
)
inline

Save the mesh to a file with default options.

See also
SaveFileOptions
Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
mpiParallelCom for managing MPI. Used to ensure file only written on main process.
fileThe filename of the file to write the file content to
formatThe mesh file format to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
true on successful output; false on failure

◆ Save() [2/8]

template<std::size_t DIM>
template<typename... Vars>
bool ptems::FEMesh< DIM >::Save ( const ParallelComm mpi,
const char *  file,
SaveFileOptions  options,
Vars...  variables 
)
inline

Save the mesh to a file with specified options.

Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
mpiParallelCom for managing MPI. Used to ensure file only written on main process.
fileThe filename of the file to write the file content to
optionsThe mesh file format and save options to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
true on successful output; false on failure

◆ Save() [3/8]

template<std::size_t DIM>
template<typename... Vars>
bool ptems::FEMesh< DIM >::Save ( const ParallelComm mpi,
const std::filesystem::path file,
MeshFileFormat  format,
Vars...  variables 
)
inline

Save the mesh to a file with default options.

See also
SaveFileOptions
Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
mpiParallelCom for managing MPI. Used to ensure file only written on main process.
fileThe filename of the file to write the file content to
formatThe mesh file format to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
true on successful output; false on failure

◆ Save() [4/8]

template<std::size_t DIM>
template<typename... Vars>
bool ptems::FEMesh< DIM >::Save ( const ParallelComm mpi,
const std::filesystem::path file,
SaveFileOptions  options,
Vars...  variables 
)
inline

Save the mesh to a file with specified options.

Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
mpiParallelCom for managing MPI. Used to ensure file only written on main process.
fileThe filename of the file to write the file content to
optionsThe mesh file format and save options to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
true on successful output; false on failure

◆ Save() [5/8]

template<std::size_t DIM>
template<typename... Vars>
bool ptems::FEMesh< DIM >::Save ( const ParallelComm mpi,
const std::string file,
MeshFileFormat  format,
Vars...  variables 
)
inline

Save the mesh to a file.

Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
mpiParallelCom for managing MPI. Used to ensure file only written on main process.
fileThe filename of the file to write the file content to
formatThe mesh file format to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
true on successful output; false on failure

◆ Save() [6/8]

template<std::size_t DIM>
template<typename... Vars>
bool ptems::FEMesh< DIM >::Save ( const ParallelComm mpi,
const std::string file,
SaveFileOptions  options,
Vars...  variables 
)
inline

Save the mesh to a file with specified options.

Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
mpiParallelCom for managing MPI. Used to ensure file only written on main process.
fileThe filename of the file to write the file content to
optionsThe mesh file format and save options to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
true on successful output; false on failure

◆ Save() [7/8]

template<std::size_t DIM>
template<typename... Vars>
std::ostream& ptems::FEMesh< DIM >::Save ( std::ostream file,
MeshFileFormat  format,
Vars...  variables 
)
inline

Save the mesh to a file with default options.

See also
SaveFileOptions
Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
fileThe file stream to write the file content to
formatThe mesh file format to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
The file stream

◆ Save() [8/8]

template<std::size_t DIM>
template<typename... Vars>
std::ostream& ptems::FEMesh< DIM >::Save ( std::ostream file,
SaveFileOptions  options,
Vars...  variables 
)
inline

Save the mesh to a file with specified options.

Todo:
: Hack code, only supporting MeshFileFormat::VTK_Legacy & MeshFileFormat::MatlabMAT currently
Parameters
fileThe file stream to write the file content to
optionsThe mesh file format and save options to use
variablesA list of pairs of string and variable arguments for the variable data to output. The variable should be an object implementing the WritableVariable interface, or a functor which takes a Vector<DIM> as its argument
Returns
The file stream

◆ size()

template<std::size_t DIM>
std::size_t ptems::FEMesh< DIM >::size ( ) const
inline

Gets the number of elements in the mesh.

Returns
Number of elements in mesh.

◆ UniformRefine()

template<std::size_t DIM>
void ptems::FEMesh< DIM >::UniformRefine ( )
inline

Performs uniform refinement of the mesh (refines every element).

◆ Vertex()

template<std::size_t DIM>
const Vector<DIM>& ptems::FEMesh< DIM >::Vertex ( std::size_t  idx) const
inline

Gets the vertex at the specified index.

Parameters
idxIndex of the vertex to get
Returns
The vertex at the specified index

◆ VertexCount()

template<std::size_t DIM>
std::size_t ptems::FEMesh< DIM >::VertexCount ( ) const
inline

Gets the number of vertices in the mesh.

Returns
Number of vertices in mesh.

◆ Vertices()

template<std::size_t DIM>
const VertexList& ptems::FEMesh< DIM >::Vertices ( ) const
inline

Gets a immutable reference to the list of vertices in the mesh.

Returns
The vertex list

Friends And Related Function Documentation

◆ CreateUniformMesh() [1/2]

template<std::size_t DIM>
PFEMesh< 2 > CreateUniformMesh ( const ParallelComm mpi,
const DomainDefinition2D domain,
std::size_t  numElementsX,
std::size_t  numElementsY,
UniformElementType2D  elementType = UniformElementType2D::Square 
)
related

Create a 2 dimensional finite element mesh by uniform subdivision of the specified domain.

Parameters
mpiMPI communicator to ensure the mesh is identical on all processes.
domainDefinition of the domain. May only contain vertical or horizontal edges.
numElementsXNumber of elements to subdivide the mesh (limits) by in the x-direction
numElementsYNumber of elements to subdivide the mesh (limits) by in the y-direction
elementTypeSpecifies how to subdivide the uniform squares into elements.
Exceptions
std::invalid_argumentIf domain.IsAligned() is false.
std::invalid_argumentIf numElementsX or numElementsY is zero
std::invalid_argumentIf the domain cannot be split into the specified number of elements due to not aligning with edges in the domain; i.e., numElementsX/numElementsY not multiple of domain.MinElementsX()/domain.MinElementsY().
Returns
The constructed mesh.

TODO: What about cut/slit domains?

◆ CreateUniformMesh() [2/2]

template<std::size_t DIM>
PFEMesh< 1 > CreateUniformMesh ( const ParallelComm mpi,
double  min,
double  max,
std::size_t  numElements 
)
related

Create a 1 dimensional finite element mesh by uniform subdivision of the specified interval.

Parameters
mpiMPI communicator to ensure the mesh is identical on all processes.
minThe start of the interval to subdivide.
maxThe end of the interval to subdivide.
numElementsNumber of finite elements to divide the interval into.
Exceptions
std::invalid_argumentIf min is not less than max
std::invalid_argumentIf numElements is zero
Returns
The constructed mesh.

◆ LoadMesh2D() [1/2]

template<std::size_t DIM>
PFEMesh< 2 > LoadMesh2D ( const ParallelComm mpi,
const std::filesystem::path path,
MeshFileFormat  format = MeshFileFormat::Automatic 
)
related

Loads 2 dimensional finite element mesh of elements from a mesh file.

If MeshFileFormat::Automatic is passed the parser attempts to calculate the file format automatically based on the start of the format

  • VTK - Legacy: First "word": vtk
  • VTK - XML: First character: <
  • VTK - HDF5: Magic byte sequence: 0x89 0x48 0x44 0x46 0x0d 0x0a 0x1a 0x0a
  • Gmsh (msh): First "word": $MeshFormat
  • UCD - ASCII: First line: N N N N N (where N is an integer) (ignoring comments, which start with #)
  • UCD - Binary: 0x07 Magic byte
  • TecPlot - ASCII: First word (ignoring comments, which start with #) one of: TITLE, FILETYPE, VARIABLES, ZONE
  • TecPlot - Binary: Magic byte sequence: #!TDV
  • PolyFEM mesh format (.pmsh/.pmshz): First word: POLYFEM:MESH (ignoring comments, which start with #)
  • Triangle/TetGen node (.node): First line: N D N B (where N is an integer, D is 2 or 3 and B is 0 or 1) (ignoring comments, which start with #)
  • Triangle/TetGen ele (.ele): First line: N T R (where N is an integer, T is in {3,4,6,10} and R is 0 or 1) (ignoring comments, which start with #)
Warning
Only experimental version of MeshFileFormat::PTEMS format supported
Parameters
mpiMPI communicator to ensure the mesh is identical on all processes.
pathPath to file load
formatSpecifies the file format of the file. Or use MeshFileFormat::Automatic to attempt to deduce the file format
Returns
The constructed mesh, or null if the mesh file is invalid

◆ LoadMesh2D() [2/2]

template<std::size_t DIM>
PFEMesh< 2 > LoadMesh2D ( const ParallelComm mpi,
std::istream input,
MeshFileFormat  format = MeshFileFormat::Automatic 
)
related

Loads 2 dimensional finite element mesh of elements from a input stream representing a mesh file.

If MeshFileFormat::Automatic is passed the parser attempts to calculate the file format automatically based on the start of the format

  • VTK - Legacy: First "word": vtk
  • VTK - XML: First character: <
  • VTK - HDF5: Magic byte sequence: 0x89 0x48 0x44 0x46 0x0d 0x0a 0x1a 0x0a
  • Gmsh (msh): First "word": $MeshFormat
  • UCD - ASCII: First line: N N N N N (where N is an integer) (ignoring comments, which start with #)
  • UCD - Binary: 0x07 Magic byte
  • TecPlot - ASCII: First word (ignoring comments, which start with #) one of: TITLE, FILETYPE, VARIABLES, ZONE
  • TecPlot - Binary: Magic byte sequence: #!TDV
  • PolyFEM mesh format (.pmsh/.pmshz): First word: POLYFEM:MESH (ignoring comments, which start with #)
  • Triangle/TetGen node (.node): First line: N D N B (where N is an integer, D is 2 or 3 and B is 0 or 1) (ignoring comments, which start with #)
  • Triangle/TetGen ele (.ele): First line: N T R (where N is an integer, T is in {3,4,6,10} and R is 0 or 1) (ignoring comments, which start with #)
Warning
Only experimental version of MeshFileFormat::PTEMS format supported
Parameters
mpiMPI communicator to ensure the mesh is identical on all processes.
inputInput stream containing mesh file
formatSpecifies the file format of the file. Or use MeshFileFormat::Automatic to attempt to deduce the file format
Returns
The constructed mesh, or null if the mesh file is invalid

Member Data Documentation

◆ Dimensions

template<std::size_t DIM>
constexpr std::size_t ptems::FEMesh< DIM >::Dimensions = DIM
staticconstexpr

The dimension of the mesh.


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