LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
all_codim_mesh_data_set.h
1
9#ifndef INCGdf4311acf6554f11919b7b1edfc5b3dd
10#define INCGdf4311acf6554f11919b7b1edfc5b3dd
11
12#include <lf/mesh/mesh.h>
13
14#include <boost/container/vector.hpp>
15#include <concepts>
16
17#include "lf/base/lf_assert.h"
18#include "mesh_data_set.h"
19
20namespace lf::mesh::utils {
21
28template <class T>
30 public:
33
36 AllCodimMeshDataSet& operator=(const AllCodimMeshDataSet&) = delete;
37 AllCodimMeshDataSet& operator=(AllCodimMeshDataSet&&) noexcept = default;
38 ~AllCodimMeshDataSet() override = default;
39
47 [[nodiscard]] T& operator()(const Entity& e) {
48 LF_ASSERT_MSG(DefinedOn(e), "MeshDataSet is not defined on this entity.");
49 return data_[e.Codim()][mesh_->Index(e)];
50 }
51 // NOLINTNEXTLINE(readability-const-return-type)
52 [[nodiscard]] const T& operator()(const Entity& e) const override {
53 LF_ASSERT_MSG(DefinedOn(e), "MeshDataSet is not defined on this entity.");
54 return data_[e.Codim()][mesh_->Index(e)];
55 }
56 [[nodiscard]] bool DefinedOn(const Entity& e) const override {
57 return mesh_->Contains(e);
58 }
59
68 const std::shared_ptr<const lf::mesh::Mesh>& mesh)
69 : MeshDataSet<T>(),
70 dim_mesh_(mesh->DimMesh()),
71 mesh_(mesh),
72 data_(dim_mesh_ + 1) {
73 for (dim_t codim = 0; codim <= dim_mesh_; ++codim) {
74 data_[codim].resize(mesh_->NumEntities(codim));
75 }
76 }
77
86 template <class X,
87 class = typename std::enable_if_t<std::is_convertible_v<X, T> &&
88 std::is_copy_constructible_v<X>>>
89 AllCodimMeshDataSet(const std::shared_ptr<const lf::mesh::Mesh>& mesh,
90 X init_value)
91 : MeshDataSet<T>(),
92 dim_mesh_(mesh->DimMesh()),
93 mesh_(mesh),
94 data_(dim_mesh_ + 1) {
95 for (dim_t codim = 0; codim <= dim_mesh_; ++codim) {
96 data_[codim] =
97 boost::container::vector<T>(mesh_->NumEntities(codim), init_value);
98 }
99 }
100
101 private:
103 std::shared_ptr<const lf::mesh::Mesh> mesh_;
104
105 // Note(craffael): We use boost container here which doesn't have the ridicule
106 // specialization that std::vector<bool> has. In this way we can actually
107 // return references in operator() const.
108 boost::container::vector<boost::container::vector<T>> data_;
109};
110
118template <class T>
119std::shared_ptr<AllCodimMeshDataSet<T>> make_AllCodimMeshDataSet(
120 const std::shared_ptr<const lf::mesh::Mesh>& mesh) {
121 using impl_t = AllCodimMeshDataSet<T>;
122 auto t = new AllCodimMeshDataSet<T>(mesh);
123 return std::shared_ptr<impl_t>(t);
124}
125
133template <std::copy_constructible T>
134std::shared_ptr<AllCodimMeshDataSet<T>> make_AllCodimMeshDataSet(
135 const std::shared_ptr<const lf::mesh::Mesh>& mesh, T init_value) {
136 using impl_t = AllCodimMeshDataSet<T>;
137 return std::make_shared<impl_t>(mesh, init_value);
138}
139
140} // namespace lf::mesh::utils
141
142#endif // INCGdf4311acf6554f11919b7b1edfc5b3dd
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
Assigns to every entity(all codims) in a mesh a value of type T
const T & operator()(const Entity &e) const override
Get the data stored with entity e.
bool DefinedOn(const Entity &e) const override
Does the dataset store information with this entity?
AllCodimMeshDataSet(const std::shared_ptr< const lf::mesh::Mesh > &mesh)
set up default-initialized data arrays
boost::container::vector< boost::container::vector< T > > data_
std::shared_ptr< const lf::mesh::Mesh > mesh_
AllCodimMeshDataSet(AllCodimMeshDataSet &&) noexcept=default
AllCodimMeshDataSet(const AllCodimMeshDataSet &)=delete
AllCodimMeshDataSet(const std::shared_ptr< const lf::mesh::Mesh > &mesh, X init_value)
Set up data array for entities and initialize it with a given value.
Interface that specifies how data is stored with an entity.
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.
std::shared_ptr< AllCodimMeshDataSet< T > > make_AllCodimMeshDataSet(const std::shared_ptr< const lf::mesh::Mesh > &mesh)
Create a new AllCodimMeshDataSet and Default initialize the data.