1 #ifndef DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
2 #define DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
7 #include <dune/common/typetraits.hh>
21 template<
class HostGr
id,
class CoordFunction,
class Allocator >
32 template<
class HostGr
id,
class Coordinate,
class Allocator = std::allocator< Coordinate > >
37 static const unsigned int dimension = HostGrid::dimension;
39 typedef typename HostGrid::template Codim< dimension >::Entity Vertex;
44 explicit CoordCache (
const HostGrid &hostGrid,
const Allocator &allocator = Allocator() )
45 : data_( hostGrid, dimension, allocator )
48 template<
class Entity >
51 return data_( entity, corner );
56 assert( corner == 0 );
60 template<
class Entity >
63 return data_( entity,corner) ;
68 assert( corner == 0 );
79 This &operator= (
const This & );
81 mutable DataCache data_;
91 template<
class HostGr
id,
class CoordFunction,
class Allocator = std::allocator<
void > >
92 class CachedCoordFunction
93 :
public DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, CachedCoordFunction< HostGrid, CoordFunction > >
95 typedef CachedCoordFunction< HostGrid, CoordFunction > This;
96 typedef DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, This > Base;
109 const CoordFunction &coordFunction = CoordFunction(),
110 const Allocator &allocator = Allocator() )
111 : hostGrid_( hostGrid ),
112 coordFunction_( coordFunction ),
113 cache_( hostGrid, allocator )
126 template<
class HostEntity >
129 template<
class HostEntity >
132 y = cache_( hostEntity, corner );
138 CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
139 coordFunctionCaller.evaluate( corner, z );
140 assert( ((y - z).two_norm() < 1e-6) );
145 const HostGrid &hostGrid_;
146 const CoordFunction &coordFunction_;
155 template<
class HostGr
id,
class CoordFunction,
class Allocator >
158 typedef typename HostGrid::template Codim< 0 >::Entity
Element;
159 typedef typename HostGrid::LevelGridView MacroView;
162 typedef typename MacroView::template Codim< 0 >::template Partition< All_Partition >::Iterator MacroIterator;
164 const MacroView macroView = hostGrid_.levelView( 0 );
165 const int maxLevel = hostGrid_.maxLevel();
167 const MacroIterator mend = macroView.template end< 0, All_Partition >();
168 for( MacroIterator mit = macroView.template begin< 0, All_Partition >(); mit != mend; ++mit )
170 const Element ¯oElement = *mit;
171 insertEntity( macroElement );
173 const HierarchicIterator hend = macroElement.hend( maxLevel );
174 for( HierarchicIterator hit = macroElement.hbegin( maxLevel ); hit != hend; ++hit )
175 insertEntity( *hit );
180 template<
class HostGr
id,
class CoordFunction,
class Allocator >
181 template<
class HostEntity >
188 CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
189 const GenericReferenceElement< ctype, HostEntity::dimension > &refElement
190 = GenericReferenceElements< ctype, HostEntity::dimension >::general( hostEntity.type() );
192 const unsigned int numCorners = refElement.size( HostEntity::dimension );
193 for(
unsigned int i = 0; i < numCorners; ++i )
194 coordFunctionCaller.evaluate( i, cache_( hostEntity, i ) );
199 #endif // #ifndef DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH