DUNE-FEM (unstable)

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>
6
13namespace Dune
14{
15
16 namespace Fem
17 {
18
19 // RestrictProlongWrapper
20 // ----------------------
21
22 template< class Grid, class DofManager, class RestrictProlongOperator >
23 class RestrictProlongWrapper
24 : public AdaptDataHandle
25 < Grid, RestrictProlongWrapper< Grid, DofManager, RestrictProlongOperator > >
26 {
27 typedef RestrictProlongWrapper< Grid, DofManager, RestrictProlongOperator > This;
28 typedef AdaptDataHandle< Grid, This > Base;
29
30 protected:
31 DofManager &dofManager_;
32 RestrictProlongOperator &rpOp_;
33
34 // flag that is set to true when at least one entity was coarsend or refined
35 mutable bool wasChanged_ ;
36 bool initializeCalled_;
37 bool finalizeCalled_;
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
51 RestrictProlongWrapper ( const RestrictProlongWrapper& org )
52 : dofManager_( org.dofManager_ ),
53 rpOp_( org.rpOp_ ),
54 wasChanged_( org.wasChanged_ ),
55 initializeCalled_( org.initializeCalled_ ),
56 finalizeCalled_( org.finalizeCalled_ )
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
101 if( dofManager_.notifyGlobalChange( wasChanged_ ) )
102 {
103 // make sure that no communication calls
104 // are done during DofManager::compress
105 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 {
144 dofManager_.indexSetRestrictProlong().restrictLocal( father, son, initialize );
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 {
171 dofManager_.indexSetRestrictProlong().prolongLocal( father, son, initialize );
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
interfaces and wrappers needed for the callback adaptation provided by AlbertaGrid and dune-ALUGrid
@ GhostEntity
ghost entities
Definition: gridenums.hh:35
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)