13#ifndef ITERATE_GRID_HH
14#define ITERATE_GRID_HH
16#include <boost/fusion/algorithm.hpp>
17#include <boost/fusion/sequence.hpp>
19#include "dune/grid/common/grid.hh"
20#include "dune/geometry/quadraturerules.hh"
30 namespace GridIterateDetail
32 template <
class VariableDescriptions,
class Functor,
class Functions,
class Spaces,
class CellRange>
33 void gridIterateRange(VariableDescriptions
const& , Functions
const& functions, Spaces
const& spaces,
34 Functor& f, CellRange cells)
41 typedef typename Grid::ctype CoordType;
42 int const dim = Grid::dimension;
44 auto const& gridView = at_c<0>(spaces)->gridView();
56 auto evaluators = getEvaluators(spaces,&sfCache);
59 for (
auto const& cell: cells)
64 auto idx = gridView.indexSet().index(cell);
68 int const p = f.integrationOrder(cell,
maxOrder(evaluators));
70 QuadRule
const& qr = quadratureCache.
rule(cell.type(),p);
73 size_t nQuadPos = qr.size();
74 for (
size_t g=0; g<nQuadPos; ++g)
77 auto const& quadPos = qr[g].position();
84 f(cell,idx,quadPos,cell.geometry().integrationElement(quadPos)*qr[g].weight(),
85 evaluateFunctions<VariableDescriptions>(functions,evaluators,
valueMethod));
120 template <
class VariableList,
class Collector,
class Functions,
class Spaces>
124 auto const& gridView = at_c<0>(spaces)->gridView();
125 auto const& cellRanges = at_c<0>(spaces)->gridManager().cellRanges(gridView);
128 std::vector<Collector> fs(n,f);
130 parallelFor([&vars,&functions,&spaces,&cellRanges,&fs](
int i,
int n)
147 template <
class VariableSet,
class Collector>
150 gridIterate(
typename VariableSet::Descriptions::Variables(),functions.
data,
166 template <
class Cell,
class F>
180 template <
class Cell>
183 return shapeFunctionOrder;
186 template <
class Cell,
class Index,
class LocalPosition,
class Sequence>
190 sum.resize(boost::fusion::size(x),0);
191 auto i =
sum.begin();
192 boost::fusion::for_each(x,Add(weight,i));
201 assert(
sum.size()==c.
sum.size());
202 for (
int i=0; i<
sum.size(); ++i)
212 Add(
double w_, std::vector<double>::iterator& i_): w(w_), i(i_) {}
214 void operator()(T
const& t)
const { *i += w*t; ++i; }
218 std::vector<double>::iterator& i;
231 template <
class Functions,
class Scaling,
class Collector>
244 , collector(collector_)
247 template <
class Cell>
253 template <
class Cell,
class Index,
class Sequence>
256 double weight, Sequence
const& seq)
259 typename result_of::as_vector<Sequence>::type values(seq);
260 scaling(cell,xi,values);
261 collector(cell,idx,xi,weight,transform(values,TwoNorm2()));
266 collector.
join(c.collector);
281 typename result<TwoNorm2(Vec)>::type
operator()(Vec
const& v)
const {
return v.two_norm2(); }
303 template <
class Variables,
class Functions,
class Spaces,
class Scaling,
class Collector>
309 sum = collector.
data();
318 namespace relativeErrorDetail {
323 typedef typename F::Scalar RT;
326 static int const Components = F::components;
328 typedef typename F::Space Space;
329 typedef typename F::ValueType ValueType;
331 Difference(F
const& f1_, F
const& f2_): f1(f1_), f2(f2_) { }
333 ValueType value(
typename Space::Evaluator
const& evaluator)
const
335 return f1.value(evaluator)-f2.value(evaluator);
338 Space
const& space()
const {
return f1.space(); }
346 struct MakeDifference
348 template <
class T>
struct result {};
350 template <
class Pair>
351 struct result<MakeDifference(Pair)>
353 typedef typename boost::fusion::result_of::value_at_c<Pair,0>::type T;
355 typedef Difference<typename boost::remove_const<typename boost::remove_reference<T>::type>::type> type;
358 template <
class Pair>
359 typename result<MakeDifference(Pair)>::type operator()(Pair
const& pair)
const
361 return typename result<MakeDifference(Pair)>::type(boost::fusion::at_c<0>(pair),boost::fusion::at_c<1>(pair));
381 template <
class Variables,
class OutIter,
class Functions,
class Spaces,
class Scaling>
382 void relativeError(Variables
const& varDesc, Functions
const& f1, Functions
const& f2, Functions
const& f3,
383 Spaces
const& spaces,
Scaling const& scaling, OutIter out)
387 int const s = size(f1);
393 join(as_vector(transform(zip(f1,f2),relativeErrorDetail::MakeDifference())),f3),
404 for (
int i=0; i<s; ++i) {
405 *out = std::make_pair(std::sqrt(sum.
sum[i]),std::sqrt(sum.
sum[i+s]));
Defines an interface for integrating values computed over a grid.
void join(Collector &c)
Merges the result of two concurrently filled collectors.
int integrationOrder(Cell const &, int shapeFunctionOrder) const
static NumaThreadPool & instance(int maxThreads=std::numeric_limits< int >::max())
Returns a globally unique thread pool instance.
A functor for computing scaled -norms of a set of (possibly vector-valued) functions.
void join(ScaledTwoNorm2Collector const &c)
int integrationOrder(Cell const &cell, int shapeFunctionOrder) const
ScaledTwoNorm2Collector(Scaling const &scaling_, Collector &collector_)
Constructor.
Collector const & data() const
void operator()(Cell const &cell, Index idx, Dune::FieldVector< typename Cell::Geometry::ctype, Cell::dimension > const &xi, double weight, Sequence const &seq)
A class for storing a heterogeneous collection of FunctionSpaceElement s.
Descriptions const & descriptions
Descriptions of variable set, of type VariableSetDescription (lots of useful infos)
A callable that allows to implement weighted (scaled) norms.
FEFunctionSpace and FunctionSpaceElement and the like.
void useQuadratureRuleInEvaluators(Evaluator &evals, QuadratureRule const &qr, int subId)
Tells all evaluators to use the given quadrature rule on the given subentity.
void moveEvaluatorsToIntegrationPoint(Evaluators &evals, Dune::FieldVector< CoordType, dim > const &x, Dune::QuadratureRule< CoordType, subDim > const &qr, int ip, int subId)
Moves all provided evaluators to the given integration point, evaluating the shape functions there.
int maxOrder(Evaluators const &evals)
Computes the maximum ansatz order used in a collection of evaluators.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Dune::FieldVector< T, n > min(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise minimum.
void parallelFor(Func const &f, int maxTasks=std::numeric_limits< int >::max())
A parallel for loop that executes the given functor in parallel on different CPUs.
constexpr auto valueMethod
Helper method for evaluating whole variable sets.
void gridIterateRange(VariableDescriptions const &, Functions const &functions, Spaces const &spaces, Functor &f, CellRange cells)
void gridIterate(VariableList const &vars, Functions const &functions, Spaces const &spaces, Collector &f)
A function that supports general iterations over a spatial domain and supports efficient evaluation o...
void scaledTwoNormSquared(Variables const &varDesc, Functions const &f, Spaces const &spaces, Scaling const &scaling, Collector &sum)
Evaluates the square of the scaled -norms of a set of functions.
void relativeError(Variables const &varDesc, Functions const &f1, Functions const &f2, Functions const &f3, Spaces const &spaces, Scaling const &scaling, OutIter out)
void moveEvaluatorsToCell(Evaluators &evals, Cell const &cell)
Moves all provided evaluators to the given cell.
void operator()(Cell const &, Dune::FieldVector< typename Cell::Geometry::ctype, Cell::dimension > const &, F &) const
A cache that stores suitable quadrature rules for quick retrieval.
static Rule const & rule(const Dune::GeometryType &t, int p)
Dune::FieldVector< double, 1 > type
Extracts the type of FE space with given index from set of spaces.
A Collector that sums up the weighted contributions.
void join(SummationCollector const &c)
int integrationOrder(Cell const &, int shapeFunctionOrder) const
void operator()(Cell const &, Index, LocalPosition const &, double weight, Sequence const &x)
std::vector< double > sum
Variables and their descriptions.