13#ifndef SHAPEFUNCTIONCACHE_HH
14#define SHAPEFUNCTIONCACHE_HH
18#include "boost/multi_array.hpp"
19#include "boost/signals2.hpp"
20#include "boost/thread.hpp"
22#include <boost/fusion/algorithm.hpp>
23#include <boost/fusion/sequence.hpp>
24#include <boost/mpl/int.hpp>
25#include <boost/mpl/range_c.hpp>
27#include "dune/geometry/quadraturerules.hh"
28#include "dune/istl/bvector.hh"
51 template <
typename Scalar,
int dim,
int components=1>
114 template <
class G,
class T,
int ComponentsEnd=4>
119 typedef typename boost::mpl::range_c<int,1,ComponentsEnd>::type ComponentRange;
129 auto operator()(Int i)
131 static int const nComp = Int::value;
134 typedef boost::multi_array<EntryType,2>
DataType;
136 typedef std::tuple<Sfs const*,void const*> KeyType;
137 return std::map<KeyType,DataType>();
141 typedef typename boost::fusion::result_of::as_vector<
142 typename boost::fusion::result_of::transform<ComponentRange,MakeMapType>::type
156 typedef typename std::result_of<MakeMapType(boost::mpl::int_<nComp>)>::type::mapped_type
type;
179 template <
int nComp,
int subDim>
183 assert(0<=isf && isf<sfs.
size());
184 assert(0<=ip && ip<qr.size());
185 return get(sfs,qr,subId)[ip][isf].value;
195 template <
int nComp,
int subDim>
200 assert(0<=isf && isf<sfs.
size());
201 assert(0<=ip && ip<qr.size());
202 return get(sfs,qr,subId)[ip][isf].derivative;
218 template <
int nComp,
int subDim>
224 typedef typename DType::index_range range;
225 typename DType::index_gen indices;
226 assert(sfs.
size()>=0);
227 return get(sfs,qr,subId)[indices[ip][range(0,sfs.
size())]];
244 template <
int nComp,
int subDim>
248 return get(sfs,qr,subId);
263 static int const maxSubId = 11;
266 MapsType caches[maxSubId+1];
268 template <
int nComp,
int subDim>
272 assert(0<=subId && subId<=maxSubId);
273 using MapType =
typename std::result_of<MakeMapType(boost::mpl::int_<nComp>)>::type;
274 typedef typename MapType::key_type KeyType;
276 MapType& cache = boost::fusion::at_c<nComp-1>(caches[subId]);
278 typename MapType::const_iterator i = cache.find(KeyType(&sfs,&qr));
286 assert(sfs.
size()>=0);
287 DType data(boost::extents[qr.size()][sfs.
size()]);
289 if (G::dimension != subDim)
290 for (
int isf=0; isf<sfs.
size(); ++isf)
291 for (
int ip=0; ip<qr.size(); ++ip)
295 pos = refElem.template geometry<G::dimension-subDim>(subId).global(qr[ip].position());
297 data[ip][isf].value = sfs[isf].evaluateFunction(pos);
298 data[ip][isf].derivative = sfs[isf].evaluateDerivative(pos);
299 data[ip][isf].hessian = sfs[isf].evaluate2ndDerivative(pos);
302 for (
int isf=0; isf<sfs.
size(); ++isf)
303 for (
int ip=0; ip<qr.size(); ++ip)
305 pos = refElem.template geometry<G::dimension-subDim>(subId).global(qr[ip].position());
306 data[ip][isf].value = sfs[isf].evaluateFunction(pos);
307 data[ip][isf].derivative = sfs[isf].evaluateDerivative(pos);
308 data[ip][isf].hessian = sfs[isf].evaluate2ndDerivative(pos);
312 i = cache.insert(cache.begin(),
typename MapType::value_type(KeyType(&sfs,&qr),data));
This class caches values and derivatives of shape functions at quadrature points.
int maximumSubentityIndex() const
Reports the maximum subentity number that is allowed.
DataType< nComp >::type const & evaluate(ShapeFunctionSet< typename G::ctype, G::dimension, T, nComp > const &sfs, Dune::QuadratureRule< typename G::ctype, subDim > const &qr, int subId)
Returns the values of all shape functions.
Dune::FieldVector< T, nComp > evaluateFunction(ShapeFunctionSet< typename G::ctype, G::dimension, T, nComp > const &sfs, int isf, Dune::QuadratureRule< typename G::ctype, subDim > const &qr, int ip, int subId)
Evaluate comp-th component of isf-th shape function of the shape function set sfs ath the ip-th integ...
Dune::FieldMatrix< T, nComp, G::dimension > const & evaluateDerivative(ShapeFunctionSet< typename G::ctype, G::dimension, T, nComp > const &sfs, int isf, Dune::QuadratureRule< typename G::ctype, subDim > const &qr, int ip, int subId)
Evaluate derivative of comp-th component of isf-th shape function of the shape function set sfs ath t...
LocalDataType< nComp >::type evaluate(ShapeFunctionSet< typename G::ctype, G::dimension, T, nComp > const &sfs, Dune::QuadratureRule< typename G::ctype, subDim > const &qr, int ip, int subId)
Returns the values of all shape functions at given integration point.
A set of shape functions.
auto referenceElement() const
virtual int size() const
Number of shape functions in the set.
Tools for transfer of data between grids.
boost::mutex refElementMutex
A global lock for the Dune::GenericReferenceElement singletons, which are not thread-safe.
Defines the type returned by evaluate(sfs,qr,subId).
std::result_of< MakeMapType(boost::mpl::int_< nComp >)>::type::mapped_type type
Defines the type returned by evaluate(sfs,qr,ip,subId).
DataType< nComp >::type::template const_array_view< 1 >::type type
A class that stores values, gradients, and Hessians of evaluated shape functions.
VariationalArg(ValueType const &value_, Dune::FieldMatrix< Scalar, components, dim > const &derivative_, Tensor< Scalar, components, dim, dim > const &hessian_)
Dune::FieldMatrix< Scalar, components, dim > derivative
The shape function's spatial derivative, a components x dim matrix.
ValueType value
The shape function's value, a vector of dimension components
VariationalArg(ValueType const &value_, Dune::FieldMatrix< Scalar, components, dim > const &derivative_)
VariationalArg(ValueType const &value_)
Constructor.
Tensor< Scalar, components, dim, dim > hessian