DUNE-FEM (unstable)

persistentindexset.hh
1#ifndef DUNE_FEM_GRIDPART_TEST_PERSISTENTINDEXSET_HH
2#define DUNE_FEM_GRIDPART_TEST_PERSISTENTINDEXSET_HH
3
4#include <type_traits>
5#include <utility>
6
7#include <dune/fem/gridpart/common/indexset.hh>
8#include <dune/fem/io/file/persistencemanager.hh>
9#include <dune/fem/io/streams/streams.hh>
10#include <dune/fem/space/common/dofmanager.hh>
11
12namespace Dune
13{
14
15 namespace Fem
16 {
17
18 // Internal forward declaration
19 // ----------------------------
20
21 template< class Traits >
22 class PersistentConsecutiveIndexSet;
23 template< class Traits >
24 class PersistentAdaptiveIndexSet;
25
26
27
28 // PersistentIndexSetInterface
29 // ---------------------------
30
35 {
37
39 virtual void addBackupRestore () = 0;
40
42 virtual void removeBackupRestore () = 0;
43 };
44
45
46
47 namespace Capabilities
48 {
49
50 // isPersistentIndexSet
51 // --------------------
52
53#ifndef DOXYGEN
54
55 template< class IndexSet, bool value = std::is_base_of< PersistentIndexSetInterface, IndexSet >::type::value >
56 struct __isPersistentIndexSet;
57
58 template< class IndexSet >
59 struct __isPersistentIndexSet< IndexSet, true >
60 {
61 static const bool v = true;
62
63 static constexpr PersistentIndexSetInterface* map ( IndexSet &indexSet )
64 {
65 return static_cast< PersistentIndexSetInterface * >( &indexSet );
66 }
67 };
68
69 template< class IndexSet >
70 struct __isPersistentIndexSet< IndexSet, false >
71 {
72 static const bool v = false;
73
74 static constexpr PersistentIndexSetInterface* map ( IndexSet & ) noexcept
75 {
76 return nullptr;
77 }
78 };
79
80#endif // #ifndef DOXYGEN
81
89 template< class IndexSet >
91 : public __isPersistentIndexSet< IndexSet >
92 {
93 private:
94 typedef __isPersistentIndexSet< IndexSet > BaseType;
95
96 public:
98 static const bool v = BaseType::v;
99
101 static constexpr PersistentIndexSetInterface* map ( IndexSet &indexSet ) noexcept
102 {
103 return BaseType::map( indexSet );
104 }
105 };
106
107#ifndef DOXYGEN
108
109 template< class IndexSet >
110 struct isPersistentIndexSet< const IndexSet >
111 : public isPersistentIndexSet< IndexSet >
112 {};
113
114#endif // #ifndef DOXYGEN
115
116 } // namespace Capabilities
117
118
119
120 // PersistentIndexSet
121 // ------------------
122
128 template< class Traits, template< class > class Base >
130 : public Base< Traits >,
132 {
133 typedef Base< Traits > BaseType;
134
135 protected:
136 using BaseType::impl;
137
139 typedef typename Traits::GridType GridType;
142
143 explicit PersistentIndexSet ( const GridType &grid )
144 : grid_( grid ),
145 dofManager_( DofManagerType::instance( grid ) ),
146 counter_( 0 )
147 {
148 dofManager_.addIndexSet( impl() );
149 }
150
151 public:
152 using BaseType::read;
153 using BaseType::write;
154
156 {
157 dofManager_.removeIndexSet( impl() );
158 }
159
161 void backup () const
162 {
163 if( needsBackupRestore() )
164 write( PersistenceManager::backupStream() );
165 }
166
168 void restore ()
169 {
170 if( needsBackupRestore() )
171 read( PersistenceManager::restoreStream() );
172 }
173
175 void addBackupRestore () override final { ++counter_; }
176
178 void removeBackupRestore () override final { --counter_; }
179
180 private:
181 bool needsBackupRestore () const { return counter_ > 0; }
182
183 protected:
184 const GridType &grid_;
185 DofManagerType &dofManager_;
186
187 private:
188 int counter_ ;
189 };
190
191
192
193 // PersistentConsecutiveIndexSet
194 // -----------------------------
195
196 template< class Traits >
197 class PersistentConsecutiveIndexSet
198 : public PersistentIndexSet< Traits, ConsecutiveIndexSet >
199 {
201
202 protected:
203 explicit PersistentConsecutiveIndexSet ( const typename BaseType::GridType &grid )
204 : BaseType( grid )
205 {}
206 };
207
208
209
210 // PersistentAdaptiveIndexSet
211 // --------------------------
212
213 template< class Traits >
214 class PersistentAdaptiveIndexSet
215 : public PersistentIndexSet< Traits, AdaptiveIndexSet >
216 {
218
219 protected:
220 explicit PersistentAdaptiveIndexSet ( const typename BaseType::GridType &grid )
221 : BaseType( grid )
222 {}
223 };
224
225 } // namespace Fem
226
227} // namespace Dune
228
229#endif // #ifndef DUNE_FEM_GRIDPART_TEST_PERSISTENTINDEXSET_HH
Definition: dofmanager.hh:786
interface documentation for (grid part) index sets
Definition: indexset.hh:123
please doc me
Definition: persistentindexset.hh:132
Traits::GridType GridType
grid type
Definition: persistentindexset.hh:139
void backup() const
please doc me
Definition: persistentindexset.hh:161
void restore()
please doc me
Definition: persistentindexset.hh:168
void removeBackupRestore() override final
please doc me
Definition: persistentindexset.hh:178
void addBackupRestore() override final
please doc me
Definition: persistentindexset.hh:175
DofManager< GridType > DofManagerType
dof manager type
Definition: persistentindexset.hh:141
Index Set Interface base class.
Definition: indexidset.hh:78
void removeIndexSet(const IndexSetType &iset)
removed index set from dof manager's list of index sets
Definition: dofmanager.hh:1331
void addIndexSet(const IndexSetType &iset)
add index set to dof manager's list of index sets
Definition: dofmanager.hh:1296
Dune namespace.
Definition: alignedallocator.hh:13
capability for persistent index sets
Definition: persistentindexset.hh:92
static constexpr PersistentIndexSetInterface * map(IndexSet &indexSet) noexcept
please doc me
Definition: persistentindexset.hh:101
static const bool v
please doc me
Definition: persistentindexset.hh:98
virtual base class for persistent index sets
Definition: persistentindexset.hh:35
virtual void addBackupRestore()=0
please doc me
virtual void removeBackupRestore()=0
please doc me
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)