00001 #ifndef DUNE_ADAPTCALLBACK_HH
00002 #define DUNE_ADAPTCALLBACK_HH
00003
00010 namespace Dune
00011 {
00012
00013
00014
00015
00016 template< class Grid, class Impl >
00017 class AdaptDataHandle;
00018
00019
00020
00021
00022
00023
00024 template< class Grid, class Impl >
00025 class AdaptDataHandleInterface
00026 {
00027 typedef AdaptDataHandleInterface< Grid, Impl > This;
00028
00029 friend class AdaptDataHandle< Grid, Impl >;
00030
00031 public:
00032 typedef typename Grid::template Codim< 0 >::Entity Entity;
00033
00034 private:
00035 AdaptDataHandleInterface ()
00036 {}
00037
00038 AdaptDataHandleInterface ( const This & );
00039 This &operator= ( const This & );
00040
00041 public:
00042 void preAdapt ( const size_t estimateAdditionalElements )
00043 {
00044 asImp().preAdapt( estimateAdditionalElements );
00045 }
00046
00047 void postAdapt ()
00048 {
00049 asImp().postAdapt();
00050 }
00051
00052 void preCoarsening ( const Entity &father ) const
00053 {
00054 asImp().preCoarsening( father );
00055 }
00056
00057 void postRefinement ( const Entity &father ) const
00058 {
00059 asImp().postRefinement( father );
00060 }
00061
00062 protected:
00063 const Impl &asImp () const
00064 {
00065 return static_cast< const Impl & >( *this );
00066 }
00067
00068 Impl &asImp ()
00069 {
00070 return static_cast< Impl & >( *this );
00071 }
00072 };
00073
00074
00075
00076
00077
00078
00079 template< class Grid, class Impl >
00080 class AdaptDataHandle
00081 : public AdaptDataHandleInterface< Grid, Impl >
00082 {
00083 typedef AdaptDataHandle< Grid, Impl > This;
00084 typedef AdaptDataHandleInterface< Grid, Impl > Base;
00085
00086 public:
00087 typedef typename Base::Entity Entity;
00088
00089 protected:
00090 AdaptDataHandle ()
00091 {}
00092
00093 private:
00094 AdaptDataHandle ( const This & );
00095 This &operator= ( const This & );
00096
00097 void preAdapt ( const size_t estimateAdditionalElements );
00098 void postAdapt ();
00099 void preCoarsening ( const Entity &father ) const;
00100 void postRefinement ( const Entity &father ) const;
00101 };
00102
00103
00104
00105
00106
00107
00108 template< class Grid, class DofManager, class RestrictProlongOperator >
00109 class RestrictProlongWrapper
00110 : public AdaptDataHandle
00111 < Grid, RestrictProlongWrapper< Grid, DofManager, RestrictProlongOperator > >
00112 {
00113 typedef RestrictProlongWrapper< Grid, DofManager, RestrictProlongOperator > This;
00114 typedef AdaptDataHandle< Grid, This > Base;
00115
00116 DofManager &dofManager_;
00117 RestrictProlongOperator &rpOp_;
00118
00119 public:
00120 typedef typename Base::Entity Entity;
00121
00122 RestrictProlongWrapper ( DofManager &dofManager, RestrictProlongOperator &rpOp )
00123 : dofManager_( dofManager ),
00124 rpOp_( rpOp )
00125 {}
00126
00127 void preAdapt ( const size_t estimatedAdditionalElements )
00128 {
00129 dofManager_.reserveMemory( estimatedAdditionalElements );
00130 }
00131
00132 void postAdapt ()
00133 {
00134 dofManager_.compress();
00135 }
00136
00137 void preCoarsening ( const Entity &father ) const
00138 {
00139 typedef typename Entity::HierarchicIterator HIterator;
00140
00141 bool initialize = true;
00142 const int childLevel = father.level()+1;
00143 const HIterator end = father.hend( childLevel );
00144 for( HIterator it = father.hbegin( childLevel ); it != end; ++it )
00145 {
00146 restrictLocal( father, *it, initialize );
00147 initialize = false;
00148 }
00149 }
00150
00151 void restrictLocal ( const Entity &father, const Entity &son, bool initialize ) const
00152 {
00153 dofManager_.indexSetRPop().restrictLocal( const_cast< Entity & >( father ), const_cast< Entity & >( son ), initialize );
00154 rpOp_.restrictLocal( const_cast< Entity & >( father ), const_cast< Entity & >( son ), initialize );
00155 }
00156
00157 void postRefinement ( const Entity &father ) const
00158 {
00159 typedef typename Entity::HierarchicIterator HIterator;
00160
00161 bool initialize = true;
00162 const int childLevel = father.level()+1;
00163 const HIterator end = father.hend( childLevel );
00164 for( HIterator it = father.hbegin( childLevel ); it != end; ++it )
00165 {
00166 prolongLocal( father, *it, initialize );
00167 initialize = false;
00168 }
00169 }
00170
00171 void prolongLocal ( const Entity &father, const Entity &son, bool initialize ) const
00172 {
00173 dofManager_.indexSetRPop().prolongLocal( const_cast< Entity & >( father ), const_cast< Entity & >( son ), initialize );
00174 rpOp_.prolongLocal( const_cast< Entity & >( father ), const_cast< Entity & >( son ), initialize );
00175 }
00176 };
00177
00178
00179
00180
00181
00182
00184 template <class A, class B >
00185 class CombinedAdaptProlongRestrict
00186 {
00188 const A & _a;
00189 const B & _b;
00190 public:
00192 CombinedAdaptProlongRestrict ( const A & a, const B & b ) : _a ( a ) , _b ( b )
00193 {}
00194
00196 template <class EntityType>
00197 void restrictLocal ( EntityType &father, EntityType &son, bool initialize ) const
00198 {
00199 _a.restrictLocal(father,son,initialize);
00200 _b.restrictLocal(father,son,initialize);
00201 }
00202
00204 template <class EntityType>
00205 void prolongLocal ( EntityType &father, EntityType &son, bool initialize ) const
00206 {
00207 _a.prolongLocal(father,son,initialize);
00208 _b.prolongLocal(father,son,initialize);
00209 }
00210 };
00211
00212 }
00213
00214 #endif