- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH 00002 #define DUNE_GEOGRID_CORNERSTORAGE_HH 00003 00004 #include <dune/grid/genericgeometry/geometry.hh> 00005 00006 #include <dune/grid/geometrygrid/hostcorners.hh> 00007 #include <dune/grid/geometrygrid/coordfunction.hh> 00008 00009 namespace Dune 00010 { 00011 00012 namespace GeoGrid 00013 { 00014 00015 // CoordFunctionCaller 00016 // ------------------- 00017 00018 template< class HostEntity, class CoordFunctionInterface > 00019 class CoordFunctionCaller; 00020 00021 template< class HostEntity, class ct, unsigned int dimD, unsigned int dimR, class Impl > 00022 class CoordFunctionCaller< HostEntity, AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl > > 00023 { 00024 typedef AnalyticalCoordFunctionInterface< ct, dimD, dimR, Impl > CoordFunctionInterface; 00025 typedef CoordFunctionCaller< HostEntity, CoordFunctionInterface > This; 00026 00027 static const int codimension = HostEntity::codimension; 00028 00029 public: 00030 typedef typename CoordFunctionInterface::RangeVector RangeVector; 00031 00032 CoordFunctionCaller ( const HostEntity &hostEntity, 00033 const CoordFunctionInterface &coordFunction ) 00034 : hostCorners_( hostEntity ), 00035 coordFunction_( coordFunction ) 00036 {} 00037 00038 void evaluate ( unsigned int i, RangeVector &y ) const 00039 { 00040 coordFunction_.evaluate( hostCorners_.corner( i ), y ); 00041 } 00042 00043 GeometryType type () const 00044 { 00045 return hostCorners_.type(); 00046 } 00047 00048 unsigned int numCorners () const 00049 { 00050 return hostCorners_.numCorners(); 00051 } 00052 00053 private: 00054 const HostCorners< HostEntity > hostCorners_; 00055 const CoordFunctionInterface &coordFunction_; 00056 }; 00057 00058 template< class HostEntity, class ct, unsigned int dimR, class Impl > 00059 class CoordFunctionCaller< HostEntity, DiscreteCoordFunctionInterface< ct, dimR, Impl > > 00060 { 00061 typedef DiscreteCoordFunctionInterface< ct, dimR, Impl > CoordFunctionInterface; 00062 typedef CoordFunctionCaller< HostEntity, CoordFunctionInterface > This; 00063 00064 typedef typename CoordFunctionInterface::RangeVector RangeVector; 00065 00066 public: 00067 CoordFunctionCaller ( const HostEntity &hostEntity, 00068 const CoordFunctionInterface &coordFunction ) 00069 : hostEntity_( hostEntity ), 00070 coordFunction_( coordFunction ) 00071 {} 00072 00073 void evaluate ( unsigned int i, RangeVector &y ) const 00074 { 00075 coordFunction_.evaluate( hostEntity_, i, y ); 00076 } 00077 00078 GeometryType type () const 00079 { 00080 return hostEntity_.type(); 00081 } 00082 00083 unsigned int numCorners () const 00084 { 00085 return hostEntity_.geometry().corners(); 00086 } 00087 00088 private: 00089 const HostEntity &hostEntity_; 00090 const CoordFunctionInterface &coordFunction_; 00091 }; 00092 00093 00094 00095 // CoordVector 00096 // ----------- 00097 00098 template< int mydim, class Grid, bool fake > 00099 class CoordVector; 00100 00101 00102 template< int mydim, class Grid > 00103 class CoordVector< mydim, Grid, false > 00104 { 00105 typedef typename remove_const< Grid >::type::Traits Traits; 00106 00107 typedef typename Traits::ctype ctype; 00108 00109 static const int dimension = Traits::dimension; 00110 static const int mydimension = mydim; 00111 static const int codimension = dimension - mydimension; 00112 static const int dimensionworld = Traits::dimensionworld; 00113 00114 typedef FieldVector< ctype, dimensionworld > Coordinate; 00115 00116 typedef typename Traits::HostGrid HostGrid; 00117 typedef typename Traits::CoordFunction CoordFunction; 00118 00119 typedef typename HostGrid::template Codim< codimension >::Entity HostEntity; 00120 00121 typedef GeoGrid :: CoordFunctionCaller< HostEntity, typename CoordFunction::Interface > 00122 CoordFunctionCaller; 00123 00124 public: 00125 CoordVector ( const HostEntity &hostEntity, 00126 const CoordFunction &coordFunction ) 00127 : coordFunctionCaller_( hostEntity, coordFunction ) 00128 {} 00129 00130 template< unsigned int numCorners > 00131 void calculate ( Coordinate (&corners)[ numCorners ] ) const 00132 { 00133 assert( numCorners == coordFunctionCaller_.numCorners() ); 00134 for( unsigned int i = 0; i < numCorners; ++i ) 00135 coordFunctionCaller_.evaluate( i, corners[ i ] ); 00136 } 00137 00138 private: 00139 const CoordFunctionCaller coordFunctionCaller_; 00140 }; 00141 00142 00143 template< int mydim, class Grid > 00144 class CoordVector< mydim, Grid, true > 00145 { 00146 typedef typename remove_const< Grid > :: type :: Traits Traits; 00147 00148 typedef typename Traits::ctype ctype; 00149 00150 static const int dimension = Traits::dimension; 00151 static const int mydimension = mydim; 00152 static const int codimension = dimension - mydimension; 00153 static const int dimensionworld = Traits::dimensionworld; 00154 00155 typedef FieldVector< ctype, dimensionworld > Coordinate; 00156 00157 typedef typename Traits::HostGrid HostGrid; 00158 typedef typename Traits::CoordFunction CoordFunction; 00159 00160 typedef typename HostGrid::template Codim< 0 >::Entity HostElement; 00161 00162 typedef GeoGrid::CoordFunctionCaller< HostElement, typename CoordFunction::Interface > 00163 CoordFunctionCaller; 00164 00165 public: 00166 CoordVector ( const HostElement &hostElement, 00167 const unsigned int subEntity, 00168 const CoordFunction &coordFunction ) 00169 : coordFunctionCaller_( hostElement, coordFunction ), 00170 subEntity_( subEntity ) 00171 {} 00172 00173 template< unsigned int numCorners > 00174 void calculate ( Coordinate (&corners)[ numCorners ] ) const 00175 { 00176 const GeometryType type = coordFunctionCaller_.type(); 00177 const GenericReferenceElement< ctype, dimension > &refElement 00178 = GenericReferenceElements< ctype, dimension >::general( type ); 00179 assert( numCorners == refElement.size( subEntity_, codimension, dimension ) ); 00180 00181 for( unsigned int i = 0; i < numCorners; ++i ) 00182 { 00183 const unsigned int j = refElement.subEntity( subEntity_, codimension, i, dimension ); 00184 coordFunctionCaller_.evaluate( j, corners[ i ] ); 00185 } 00186 } 00187 00188 private: 00189 const CoordFunctionCaller coordFunctionCaller_; 00190 const unsigned int subEntity_; 00191 }; 00192 00193 00194 00195 // IntersectionCoordVector 00196 // ----------------------- 00197 00198 template< class Grid > 00199 class IntersectionCoordVector 00200 { 00201 typedef typename remove_const< Grid >::type::Traits Traits; 00202 00203 typedef typename Traits::ctype ctype; 00204 00205 static const int dimension = Traits::dimension; 00206 static const int codimension = 1; 00207 static const int mydimension = dimension-codimension; 00208 static const int dimensionworld = Traits::dimensionworld; 00209 00210 typedef FieldVector< ctype, dimensionworld > Coordinate; 00211 00212 typedef typename Traits::HostGrid HostGrid; 00213 00214 typedef typename Traits::template Codim< 0 >::Geometry ElementGeometry; 00215 typedef typename Traits::template Codim< codimension >::LocalGeometry HostLocalGeometry; 00216 00217 public: 00218 IntersectionCoordVector ( const ElementGeometry &elementGeometry, 00219 const HostLocalGeometry &hostLocalGeometry ) 00220 : elementGeometry_( elementGeometry ), 00221 hostLocalGeometry_( hostLocalGeometry ) 00222 {} 00223 00224 template< unsigned int numCorners > 00225 void calculate ( Coordinate (&corners)[ numCorners ] ) const 00226 { 00227 assert( numCorners == hostLocalGeometry_.corners() ); 00228 for( unsigned int i = 0; i < numCorners; ++i ) 00229 corners[ i ] = elementGeometry_.global( hostLocalGeometry_.corner( i ) ); 00230 } 00231 00232 private: 00233 const ElementGeometry &elementGeometry_; 00234 const HostLocalGeometry &hostLocalGeometry_; 00235 }; 00236 00237 00238 00239 00240 // CornerStorage 00241 // ------------- 00242 00243 template< class Topology, class Grid > 00244 class CornerStorage 00245 { 00246 typedef typename remove_const< Grid >::type::Traits Traits; 00247 00248 typedef typename Traits::ctype ctype; 00249 00250 static const int dimension = Traits::dimension; 00251 static const int mydimension = Topology::dimension; 00252 static const int codimension = dimension - mydimension; 00253 static const int dimensionworld = Traits::dimensionworld; 00254 00255 typedef FieldVector< ctype, dimensionworld > Coordinate; 00256 00257 public: 00258 static const unsigned int size = Topology::numCorners; 00259 00260 template< class SubTopology > 00261 struct SubStorage 00262 { 00263 typedef CornerStorage< SubTopology, Grid > type; 00264 }; 00265 00266 template< bool fake > 00267 explicit 00268 CornerStorage ( const CoordVector< mydimension, Grid, fake > &coords ) 00269 { 00270 coords.calculate( coords_ ); 00271 } 00272 00273 explicit CornerStorage ( const IntersectionCoordVector< Grid > &coords ) 00274 { 00275 coords.calculate( coords_ ); 00276 } 00277 00278 template< class Mapping, unsigned int codim > 00279 explicit 00280 CornerStorage ( const GenericGeometry::SubMappingCoords< Mapping, codim > &coords ) 00281 { 00282 for( unsigned int i = 0; i < size; ++i ) 00283 coords_[ i ] = coords[ i ]; 00284 } 00285 00286 const Coordinate &operator[] ( unsigned int i ) const 00287 { 00288 return coords_[ i ]; 00289 } 00290 00291 private: 00292 Coordinate coords_[ size ]; 00293 }; 00294 00295 } 00296 00297 } 00298 00299 #endif // #ifndef DUNE_GEOGRID_CORNERSTORAGE_HH
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].