1#ifndef __DUNE_ACFEM_DIRACFUNCTIONAL_HH__
2#define __DUNE_ACFEM_DIRACFUNCTIONAL_HH__
4#include "linearfunctional.hh"
5#include "../../common/stringconversion.hh"
19 template<
class DiscreteFunctionSpace>
20 class DiracDistribution;
22 template<
class DiscreteFunctionSpace>
23 class LocalDiracDistribution;
25 template<
class DiscreteFunctionSpace>
26 struct DiracDistributionTraits
27 :
public LinearFunctionalTraitsDefault<DiracDistribution<DiscreteFunctionSpace>,
28 LocalDiracDistribution<DiscreteFunctionSpace> >
49 template<
class DiscreteFunctionSpace>
52 DiracDistributionTraits<DiscreteFunctionSpace> >
57 DiscreteFunctionSpace, DiracDistributionTraits<DiscreteFunctionSpace> >
60 typedef DiracDistributionTraits<DiscreteFunctionSpace> TraitsType;
61 typedef typename TraitsType::LocalFunctionalType LocalFunctionalType;
62 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
63 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
64 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
65 typedef typename DiscreteFunctionSpaceType::RangeFieldType FieldType;
66 typedef typename DiscreteFunctionSpaceType::DomainType GlobalCoordinateType;
67 typedef FieldType RangeType;
69 typedef typename GridPartType::IndexSetType IndexSetType;
70 typedef typename IndexSetType::IndexType EntityIndexType;
71 typedef std::vector<RangeType> CoeffsType;
72 typedef typename GridPartType::template Codim<0>::GeometryType GeometryType;
73 typedef typename GeometryType::LocalCoordinate LocalCoordinateType;
75 ReferenceElements<typename GeometryType::ctype, GridPartType::dimension>
76 ReferenceElementsType;
78 friend LocalDiracDistribution<DiscreteFunctionSpace>;
93 const GlobalCoordinateType& x0,
unsigned component = 0)
96 component_(component),
97 gridPart_(space_.gridPart()),
98 indexSet_(gridPart_.indexSet()),
101 continuous_(space_.continuous())
104 using BaseType::operator();
106 using BaseType::space;
107 using BaseType::localFunctional;
109 std::string name()
const
113 return "<delta_["+result+
"],...>";
115 return "<Dirac_x0,...>";
122 GlobalCoordinateType& x0() {
return x0_; }
123 const GlobalCoordinateType& x0()
const {
return x0_; }
124 unsigned& component() {
return component_; }
125 const unsigned& component()
const {
return component_; }
129 template<
class Entity>
130 bool doCheckEntity(
const Entity& entity)
const
132 const auto& geometry = entity.geometry();
133 x0Local_ = geometry.local(x0_);
135 if (ReferenceElementsType::general(geometry.type()).checkInside(x0Local_)) {
140 template<
class Entity>
141 bool checkEntity(
const Entity& entity)
const
144 return doCheckEntity(entity);
146 if (sequence_ != space_.sequence()) {
148 sequence_ = space_.sequence();
151 return indexSet_.index(entity) == entityIndex_;
154 if (doCheckEntity(entity)) {
156 entityIndex_ = indexSet_.index(entity);
162 Fem::EntitySearch<GridPartType> entitySearch(gridPart_);
164 const auto entityOfXZero = entitySearch(x0_);
166 entityIndex_ = indexSet_.index(entityOfXZero);
167 const auto& geometry = entityOfXZero.geometry();
168 x0Local_ = geometry.local(x0_);
170 return indexSet_.index(entity) == entityIndex_;
175 using BaseType::space_;
176 GlobalCoordinateType x0_;
177 unsigned int component_;
178 const GridPartType& gridPart_;
179 const IndexSetType& indexSet_;
180 mutable int sequence_;
181 mutable EntityIndexType entityIndex_;
183 mutable LocalCoordinateType x0Local_;
184 const bool continuous_;
187 template<
class DiscreteFunctionSpace>
188 class LocalDiracDistribution
189 :
public LocalLinearFunctionalDefault<DiscreteFunctionSpace,
190 DiracDistributionTraits<DiscreteFunctionSpace> >
192 typedef LocalDiracDistribution ThisType;
194 LocalLinearFunctionalDefault<DiscreteFunctionSpace,
195 DiracDistributionTraits<DiscreteFunctionSpace> >
198 typedef DiracDistributionTraits<DiscreteFunctionSpace> TraitsType;
199 typedef DiracDistribution<DiscreteFunctionSpace> FunctionalType;
200 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
201 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
202 typedef typename DiscreteFunctionSpaceType::RangeFieldType FieldType;
203 typedef FieldType RangeType;
206 LocalDiracDistribution(
const FunctionalType& phi)
211 LocalDiracDistribution(
const EntityType& entity,
const FunctionalType& phi)
212 : BaseType(entity, phi),
217 void init(
const EntityType& entity)
219 activeEntity_ = functional().checkEntity(entity);
223 template<
class LocalFunction>
224 RangeType operator()(
const LocalFunction& arg)
const
226 if (!activeEntity_) {
233 template<
class LocalFunction>
234 void coefficients(
const RangeType& c, LocalFunction& coeffs)
const
236 if (!activeEntity_) {
239 typename LocalFunction::RangeType value(0);
240 value[functional().component_] = c;
241 coeffs.axpy(functional().x0Local_, value);
245 template<
class LocalFunction>
251 using BaseType::operator();
252 using BaseType::functional;
253 using BaseType::entity;
256 using BaseType::entity_;
Dirac-distribution.
Definition: diracfunctional.hh:53
DiracDistribution(const DiscreteFunctionSpaceType &space, const GlobalCoordinateType &x0, unsigned component=0)
Constructor.
Definition: diracfunctional.hh:92
Default implementation for linear functionals.
Definition: linearfunctional.hh:132
void coefficients(Fem::DiscreteFunctionInterface< DFTraits > &coeffs)
Compute the basis representation, which means: do the assembling stuff.
Definition: linearfunctional.hh:191
void coefficients(const RangeType &c, LocalFunction &coeffs) const
Definition: linearfunctional.hh:443
void coefficients(LocalFunction &coeffs) const
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
bool objectToString(const T &something, std::string &text)
Convert any object which has an associated output stream operator "<<" to a string,...
Definition: stringconversion.hh:20