dune-fem 2.12-git
Loading...
Searching...
No Matches
entitygeometry.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_STORAGE_ENTITYGEOMETRY_HH
2#define DUNE_FEM_STORAGE_ENTITYGEOMETRY_HH
3
4// C++ includes
5#include <cassert>
6#include <cstddef>
7#include <memory>
8#include <optional>
9
10// dune-common includes
12
13// dune-geometry includes
15#include <dune/geometry/type.hh>
16
18
19namespace Dune
20{
21
22 namespace Fem
23 {
33 template< class Entity, bool storeGeometry = true >
35 {
36
37 public:
40
42 typedef typename EntityType::Geometry Geometry ;
43
45 typedef typename Geometry::ctype ctype;
46
48 typedef std::decay_t< decltype( Dune::ReferenceElements< ctype, Geometry::coorddimension >::
50
51 protected:
53
54 struct Empty
55 {
56 operator bool () const { return false; }
57 };
58 typedef typename std::conditional< storeGeometry,
61
62 public:
65#ifdef TESTTHREADING
66 : thread_(-1)
67#endif
68 {}
69
72#ifdef TESTTHREADING
73 : thread_( MPIManager::thread() )
74#endif
75 {
76 bind( entity );
77 }
78
81 : entity_( other.entity_ )
82#ifdef TESTTHREADING
83 , thread_( MPIManager::thread() )
84#endif
85 {
86 copyGeometry( other );
87 }
88
91 {
92 entity_ = other.entity_;
93 copyGeometry( other );
94#ifdef TESTTHREADING
95 thread_ = MPIManager::thread();
96#endif
97 return *this;
98 }
99
101 const Entity &entity () const
102 {
103 assert( valid() );
104 return entity_.value();
105 }
106
108 bool valid () const { return bool(entity_); }
109
111 const Geometry& geometry () const
112 {
113 if constexpr ( storeGeometry )
114 {
115 assert( geometry_ );
116 return geometry_.value();
117 }
118 else
119 {
120 DUNE_THROW(InvalidStateException,"EntityGeometryStorageImpl::geometry not available when storeGeometry is false!");
121 return *((Geometry *) nullptr);
122 }
123 }
124
126 Dune::GeometryType type () const { return entity().type(); }
127
130 {
131 return Dune::ReferenceElements< ctype, Geometry::coorddimension >::general( type() );
132 }
133
135 void bind( const EntityType& entity )
136 {
137#ifdef TESTTHREADING
138 if (thread_==-1) thread_ = MPIManager::thread();
139 if (thread_ != MPIManager::thread())
140 {
141 std::cout << "EntityGeometryStorageImpl::bind: wrong thread number!" std::endl;
142 assert(0);
143 std::abort();
144 }
145 if (entity_ || (storeGeometry && geometry_) )
146 {
147 std::cout << "EntityGeometryStorageImpl::bind: bind called on object before unbind was called" << std::endl;
148 std::abort();
149 }
150 assert(!entity_ && !geometry_); // this will fail with dune-fem-dg
151#endif
152
154 if constexpr ( storeGeometry )
155 {
156 // Note that this should be geometry_ = entity.geometry()
157 // But Dune::Geometries are not assignable ...
158 // geometry_.reset();
159 geometry_.emplace( entity.geometry() );
160 }
161 }
162
164 void unbind()
165 {
166#ifdef TESTTHREADING
167 if (thread_ != MPIManager::thread())
168 {
169 std::cout << "EntityGeometryStorageImpl::unbind: wrong thread number" << std::endl;
170 assert(0);
171 std::abort();
172 }
173#endif
174 entity_.reset();
175 if constexpr ( storeGeometry )
176 {
177 geometry_.reset();
178 }
179 }
180
181 protected:
183 {
184 if constexpr ( storeGeometry )
185 {
186 // Note that this should be geometry_ = entity.geometry()
187 // But Dune::Geometries are not assignable ...
188 geometry_.reset();
189 if( other.geometry_ )
190 geometry_.emplace( other.geometry_.value() );
191 }
192 }
193
194 protected:
197#ifdef TESTTHREADING
198 int thread_;
199#endif
200 };
201
202 template <class Entity>
204
205 template <class Entity>
207 } // end namespace Fem
208
209} // end namespace Dune
210#endif
#define DUNE_THROW(E,...)
Geometry geometry() const
GridImp::template Codim< cd >::Geometry Geometry
GeometryType type() const
GridImp::ctype ctype
Definition mpimanager.hh:353
static int thread()
return thread number
Definition mpimanager.hh:445
implementation of entity and geometry storage for basis function set and local functions
Definition entitygeometry.hh:35
Dune::GeometryType type() const
return geometry type
Definition entitygeometry.hh:126
EntityGeometryStorageImpl()
constructor
Definition entitygeometry.hh:64
EntityStorageType entity_
Definition entitygeometry.hh:195
std::optional< EntityType > EntityStorageType
Definition entitygeometry.hh:52
EntityGeometryStorageImpl & operator=(const EntityGeometryStorageImpl &other)
assignment operator
Definition entitygeometry.hh:90
std::conditional< storeGeometry, std::optional< Geometry >, Empty >::type GeometryStorageType
Definition entitygeometry.hh:60
Geometry::ctype ctype
type of coordinate field
Definition entitygeometry.hh:45
const Entity & entity() const
return entity
Definition entitygeometry.hh:101
const Geometry & geometry() const
return geometry
Definition entitygeometry.hh:111
void copyGeometry(const EntityGeometryStorageImpl &other)
Definition entitygeometry.hh:182
void unbind()
release entity and geometry object
Definition entitygeometry.hh:164
EntityGeometryStorageImpl(const EntityGeometryStorageImpl &other)
copy constructor
Definition entitygeometry.hh:80
GeometryStorageType geometry_
Definition entitygeometry.hh:196
const ReferenceElementType & referenceElement() const
return reference element
Definition entitygeometry.hh:129
EntityGeometryStorageImpl(const EntityType &entity)
constructor
Definition entitygeometry.hh:71
bool valid() const
return true if entity pointer is set
Definition entitygeometry.hh:108
Entity EntityType
entity type
Definition entitygeometry.hh:39
void bind(const EntityType &entity)
set new entity object and geometry if enabled
Definition entitygeometry.hh:135
EntityType::Geometry Geometry
type of geometry
Definition entitygeometry.hh:42
Definition entitygeometry.hh:55
T abort(T... args)
T emplace(T... args)
T endl(T... args)
T forward(T... args)
T reset(T... args)
T value(T... args)