DUNE-ACFEM (2.5.1)

diracfunctional.hh
1#ifndef __DUNE_ACFEM_DIRACFUNCTIONAL_HH__
2#define __DUNE_ACFEM_DIRACFUNCTIONAL_HH__
3
4#include "linearfunctional.hh"
5#include "../../common/stringconversion.hh"
6
7namespace Dune {
8
9 namespace ACFem {
10
19 template<class DiscreteFunctionSpace>
20 class DiracDistribution;
21
22 template<class DiscreteFunctionSpace>
23 class LocalDiracDistribution;
24
25 template<class DiscreteFunctionSpace>
26 struct DiracDistributionTraits
27 : public LinearFunctionalTraitsDefault<DiracDistribution<DiscreteFunctionSpace>,
28 LocalDiracDistribution<DiscreteFunctionSpace> >
29 {};
30
49 template<class DiscreteFunctionSpace>
51 : public DiscreteLinearFunctionalDefault<DiscreteFunctionSpace,
52 DiracDistributionTraits<DiscreteFunctionSpace> >
53 {
55 typedef
57 DiscreteFunctionSpace, DiracDistributionTraits<DiscreteFunctionSpace> >
59 public:
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;
68 protected:
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;
74 typedef
75 ReferenceElements<typename GeometryType::ctype, GridPartType::dimension>
76 ReferenceElementsType;
77
78 friend LocalDiracDistribution<DiscreteFunctionSpace>;
79 public:
92 DiracDistribution(const DiscreteFunctionSpaceType& space,
93 const GlobalCoordinateType& x0, unsigned component = 0)
94 : BaseType(space),
95 x0_(x0),
96 component_(component),
97 gridPart_(space_.gridPart()),
98 indexSet_(gridPart_.indexSet()),
99 sequence_(-1),
100 found_(false),
101 continuous_(space_.continuous())
102 {}
103
104 using BaseType::operator();
106 using BaseType::space;
107 using BaseType::localFunctional;
108
109 std::string name() const
110 {
111 std::string result;
112 if (objectToString(x0_, result)) {
113 return "<delta_["+result+"],...>";
114 } else {
115 return "<Dirac_x0,...>";
116 }
117 }
118
122 GlobalCoordinateType& x0() { return x0_; }
123 const GlobalCoordinateType& x0() const { return x0_; }
124 unsigned& component() { return component_; }
125 const unsigned& component() const { return component_; }
127
128 protected:
129 template<class Entity>
130 bool doCheckEntity(const Entity& entity) const
131 {
132 const auto& geometry = entity.geometry();
133 x0Local_ = geometry.local(x0_);
134
135 if (ReferenceElementsType::general(geometry.type()).checkInside(x0Local_)) {
136 return true;
137 }
138 return false;
139 }
140 template<class Entity>
141 bool checkEntity(const Entity& entity) const
142 {
143 if (!continuous_) {
144 return doCheckEntity(entity);
145 }
146 if (sequence_ != space_.sequence()) {
147 found_ = false;
148 sequence_ = space_.sequence();
149 }
150 if (found_) {
151 return indexSet_.index(entity) == entityIndex_;
152 }
153#if 0
154 if (doCheckEntity(entity)) {
155 found_ = true;
156 entityIndex_ = indexSet_.index(entity);
157 return true;
158 }
159 return false;
160#else
161 // should be faster for hiearchical grids
162 Fem::EntitySearch<GridPartType> entitySearch(gridPart_);
163
164 const auto entityOfXZero = entitySearch(x0_);
165 found_ = true; // otherwise error
166 entityIndex_ = indexSet_.index(entityOfXZero);
167 const auto& geometry = entityOfXZero.geometry();
168 x0Local_ = geometry.local(x0_);
169
170 return indexSet_.index(entity) == entityIndex_;
171#endif
172 }
173
174 protected:
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_;
182 mutable bool found_;
183 mutable LocalCoordinateType x0Local_;
184 const bool continuous_;
185 };
186
187 template<class DiscreteFunctionSpace>
188 class LocalDiracDistribution
189 : public LocalLinearFunctionalDefault<DiscreteFunctionSpace,
190 DiracDistributionTraits<DiscreteFunctionSpace> >
191 {
192 typedef LocalDiracDistribution ThisType;
193 typedef
194 LocalLinearFunctionalDefault<DiscreteFunctionSpace,
195 DiracDistributionTraits<DiscreteFunctionSpace> >
196 BaseType;
197 public:
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;
204 public:
205
206 LocalDiracDistribution(const FunctionalType& phi)
207 : BaseType(phi),
208 activeEntity_(false)
209 {}
210
211 LocalDiracDistribution(const EntityType& entity, const FunctionalType& phi)
212 : BaseType(entity, phi),
213 activeEntity_(false)
214 {}
215
216 public:
217 void init(const EntityType& entity)
218 {
219 activeEntity_ = functional().checkEntity(entity);
220 BaseType::init(entity);
221 }
222
223 template<class LocalFunction>
224 RangeType operator()(const LocalFunction& arg) const
225 {
226 if (!activeEntity_) {
227 return 0;
228 }
229 return BaseType::operator()(arg);
230 }
231
233 template<class LocalFunction>
234 void coefficients(const RangeType& c, LocalFunction& coeffs) const
235 {
236 if (!activeEntity_) {
237 return;
238 }
239 typename LocalFunction::RangeType value(0);
240 value[functional().component_] = c;
241 coeffs.axpy(functional().x0Local_, value);
242 }
243
245 template<class LocalFunction>
246 void coefficients(LocalFunction& coeffs) const
247 {
249 }
250
251 using BaseType::operator();
252 using BaseType::functional;
253 using BaseType::entity;
254
255 protected:
256 using BaseType::entity_;
257 bool activeEntity_;
258 };
259
261
263
264 } // namespace ACFem
265
266} // namespace Dune
267
268#endif // __DUNE_ACFEM_DIRACFUNCTIONAL_HH__
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 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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)