DUNE-ACFEM (unstable)

diracfunctional.hh
1#ifndef __DUNE_ACFEM_OPERATORS_FUNCTIONALS_MODULES_DIRACFUNCTIONAL_HH__
2#define __DUNE_ACFEM_OPERATORS_FUNCTIONALS_MODULES_DIRACFUNCTIONAL_HH__
3
4#include <dune/fem/gridpart/common/entitysearch.hh>
5
6#include "../../../common/tostring.hh"
7#include "../../../common/literals.hh"
8#include "../../../expressions/terminal.hh"
9#include "../linearfunctional.hh"
10
11namespace Dune {
12
13 namespace ACFem {
14
15 namespace LinearFunctional {
16
17 using namespace Literals;
18
46 template<class DiscreteFunctionSpace>
48 : public LinearFunctionalBase<DiscreteFunctionSpace>
49 , Expressions::SelfExpression<DiracDistribution<DiscreteFunctionSpace> >
50 {
51 using BaseType = LinearFunctionalBase<DiscreteFunctionSpace>;
52 public:
53 using typename BaseType::DiscreteFunctionSpaceType;
54 using typename BaseType::RangeFieldType;
55 using BaseType::space;
56 using RangeType = typename DiscreteFunctionSpaceType::RangeType;
57 using DomainType = typename DiscreteFunctionSpaceType::DomainType;
58 using GridPartType = typename DiscreteFunctionSpaceType::GridPartType;
59
67 template<class X0Arg, std::enable_if_t<std::is_constructible<DomainType, X0Arg>::value, int> = 0>
68 DiracDistribution(X0Arg&& x0, const DiscreteFunctionSpaceType& space)
69 : BaseType(space)
70 , x0_(std::forward<X0Arg>(x0))
71 {}
72
73 template<class T>
74 DiracDistribution(const std::initializer_list<T> &values, const DiscreteFunctionSpaceType& space)
75 : BaseType(space)
76 , x0_(values)
77 {}
78
79 template<class FieldArg, class DiscreteFunction,
80 std::enable_if_t<std::is_constructible<RangeFieldType, FieldArg>::value, int> = 0>
81 void coefficients(FieldArg&& s, DiscreteFunction& values) const
82 {
84 try {
85 const auto entity = Fem::EntitySearch<GridPartType>(space().gridPart())(x0_);
86 values.localFunction(entity).axpy(entity.geometry().local(x0_), RangeType(s));
87 } catch (const Dune::Exception& e) {
88 // That's ok. The point is just not located inside the mesh.
89 }
90 }
91 }
92
93 template<class DiscreteFunction>
94 void coefficients(DiscreteFunction& df) const
95 {
96 coefficients(1_f, df);
97 }
98
99 template<class DiscreteFunction>
100 auto operator()(const DiscreteFunction& df) const
101 {
102 return inner(*this, df);
103 }
104
105 std::string name() const
106 {
107 return "<delta_["+toString(x0_)+"],...>";
108 }
109
110 const auto& x0() const& { return x0_; }
111 auto& x0() & { return x0_; }
112 DomainType x0() && { return x0_; }
113
114 protected:
115 DomainType x0_;
116 };
117
118 template<class X0Arg, class DiscreteFunctionSpace,
119 std::enable_if_t<std::is_constructible<typename DiscreteFunctionSpace::DomainType, X0Arg>::value, int> = 0>
120 auto diracFunctional(X0Arg&& x0, const DiscreteFunctionSpace& space)
121 {
122 return expressionClosure(DiracDistribution<DiscreteFunctionSpace>(std::forward<X0Arg>(x0), space));
123 }
124
125 template<class T, class DiscreteFunctionSpace>
126 auto diracFunctional(const std::initializer_list<T>& x0, const DiscreteFunctionSpace& space)
127 {
128 return DiracDistribution<DiscreteFunctionSpace>(x0, space);
129 }
130
132
134
135 } // LinearFunctional::
136
137 using LinearFunctional::diracFunctional;
138
139 } // namespace ACFem
140
141} // namespace Dune
142
143#endif // __DUNE_ACFEM_OPERATORS_FUNCTIONALS_MODULES_DIRACFUNCTIONAL_HH__
Dirac-distribution.
Definition: diracfunctional.hh:50
DiracDistribution(X0Arg &&x0, const DiscreteFunctionSpaceType &space)
Constructor.
Definition: diracfunctional.hh:68
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
STL namespace.
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)