5#ifndef DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
6#define DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
13#include <dune/grid/common/gridenums.hh>
15#include <dune/grid/geometrygrid/capabilities.hh>
16#include <dune/grid/geometrygrid/coordfunctioncaller.hh>
17#include <dune/grid/utility/persistentcontainer.hh>
25 template<
class HostGr
id,
class CoordFunction >
26 class CachedCoordFunction;
36 template<
class HostGr
id,
class Coordinate >
39 typedef CoordCache< HostGrid, Coordinate > This;
41 static const unsigned int dimension = HostGrid::dimension;
43 typedef typename HostGrid::template Codim< dimension >::Entity Vertex;
48 explicit CoordCache (
const HostGrid &hostGrid )
49 : data_( hostGrid, dimension )
52 template<
class Entity >
53 const Coordinate &operator() (
const Entity &entity,
unsigned int corner )
const
55 return data_( entity, corner );
58 const Coordinate &operator() (
const Vertex &
vertex,
unsigned int corner )
const
60 assert( corner == 0 );
64 template<
class Entity >
65 Coordinate &operator() (
const Entity &entity,
unsigned int corner )
67 return data_( entity,corner) ;
70 Coordinate &operator() (
const Vertex &
vertex,
unsigned int corner )
72 assert( corner == 0 );
83 CoordCache (
const This & );
84 This &operator= (
const This & );
96 template<
class HostGr
id,
class CoordFunction >
97 class CachedCoordFunction
98 :
public DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, CachedCoordFunction< HostGrid, CoordFunction > >
100 typedef CachedCoordFunction< HostGrid, CoordFunction > This;
101 typedef DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, This > Base;
106 typedef typename Base::RangeVector RangeVector;
109 typedef GeoGrid::CoordCache< HostGrid, RangeVector > Cache;
113 CachedCoordFunction (
const HostGrid &hostGrid,
114 const CoordFunction &coordFunction = CoordFunction() )
115 : hostGrid_( hostGrid ),
116 coordFunction_( coordFunction ),
130 template<
class HostEntity >
131 void insertEntity (
const HostEntity &hostEntity );
133 template<
class HostEntity >
134 void evaluate (
const HostEntity &hostEntity,
unsigned int corner, RangeVector &y )
const
136 y = cache_( hostEntity, corner );
138 typedef GeoGrid::CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
142 CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
143 coordFunctionCaller.evaluate( corner, z );
144 assert( ((y - z).two_norm() < 1e-6) );
149 const HostGrid &hostGrid_;
150 const CoordFunction &coordFunction_;
159 template<
class HostGr
id,
class CoordFunction >
160 inline void CachedCoordFunction< HostGrid, CoordFunction >::buildCache ()
162 typedef typename HostGrid::template Codim< 0 >::Entity Element;
163 typedef typename HostGrid::LevelGridView MacroView;
164 typedef typename HostGrid::HierarchicIterator HierarchicIterator;
166 typedef typename MacroView::template Codim< 0 >::template Partition< All_Partition >::Iterator MacroIterator;
168 const MacroView macroView = hostGrid_.levelGridView( 0 );
169 const int maxLevel = hostGrid_.maxLevel();
171 const MacroIterator mend = macroView.template end< 0, All_Partition >();
172 for( MacroIterator mit = macroView.template begin< 0, All_Partition >(); mit != mend; ++mit )
174 const Element ¯oElement = *mit;
175 insertEntity( macroElement );
177 const HierarchicIterator hend = macroElement.hend( maxLevel );
178 for( HierarchicIterator hit = macroElement.hbegin( maxLevel ); hit != hend; ++hit )
179 insertEntity( *hit );
184 template<
class HostGr
id,
class CoordFunction >
185 template<
class HostEntity >
186 inline void CachedCoordFunction< HostGrid, CoordFunction >
187 ::insertEntity (
const HostEntity &hostEntity )
189 typedef GeoGrid::CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
192 CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
193 auto refElement = referenceElement< ctype, HostEntity::dimension >( hostEntity.type() );
195 const unsigned int numCorners = refElement.size( HostEntity::dimension );
196 for(
unsigned int i = 0; i < numCorners; ++i )
197 coordFunctionCaller.evaluate( i, cache_( hostEntity, i ) );
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:185
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
Dune namespace.
Definition: alignedallocator.hh:13
Traits for type conversions and type information.