40#ifndef DUNE_DIRICHLETCONSTRAINTS_HH
41#define DUNE_DIRICHLETCONSTRAINTS_HH
54class HasLocalFunction;
57template <
class Model,
class DiscreteFunctionSpace >
64 typedef typename DiscreteFunctionSpaceType::DomainType
DomainType;
65 typedef typename DiscreteFunctionSpaceType::RangeType
RangeType;
70 typedef typename DiscreteFunctionSpaceType :: GridPartType
GridPartType;
72 typedef typename DiscreteFunctionSpaceType :: GridType
GridType;
76 static const int localBlockSize = DiscreteFunctionSpaceType :: localBlockSize ;
77 static_assert(
localBlockSize == DiscreteFunctionSpaceType::FunctionSpaceType::dimRange,
78 "local block size of the space must be identical to the dimension of the range of the function space.");
87 typedef typename DiscreteFunctionSpaceType::EntityType
EntityType;
89 typedef typename DiscreteFunctionSpaceType::DomainType
DomainType;
90 typedef typename DiscreteFunctionSpace::RangeType
RangeType;
103 : impl_( impl ), entity_(
entity), order_(
order), bndId_(bndId) {}
105 const int order ()
const {
return order_; }
106 template <
class Po
int>
109 template <
class Po
int>
111 { DUNE_THROW(Dune::NotImplemented,
"rhs jacobian not implemented"); }
130 template <
class DiscreteFunctionType >
131 void operator ()(
const DiscreteFunctionType& u, DiscreteFunctionType& w )
const
138 typedef typename DiscreteFunctionType :: DofIteratorType DofIteratorType ;
139 typedef typename DiscreteFunctionType :: ConstDofIteratorType ConstDofIteratorType ;
141 ConstDofIteratorType uIt = u.dbegin();
142 DofIteratorType wIt = w.dbegin();
145 const unsigned int blocks =
space_.blockMapper().size();
146 for(
unsigned int blockDof = 0; blockDof < blocks ; ++ blockDof )
153 assert( uIt != u.dend() );
154 assert( wIt != w.dend() );
168 template <
class DiscreteFunctionType >
169 void operator ()(
const typename DiscreteFunctionType::RangeType& value, DiscreteFunctionType& w )
const
176 typedef typename DiscreteFunctionType :: DofIteratorType DofIteratorType ;
178 DofIteratorType wIt = w.dbegin();
181 const unsigned int blocks =
space_.blockMapper().size();
182 for(
unsigned int blockDof = 0; blockDof < blocks ; ++ blockDof )
189 assert( wIt != w.dend() );
204 template <
class DiscreteFunctionType >
211 typedef typename DiscreteFunctionSpaceType :: IteratorType IteratorType;
212 typedef typename IteratorType :: Entity EntityType;
216 for(
const EntityType &entity :
space_ )
223 auto iGuard = bindGuard( interpolation, entity );
230 template <
class GridFunctionType,
class DiscreteFunctionType,
231 typename = std::enable_if_t< std::is_base_of<Dune::Fem::HasLocalFunction, GridFunctionType>::value > >
233 DiscreteFunctionType& w,
Operation op=Operation::setDF )
const
243 for(
const auto &entity :
space_ )
247 auto iGuard = bindGuard( interpolation, entity );
265 template <
class LinearOperator>
270 typedef typename DiscreteFunctionSpaceType :: IteratorType IteratorType;
271 typedef typename IteratorType :: Entity EntityType;
276 typedef typename LinearOperator::DomainSpaceType DomainSpaceType;
277 typedef typename LinearOperator::RangeSpaceType RangeSpaceType;
279 TemporaryLocalMatrixType localMatrix( linearOperator.domainSpace(), linearOperator.rangeSpace() );
281 const IteratorType end =
space_.end();
282 for( IteratorType it =
space_.begin(); it != end; ++it )
284 const EntityType &entity = *it;
286 localMatrix.init( entity, entity );
288 linearOperator.getLocalMatrix( entity, entity, localMatrix );
292 linearOperator.setLocalMatrix( entity, entity, localMatrix );
313 template<
class EntityType,
class LocalMatrix >
315 LocalMatrix& localMatrix )
const
318 const auto &auxiliaryDofs = localMatrix.rangeSpace().auxiliaryDofs();
321 const int localBlocks =
space_.blockMapper().numDofs( entity );
324 std::vector<std::size_t> globalBlockDofs(localBlocks);
326 space_.blockMapper().map( entity, globalBlockDofs );
331 for(
int localBlockDof = 0 ; localBlockDof < localBlocks; ++ localBlockDof )
333 int global = globalBlockDofs[localBlockDof];
339 localMatrix.clearRow( localDof );
342 double value = auxiliaryDofs.contains( global )? 0.0 : 1.0;
343 localMatrix.set( localDof, localDof, value );
350 template<
class LocalInterpolationType,
class LocalFunctionType >
354 const typename LocalFunctionType::EntityType &entity = wLocal.entity();
357 const int localBlocks =
space_.blockMapper().numDofs( entity );
360 std::vector<std::size_t> globalBlockDofs(localBlocks);
361 space_.blockMapper().map( entity, globalBlockDofs );
362 std::vector<typename LocalFunctionType::RangeFieldType> values( localBlocks*
localBlockSize );
367 for(
int localBlock = 0 ; localBlock < localBlocks; ++ localBlock )
370 int global = globalBlockDofs[localBlock];
377 assert( (
unsigned int)localDof < wLocal.size() );
378 wLocal[ localDof ] = values[ localDof ];
384 template<
class LocalInterpolationType,
class Gr
idLocalFunctionType,
class LocalFunctionType >
386 const GridLocalFunctionType &uLocal,
387 LocalFunctionType &wLocal,
Operation op )
const
390 const typename LocalFunctionType::EntityType &entity = wLocal.entity();
393 const int localBlocks =
space_.blockMapper().numDofs( entity );
395 typedef typename DiscreteFunctionSpaceType::BlockMapperType::GlobalKeyType GlobalKeyType;
398 std::vector< GlobalKeyType > globalBlockDofs(localBlocks);
399 space_.blockMapper().map(entity,globalBlockDofs);
403 interpolation( uLocal, values );
408 for(
int localBlock = 0 ; localBlock < localBlocks; ++ localBlock )
411 int global = globalBlockDofs[localBlock];
419 values[ localDof ] -= valuesModel[ localDof ];
422 assert( (
unsigned int)localDof < wLocal.size() );
423 wLocal[ localDof ] = values[ localDof ];
436 if( !
model_.hasDirichletBoundary() )
443 const int blocks =
space_.blockMapper().size() ;
445 for(
int i=0; i<blocks; ++i )
448 typedef typename DiscreteFunctionSpaceType :: IteratorType IteratorType;
449 typedef typename IteratorType :: Entity EntityType;
451 bool hasDirichletBoundary =
false;
452 const IteratorType end =
space_.end();
453 for( IteratorType it =
space_.begin(); it != end; ++it )
455 const EntityType &entity = *it;
457 if( entity.hasBoundaryIntersections() )
465 if(
space_.gridPart().comm().size() > 1 )
469 DirichletBuilder handle( *
this,
space_ ,
space_.blockMapper() );
470 space_.gridPart().communicate
471 ( handle, GridPartType::indexSetInterfaceType, ForwardCommunication );
474 catch(
const Exception &e )
476 std::cerr << e << std::endl;
477 std::cerr <<
"Exception thrown in: " << __FILE__ <<
" line:" << __LINE__ << std::endl;
490 template<
class EntityType >
493 typedef typename DiscreteFunctionSpaceType :: GridPartType
GridPartType;
495 typedef typename GridPartType :: IntersectionIteratorType
496 IntersectionIteratorType;
501 bool hasDirichletBoundary =
false;
504 std::vector< size_t> globalBlockDofs(
space_.blockMapper().numDofs(entity));
505 space_.blockMapper().map(entity,globalBlockDofs);
507 std::vector< bool> globalBlockDofsFilter(
space_.blockMapper().numDofs(entity));
509 IntersectionIteratorType it = gridPart.ibegin( entity );
510 const IntersectionIteratorType endit = gridPart.iend( entity );
511 for( ; it != endit; ++it )
513 typedef typename IntersectionIteratorType :: Intersection IntersectionType;
514 const IntersectionType& intersection = *it;
517 if( intersection.boundary() )
522 const bool isDirichletIntersection = model.isDirichletIntersection( intersection, block );
523 if (isDirichletIntersection)
526 const int face = intersection.indexInInside();
527 space_.blockMapper().onSubEntity(entity,face,1,globalBlockDofsFilter);
528 for(
unsigned int i=0;i<globalBlockDofs.size();++i)
530 if ( !globalBlockDofsFilter[i] )
continue;
536 hasDirichletBoundary = true ;
542 return hasDirichletBoundary;
551 class DirichletBuilder;
554template <
class Model,
class Space >
556 :
public CommDataHandleIF< DirichletBuilder, int >
562 enum { nCodim = SpaceType :: GridType :: dimension + 1 };
576 static const int blockSize = SpaceType::localBlockSize;
582 : myRank_( space.gridPart().comm().rank() ),
583 mySize_( space.gridPart().comm().size() ),
584 dirichlet_( dirichlet ),
591 return mapper_.contains( codim );
600 template<
class MessageBuffer,
class Entity >
601 inline void gather ( MessageBuffer &buffer,
602 const Entity &entity )
const
604 unsigned int localBlocks = mapper_.numEntityDofs( entity );
605 std::vector<std::size_t> globalBlockDofs(localBlocks);
606 mapper_.mapEntityDofs( entity, globalBlockDofs );
607 assert( size(entity) == globalBlockDofs.size()*blockSize );
608 for(
unsigned int localBlock = 0 ; localBlock < globalBlockDofs.size(); ++ localBlock )
610 int global = globalBlockDofs[localBlock];
611 for (
int r=0;r<blockSize;++r)
623 template<
class MessageBuffer,
class EntityType >
625 const EntityType &entity,
628 unsigned int localBlocks = mapper_.numEntityDofs( entity );
629 std::vector<std::size_t> globalBlockDofs(localBlocks);
630 mapper_.mapEntityDofs( entity, globalBlockDofs );
631 assert( n == globalBlockDofs.size()*blockSize );
632 assert( n == size(entity) );
633 for(
unsigned int localBlock = 0 ; localBlock < globalBlockDofs.size(); ++ localBlock )
635 int global = globalBlockDofs[localBlock];
636 for (
int r=0;r<blockSize;++r)
646 template<
class Entity >
647 size_t size (
const Entity &entity )
const
649 return blockSize * mapper_.numEntityDofs( entity );
Definition: bindguard.hh:11
typename Impl::ConstLocalFunction< GridFunction >::Type ConstLocalFunction
Definition: const.hh:604
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:14
static auto bindGuard(Object &object, Args &&... args) -> std::enable_if_t< isBindable< Object, Args... >::value, BindGuard< Object > >
Definition: bindguard.hh:67
Definition: common/localcontribution.hh:14
A local matrix with a small array as storage.
Definition: temporarylocalmatrix.hh:100
Definition: dirichletconstraints.hh:59
std::array< int, localBlockSize > DirichletBlock
Definition: dirichletconstraints.hh:79
DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: dirichletconstraints.hh:66
Operation
Definition: dirichletconstraints.hh:61
@ set
Definition: dirichletconstraints.hh:61
@ sub
Definition: dirichletconstraints.hh:61
DirichletBlockVector dirichletBlocks_
Definition: dirichletconstraints.hh:547
DiscreteFunctionSpaceType::DomainType DomainType
Definition: dirichletconstraints.hh:64
DiscreteFunctionSpaceType::RangeType RangeType
Definition: dirichletconstraints.hh:65
void dirichletDofTreatment(const LocalInterpolationType &interpolation, const GridLocalFunctionType &uLocal, LocalFunctionType &wLocal, Operation op) const
Definition: dirichletconstraints.hh:385
static const int localBlockSize
Definition: dirichletconstraints.hh:76
DiscreteFunctionSpaceType::GridPartType GridPartType
type of grid partition
Definition: dirichletconstraints.hh:70
void updateDirichletDofs() const
Definition: dirichletconstraints.hh:431
Model ModelType
Definition: dirichletconstraints.hh:62
void applyToOperator(LinearOperator &linearOperator) const
Definition: dirichletconstraints.hh:266
const DirichletBlockVector & dirichletBlocks() const
Definition: dirichletconstraints.hh:297
bool hasDirichletDofs_
Definition: dirichletconstraints.hh:548
const DiscreteFunctionSpaceType & space_
Definition: dirichletconstraints.hh:546
std::vector< DirichletBlock > DirichletBlockVector
Definition: dirichletconstraints.hh:80
ModelType & model_
Definition: dirichletconstraints.hh:545
void operator()(const DiscreteFunctionType &u, DiscreteFunctionType &w) const
Definition: dirichletconstraints.hh:131
int sequence_
Definition: dirichletconstraints.hh:549
void dirichletDofsCorrectOnEntity(const EntityType &entity, LocalMatrix &localMatrix) const
Definition: dirichletconstraints.hh:314
DiscreteFunctionSpaceType::GridType GridType
type of grid
Definition: dirichletconstraints.hh:72
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: dirichletconstraints.hh:63
DirichletConstraints(ModelType &model, const DiscreteFunctionSpaceType &space)
Definition: dirichletconstraints.hh:114
bool searchEntityDirichletDofs(const EntityType &entity, ModelType &model) const
Definition: dirichletconstraints.hh:491
DiscreteFunctionSpaceType::HessianRangeType HessianRangeType
Definition: dirichletconstraints.hh:67
void dirichletDofTreatment(const LocalInterpolationType &interpolation, LocalFunctionType &wLocal) const
set the Dirichlet points to exact values
Definition: dirichletconstraints.hh:351
Definition: dirichletconstraints.hh:85
DiscreteFunctionSpaceType::DomainType DomainType
Definition: dirichletconstraints.hh:89
BoundaryWrapper(const ModelType &impl, const EntityType &entity, const int order, int bndId)
Definition: dirichletconstraints.hh:102
DiscreteFunctionSpace::HessianRangeType HessianRangeType
Definition: dirichletconstraints.hh:92
DiscreteFunctionSpace::JacobianRangeType JacobianRangeType
Definition: dirichletconstraints.hh:91
static const int dimRange
Definition: dirichletconstraints.hh:101
const EntityType & entity() const
Definition: dirichletconstraints.hh:104
const int order() const
Definition: dirichletconstraints.hh:105
DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType
Definition: dirichletconstraints.hh:88
void jacobian(const Point &x, JacobianRangeType &ret) const
Definition: dirichletconstraints.hh:110
void evaluate(const Point &x, RangeType &ret) const
Definition: dirichletconstraints.hh:107
DiscreteFunctionSpace::RangeType RangeType
Definition: dirichletconstraints.hh:90
DiscreteFunctionSpaceType::EntityType EntityType
Definition: dirichletconstraints.hh:87
Definition: dirichletconstraints.hh:557
DirichletConstraints< Model, Space > DirichletType
Definition: dirichletconstraints.hh:570
void gather(MessageBuffer &buffer, const Entity &entity) const
read buffer and apply operation
Definition: dirichletconstraints.hh:601
const SpaceType & space_
Definition: dirichletconstraints.hh:573
int DataType
Definition: dirichletconstraints.hh:565
DirichletBuilder(const DirichletType &dirichlet, const SpaceType &space, const MapperType &mapper)
Definition: dirichletconstraints.hh:579
bool contains(int dim, int codim) const
Definition: dirichletconstraints.hh:589
bool fixedSize(int dim, int codim) const
Definition: dirichletconstraints.hh:594
const int mySize_
Definition: dirichletconstraints.hh:568
const int myRank_
Definition: dirichletconstraints.hh:567
void scatter(MessageBuffer &buffer, const EntityType &entity, size_t n)
Definition: dirichletconstraints.hh:624
size_t size(const Entity &entity) const
return local dof size to be communicated
Definition: dirichletconstraints.hh:647
Space SpaceType
Definition: dirichletconstraints.hh:559
const MapperType & mapper_
Definition: dirichletconstraints.hh:574
const DirichletType & dirichlet_
Definition: dirichletconstraints.hh:571
SpaceType::BlockMapperType MapperType
Definition: dirichletconstraints.hh:560
Definition: common/localinterpolation.hh:22