LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
codim_mesh_data_set.h
1#ifndef INCGbae24f2390174bff85f65c2c2e558a9e
2#define INCGbae24f2390174bff85f65c2c2e558a9e
3
4#include <boost/container/vector.hpp>
5#include <utility>
6
7#include "mesh_data_set.h"
8
9namespace lf::mesh::utils {
10
27template <class T>
28class CodimMeshDataSet : public MeshDataSet<T> {
29 public:
32
42 CodimMeshDataSet(std::shared_ptr<const Mesh> mesh, dim_t codim)
43 : MeshDataSet<T>(),
44 mesh_(std::move(mesh)),
45 data_(mesh_->NumEntities(codim)),
46 codim_(codim) {}
47
55 CodimMeshDataSet(std::shared_ptr<const Mesh> mesh, dim_t codim, T init)
56 requires std::copy_constructible<T>
58 mesh_(std::move(mesh)),
59 data_(mesh_->NumEntities(codim), init),
60 codim_(codim) {}
61
69 [[nodiscard]] T& operator()(const Entity& e) {
70 LF_ASSERT_MSG(DefinedOn(e), "MeshDataSet is not defined on this entity.");
71 return data_[mesh_->Index(e)];
72 }
73 // NOLINTNEXTLINE(readability-const-return-type)
74 [[nodiscard]] const T& operator()(const Entity& e) const override {
75 LF_ASSERT_MSG(DefinedOn(e), "MeshDataSet not defined on this entity.");
76 return data_[mesh_->Index(e)];
77 }
78 [[nodiscard]] bool DefinedOn(const Entity& e) const override {
79 return e.Codim() == codim_ && mesh_->Contains(e);
80 }
81
82 private:
84 std::shared_ptr<const Mesh> mesh_;
86 boost::container::vector<T> data_;
89};
90
100template <class T>
101std::shared_ptr<CodimMeshDataSet<T>> make_CodimMeshDataSet(
102 const std::shared_ptr<const lf::mesh::Mesh>& mesh, base::dim_t codim) {
103 using impl_t = CodimMeshDataSet<T>;
104 return std::shared_ptr<impl_t>(new impl_t(mesh, codim));
105}
106
115template <std::copy_constructible T>
116std::shared_ptr<CodimMeshDataSet<T>> make_CodimMeshDataSet(
117 const std::shared_ptr<const Mesh>& mesh, base::dim_t codim, T init) {
118 using impl_t = CodimMeshDataSet<T>;
119 return std::shared_ptr<impl_t>(new impl_t(mesh, codim, init));
120}
121
122} // namespace lf::mesh::utils
123
124#endif // INCGbae24f2390174bff85f65c2c2e558a9e
unsigned int dim_t
Definition ref_el.h:132
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
virtual unsigned Codim() const =0
The codimension of this entity w.r.t. the Mesh.dimMesh() of the owning mesh manager.
lf::base::size_type size_type
A MeshDataSet that attaches data of type T to every entity of a mesh that has a specified codimension...
boost::container::vector< T > data_
bool DefinedOn(const Entity &e) const override
Does the dataset store information with this entity?
std::shared_ptr< const Mesh > mesh_
T & operator()(const Entity &e)
Get a (modifiable) reference to the data stored with entity e.
CodimMeshDataSet(std::shared_ptr< const Mesh > mesh, dim_t codim, T init)
construct and initialize data vector indexed by entities of a particula co-dimension
CodimMeshDataSet(std::shared_ptr< const Mesh > mesh, dim_t codim)
construct data vector indexed by entities of a particular co-dimension
const T & operator()(const Entity &e) const override
Get the data stored with entity e.
unsigned int dim_t
type for dimensions and co-dimensions and numbers derived from them
Definition types.h:32
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.
std::shared_ptr< CodimMeshDataSet< T > > make_CodimMeshDataSet(const std::shared_ptr< const lf::mesh::Mesh > &mesh, base::dim_t codim)
Create a new CodimMeshDataSet that attaches data of type T with every entity with codimension codim....
Defines a set of interface classes that define a mesh manager and provides mesh-related tools that bu...
Definition entity.cc:5