3#ifndef DUNE_PDELAB_LOCALOPERATOR_WEIGHTEDSUM_HH
4#define DUNE_PDELAB_LOCALOPERATOR_WEIGHTEDSUM_HH
6#include <dune/common/concept.hh>
25 template<
typename K,
typename... Args>
35 using Weights = FieldVector<K,
sizeof...(Args)>;
42 Concept::requireType<typename C::weight_type>(),
43 const_cast<C&
>(c).weight()
48 template<
typename... FArgs>
49 void getWeights(FieldVector<K,
sizeof...(FArgs)> & aweights,
50 std::tuple<FArgs...> fargs)
const
52 Hybrid::forEach(std::make_index_sequence<
sizeof...(FArgs)>{},
54 const auto & a = get<j>(fargs);
57 aweights[j] = id(a).weight();});
61 template<
typename... FArgs>
62 void setWeights(
const FieldVector<K,
sizeof...(FArgs)> & aweights,
63 std::tuple<FArgs...> fargs)
const
65 Hybrid::forEach(std::make_index_sequence<
sizeof...(FArgs)>{},
67 auto & a = get<j>(fargs);
70 id(a).setWeight(aweights[j]);});
74 template<
typename F,
typename... FArgs>
78 FieldVector<K,
sizeof...(FArgs)> aweights(K(0));
79 FieldVector<K,
sizeof...(FArgs)> current_weights;
80 getWeights(aweights, std::forward_as_tuple(fargs...));
81 Hybrid::forEach(std::make_index_sequence<
sizeof...(Args)>{},
85 current_weights = aweights;
87 setWeights(current_weights, std::forward_as_tuple(fargs...));
88 f(*Hybrid::elementAt(this->
lops, i), fargs...);}}
91 setWeights(aweights, std::forward_as_tuple(fargs...));
152 template<
typename K,
typename... Args>
166 [[deprecated(
"The specialization WeightedSumLocalOperator<K,Tuple<...>> is"
167 "deprecated and will be removed after PDELab 2.7.")]]
173 [[deprecated(
"The specialization WeightedSumLocalOperator<K,Tuple<...>> is"
174 "deprecated and will be removed after PDELab 2.7.")]]
176 :
Base(genericTransformTuple(lops_,
177 [](auto & l){
return stackobject_to_shared_ptr(l);}), weights_)
VTKWriter & w
Definition function.hh:842
auto require(C &c) -> decltype(Concept::requireType< typename C::weight_type >(), const_cast< C & >(c).weight())
WeightedSumLocalOperator(ArgPtrs &&lops, const Weights &weights_)
Definition weightedsum.hh:125
WeightedSumLocalOperator(Args &... lops_, const Weights &weights_=Weights(1))
Definition weightedsum.hh:112
FieldVector< K, sizeof...(Args)> Weights
Definition weightedsum.hh:35
WeightedSumLocalOperator(Args &&... lops_, const Weights &weights_=Weights(1))
Definition weightedsum.hh:119
WeightedSumLocalOperator(const Weights &weights_=Weights(1))
construct a WeightedSumLocalOperator
Definition weightedsum.hh:106
void setWeight(K w, std::size_t i)
set the weight for the i'th component of the sum
Definition weightedsum.hh:131
ArgPtrs lops
Definition combinedoperator.hh:35
std::tuple< Args &... > ArgRefs
Definition combinedoperator.hh:33
WeightedSumLocalOperator(const ArgRefs &lops_, const Weights &weights_=Weights(1))
construct a WeightedSumLocalOperator from a tuple of local operators
Definition weightedsum.hh:175
Weights weights
Definition weightedsum.hh:36
typename Base::ArgRefs ArgRefs
Definition weightedsum.hh:32
void setWeights(const FieldVector< K, sizeof...(FArgs)> &aweights, std::tuple< FArgs... > fargs) const
Definition weightedsum.hh:62
K getWeight(std::size_t i)
get the weight for the i'th component of the sum
Definition weightedsum.hh:135
void getWeights(FieldVector< K, sizeof...(FArgs)> &aweights, std::tuple< FArgs... > fargs) const
Definition weightedsum.hh:49
typename Base::ArgPtrs ArgPtrs
Definition weightedsum.hh:31
WeightedSumLocalOperator(const Weights &weights_=Weights(1))
construct a WeightedSumLocalOperator
Definition weightedsum.hh:168
void applyLops(F &&f, FArgs &... fargs) const
Definition weightedsum.hh:75
friend Base
Definition weightedsum.hh:33
std::tuple< std::shared_ptr< std::remove_reference_t< Args > >... > ArgPtrs
Definition combinedoperator.hh:32
For backward compatibility – Do not use this!
Definition adaptivity.hh:28
A local operator to take combine different local operators.
Definition combinedoperator.hh:30
A local operator to take the weighted sum of other local operators.
Definition weightedsum.hh:28
Definition weightedsum.hh:39