1#ifndef _DUNE_ACFEM_DISCRETELINEARFUNCTIONAL_HH_
2#define _DUNE_ACFEM_DISCRETELINEARFUNCTIONAL_HH_
4#include <dune/fem/misc/bartonnackmaninterface.hh>
5#include <dune/fem/function/common/discretefunction.hh>
6#include <dune/fem/function/localfunction/temporary.hh>
8#include "../../common/localobjectstorage.hh"
36 template<
class GlobalFunctional,
class LocalFunctional>
39 typedef GlobalFunctional GlobalFunctionalType;
40 typedef LocalFunctional LocalFunctionalType;
48 template<
class DiscreteFunctionSpace,
class Traits>
50 :
public Fem::BartonNackmanInterface<DiscreteLinearFunctional<DiscreteFunctionSpace, Traits>,
51 typename Traits::GlobalFunctionalType>
55 Fem::BartonNackmanInterface<DiscreteLinearFunctional<DiscreteFunctionSpace, Traits>,
56 typename Traits::GlobalFunctionalType>
59 typedef Traits TraitsType;
60 typedef typename TraitsType::LocalFunctionalType LocalFunctionalType;
61 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
62 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
63 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
64 typedef typename DiscreteFunctionSpace::FunctionSpaceType FunctionSpaceType;
65 typedef typename FunctionSpaceType::RangeFieldType FieldType;
66 typedef FieldType RangeType;
81 template<
class DFImpl>
82 RangeType
operator()(
const Fem::DiscreteFunctionInterface<DFImpl>& arg)
const
84 static_assert(std::is_same<DiscreteFunctionSpaceType, typename DFImpl::DiscreteFunctionSpaceType>::value,
86 CHECK_INTERFACE_IMPLEMENTATION(
asImp()(arg));
91 template<
class DFImpl>
94 static_assert(std::is_same<DiscreteFunctionSpaceType, typename DFImpl::DiscreteFunctionSpaceType>::value,
99 const DiscreteFunctionSpaceType& space()
const
101 CHECK_INTERFACE_IMPLEMENTATION(
asImp().space());
102 return asImp().space();
105 LocalFunctionalType localFunctional(
const EntityType& entity)
107 CHECK_INTERFACE_IMPLEMENTATION(
asImp().localFunctional(entity));
108 return asImp().localFunctional(entity);
111 const LocalFunctionalType localFunctional(
const EntityType& entity)
const
113 CHECK_INTERFACE_IMPLEMENTATION(
asImp().localFunctional(entity));
114 return asImp().localFunctional(entity);
117 std::string name()
const
119 CHECK_INTERFACE_IMPLEMENTATION(
asImp().name());
120 return asImp().name();
129 template<
class DiscreteFunctionSpace,
class Traits>
136 typedef Traits TraitsType;
137 typedef typename TraitsType::LocalFunctionalType LocalFunctionalType;
138 typedef typename TraitsType::GlobalFunctionalType GlobalFunctionalType;
139 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
140 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
141 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
142 typedef typename DiscreteFunctionSpace::FunctionSpaceType FunctionSpaceType;
143 typedef typename FunctionSpaceType::RangeFieldType FieldType;
144 typedef FieldType RangeType;
154 : space_(other.space_)
161 template<
class DFTraits>
162 RangeType
operator()(
const Fem::DiscreteFunctionInterface<DFTraits>& arg)
const
164 static_assert(std::is_same<DiscreteFunctionSpaceType, typename DFTraits::DiscreteFunctionSpaceType>::value,
167 typedef typename Fem::DiscreteFunctionInterface<DFTraits> DiscreteFunctionType;
168 typedef typename DiscreteFunctionType::LocalFunctionType LocalFunctionType;
171 const auto& dfSpace = arg.space();
173 auto localPhi =
asImp().localFunctional();
177 auto end = dfSpace.end();
178 for (
auto it = dfSpace.begin(); it != end; ++it) {
180 const auto &entity = *it;
181 localPhi.init(entity);
182 localArg.init(entity);
184 value += localPhi(localArg);
190 template<
class DFTraits>
193 static_assert(std::is_same<DiscreteFunctionSpaceType, typename DFTraits::DiscreteFunctionSpaceType>::value,
196 typedef typename Fem::DiscreteFunctionInterface<DFTraits> DiscreteFunctionType;
197 typedef typename DiscreteFunctionType::LocalFunctionType LocalFunctionType;
200 const auto& dfSpace = coeffs.space();
202 auto localPhi =
asImp().localFunctional();
206 auto end = dfSpace.end();
207 for (
auto it = dfSpace.begin(); it != end; ++it) {
209 const auto &entity = *it;
211 localPhi.init(entity);
212 localCoeffs.init(entity);
214 localPhi.coefficients(localCoeffs);
216 coeffs.communicate();
219 const DiscreteFunctionSpaceType& space()
const
224 LocalFunctionalType localFunctional()
226 return LocalFunctionalType(
asImp());
229 const LocalFunctionalType localFunctional()
const
231 return LocalFunctionalType(
asImp());
234 LocalFunctionalType localFunctional(
const EntityType& entity)
236 return LocalFunctionalType(entity,
asImp());
239 const LocalFunctionalType localFunctional(
const EntityType& entity)
const
241 return LocalFunctionalType(entity,
asImp());
244 std::string name()
const
250 const DiscreteFunctionSpaceType& space_;
254 template<
class DiscreteFunctionSpace,
class Traits>
256 :
public Fem::BartonNackmanInterface<LocalLinearFunctional<DiscreteFunctionSpace, Traits>,
257 typename Traits::LocalFunctionalType>
261 Fem::BartonNackmanInterface<ThisType, typename Traits::LocalFunctionalType>
264 typedef Traits TraitsType;
265 typedef typename TraitsType::GlobalFunctionalType FunctionalType;
268 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
269 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
270 typedef typename DiscreteFunctionSpace::FunctionSpaceType FunctionSpaceType;
271 typedef typename FunctionSpaceType::RangeFieldType FieldType;
272 typedef FieldType RangeType;
302 template<
class LocalFunction>
315 template<
class LocalFunction>
318 asImp().coefficients(coeffs);
329 template<
class LocalFunction>
332 asImp().coefficients(c, coeffs);
339 return asImp().functional();
346 return asImp().entity();
359 template<
class DiscreteFunctionSpace,
class Traits>
366 typedef Traits TraitsType;
367 typedef typename TraitsType::GlobalFunctionalType FunctionalType;
368 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
369 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
370 typedef typename DiscreteFunctionSpace::FunctionSpaceType FunctionSpaceType;
371 typedef typename FunctionSpaceType::RangeFieldType FieldType;
372 typedef FieldType RangeType;
374 typedef Fem::TemporaryLocalFunction<DiscreteFunctionSpaceType, FieldType> TemporaryCoefficientsType;
380 functional_(functional),
381 localCoeffs_(functional_.space())
385 const FunctionalType& functional)
387 functional_(functional),
388 localCoeffs_(functional_.space())
392 : entity_(other.entity_),
393 functional_(other.functional_),
394 localCoeffs_(functional_.space())
403 void init(
const EntityType& entity)
409 template<
class LocalFunction>
412 typedef LocalFunction LocalDomainFunctionType;
414 localCoeffs_.init(entity());
415 localCoeffs_.clear();
416 asImp().coefficients(FieldType(1.0), localCoeffs_);
417 RangeType result = 0;
418 for (
unsigned i = 0; i < arg.size(); ++i) {
419 result += arg[i] * localCoeffs_[i];
424 const FunctionalType& functional()
const
429 const EntityType& entity()
const
435 template<
class LocalFunction>
438 asImp().coefficients(FieldType(1.0), coeffs);
442 template<
class LocalFunction>
448 const EntityType* entity_;
449 const FunctionalType& functional_;
450 mutable TemporaryCoefficientsType localCoeffs_;
Default implementation for linear functionals.
Definition: linearfunctional.hh:132
RangeType operator()(const Fem::DiscreteFunctionInterface< DFTraits > &arg) const
Definition: linearfunctional.hh:162
void coefficients(Fem::DiscreteFunctionInterface< DFTraits > &coeffs)
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:191
Interface class for a discrete linear functional.
Definition: linearfunctional.hh:52
RangeType operator()(const Fem::DiscreteFunctionInterface< DFImpl > &arg) const
Compute the value.
Definition: linearfunctional.hh:82
void coefficients(Fem::DiscreteFunctionInterface< DFImpl > &coeffs)
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:92
Default implementation for LocalLinearFunctional.
Definition: linearfunctional.hh:362
void coefficients(const RangeType &c, LocalFunction &coeffs) const
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:443
void coefficients(LocalFunction &coeffs) const
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:436
void init(const EntityType &entity)
Bind to an entity.
Definition: linearfunctional.hh:403
RangeType operator()(const LocalFunction &arg) const
Compute the value.
Definition: linearfunctional.hh:410
Interface or better: factory for local functionals.
Definition: linearfunctional.hh:258
void coefficients(LocalFunction &coeffs) const
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:316
const FunctionalType & functional() const
Return the underlying global functional this LocalLinearFunctional instance belongs to.
Definition: linearfunctional.hh:337
const EntityType & entity() const
Return the entity the LocalLinearFunctional instance is tied to.
Definition: linearfunctional.hh:344
RangeType operator()(const LocalFunction &arg) const
Compute the value of the functional.
Definition: linearfunctional.hh:303
void coefficients(const RangeType &c, LocalFunction &coeffs) const
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:330
void init(const EntityType &entity)
Bind to an entity.
Definition: linearfunctional.hh:288
const Implementation & asImp(const Fem::BartonNackmanInterface< Interface, Implementation > &arg)
Up-cast to the implementation for any Fem::BartonNackmanInterface.
Definition: expressionoperations.hh:71
Default traits were the local objects are not cached, but created on the fly.
Definition: linearfunctional.hh:38