LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
all_codim_mesh_data_set.h
1
8
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
37template <class T>
39 public:
42
45 AllCodimMeshDataSet& operator=(const AllCodimMeshDataSet&) = delete;
46 AllCodimMeshDataSet& operator=(AllCodimMeshDataSet&&) noexcept = default;
47 ~AllCodimMeshDataSet() override = default;
48
56 [[nodiscard]] T& operator()(const Entity& e) {
57 LF_ASSERT_MSG(DefinedOn(e), "MeshDataSet is not defined on this entity.");
58 return data_[e.Codim()][mesh_->Index(e)];
59 }
60 // NOLINTNEXTLINE(readability-const-return-type)
61 [[nodiscard]] const T& operator()(const Entity& e) const override {
62 LF_ASSERT_MSG(DefinedOn(e), "MeshDataSet is not defined on this entity.");
63 return data_[e.Codim()][mesh_->Index(e)];
64 }
65 [[nodiscard]] bool DefinedOn(const Entity& e) const override {
66 return mesh_->Contains(e);
67 }
68
77 const std::shared_ptr<const lf::mesh::Mesh>& mesh)
78 : MeshDataSet<T>(),
79 dim_mesh_(mesh->DimMesh()),
80 mesh_(mesh),
81 data_(dim_mesh_ + 1) {
82 for (dim_t codim = 0; codim <= dim_mesh_; ++codim) {
83 data_[codim].resize(mesh_->NumEntities(codim));
84 }
85 }
86
95 template <class X,
96 class = typename std::enable_if_t<std::is_convertible_v<X, T> &&
97 std::is_copy_constructible_v<X>>>
98 AllCodimMeshDataSet(const std::shared_ptr<const lf::mesh::Mesh>& mesh,
99 X init_value)
100 : MeshDataSet<T>(),
101 dim_mesh_(mesh->DimMesh()),
102 mesh_(mesh),
103 data_(dim_mesh_ + 1) {
104 for (dim_t codim = 0; codim <= dim_mesh_; ++codim) {
105 data_[codim] =
106 boost::container::vector<T>(mesh_->NumEntities(codim), init_value);
107 }
108 }
109
110 private:
112 std::shared_ptr<const lf::mesh::Mesh> mesh_;
113
114 // Note(craffael): We use boost container here which doesn't have the ridicule
115 // specialization that std::vector<bool> has. In this way we can actually
116 // return references in operator() const.
117 boost::container::vector<boost::container::vector<T>> data_;
118};
119
127template <class T>
128std::shared_ptr<AllCodimMeshDataSet<T>> make_AllCodimMeshDataSet(
129 const std::shared_ptr<const lf::mesh::Mesh>& mesh) {
130 using impl_t = AllCodimMeshDataSet<T>;
131 auto t = new AllCodimMeshDataSet<T>(mesh);
132 return std::shared_ptr<impl_t>(t);
133}
134
142template <std::copy_constructible T>
143std::shared_ptr<AllCodimMeshDataSet<T>> make_AllCodimMeshDataSet(
144 const std::shared_ptr<const lf::mesh::Mesh>& mesh, T init_value) {
145 using impl_t = AllCodimMeshDataSet<T>;
146 return std::make_shared<impl_t>(mesh, init_value);
147}
148
149} // namespace lf::mesh::utils
150
151#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.
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.
Defines a set of interface classes that define a mesh manager and provides mesh-related tools that bu...
Definition entity.cc:5