DUNE-FEM (unstable)

sharedgeometry.hh
1#ifndef DUNE_FEM_GRIDPART_COMMON_SHAREDGEOMETRY_HH
2#define DUNE_FEM_GRIDPART_COMMON_SHAREDGEOMETRY_HH
3
4#include <tuple>
5#include <type_traits>
6#include <utility>
7
9
11
12namespace Dune
13{
14
15 // SharedGeometry
16 // --------------
17
18 template< class Impl, class Alloc = std::allocator< Impl > >
19 class SharedGeometry
20 {
21 typedef SharedGeometry< Impl, Alloc > This;
22
23 typedef std::pair< Impl, std::size_t > Data;
24
25 public:
26 typedef Impl Implementation;
27 typedef Alloc Allocator;
28
29 static const int mydimension = Implementation::mydimension;
30 static const int coorddimension = Implementation::coorddimension;
31
32 typedef typename Implementation::ctype ctype;
33
34 typedef typename Implementation::LocalCoordinate LocalCoordinate;
35 typedef typename Implementation::GlobalCoordinate GlobalCoordinate;
36
37 typedef typename Implementation::JacobianTransposed JacobianTransposed;
38 typedef typename Implementation::JacobianInverseTransposed JacobianInverseTransposed;
39
40 typedef typename Implementation::Jacobian Jacobian;
41 typedef typename Implementation::JacobianInverse JacobianInverse;
42
43 SharedGeometry () = default;
44
45 template< class... Args, std::enable_if_t< std::is_constructible< Impl, Args &&... >::value, int > = 0 >
46 SharedGeometry ( Args &&... args )
47 : data_( construct( std::forward_as_tuple< Args... >( args... ) ) )
48 {}
49
50 SharedGeometry ( const This &other )
51 : data_( other.data_ ), allocator_( other.allocator_ )
52 {
53 if (data_)
54 ++data_->second;
55 }
56
57 SharedGeometry ( This &&other )
58 : data_( other.data_ ), allocator_( std::move( other.allocator_ ) )
59 {
60 other.data_ = nullptr;
61 }
62
63 ~SharedGeometry ()
64 {
65 if( data_ && (--data_->second == 0) )
66 destroy();
67 }
68
69 This &operator= ( const This &other )
70 {
71 if( other.data_ )
72 ++other.data_->second;
73 if( data_ && (--data_->second == 0) )
74 destroy();
75 data_ = other.data_;
76 allocator_ = other.allocator_;
77 return *this;
78 }
79
80 This &operator= ( This &&other )
81 {
82 if( data_ && (--data_->second == 0) )
83 destroy();
84 data_ = other.data_;
85 allocator_ = std::move( other.allocator_ );
86 other.data_ = nullptr;
87 return *this;
88 }
89
90 operator bool () const { return static_cast< bool >( data_ ); }
91
92 bool affine () const { return impl().affine(); }
93 GeometryType type () const { return impl().type(); }
94
95 int corners () const { return impl().corners(); }
96 GlobalCoordinate corner ( int i ) const { return impl().corner( i ); }
97 GlobalCoordinate center () const { return impl().center(); }
98
99 GlobalCoordinate global ( const LocalCoordinate &local ) const { return impl().global( local ); }
100 LocalCoordinate local ( const GlobalCoordinate &global ) const { return impl().local( global ); }
101
102 ctype integrationElement ( const LocalCoordinate &local ) const { return impl().integrationElement( local ); }
103 ctype volume () const { return impl().volume(); }
104
105 JacobianTransposed jacobianTransposed ( const LocalCoordinate &local ) const { return impl().jacobianTransposed( local ); }
106 JacobianInverseTransposed jacobianInverseTransposed ( const LocalCoordinate &local ) const { return impl().jacobianInverseTransposed( local ); }
107
108 Jacobian jacobian ( const LocalCoordinate &local ) const { return impl().jacobian( local ); }
109 JacobianInverse jacobianInverse ( const LocalCoordinate &local ) const { return impl().jacobianInverse( local ); }
110
111 Allocator allocator () const { return allocator_; }
112
113 const Impl &impl () const { assert( data_ ); return data_->first; }
114 Impl &impl () { assert( data_ ); return data_->first; }
115
116 private:
117 template< class... Args >
118 Data *construct ( std::tuple< Args... > args )
119 {
120 Data *data = allocator_.allocate( 1 );
121 return new (data) Data( std::piecewise_construct, args, std::make_tuple( 1u ) );
122 }
123
124 void destroy ()
125 {
126 data_->~Data();
127 allocator_.deallocate( data_, 1 );
128 }
129
130 Data *data_ = nullptr;
131 typename std::allocator_traits< Allocator >::template rebind_alloc< Data > allocator_;
132 };
133
134} // namespace Dune
135
136#endif // #ifndef DUNE_FEM_GRIDPART_COMMON_SHAREDGEOMETRY_HH
Wrapper and interface classes for element geometries.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)