3#ifndef DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
4#define DUNE_GEOGRID_CACHEDCOORDFUNCTION_HH
11#include <dune/grid/common/gridenums.hh>
13#include <dune/grid/geometrygrid/capabilities.hh>
14#include <dune/grid/geometrygrid/coordfunctioncaller.hh>
15#include <dune/grid/utility/persistentcontainer.hh>
23 template<
class HostGr
id,
class CoordFunction >
24 class CachedCoordFunction;
34 template<
class HostGr
id,
class Coordinate >
37 typedef CoordCache< HostGrid, Coordinate > This;
39 static const unsigned int dimension = HostGrid::dimension;
41 typedef typename HostGrid::template Codim< dimension >::Entity Vertex;
46 explicit CoordCache (
const HostGrid &hostGrid )
47 : data_( hostGrid, dimension )
50 template<
class Entity >
51 const Coordinate &operator() (
const Entity &entity,
unsigned int corner )
const
53 return data_( entity, corner );
56 const Coordinate &operator() (
const Vertex &
vertex,
unsigned int corner )
const
58 assert( corner == 0 );
62 template<
class Entity >
63 Coordinate &operator() (
const Entity &entity,
unsigned int corner )
65 return data_( entity,corner) ;
68 Coordinate &operator() (
const Vertex &
vertex,
unsigned int corner )
70 assert( corner == 0 );
81 CoordCache (
const This & );
82 This &operator= (
const This & );
94 template<
class HostGr
id,
class CoordFunction >
95 class CachedCoordFunction
96 :
public DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, CachedCoordFunction< HostGrid, CoordFunction > >
98 typedef CachedCoordFunction< HostGrid, CoordFunction > This;
99 typedef DiscreteCoordFunction< typename CoordFunction::ctype, CoordFunction::dimRange, This > Base;
104 typedef typename Base::RangeVector RangeVector;
107 typedef GeoGrid::CoordCache< HostGrid, RangeVector > Cache;
111 CachedCoordFunction (
const HostGrid &hostGrid,
112 const CoordFunction &coordFunction = CoordFunction() )
113 : hostGrid_( hostGrid ),
114 coordFunction_( coordFunction ),
128 template<
class HostEntity >
129 void insertEntity (
const HostEntity &hostEntity );
131 template<
class HostEntity >
132 void evaluate (
const HostEntity &hostEntity,
unsigned int corner, RangeVector &y )
const
134 y = cache_( hostEntity, corner );
136 typedef GeoGrid::CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
140 CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
141 coordFunctionCaller.evaluate( corner, z );
142 assert( ((y - z).two_norm() < 1e-6) );
147 const HostGrid &hostGrid_;
148 const CoordFunction &coordFunction_;
157 template<
class HostGr
id,
class CoordFunction >
158 inline void CachedCoordFunction< HostGrid, CoordFunction >::buildCache ()
160 typedef typename HostGrid::template Codim< 0 >::Entity Element;
161 typedef typename HostGrid::LevelGridView MacroView;
162 typedef typename HostGrid::HierarchicIterator HierarchicIterator;
164 typedef typename MacroView::template Codim< 0 >::template Partition< All_Partition >::Iterator MacroIterator;
166 const MacroView macroView = hostGrid_.levelGridView( 0 );
167 const int maxLevel = hostGrid_.maxLevel();
169 const MacroIterator mend = macroView.template end< 0, All_Partition >();
170 for( MacroIterator mit = macroView.template begin< 0, All_Partition >(); mit != mend; ++mit )
172 const Element ¯oElement = *mit;
173 insertEntity( macroElement );
175 const HierarchicIterator hend = macroElement.hend( maxLevel );
176 for( HierarchicIterator hit = macroElement.hbegin( maxLevel ); hit != hend; ++hit )
177 insertEntity( *hit );
182 template<
class HostGr
id,
class CoordFunction >
183 template<
class HostEntity >
184 inline void CachedCoordFunction< HostGrid, CoordFunction >
185 ::insertEntity (
const HostEntity &hostEntity )
187 typedef GeoGrid::CoordFunctionCaller< HostEntity, typename CoordFunction::Interface >
190 CoordFunctionCaller coordFunctionCaller( hostEntity, coordFunction_ );
191 auto refElement = referenceElement< ctype, HostEntity::dimension >( hostEntity.type() );
193 const unsigned int numCorners = refElement.size( HostEntity::dimension );
194 for(
unsigned int i = 0; i < numCorners; ++i )
195 coordFunctionCaller.evaluate( i, cache_( hostEntity, i ) );
ct ctype
field type of the coordinate vector
Definition: coordfunction.hh:183
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:797
Dune namespace.
Definition: alignedallocator.hh:14
Traits for type conversions and type information.