1#ifndef DUNE_ACFEM_DIRICHLETCONSTRAINTS_HH
2#define DUNE_ACFEM_DIRICHLETCONSTRAINTS_HH
4#include <dune/fem/function/common/scalarproducts.hh>
6#include "../../models/boundaryindicator.hh"
7#include "../../functions/boundarysupportedfunction.hh"
8#include "../../functions/gridfunctionexpression.hh"
9#include "bulkblockconstraints.hh"
23 template<
class JacobianOperator,
class BoundaryValues,
class Indicator = EntireBoundaryIndicatorType >
24 class DirichletConstraints;
26 template<
class JacobianOperator,
class BoundaryValues,
class Indicator>
27 class LocalDirichletConstraints;
29 template<
class JacobianOperator,
class BoundaryValues,
class Indicator>
30 struct DirichletBlockConstraintsTraits
32 BlockConstraintsDefaultStorageTraits<
33 DirichletConstraints<JacobianOperator, BoundaryValues, Indicator>,
34 LocalDirichletConstraints<JacobianOperator, BoundaryValues, Indicator> >
39 template<
class JacobianOperator,
class BoundaryValues>
40 struct DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType>
42 LocalDirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType> >
45 template<
class JacobianOperator,
class BoundaryValues>
48 DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType> >
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;
62 const BoundaryValuesFunctionType& boundaryValues,
63 const IndicatorType& indicator)
66 void operator()(
const DiscreteFunctionType& arg, DiscreteFunctionType& result)
const {}
67 void jacobian(
const DiscreteFunctionType& u, JacobianOperatorType& jOp)
const {}
69 LocalOperatorType localOperator(
const EntityType& entity)
const
71 return LocalOperatorType();
74 LocalOperatorType localOperator()
const
76 return LocalOperatorType();
80 void constrain(DiscreteFunctionType& w)
const {}
82 size_t size()
const {
return 0; }
86 template<
class JacobianOperator,
class BoundaryValues>
87 class LocalDirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType>
90 typedef DirichletConstraints<JacobianOperator, BoundaryValues, EmptyBoundaryIndicatorType> OperatorType;
93 LocalDirichletConstraints(
const OperatorType& op) {}
94 LocalDirichletConstraints() {}
96 typedef typename OperatorType::EntityType EntityType;
97 typedef typename OperatorType::DiscreteFunctionType::LocalFunctionType LocalFunctionType;
98 typedef JacobianOperator JacobianOperatorType;
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 , 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; }
113 template<
class JacobianOperator,
class BoundaryValues,
class Indicator>
116 DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> >
120 typedef DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> TraitsType;
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;
132 typedef BoundaryValues BoundaryValuesFunctionType;
133 typedef decltype(*std::declval<Indicator>()) IndicatorType;
136 typedef typename DiscreteFunctionSpaceType::GridType
GridType;
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;
146 typedef std::size_t GlobalKeyType;
149 const BoundaryValuesFunctionType& boundaryValues,
150 const IndicatorType& indicator)
152 boundaryValues_(boundaryValues),
153 indicator_(indicator)
156 using BaseType::size;
160 using BaseType::localOperator;
163 void operator()(
const DiscreteFunctionType& arg, DiscreteFunctionType& result)
const {
177 if (sequence_ !=
space_.sequence()) {
179 BaseType::rebuildSlaveDofs();
183 sequence_ =
space_.sequence();
192 if (sequence_ !=
space_.sequence()) {
193 BaseType::rebuildSlaveDofs();
198 sequence_ =
space_.sequence();
202 enum { localBlockSize = DiscreteFunctionSpaceType::localBlockSize };
207 const auto& mapper =
space_.blockMapper();
208 const int maxNumDofs = mapper.maxNumDofs();
211 constrainedDofsMask_.resize(mapper.size());
212 std::fill(constrainedDofsMask_.begin(), constrainedDofsMask_.end(), 0U);
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);
230 for (
const auto& entity :
space_) {
231 for (
const auto& intersection : intersections(
space_.gridPart(), entity)) {
234 if (intersection.neighbor() || !intersection.boundary()) {
239 if (!indicator_().applies(intersection)) {
244 const int numDofs = mapper.numDofs(entity);
247 blockDofIndices.resize(numDofs, GlobalKeyType(-1));
248 blockDofFaceMask.resize(numDofs,
false);
249 uValues.init(entity);
250 uLocal.init(entity, intersection);
254 space_.blockMapper().map(entity, blockDofIndices);
258 const int face = intersection.indexInInside();
259 mapper.onSubEntity(entity, face, 1 , blockDofFaceMask);
262 space_.interpolation(entity)(uLocal, uValues);
264 for(
int localBlock = 0; localBlock < numDofs; ++localBlock) {
265 if (!blockDofFaceMask[localBlock]) {
268 ++constrainedDofsMask_[blockDofIndices[localBlock]];
271 int localDof = localBlock * localBlockSize;
272 for(
int l = 0; l < localBlockSize; ++l, ++localDof) {
273 wLocal[localDof] = uValues[localDof];
282 using BaseType::space_;
283 using BaseType::affineOffset_;
284 using BaseType::constrainedDofsMask_;
285 using BaseType::sequence_;
286 using BaseType::numConstrained_;
292 template<
class JacobianOperator,
class BoundaryValues,
class Indicator>
293 class LocalDirichletConstraints
294 :
public LocalBulkBlockConstraints<JacobianOperator,
295 DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> >
297 typedef DirichletBlockConstraintsTraits<JacobianOperator, BoundaryValues, Indicator> TraitsType;
298 typedef LocalBulkBlockConstraints<JacobianOperator, TraitsType> BaseType;
300 typedef typename TraitsType::GlobalOperatorType OperatorType;
301 typedef typename OperatorType::LocalObjectFactoryType LocalObjectFactoryType;
302 friend LocalObjectFactoryType;
304 LocalDirichletConstraints(
const OperatorType& op)
310 bool totallyConstrained()
const
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