dune-fem  2.6-git
adaptcallbackhandle.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_ADAPTCALLBACKHANDLE_HH
2 #define DUNE_FEM_ADAPTCALLBACKHANDLE_HH
3 
4 #include <dune/grid/common/gridenums.hh>
5 #include <dune/grid/common/adaptcallback.hh>
6 
13 namespace Dune
14 {
15 
16  namespace Fem
17  {
18 
19  // RestrictProlongWrapper
20  // ----------------------
21 
22  template< class Grid, class DofManager, class RestrictProlongOperator >
24  : public AdaptDataHandle
25  < Grid, RestrictProlongWrapper< Grid, DofManager, RestrictProlongOperator > >
26  {
28  typedef AdaptDataHandle< Grid, This > Base;
29 
30  protected:
32  RestrictProlongOperator &rpOp_;
33 
34  // flag that is set to true when at least one entity was coarsend or refined
35  mutable bool wasChanged_ ;
38 
39  public:
40  typedef typename Base::Entity Entity;
41 
42  RestrictProlongWrapper ( DofManager &dofManager, RestrictProlongOperator &rpOp )
43  : dofManager_( dofManager ),
44  rpOp_( rpOp ),
45  wasChanged_( false ),
46  initializeCalled_( false ),
47  finalizeCalled_( false )
48  {
49  }
50 
52  : dofManager_( org.dofManager_ ),
53  rpOp_( org.rpOp_ ),
54  wasChanged_( org.wasChanged_ ),
57  {}
58 
59  bool isValidEntity( const Entity& entity ) const
60  {
61  // grid was changed, if this method is called
62  wasChanged_ = true ;
63 
64  // ghosts are not valid for restriction/prolongation
65  assert( entity.partitionType() != GhostEntity );
66  return true ;
67  }
68 
69  // old interface methods
70  void preAdapt ( const unsigned int estimatedAdditionalElements ) { initialize (); }
71  void postAdapt () { finalize(); }
72 
74  void initialize ( unsigned int estimatedAdditionalElements = 0 )
75  {
76  // if preAdapt was already called just return
77  if( initializeCalled_ ) return ;
78 
79  // unset was changed
80  wasChanged_ = false;
81  // reserve memory
82  dofManager_.reserveMemory( estimatedAdditionalElements );
83 
84  // set initializeCalled_ flag in case method is called again (only dune-grid version)
85  initializeCalled_ = true;
86  // reset postAdaptCalled flag
87  finalizeCalled_ = false ;
88 
89  }
90 
92  void finalize ()
93  {
94  // if method has been called already do nothing
95  if( finalizeCalled_ ) return ;
96 
97  // notifyGlobalChange make wasChanged equal on all cores
99  {
100  // make sure that no communication calls
101  // are done during DofManager::compress
103 
104  // unset was changed flag
105  wasChanged_ = false;
106  }
107 
108  // set postAdaptCalled flag
109  finalizeCalled_ = true ;
110 
111  // reset initializeCalled_ flag
112  initializeCalled_ = false ;
113  }
114 
116  void preCoarsening ( const Entity &father ) const
117  {
118  if( isValidEntity( father ) )
119  {
120  typedef typename Entity::HierarchicIterator HIterator;
121 
122  bool initialize = true;
123  const int childLevel = father.level() + 1;
124  const HIterator end = father.hend( childLevel );
125  for( HIterator it = father.hbegin( childLevel ); it != end; ++it )
126  {
127  restrictLocal( father, *it, initialize );
128  initialize = false;
129  }
130  }
131  }
132 
133  void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
134  {
135  if( isValidEntity( father ) )
136  {
138  rpOp_.restrictLocal( father, son, initialize );
139  }
140  }
141 
143  void postRefinement ( const Entity &father ) const
144  {
145  if( isValidEntity( father ) )
146  {
147  typedef typename Entity::HierarchicIterator HIterator;
148 
149  bool initialize = true;
150  const int childLevel = father.level() + 1;
151  const HIterator end = father.hend( childLevel );
152  for( HIterator it = father.hbegin( childLevel ); it != end; ++it )
153  {
154  prolongLocal( father, *it, initialize );
155  initialize = false;
156  }
157  }
158  }
159 
160  void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
161  {
162  if( isValidEntity( father ) )
163  {
165  rpOp_.prolongLocal( father, son, initialize );
166  }
167  }
168  };
169 
170  } // namespace Fem
171 
172 } // namespace Dune
173 
174 #endif // #ifndef DUNE_FEM_ADAPTCALLBACKHANDLE_HH
void restrictLocal(const EntityType &father, const EntityType &son, bool initialize) const
restrict data to father and resize memory if doResize is true
Definition: dofmanager.hh:753
void reserveMemory(int nsize, bool dummy=false)
reserve memory for at least nsize elements, dummy is needed for dune-grid ALUGrid version
Definition: dofmanager.hh:1026
void prolongLocal(const EntityType &father, const EntityType &son, bool initialize) const
prolong data to children and resize memory if doResize is true
Definition: dofmanager.hh:769
void compress()
Compress all data that is hold by this dofmanager.
Definition: dofmanager.hh:1099
NewIndexSetRestrictProlongType & indexSetRestrictProlong()
returns the index set restriction and prolongation operator
Definition: dofmanager.hh:984
bool notifyGlobalChange(const bool wasChanged) const
communicate new sequence number
Definition: dofmanager.hh:1120
Definition: bindguard.hh:11
Definition: adaptcallbackhandle.hh:26
void preCoarsening(const Entity &father) const
Definition: adaptcallbackhandle.hh:116
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
Definition: adaptcallbackhandle.hh:133
void finalize()
finalize calls the compress on the DofManager
Definition: adaptcallbackhandle.hh:92
RestrictProlongOperator & rpOp_
Definition: adaptcallbackhandle.hh:32
DofManager & dofManager_
Definition: adaptcallbackhandle.hh:31
RestrictProlongWrapper(DofManager &dofManager, RestrictProlongOperator &rpOp)
Definition: adaptcallbackhandle.hh:42
void postRefinement(const Entity &father) const
Definition: adaptcallbackhandle.hh:143
void initialize(unsigned int estimatedAdditionalElements=0)
initialize basically reserves some memory on the DofManager
Definition: adaptcallbackhandle.hh:74
bool initializeCalled_
Definition: adaptcallbackhandle.hh:36
Base::Entity Entity
Definition: adaptcallbackhandle.hh:40
bool finalizeCalled_
Definition: adaptcallbackhandle.hh:37
void prolongLocal(const Entity &father, const Entity &son, bool initialize) const
Definition: adaptcallbackhandle.hh:160
void preAdapt(const unsigned int estimatedAdditionalElements)
Definition: adaptcallbackhandle.hh:70
bool isValidEntity(const Entity &entity) const
Definition: adaptcallbackhandle.hh:59
bool wasChanged_
Definition: adaptcallbackhandle.hh:35
RestrictProlongWrapper(const RestrictProlongWrapper &org)
Definition: adaptcallbackhandle.hh:51
void postAdapt()
Definition: adaptcallbackhandle.hh:71
Definition: dofmanager.hh:825