DUNE-FEM (unstable)

entitygeometry.hh
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
14#include <dune/geometry/referenceelements.hh>
15#include <dune/geometry/type.hh>
16
17#include <dune/fem/misc/mpimanager.hh>
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
49 general( std::declval< const Dune::GeometryType & >() ) ) > ReferenceElementType;
50
51 protected:
52 typedef std::optional< EntityType > EntityStorageType;
53
54 struct Empty
55 {
56 operator bool () const { return false; }
57 };
58 typedef typename std::conditional< storeGeometry,
59 std::optional< Geometry >,
60 Empty > :: type GeometryStorageType;
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 {
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
153 entity_.emplace( entity );
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:
182 void copyGeometry( const EntityGeometryStorageImpl& other )
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:
195 EntityStorageType entity_;
196 GeometryStorageType geometry_;
197#ifdef TESTTHREADING
198 int thread_;
199#endif
200 };
201
202 template <class Entity>
203 using EntityGeometryStorage = EntityGeometryStorageImpl< Entity, true >;
204
205 template <class Entity>
206 using EntityStorage = EntityGeometryStorageImpl< Entity, false >;
207 } // end namespace Fem
208
209} // end namespace Dune
210#endif
Wrapper class for entities.
Definition: entity.hh:66
Geometry geometry() const
obtain geometric realization of the entity
Definition: entity.hh:141
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:100
GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: entity.hh:146
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
EntityGeometryStorageImpl & operator=(const EntityGeometryStorageImpl &other)
assignment operator
Definition: entitygeometry.hh:90
std::decay_t< decltype(Dune::ReferenceElements< ctype, Geometry::coorddimension >::general(std::declval< const Dune::GeometryType & >())) > ReferenceElementType
type of reference element
Definition: entitygeometry.hh:49
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 unbind()
release entity and geometry object
Definition: entitygeometry.hh:164
EntityGeometryStorageImpl(const EntityGeometryStorageImpl &other)
copy constructor
Definition: entitygeometry.hh:80
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
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
GridImp::ctype ctype
define type used for coordinates in grid module
Definition: geometry.hh:100
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:281
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Just an empty class.
Definition: typetraits.hh:55
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)