- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 #ifndef DUNE_ALUGRID_LBDATAHANDLE_HH 00002 #define DUNE_ALUGRID_LBDATAHANDLE_HH 00003 00004 #include <dune/grid/alugrid/3d/datahandle.hh> 00005 00006 #include <dune/grid/common/datahandleif.hh> 00007 00008 namespace Dune 00009 { 00010 00011 template< class Grid, class DataHandleImpl, class Data > 00012 class ALUGridLoadBalanceDataHandle 00013 { 00014 typedef typename Grid :: Traits :: HierarchicIterator HierarchicIterator; 00015 00016 public: 00017 typedef typename Grid :: ObjectStreamType ObjectStream; 00018 00019 typedef CommDataHandleIF< DataHandleImpl, Data > DataHandle; 00020 00021 static const int dimension = Grid :: dimension; 00022 00023 template< int codim > 00024 struct Codim 00025 { 00026 typedef typename Grid :: Traits :: template Codim< codim > :: Entity Entity; 00027 typedef typename Grid :: Traits :: template Codim< codim > :: EntityPointer 00028 EntityPointer; 00029 }; 00030 00031 typedef typename Codim< 0 > :: Entity Element; 00032 00033 private: 00034 const Grid &grid_; 00035 DataHandle &dataHandle_; 00036 00037 public: 00038 ALUGridLoadBalanceDataHandle ( const Grid &grid, DataHandle &dataHandle ) 00039 : grid_( grid ), 00040 dataHandle_( dataHandle ) 00041 {} 00042 00043 void inlineData ( ObjectStream &stream, const Element &element ) const 00044 { 00045 inlineElementData( stream, element ); 00046 00047 const int maxLevel = grid_.maxLevel(); 00048 const HierarchicIterator end = element.hend( maxLevel ); 00049 for( HierarchicIterator it = element.hbegin( maxLevel ); it != end; ++it ) 00050 inlineElementData( stream, *it ); 00051 } 00052 00053 void xtractData ( ObjectStream &stream, const Element &element, size_t newElements ) 00054 { 00055 xtractElementData( stream, element ); 00056 00057 const int maxLevel = grid_.maxLevel(); 00058 const HierarchicIterator end = element.hend( maxLevel ); 00059 for( HierarchicIterator it = element.hbegin( maxLevel ); it != end; ++it ) 00060 xtractElementData( stream, *it ); 00061 } 00062 00063 void compress () 00064 {} 00065 00066 private: 00067 void inlineElementData ( ObjectStream &stream, const Element &element ) const 00068 { 00069 // call element data direct without creating entity pointer 00070 if( dataHandle_.contains( dimension, 0 ) ) 00071 { 00072 inlineEntityData<0>( stream, element ); 00073 } 00074 00075 // now call all higher codims 00076 inlineCodimData< 1 >( stream, element ); 00077 inlineCodimData< 2 >( stream, element ); 00078 inlineCodimData< 3 >( stream, element ); 00079 } 00080 00081 void xtractElementData ( ObjectStream &stream, const Element &element ) 00082 { 00083 // call element data direct without creating entity pointer 00084 if( dataHandle_.contains( dimension, 0 ) ) 00085 { 00086 xtractEntityData<0>( stream, element ); 00087 } 00088 00089 // now call all higher codims 00090 xtractCodimData< 1 >( stream, element ); 00091 xtractCodimData< 2 >( stream, element ); 00092 xtractCodimData< 3 >( stream, element ); 00093 } 00094 00095 template< int codim > 00096 void inlineCodimData ( ObjectStream &stream, const Element &element ) const 00097 { 00098 typedef typename Codim< codim > :: EntityPointer EntityPointer; 00099 00100 if( dataHandle_.contains( dimension, codim ) ) 00101 { 00102 const int numSubEntities = element.template count< codim >(); 00103 for( int i = 0; i < numSubEntities; ++i ) 00104 { 00105 const EntityPointer pEntity = element.template subEntity< codim >( i ); 00106 inlineEntityData< codim >( stream, *pEntity ); 00107 } 00108 } 00109 } 00110 00111 template< int codim > 00112 void xtractCodimData ( ObjectStream &stream, const Element &element ) 00113 { 00114 typedef typename Codim< codim > :: EntityPointer EntityPointer; 00115 00116 if( dataHandle_.contains( dimension, codim ) ) 00117 { 00118 const int numSubEntities = element.template count< codim >(); 00119 for( int i = 0; i < numSubEntities; ++i ) 00120 { 00121 const EntityPointer pEntity = element.template subEntity< codim >( i ); 00122 xtractEntityData< codim >( stream, *pEntity ); 00123 } 00124 } 00125 } 00126 00127 template< int codim > 00128 void inlineEntityData ( ObjectStream &stream, 00129 const typename Codim< codim > :: Entity &entity ) const 00130 { 00131 const size_t size = dataHandle_.size( entity ); 00132 stream.write( size ); 00133 dataHandle_.gather( stream, entity ); 00134 } 00135 00136 template< int codim > 00137 void xtractEntityData ( ObjectStream &stream, 00138 const typename Codim< codim > :: Entity &entity ) 00139 { 00140 size_t size = 0; 00141 stream.read( size ); 00142 dataHandle_.scatter( stream, entity, size ); 00143 } 00144 }; 00145 00146 } 00147 00148 #endif
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].