dune-fem 2.8.0
Loading...
Searching...
No Matches
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
13namespace 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_ ),
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 // initialize restrict-prolong object
80 rpOp_.initialize();
81
82 // unset was changed
83 wasChanged_ = false;
84 // reserve memory
85 dofManager_.reserveMemory( estimatedAdditionalElements );
86
87 // set initializeCalled_ flag in case method is called again (only dune-grid version)
88 initializeCalled_ = true;
89 // reset postAdaptCalled flag
90 finalizeCalled_ = false ;
91
92 }
93
95 void finalize ()
96 {
97 // if method has been called already do nothing
98 if( finalizeCalled_ ) return ;
99
100 // notifyGlobalChange make wasChanged equal on all cores
102 {
103 // make sure that no communication calls
104 // are done during DofManager::compress
106
107 // unset was changed flag
108 wasChanged_ = false;
109 }
110
111 // initialize restrict-prolong object
112 rpOp_.finalize();
113
114 // set postAdaptCalled flag
115 finalizeCalled_ = true ;
116
117 // reset initializeCalled_ flag
118 initializeCalled_ = false ;
119 }
120
122 void preCoarsening ( const Entity &father ) const
123 {
124 if( isValidEntity( father ) )
125 {
126 typedef typename Entity::HierarchicIterator HIterator;
127
128 bool initialize = true;
129 const int childLevel = father.level() + 1;
130 const HIterator end = father.hend( childLevel );
131 for( HIterator it = father.hbegin( childLevel ); it != end; ++it )
132 {
133 restrictLocal( father, *it, initialize );
134 initialize = false;
135 }
136 rpOp_.restrictFinalize( father );
137 }
138 }
139
140 void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
141 {
142 if( isValidEntity( father ) )
143 {
145 rpOp_.restrictLocal( father, son, initialize );
146 }
147 }
148
150 void postRefinement ( const Entity &father ) const
151 {
152 if( isValidEntity( father ) )
153 {
154 typedef typename Entity::HierarchicIterator HIterator;
155
156 bool initialize = true;
157 const int childLevel = father.level() + 1;
158 const HIterator end = father.hend( childLevel );
159 for( HIterator it = father.hbegin( childLevel ); it != end; ++it )
160 {
161 prolongLocal( father, *it, initialize );
162 initialize = false;
163 }
164 }
165 }
166
167 void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
168 {
169 if( isValidEntity( father ) )
170 {
172 rpOp_.prolongLocal( father, son, initialize );
173 }
174 }
175 };
176
177 } // namespace Fem
178
179} // namespace Dune
180
181#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:685
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:965
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:705
NewIndexSetRestrictProlongType & indexSetRestrictProlong()
returns the index set restriction and prolongation operator
Definition: dofmanager.hh:923
void compress()
Compress all data that is hold by this dofmanager.
Definition: dofmanager.hh:1038
bool notifyGlobalChange(const bool wasChanged) const
communicate new sequence number
Definition: dofmanager.hh:1063
Definition: bindguard.hh:11
Definition: adaptcallbackhandle.hh:26
void preCoarsening(const Entity &father) const
Definition: adaptcallbackhandle.hh:122
void restrictLocal(const Entity &father, const Entity &son, bool initialize) const
Definition: adaptcallbackhandle.hh:140
void finalize()
finalize calls the compress on the DofManager
Definition: adaptcallbackhandle.hh:95
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:150
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:167
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:761