A finite element mesh for a domain in the specified dimensions. More...
#include <ptems/mesh.hpp>
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< ModificationStep > | Modifications |
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 VertexList & | Vertices () 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 ElementList & | Elements () 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::ostream & | Save (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::ostream & | Save (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... | |
T | shared_from_this (T... args) |
T | 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... | |
A finite element mesh for a domain in the specified dimensions.
DIM | The dimension of the mesh |
typedef ElementList::const_iterator ptems::FEMesh< DIM >::const_iterator |
Const iterator type for iterating thorough the list of elements in the mesh.
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.
typedef std::vector<PElement<DIM> > ptems::FEMesh< DIM >::ElementList |
Defines a list of elements.
typedef ElementList::const_iterator ptems::FEMesh< DIM >::iterator |
Iterator type for iterating thorough the list of elements in the mesh.
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)
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)
typedef ElementList::const_reverse_iterator ptems::FEMesh< DIM >::reverse_iterator |
Iterator type for iterating thorough the list of elements in the mesh in reverse.
typedef std::vector<Vector<DIM> > ptems::FEMesh< DIM >::VertexList |
Defines a list of vertices.
|
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:
Container | Container type containing AdaptationType or std::size_t, or map from std::size_t to AdaptationType |
flags | Container of AdaptationType or std::size_t, or map from std::size_t to AdaptationType |
smoother | Specifies the paramters for mesh smoothing |
|
inline |
Performs refinement on the mesh using a set of elements to refine and coarsen.
refine | Container of indices of elements to refine |
coarsen | Container of indices of elements to coarsen |
smoother | Specifies the paramters for mesh smoothing |
|
inline |
Performs refinement on the mesh using a function for deciding which elements to refine.
std::logic_error | if an element cannot be refined for some reason (concave, METIS not available for agglomerated meshes, etc.). |
Func | A function type which takes a std::size_t, and returns an AdaptionType; e.g., of form AdaptionType operator()(std::size_t idx) . |
flagFunction | Function 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' |
smoother | Specifies the parameters for mesh smoothing |
|
inline |
Adds an element to the mesh defined by a polytope.
polytope | Polytope to define the element |
std::invalid_argument | If any of the vertex indices are not in the mesh vertex list or if the polytope is not "valid", |
|
inline |
Adds an element to the mesh defined by a polytope.
T | Types of the arguments to pass to the Polytope<DIM> constructor |
args | Arguments to pass to the Polytope<DIM> constructor to define the element |
std::invalid_argument | If any of the vertex indices are not in the mesh vertex list or if the polytope is not "valid", |
|
inline |
Adds a listener to be notified when the mesh is modified (refine/derefine)
listener | The listener to be modified on mesh changes |
|
inline |
Adds a vertex to the mesh.
vertex | Vertex to add. |
|
inline |
Adds a vertex to the mesh.
Must be called with exactly DIM arguments.
T | Must be convertible to double |
x | The first component of the vertex. |
args | The rest of the components (must be DIM-1) arguments. |
|
inline |
Create a mesh of agglomerated elements.
std::out_of_range | If any index in the containers of agglomerations is greater or equal to VertexCount() |
std::invalid_argument | If any element is contained within two agglomerated elements |
std::invalid_argument | If any agglomerated element is disjoint |
Container | Type of a container (in the STL-sense) containing a container of (convertible to) std::size_t elements |
elements | Container 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 |
|
inline |
Create a mesh of agglomerated elements.
std::out_of_range | If any index in the containers of agglomerations is greater or equal to VertexCount() |
std::invalid_argument | If any element is contained within two agglomerated elements |
std::invalid_argument | If any agglomerated element is disjoint |
elements | Container 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 |
|
inline |
Create a mesh of agglomerated elements.
std::out_of_range | If any index in the containers of agglomerations is greater or equal to VertexCount() |
std::invalid_argument | If any element is contained within two agglomerated elements |
std::invalid_argument | If any agglomerated element is disjoint |
It | Iterator type for a container (in the STL-sense) containing a container of (convertible to) std::size_t elements |
begin | Begin 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 |
end | End element to the container |
eleCountEstimate | Estimate of the number of elements the mesh will contain (Default=0). |
|
inline |
Returns the mesh that this mesh agglomerates.
|
inline |
Begin iterator for iterating over the list of elements.
|
inline |
Begin iterator for iterating over the list of elements.
|
inline |
End iterator for iterating over the list of elements.
|
inline |
Returns a deep copy of this mesh, excluding refinement history.
|
inline |
Begin iterator for iterating over the list of elements in reverse order.
|
inlinestatic |
Creates an empty finite element mesh.
It is necessary to call AddVertex and AddElement to fully initialise the mesh.
numVertices | Estimate of the number of vertices the mesh will contain (Default=0). |
numElements | Estimate of the number of elements the mesh will contain (Default=0). |
|
inline |
End iterator for iterating over the list of elements in reverse order.
|
inline |
Gets the element at the specified index.
idx | Index of the element to get |
|
inline |
Gets the number of elements in the mesh.
|
inline |
Gets a immutable reference to the list of elements in the mesh.
|
inline |
End iterator for iterating over the list of elements.
|
inline |
Returns if this mesh is an agglomerated mesh.
|
inline |
Returns if the mesh is a conforming mesh of standard elements.
|
inline |
Returns if the mesh contains general polytopal elements; i.e.
no standard elements.
|
inline |
Returns if the mesh consists of only finite elements which map to standard reference elements; e.g, simplices, hypercubes, triangular prisms, square pyramids, ...
|
inline |
Gets the element at the specified index.
idx | Index of the element to get |
|
inline |
Begin iterator for iterating over the list of elements in reverse order.
|
inline |
End iterator for iterating over the list of elements in reverse order.
|
inline |
Save the mesh to a file with default options.
mpi | ParallelCom for managing MPI. Used to ensure file only written on main process. |
file | The filename of the file to write the file content to |
format | The mesh file format to use |
variables | A 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 |
|
inline |
Save the mesh to a file with specified options.
mpi | ParallelCom for managing MPI. Used to ensure file only written on main process. |
file | The filename of the file to write the file content to |
options | The mesh file format and save options to use |
variables | A 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 |
|
inline |
Save the mesh to a file with default options.
mpi | ParallelCom for managing MPI. Used to ensure file only written on main process. |
file | The filename of the file to write the file content to |
format | The mesh file format to use |
variables | A 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 |
|
inline |
Save the mesh to a file with specified options.
mpi | ParallelCom for managing MPI. Used to ensure file only written on main process. |
file | The filename of the file to write the file content to |
options | The mesh file format and save options to use |
variables | A 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 |
|
inline |
Save the mesh to a file.
mpi | ParallelCom for managing MPI. Used to ensure file only written on main process. |
file | The filename of the file to write the file content to |
format | The mesh file format to use |
variables | A 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 |
|
inline |
Save the mesh to a file with specified options.
mpi | ParallelCom for managing MPI. Used to ensure file only written on main process. |
file | The filename of the file to write the file content to |
options | The mesh file format and save options to use |
variables | A 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 |
|
inline |
Save the mesh to a file with default options.
file | The file stream to write the file content to |
format | The mesh file format to use |
variables | A 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 |
|
inline |
Save the mesh to a file with specified options.
file | The file stream to write the file content to |
options | The mesh file format and save options to use |
variables | A 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 |
|
inline |
Gets the number of elements in the mesh.
|
inline |
Performs uniform refinement of the mesh (refines every element).
|
inline |
Gets the vertex at the specified index.
idx | Index of the vertex to get |
|
inline |
Gets the number of vertices in the mesh.
|
inline |
Gets a immutable reference to the list of vertices in the mesh.
|
related |
Create a 2 dimensional finite element mesh by uniform subdivision of the specified domain.
mpi | MPI communicator to ensure the mesh is identical on all processes. |
domain | Definition of the domain. May only contain vertical or horizontal edges. |
numElementsX | Number of elements to subdivide the mesh (limits) by in the x-direction |
numElementsY | Number of elements to subdivide the mesh (limits) by in the y-direction |
elementType | Specifies how to subdivide the uniform squares into elements. |
std::invalid_argument | If domain.IsAligned() is false. |
std::invalid_argument | If numElementsX or numElementsY is zero |
std::invalid_argument | If 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(). |
TODO: What about cut/slit domains?
|
related |
Create a 1 dimensional finite element mesh by uniform subdivision of the specified interval.
mpi | MPI communicator to ensure the mesh is identical on all processes. |
min | The start of the interval to subdivide. |
max | The end of the interval to subdivide. |
numElements | Number of finite elements to divide the interval into. |
std::invalid_argument | If min is not less than max |
std::invalid_argument | If numElements is zero |
|
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
mpi | MPI communicator to ensure the mesh is identical on all processes. |
path | Path to file load |
format | Specifies the file format of the file. Or use MeshFileFormat::Automatic to attempt to deduce the file format |
|
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
mpi | MPI communicator to ensure the mesh is identical on all processes. |
input | Input stream containing mesh file |
format | Specifies the file format of the file. Or use MeshFileFormat::Automatic to attempt to deduce the file format |
|
staticconstexpr |
The dimension of the mesh.