DUNE-ACFEM (2.5.1)

dirichletconstraints.hh
1#ifndef DUNE_ACFEM_DIRICHLETCONSTRAINTS_HH
2#define DUNE_ACFEM_DIRICHLETCONSTRAINTS_HH
3
4#include <dune/fem/function/common/scalarproducts.hh>
5
6#include "../../models/boundaryindicator.hh"
7#include "../../functions/boundarysupportedfunction.hh"
8#include "../../functions/gridfunctionexpression.hh"
9#include "bulkblockconstraints.hh"
10
11namespace Dune {
12
13 namespace ACFem {
14
23 template<class JacobianOperator, class BoundaryValues, class Indicator = EntireBoundaryIndicatorType >
24 class DirichletConstraints;
25
26 template<class JacobianOperator, class BoundaryValues, class Indicator>
27 class LocalDirichletConstraints;
28
29 template<class JacobianOperator, class BoundaryValues, class Indicator>
30 struct DirichletBlockConstraintsTraits
31 : public
32 BlockConstraintsDefaultStorageTraits<
33 DirichletConstraints<JacobianOperator, BoundaryValues, Indicator>,
34 LocalDirichletConstraints<JacobianOperator, BoundaryValues, Indicator> >
35 {};
36
39 template<class JacobianOperator, class BoundaryValues>
40 struct DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType>
41 : public BlockConstraintsDefaultTraits<DirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType>,
42 LocalDirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType> >
43 {};
44
45 template<class JacobianOperator, class BoundaryValues>
46 class DirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType>
48 DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType> >
49 {
50 public:
52 typedef typename TraitsType::LocalOperatorType LocalOperatorType;
53 typedef JacobianOperator JacobianOperatorType;
54 typedef typename JacobianOperatorType::DomainFunctionType DiscreteFunctionType;
55 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
56 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
57 typedef typename DiscreteFunctionSpaceType::EntityType EntityType;
58 typedef BoundaryValues BoundaryValuesFunctionType;
59 typedef EmptyBoundaryIndicatorType IndicatorType;
60
61 DirichletConstraints(const DiscreteFunctionSpaceType& space,
62 const BoundaryValuesFunctionType& boundaryValues,
63 const IndicatorType& indicator)
64 {}
65
66 void operator()(const DiscreteFunctionType& arg, DiscreteFunctionType& result) const {}
67 void jacobian(const DiscreteFunctionType& u, JacobianOperatorType& jOp) const {}
68
69 LocalOperatorType localOperator(const EntityType& entity) const
70 {
71 return LocalOperatorType();
72 }
73
74 LocalOperatorType localOperator() const
75 {
76 return LocalOperatorType();
77 }
78
79 void rebuild() const {}
80 void constrain(DiscreteFunctionType& w) const {}
81 void zeroConstrain(DiscreteFunctionType& w) const {}
82 size_t size() const { return 0; }
83 };
84
85
86 template<class JacobianOperator, class BoundaryValues>
87 class LocalDirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType>
88 {
89 protected:
90 typedef DirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType> OperatorType;
91 friend OperatorType;
92
93 LocalDirichletConstraints(const OperatorType& op) {}
94 LocalDirichletConstraints() {}
95 public:
96 typedef typename OperatorType::EntityType EntityType;
97 typedef typename OperatorType::DiscreteFunctionType::LocalFunctionType LocalFunctionType;
98 typedef JacobianOperator JacobianOperatorType;
99
100 void init(const EntityType& entity) {}
101 void operator()(const LocalFunctionType& u, LocalFunctionType& w) const {}
102 template<class LocalMatrix>
103 void jacobian(const LocalFunctionType& u /* unused */, LocalMatrix& jOpLocal) const {}
104 void constrain(LocalFunctionType& u) const {}
105 void zeroConstrain(LocalFunctionType& u) const {}
106 size_t numConstrained() { return 0; }
107 bool unconstrained() { return true; }
108 bool totallyConstrained() const { return false; }
109 };
110
113 template<class JacobianOperator, class BoundaryValues, class Indicator>
115 : public BulkBlockConstraints<JacobianOperator,
116 DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> >
117 {
119 public:
120 typedef DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> TraitsType;
121 private:
124 public:
125 typedef typename BaseType::DiscreteFunctionType DiscreteFunctionType;
126 typedef typename BaseType::JacobianOperatorType JacobianOperatorType;
127 typedef typename BaseType::LocalOperatorType LocalOperatorType;
128 typedef typename BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
129 typedef typename BaseType::GridPartType GridPartType;
130 typedef typename BaseType::EntityType EntityType;
131
132 typedef BoundaryValues BoundaryValuesFunctionType;
133 typedef decltype(*std::declval<Indicator>()) IndicatorType;
134
136 typedef typename DiscreteFunctionSpaceType::GridType GridType;
137
138 // types for boundary treatment
139 // ----------------------------
140 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
141 typedef Dune::Fem::SlaveDofs<DiscreteFunctionSpaceType, BlockMapperType> SlaveDofsType;
142 typedef typename SlaveDofsType::SingletonKey SlaveDofsKeyType;
143 typedef Dune::Fem::SingletonList<SlaveDofsKeyType, SlaveDofsType>
144 SlaveDofsProviderType;
145 //typedef typename BlockMapperType::GlobalKeyType GlobalKeyType;
146 typedef std::size_t GlobalKeyType;
147
148 DirichletConstraints(const DiscreteFunctionSpaceType& space,
149 const BoundaryValuesFunctionType& boundaryValues,
150 const IndicatorType& indicator)
151 : BaseType(space),
152 boundaryValues_(boundaryValues),
153 indicator_(indicator)
154 {}
155
156 using BaseType::size;
157 using BaseType::jacobian;
160 using BaseType::localOperator;
161
162 //using BaseType::operator();
163 void operator()(const DiscreteFunctionType& arg, DiscreteFunctionType& result) const {
164 BaseType::operator()(arg, result);
165 }
166
170 void rebuild() const
171 {
172 // std::cerr << "rebuild called "
173 // << sequence_
174 // << " "
175 // << space_.sequence()
176 // << std::endl;
177 if (sequence_ != space_.sequence()) {
178
179 BaseType::rebuildSlaveDofs();
180
181 updateBoundaryValues(boundaryValues_(), affineOffset_);
182
183 sequence_ = space_.sequence();
184 }
185 }
186
191 {
192 if (sequence_ != space_.sequence()) {
193 BaseType::rebuildSlaveDofs();
194 }
195
196 updateBoundaryValues(boundaryValues_(), affineOffset_);
197
198 sequence_ = space_.sequence();
199 }
200
201 protected:
202 enum { localBlockSize = DiscreteFunctionSpaceType::localBlockSize };
203
205 void updateBoundaryValues(const BoundaryValuesFunctionType& u, DiscreteFunctionType& w) const
206 {
207 const auto& mapper = space_.blockMapper();
208 const int maxNumDofs = mapper.maxNumDofs();
209
210 // resize flag vector with number of blocks and reset flags
211 constrainedDofsMask_.resize(mapper.size());
212 std::fill(constrainedDofsMask_.begin(), constrainedDofsMask_.end(), 0U);
213
214 // only start search if Dirichlet boundary is present
216 numConstrained_ = 0;
217 return;
218 }
219
220 // pre-allocate local objects
221 std::vector<GlobalKeyType> blockDofIndices;
222 std::vector<bool> blockDofFaceMask;
223 blockDofIndices.reserve(maxNumDofs);
224 blockDofFaceMask.reserve(maxNumDofs);
225 auto uValues = temporaryLocalFunction(space_);
226 auto uLocal = localFunction(u);
227 auto wLocal = localFunction(w);
228
229 numConstrained_ = 0;
230 for (const auto& entity : space_) {
231 for (const auto& intersection : intersections(space_.gridPart(), entity)) {
232
233 // if intersection is with boundary, adjust data
234 if (intersection.neighbor() || !intersection.boundary()) {
235 continue;
236 }
237
238 // Check whether this segment belongs to a Dirichlet boundary ...
239 if (!indicator_().applies(intersection)) {
240 continue; // Nope
241 }
242
243 // actual number of DoFs
244 const int numDofs = mapper.numDofs(entity);
245
246 // init local stuff
247 blockDofIndices.resize(numDofs, GlobalKeyType(-1));
248 blockDofFaceMask.resize(numDofs, false);
249 uValues.init(entity);
250 uLocal.init(entity, intersection);
251 wLocal.init(entity);
252
253 // get local -> global mapping
254 space_.blockMapper().map(entity, blockDofIndices);
255
256 // get mask of affected (block)-DoFs
257 // get face number of boundary intersection
258 const int face = intersection.indexInInside();
259 mapper.onSubEntity(entity, face, 1 /* codim */, blockDofFaceMask);
260
261 // call "natural" interpolation for _ALL_ DoFs
262 space_.interpolation(entity)(uLocal, uValues);
263
264 for(int localBlock = 0; localBlock < numDofs; ++localBlock) {
265 if (!blockDofFaceMask[localBlock]) {
266 continue;
267 }
268 ++constrainedDofsMask_[blockDofIndices[localBlock]];
269 ++numConstrained_;
270
271 int localDof = localBlock * localBlockSize;
272 for(int l = 0; l < localBlockSize; ++l, ++localDof) {
273 wLocal[localDof] = uValues[localDof];
274 }
275 }
276 }
277 }
278 }
279
280 protected:
282 using BaseType::space_;
283 using BaseType::affineOffset_;
284 using BaseType::constrainedDofsMask_;
285 using BaseType::sequence_;
286 using BaseType::numConstrained_;
287
289 const ExpressionStorage<IndicatorType> indicator_;
290 };
291
292 template<class JacobianOperator, class BoundaryValues, class Indicator>
293 class LocalDirichletConstraints
294 : public LocalBulkBlockConstraints<JacobianOperator,
295 DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> >
296 {
297 typedef DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> TraitsType;
298 typedef LocalBulkBlockConstraints<JacobianOperator, TraitsType> BaseType;
299 protected:
300 typedef typename TraitsType::GlobalOperatorType OperatorType;
301 typedef typename OperatorType::LocalObjectFactoryType LocalObjectFactoryType;
302 friend LocalObjectFactoryType;
303
304 LocalDirichletConstraints(const OperatorType& op)
305 : BaseType(op)
306 {}
307 public:
310 bool totallyConstrained() const
311 {
312 return false;
313 }
314 };
315
317
319
320 } // ACFem::
321
322} // Dune::
323#endif
A default implementation for bulk block constraints.
Definition: bulkblockconstraints.hh:51
void operator()(const DiscreteFunctionType &u, DiscreteFunctionType &w) const
Apply the operator to the given argument.
Definition: bulkblockconstraints.hh:163
void zeroConstrain(DiscreteFunctionType &w) const
Unconditionally set the values of all masked DoFs to zero.
Definition: bulkblockconstraints.hh:250
void constrain(DiscreteFunctionType &w) const
The solution operator; unconditionally install the given constraints into the argument.
Definition: bulkblockconstraints.hh:224
void jacobian(const DiscreteFunctionType &u, JacobianOperatorType &jOp) const
The Jacobian of the operator.
Definition: bulkblockconstraints.hh:194
Interface class for a differentiable block-constraints-operator.
Definition: blockconstraintsoperator.hh:182
Implementation of Dirichlet constraints.
Definition: dirichletconstraints.hh:117
void zeroConstrain(DiscreteFunctionType &w) const
Unconditionally set the values of all masked DoFs to zero.
Definition: bulkblockconstraints.hh:250
const DiscreteFunctionSpaceType & space_
pointer to slave dofs
Definition: bulkblockconstraints.hh:288
void updateBoundaryValues(const BoundaryValuesFunctionType &u, DiscreteFunctionType &w) const
Update the flag vector and interpolate the boundary values.
Definition: dirichletconstraints.hh:205
void constrain(DiscreteFunctionType &w) const
The solution operator; unconditionally install the given constraints into the argument.
Definition: bulkblockconstraints.hh:224
void rebuildValues()
Interpolate the Dirichlet values in any case, but leave slave-DoFs as is if nothing changed.
Definition: dirichletconstraints.hh:190
void rebuild() const
Rebuild everything in case the sequence number of the underlying space has changed,...
Definition: dirichletconstraints.hh:170
void jacobian(const DiscreteFunctionType &u, JacobianOperatorType &jOp) const
The Jacobian of the operator.
Definition: bulkblockconstraints.hh:194
DiscreteFunctionSpaceType::GridType GridType
type of grid
Definition: dirichletconstraints.hh:136
We need the type of the implementation and the local operator type.
Definition: blockconstraintsoperator.hh:37
Spezialization of Dirichlet constraints for emptyboundaryindicator.
Definition: dirichletconstraints.hh:43
A traits class in order to collect properties of expressions.
Definition: expressionoperations.hh:465
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)