1#ifndef __DUNE_ACFEM_OPERATORS_FUNCTIONALS_MODULES_DOFSTORAGE_HH__
2#define __DUNE_ACFEM_OPERATORS_FUNCTIONALS_MODULES_DOFSTORAGE_HH__
4#include "../../../expressions/terminal.hh"
5#include "../../../common/literals.hh"
7#include "../linearfunctional.hh"
8#include "../functionaltraits.hh"
9#include "../operations/inner.hh"
15 namespace LinearFunctional {
17 using namespace Literals;
20 template<
class DiscreteFunction>
22 :
public DiscreteFunction
23 ,
public LinearFunctional<typename DiscreteFunction::DiscreteFunctionSpaceType>
28 using BaseType = DiscreteFunction;
31 using typename FunctionalBase::DiscreteFunctionSpaceType;
32 using typename FunctionalBase::RangeFieldType;
33 using BaseType::DiscreteFunction;
34 using BaseType::space;
35 using BaseType::dbegin;
39 std::enable_if_t<(IsLinearFunctional<Other>::value
41 && std::is_same<DiscreteFunctionSpaceType, typename std::decay_t<Other>::DiscreteFunctionSpaceType>::value
44 : BaseType(
"functional dof storage", other.space())
47 other.coefficients(
static_cast<BaseType&
>(*
this));
51 std::enable_if_t<(IsLinearFunctional<Other>::value
53 && std::is_same<DiscreteFunctionSpaceType, typename std::decay_t<Other>::DiscreteFunctionSpaceType>::value
58 other.coefficients(1_f,
static_cast<BaseType&
>(*
this));
62 std::enable_if_t<(IsLinearFunctional<Other>::value
64 && std::is_same<DiscreteFunctionSpaceType, typename std::decay_t<Other>::DiscreteFunctionSpaceType>::value
69 other.coefficients(
static_cast<BaseType&
>(*
this));
75 std::enable_if_t<(IsLinearFunctional<Other>::value
77 && std::is_same<DiscreteFunctionSpaceType, typename std::decay_t<Other>::DiscreteFunctionSpaceType>::value
82 other.coefficients(-1_f,
static_cast<BaseType&
>(*
this));
87 template<
class FieldArg,
class DF,
88 std::enable_if_t<std::is_constructible<RangeFieldType, FieldArg>::value,
int> = 0>
94 for (
auto&& dof : dofs(*
this)) {
101 template<
class FieldArg,
class DF,
102 std::enable_if_t<std::is_constructible<RangeFieldType, FieldArg>::value,
int> = 0>
103 void coefficients(FieldArg&& s, DF& values)
const
108 auto dofsEnd = dend();
109 for (
auto&& dof = dbegin(), dest = values.dbegin(); dof != dofsEnd; ++dof, ++dest) {
116 void coefficients(DF& df)
const
118 coefficients(1_f, df);
122 auto operator()(
const DF& df)
const
124 return inner(*
this, df);
128 template<
class DiscreteFunction>
137 using typename FunctionalBase::DiscreteFunctionSpaceType;
138 using typename FunctionalBase::RangeFieldType;
144 template<
class Other,
145 std::enable_if_t<(!std::is_const<DiscreteFunction>::value
146 && IsLinearFunctional<Other>::value
148 && std::is_same<DiscreteFunctionSpaceType, typename std::decay_t<Other>::DiscreteFunctionSpaceType>::value
150 ThisType&
operator=(Other&& other)
152 other.coefficients(1_f, dofs_);
155 template<
class FieldArg,
class DF,
156 std::enable_if_t<std::is_constructible<RangeFieldType, FieldArg>::value,
int> = 0>
157 void coefficients(FieldArg&& s, DF& values)
const
159 auto&& dof = dofs_.dbegin();
160 auto&& dest = values.dbegin();
161 auto&& dofsEnd = dofs_.dend();
162 while (dof != dofsEnd) {
170 void coefficients(DF& df)
const
172 coefficients(1_f, df);
176 auto operator()(
const DF& df)
const
178 return inner(*
this, df);
183 return dofs_.dbegin();
191 const DiscreteFunctionSpaceType& space()
const
193 return dofs_.space();
196 std::string name()
const
201 operator DiscreteFunction& () &
206 operator std::add_const_t<DiscreteFunction>& ()
const&
211 operator DiscreteFunction () &&
217 DiscreteFunction& dofs_;
220 template<
class DiscreteFunction>
221 auto dofStorageFunctional(DiscreteFunction&& df)
223 return DofStorageFunctional<DiscreteFunction>(std::forward<DiscreteFunction>(df));
226 template<
class DiscreteFunction,
class DiscreteFunctionSpace,
227 std::enable_if_t<std::is_same<typename std::decay_t<DiscreteFunction>::DiscreteFunctionSpaceType,
228 DiscreteFunctionSpace>::value,
int> = 0>
229 auto dofStorageFunctional(
const DiscreteFunctionSpace& space,
const std::string& name =
"")
231 using DiscreteFunctionType = std::decay_t<DiscreteFunction>;
232 return expressionClosure( DofStorageFunctional<DiscreteFunctionType>(DiscreteFunctionType(name, space)));
237 using LinearFunctional::dofStorageFunctional;
A functional which inherits from a proper discrete function.
Definition: dofstorage.hh:26
Light-weight base class for all linear functionals.
Definition: linearfunctional.hh:13
constexpr decltype(auto) expressionClosure(T &&t)
Do-nothing default implementation for pathologic cases.
Definition: interface.hh:93
auto inner(T1 &&t1, T2 &&t2)
"scalar product"
Definition: expressions.hh:154
A constant.
Definition: tags.hh:93
Default expression traits definition is a recursion in order to ease disambiguation.
Definition: expressiontraits.hh:54
Terminals may derive from this class to express that they are expressions.
Definition: terminal.hh:25
TrueType if T1 and T2 have the same decay types, otherwise FalseType.
Definition: types.hh:440