dune-fem  2.4.1-rc
persistentindexset.hh
Go to the documentation of this file.
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 
11 
12 namespace Dune
13 {
14 
15  namespace Fem
16  {
17 
18  // Internal forward declaration
19  // ----------------------------
20 
21  template< class Traits >
23  template< class Traits >
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() )
165  }
166 
168  void restore ()
169  {
170  if( needsBackupRestore() )
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 >
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 >
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: persistentindexset.hh:24
PersistentConsecutiveIndexSet(const typename BaseType::GridType &grid)
Definition: persistentindexset.hh:203
void addBackupRestore() overridefinal
please doc me
Definition: persistentindexset.hh:175
virtual void removeBackupRestore()=0
please doc me
DofManagerType & dofManager_
Definition: persistentindexset.hh:185
~PersistentIndexSet()
Definition: persistentindexset.hh:155
static RestoreStreamType & restoreStream()
Definition: persistencemanager.hh:338
void restore()
please doc me
Definition: persistentindexset.hh:168
DofManager< GridType > DofManagerType
dof manager type
Definition: persistentindexset.hh:141
Definition: datacollector.hh:45
please doc me
Definition: persistentindexset.hh:129
void backup() const
please doc me
Definition: persistentindexset.hh:161
virtual ~PersistentIndexSetInterface()
Definition: persistentindexset.hh:36
const GridType & grid_
Definition: persistentindexset.hh:184
static BackupStreamType & backupStream()
Definition: persistencemanager.hh:333
Definition: coordinate.hh:4
virtual void addBackupRestore()=0
please doc me
Definition: persistentindexset.hh:22
capability for persistent index sets
Definition: persistentindexset.hh:90
Traits::GridType GridType
grid type
Definition: persistentindexset.hh:139
void removeBackupRestore() overridefinal
please doc me
Definition: persistentindexset.hh:178
PersistentAdaptiveIndexSet(const typename BaseType::GridType &grid)
Definition: persistentindexset.hh:220
PersistentIndexSet(const GridType &grid)
Definition: persistentindexset.hh:143
static constexpr PersistentIndexSetInterface * map(IndexSet &indexSet) noexcept
please doc me
Definition: persistentindexset.hh:101
virtual base class for persistent index sets
Definition: persistentindexset.hh:34