1 #ifndef DUNE_FEM_SPACE_SHAPEFUNCTIONSET_CACHING_HH
2 #define DUNE_FEM_SPACE_SHAPEFUNCTIONSET_CACHING_HH
25 template<
class ShapeFunctionSet >
48 shapeFunctionSet_( shapeFunctionSet ),
61 return shapeFunctionSet_.
order();
66 return shapeFunctionSet_.
size();
69 template<
class Po
int,
class Functor >
75 template<
class Quadrature,
class Functor >
78 const bool cacheable = std::is_convertible< Quadrature, CachingInterface >::value;
82 template<
class Po
int,
class Functor >
88 template<
class Quadrature,
class Functor >
91 const bool cacheable = std::is_convertible< Quadrature, CachingInterface >::value;
95 template<
class Po
int,
class Functor >
101 GeometryType
type ()
const {
return type_; }
103 template <
class QuadratureType >
106 return ReturnCache< QuadratureType, std::is_convertible< QuadratureType, CachingInterface >::value > ::
107 ranges( *
this, quadrature, valueCaches_, *localRangeCache_ );
110 template <
class QuadratureType >
113 return ReturnCache< QuadratureType, std::is_convertible< QuadratureType, CachingInterface >::value > ::
114 jacobians( *
this, quadrature, jacobianCaches_, *localJacobianCache_ );
118 template<
class Quad,
bool cacheable >
122 ranges(
const ThisType& shapeFunctionSet,
128 const unsigned int nop = quad.nop();
129 const unsigned int size = shapeFunctionSet.size();
132 storage.resize(
size * nop );
135 for(
unsigned int qp = 0 ; qp < nop; ++ qp )
137 const int cacheQp = quad.cachingPoint( qp );
139 shapeFunctionSet.evaluateEach( quad[ qp ], funztor );
145 jacobians(
const ThisType& shapeFunctionSet,
151 const unsigned int nop = quad.nop();
152 const unsigned int size = shapeFunctionSet.size();
155 storage.resize(
size * nop );
158 for(
unsigned int qp = 0 ; qp < nop; ++ qp )
160 const int cacheQp = quad.cachingPoint( qp );
161 AssignFunctor< JacobianRangeType* > funztor( data + ( cacheQp *
size ) );
162 shapeFunctionSet.jacobianEach( quad[ qp ], funztor );
168 template<
class Quad >
169 struct ReturnCache< Quad, true >
172 ranges(
const ThisType& shapeFunctionSet,
177 return cache[ quad.id() ];
181 jacobians(
const ThisType& shapeFunctionSet,
186 return cache[ quad.id() ];
191 template<
class Quadrature,
class Functor >
192 void evaluateEach (
const Quadrature &quadrature, std::size_t pt, Functor functor,
193 std::integral_constant< bool, false > )
const
198 template<
class Quadrature,
class Functor >
199 void evaluateEach (
const Quadrature &quadrature, std::size_t pt, Functor functor,
200 std::integral_constant< bool, true > )
const;
202 template<
class Quadrature,
class Functor >
203 void jacobianEach (
const Quadrature &quadrature, std::size_t pt, Functor functor,
204 std::integral_constant< bool, false > )
const
209 template<
class Quadrature,
class Functor >
210 void jacobianEach (
const Quadrature &quadrature, std::size_t pt, Functor functor,
211 std::integral_constant< bool, true > )
const;
214 void cacheQuadrature( std::size_t
id, std::size_t codim, std::size_t
size );
216 template<
class Po
intVector >
217 void cachePoints ( std::size_t
id,
const PointVector &points );
220 ShapeFunctionSet shapeFunctionSet_;
237 template<
class ShapeFunctionSet >
244 template<
class ShapeFunctionSet >
245 template<
class Quadrature,
class Functor >
248 std::integral_constant< bool, true > )
const
250 assert( (quadrature.
id() < valueCaches_.size()) && !valueCaches_[ quadrature.
id() ].empty() );
251 const RangeType *cache = valueCaches_[ quadrature.
id() ].data();
253 const unsigned int numShapeFunctions = size();
254 const unsigned int cpt = quadrature.cachingPoint( pt );
255 for(
unsigned int i = 0; i < numShapeFunctions; ++i )
256 functor( i, cache[ cpt*numShapeFunctions + i ] );
260 template<
class ShapeFunctionSet >
261 template<
class Quadrature,
class Functor >
263 ::jacobianEach (
const Quadrature &quadrature, std::size_t pt, Functor functor,
264 std::integral_constant< bool, true > )
const
266 assert( (quadrature.id() < jacobianCaches_.size()) && !jacobianCaches_[ quadrature.id() ].empty() );
267 const JacobianRangeType *cache = jacobianCaches_[ quadrature.id() ].data();
269 const unsigned int numShapeFunctions = size();
270 const unsigned int cpt = quadrature.cachingPoint( pt );
271 for(
unsigned int i = 0; i < numShapeFunctions; ++i )
272 functor( i, cache[ cpt*numShapeFunctions + i ] );
276 template<
class ShapeFunctionSet >
277 inline void CachingShapeFunctionSet< ShapeFunctionSet >
278 ::cacheQuadrature( std::size_t
id, std::size_t codim, std::size_t size )
280 if(
id >= valueCaches_.size() )
282 valueCaches_.resize(
id+1, RangeVectorType() );
283 jacobianCaches_.resize(
id+1, JacobianRangeVectorType() );
286 assert( valueCaches_[
id ].empty() == jacobianCaches_[
id ].empty() );
288 if( valueCaches_[
id ].empty() )
290 typedef typename FunctionSpaceType::DomainFieldType ctype;
291 const int dim = FunctionSpaceType::dimDomain;
295 cachePoints(
id, PointProvider< ctype, dim, 0 >::getPoints(
id, type_ ) );
299 cachePoints(
id, PointProvider< ctype, dim, 1 >::getPoints(
id, type_ ) );
303 DUNE_THROW( NotImplemented,
"Caching for codim > 1 not implemented." );
309 template<
class ShapeFunctionSet >
310 template<
class Po
intVector >
311 inline void CachingShapeFunctionSet< ShapeFunctionSet >
312 ::cachePoints ( std::size_t
id,
const PointVector &points )
314 const unsigned int numShapeFunctions = size();
315 const unsigned int numPoints = points.size();
317 RangeVectorType& values = valueCaches_[ id ];
318 values.resize( numShapeFunctions * numPoints );
320 JacobianRangeVectorType& jacobians = jacobianCaches_[ id ];
321 jacobians.resize( numShapeFunctions * numPoints );
323 if( values.empty() || jacobians.empty() )
324 DUNE_THROW( OutOfMemoryError,
"Unable to allocate shape function set caches." );
326 for(
unsigned int pt = 0; pt < numPoints; ++pt )
328 evaluateEach( points[ pt ], AssignFunctor< RangeType * >( values.data() + pt*numShapeFunctions ) );
329 jacobianEach( points[ pt ], AssignFunctor< JacobianRangeType * >( jacobians.data() + pt*numShapeFunctions ) );
Definition: bindguard.hh:11
Definition: explicitfieldvector.hh:75
Definition: misc/functor.hh:31
static void unregisterStorage(StorageInterface &storage)
Definition: registry.hh:85
static void registerStorage(StorageInterface &storage)
Definition: registry.hh:71
Definition: registry.hh:32
wrapper for a (Quadrature,int) pair
Definition: quadrature/quadrature.hh:41
unsigned int index() const
Definition: quadrature/quadrature.hh:70
const QuadratureType & quadrature() const
Definition: quadrature/quadrature.hh:63
size_t id() const
obtain the identifier of the integration point list
Definition: quadrature/quadrature.hh:302
actual interface class for quadratures
Definition: quadrature/quadrature.hh:366
A vector valued function space.
Definition: functionspace.hh:60
Definition: caching.hh:28
void evaluateEach(const QuadraturePointWrapper< Quadrature > &x, Functor functor) const
Definition: caching.hh:76
CachingShapeFunctionSet(const ThisType &)=delete
ShapeFunctionSet::HessianRangeType HessianRangeType
Definition: caching.hh:37
void jacobianEach(const Point &x, Functor functor) const
Definition: caching.hh:83
std::vector< JacobianRangeType > JacobianRangeVectorType
Definition: caching.hh:40
void jacobianEach(const QuadraturePointWrapper< Quadrature > &x, Functor functor) const
Definition: caching.hh:89
const JacobianRangeVectorType & jacobianCache(const QuadratureType &quadrature) const
Definition: caching.hh:111
std::vector< RangeType > RangeVectorType
Definition: caching.hh:39
std::vector< JacobianRangeVectorType > JacobianCacheVectorType
Definition: caching.hh:43
void hessianEach(const Point &x, Functor functor) const
Definition: caching.hh:96
ShapeFunctionSet::RangeType RangeType
Definition: caching.hh:35
CachingShapeFunctionSet(const GeometryType &type, const ShapeFunctionSet &shapeFunctionSet=ShapeFunctionSet())
Definition: caching.hh:45
ShapeFunctionSet::DomainType DomainType
Definition: caching.hh:34
const ThisType & operator=(const ThisType &)=delete
GeometryType type() const
Definition: caching.hh:101
ShapeFunctionSet::JacobianRangeType JacobianRangeType
Definition: caching.hh:36
ShapeFunctionSet::FunctionSpaceType FunctionSpaceType
Definition: caching.hh:32
~CachingShapeFunctionSet()
Definition: caching.hh:238
void evaluateEach(const Point &x, Functor functor) const
Definition: caching.hh:70
std::vector< RangeVectorType > ValueCacheVectorType
Definition: caching.hh:42
const RangeVectorType & rangeCache(const QuadratureType &quadrature) const
Definition: caching.hh:104
std::size_t size() const
Definition: caching.hh:64
int order() const
Definition: caching.hh:59
Interface class for shape function sets.
Definition: shapefunctionset/shapefunctionset.hh:33
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian range type
Definition: shapefunctionset/shapefunctionset.hh:43
FunctionSpaceType::RangeType RangeType
range type
Definition: shapefunctionset/shapefunctionset.hh:41
void hessianEach(const Point &x, Functor functor) const
evalute hessian of each shape function
void evaluateEach(const Point &x, Functor functor) const
evalute each shape function
std::size_t size() const
return number of shape functions
int order() const
return order of shape functions
FunctionSpaceType::DomainType DomainType
domain type
Definition: shapefunctionset/shapefunctionset.hh:39
void jacobianEach(const Point &x, Functor functor) const
evalute jacobian of each shape function