5#include <dune/common/rangeutilities.hh>
6#include <dune/functions/common/multiindex.hh>
8#include <amdis/algorithm/ForEach.hpp>
9#include <amdis/algorithm/InnerProduct.hpp>
10#include <amdis/algorithm/Transform.hpp>
11#include <amdis/common/FakeContainer.hpp>
12#include <amdis/utility/MappedRangeView.hpp>
17 template <
class Derived>
21 Derived
const& asDerived()
const
23 return static_cast<Derived const&
>(*this);
28 return static_cast<Derived&
>(*this);
38 void synchronize() { }
41 template <
class MultiIndex,
class ValueType,
class Assign>
44 assign(value, asDerived().at(idx));
48 template <
class IndexRange,
class OutputIterator>
49 void gather(IndexRange
const& localInd, OutputIterator buffer)
const
51 for (
auto const& idx : localInd)
52 *buffer++ = asDerived().at(idx);
57 template <
class IndexRange,
class LocalVec,
class Assign>
60 auto vec_it = std::begin(vec);
61 for (
auto const& idx : localInd)
62 assign(*vec_it++, asDerived().at(idx));
67 template <
class IndexRange,
class LocalVec,
class MaskRange,
class Assign>
68 void scatter(IndexRange
const& localInd, LocalVec
const& vec, MaskRange
const& mask, Assign assign)
70 auto vec_it = std::begin(vec);
71 auto mask_it = std::begin(mask);
72 auto ind_it = std::begin(localInd);
73 for (; vec_it != std::end(vec); ++vec_it, ++mask_it, ++ind_it) {
75 assign(*vec_it, asDerived().at(*ind_it));
81 template <
class IndexRange,
class Func>
82 void forEach(IndexRange
const& localInd, Func&& f)
const
84 for (
auto const& idx : localInd)
85 f(idx, asDerived().at(idx));
89 template <
class IndexRange,
class Func>
90 void forEach(IndexRange
const& localInd, Func&& f)
92 for (
auto const& idx : localInd)
93 f(idx, asDerived().at(idx));
103 template <
class UnaryFunction>
104 static void impl (D& vec, UnaryFunction f)
106 for (std::size_t i = 0; i < std::size_t(vec.size()); ++i) {
107 auto idx = Dune::Functions::StaticMultiIndex<std::size_t,1>{i};
108 Recursive::forEach(vec.at(idx), f);
116 template <
class Operation,
class... Ds>
117 static void impl (D& vecOut, Operation op,
VectorBase<Ds> const&... vecIn)
119 for (std::size_t i = 0; i < std::size_t(vecOut.size()); ++i) {
120 auto idx = Dune::Functions::StaticMultiIndex<std::size_t,1>{i};
121 Recursive::transform(vecOut.at(idx), op,
static_cast<Ds const&
>(vecIn).at(idx)...);
129 template <
class D2,
class T,
class BinOp1,
class BinOp2>
130 static T impl (D
const& in1,
VectorBase<D2> const& in2, T init, BinOp1 op1, BinOp2 op2)
132 for (std::size_t i = 0; i < std::size_t(in1.size()); ++i) {
133 auto idx = Dune::Functions::StaticMultiIndex<std::size_t,1>{i};
134 init = Recursive::innerProduct(in1.at(idx),
static_cast<D2 const&
>(in2).at(idx), std::move(init), op1, op2);
A container-like data-structure not storing anything and with empty implementations in many container...
Definition: FakeContainer.hpp:36
CRTP base class for flat vector backends.
Definition: VectorBase.hpp:19
void forEach(IndexRange const &localInd, Func &&f)
Apply the functor f to all entries of the list of multi-indices localInd.
Definition: VectorBase.hpp:90
void scatter(IndexRange const &localInd, LocalVec const &vec, FakeContainer< bool, true >, Assign assign)
Scatter the values from the local vec into the container using the passed assign functor.
Definition: VectorBase.hpp:58
void insert(MultiIndex const &idx, ValueType const &value, Assign assign)
Insert or add value at position idx, using the passed assign functor.
Definition: VectorBase.hpp:42
void scatter(IndexRange const &localInd, LocalVec const &vec, MaskRange const &mask, Assign assign)
Definition: VectorBase.hpp:68
void gather(IndexRange const &localInd, OutputIterator buffer) const
Gather values from the vector into the output range buffer decribed as an output iterator.
Definition: VectorBase.hpp:49
void forEach(IndexRange const &localInd, Func &&f) const
Apply the functor f to all entries of the list of multi-indices localInd.
Definition: VectorBase.hpp:82
constexpr bool MultiIndex
A multi-index type.
Definition: Concepts.hpp:149
Definition: ForEach.hpp:39
General implementation of recursive inner-product.
Definition: InnerProduct.hpp:58