40 #ifndef DUNE_DIRICHLETCONSTRAINTS_HH
41 #define DUNE_DIRICHLETCONSTRAINTS_HH
53 class HasLocalFunction;
56 template <
class Model,
class DiscreteFunctionSpace >
63 typedef typename DiscreteFunctionSpaceType::DomainType
DomainType;
64 typedef typename DiscreteFunctionSpaceType::RangeType
RangeType;
69 typedef typename DiscreteFunctionSpaceType :: GridPartType
GridPartType;
71 typedef typename DiscreteFunctionSpaceType :: GridType
GridType;
75 static const int localBlockSize = DiscreteFunctionSpaceType :: localBlockSize ;
76 static_assert(
localBlockSize == DiscreteFunctionSpaceType::FunctionSpaceType::dimRange,
77 "local block size of the space must be identical to the dimension of the range of the function space.");
88 typedef typename DiscreteFunctionSpaceType::EntityType
EntityType;
90 typedef typename DiscreteFunctionSpaceType::DomainType
DomainType;
91 typedef typename DiscreteFunctionSpace::RangeType
RangeType;
94 static const int dimRange = RangeType::dimension;
96 : impl_( impl ), bndId_(bndId) {}
97 template <
class Po
int>
100 template <
class Po
int>
102 { DUNE_THROW(Dune::NotImplemented,
"rhs jacobian not implemented"); }
121 template <
class DiscreteFunctionType >
122 void operator ()(
const DiscreteFunctionType& u, DiscreteFunctionType& w )
const
129 typedef typename DiscreteFunctionType :: DofIteratorType DofIteratorType ;
130 typedef typename DiscreteFunctionType :: ConstDofIteratorType ConstDofIteratorType ;
132 ConstDofIteratorType uIt = u.dbegin();
133 DofIteratorType wIt = w.dbegin();
136 const unsigned int blocks =
space_.blockMapper().size();
137 for(
unsigned int blockDof = 0; blockDof < blocks ; ++ blockDof )
144 assert( uIt != u.dend() );
145 assert( wIt != w.dend() );
159 template <
class DiscreteFunctionType >
160 void operator ()(
const typename DiscreteFunctionType::RangeType& value, DiscreteFunctionType& w )
const
167 typedef typename DiscreteFunctionType :: DofIteratorType DofIteratorType ;
169 DofIteratorType wIt = w.dbegin();
172 const unsigned int blocks =
space_.blockMapper().size();
173 for(
unsigned int blockDof = 0; blockDof < blocks ; ++ blockDof )
180 assert( wIt != w.dend() );
195 template <
class DiscreteFunctionType >
202 typedef typename DiscreteFunctionSpaceType :: IteratorType IteratorType;
203 typedef typename IteratorType :: Entity EntityType;
206 for(
const EntityType &entity :
space_ )
216 template <
class GridFunctionType,
class DiscreteFunctionType,
217 typename = std::enable_if_t< std::is_base_of<Dune::Fem::HasLocalFunction, GridFunctionType>::value > >
219 DiscreteFunctionType& w,
Operation op=Operation::setDF )
const
228 for(
const auto &entity :
space_ )
248 template <
class LinearOperator>
253 typedef typename DiscreteFunctionSpaceType :: IteratorType IteratorType;
254 typedef typename IteratorType :: Entity EntityType;
259 typedef typename LinearOperator::DomainSpaceType DomainSpaceType;
260 typedef typename LinearOperator::RangeSpaceType RangeSpaceType;
262 TemporaryLocalMatrixType localMatrix( linearOperator.domainSpace(), linearOperator.rangeSpace() );
264 const IteratorType end =
space_.end();
265 for( IteratorType it =
space_.begin(); it != end; ++it )
267 const EntityType &entity = *it;
269 localMatrix.init( entity, entity );
271 linearOperator.getLocalMatrix( entity, entity, localMatrix );
275 linearOperator.setLocalMatrix( entity, entity, localMatrix );
296 template<
class EntityType,
class LocalMatrix >
298 LocalMatrix& localMatrix )
const
301 const auto &auxiliaryDofs = localMatrix.rangeSpace().auxiliaryDofs();
304 const int localBlocks =
space_.blockMapper().numDofs( entity );
307 std::vector<std::size_t> globalBlockDofs(localBlocks);
309 space_.blockMapper().map( entity, globalBlockDofs );
314 for(
int localBlockDof = 0 ; localBlockDof < localBlocks; ++ localBlockDof )
316 int global = globalBlockDofs[localBlockDof];
322 localMatrix.clearRow( localDof );
325 double value = auxiliaryDofs.contains( global )? 0.0 : 1.0;
326 localMatrix.set( localDof, localDof, value );
333 template<
class LocalFunctionType >
337 const typename LocalFunctionType::EntityType &entity = wLocal.entity();
340 const int localBlocks =
space_.blockMapper().numDofs( entity );
343 std::vector<std::size_t> globalBlockDofs(localBlocks);
344 space_.blockMapper().map(entity,globalBlockDofs);
345 std::vector<typename LocalFunctionType::RangeFieldType> values( localBlocks*
localBlockSize );
350 for(
int localBlock = 0 ; localBlock < localBlocks; ++ localBlock )
353 int global = globalBlockDofs[localBlock];
358 space_.interpolation(entity)
361 assert( (
unsigned int)localDof < wLocal.size() );
362 wLocal[ localDof ] = values[ localDof ];
367 template<
class Gr
idLocalFunctionType,
class LocalFunctionType >
369 LocalFunctionType &wLocal,
Operation op )
const
372 const typename LocalFunctionType::EntityType &entity = wLocal.entity();
375 const int localBlocks =
space_.blockMapper().numDofs( entity );
378 std::vector<std::size_t> globalBlockDofs(localBlocks);
379 space_.blockMapper().map(entity,globalBlockDofs);
382 space_.interpolation(entity)(uLocal, values);
387 for(
int localBlock = 0 ; localBlock < localBlocks; ++ localBlock )
390 int global = globalBlockDofs[localBlock];
397 space_.interpolation(entity)
399 values[ localDof ] -= valuesModel[ localDof ];
402 assert( (
unsigned int)localDof < wLocal.size() );
403 wLocal[ localDof ] = values[ localDof ];
416 if( !
model_.hasDirichletBoundary() )
423 const int blocks =
space_.blockMapper().size() ;
425 for(
int i=0; i<blocks; ++i )
428 typedef typename DiscreteFunctionSpaceType :: IteratorType IteratorType;
429 typedef typename IteratorType :: Entity EntityType;
431 bool hasDirichletBoundary =
false;
432 const IteratorType end =
space_.end();
433 for( IteratorType it =
space_.begin(); it != end; ++it )
435 const EntityType &entity = *it;
437 if( entity.hasBoundaryIntersections() )
445 if(
space_.gridPart().comm().size() > 1 )
449 DirichletBuilder handle( *
this,
space_ ,
space_.blockMapper() );
450 space_.gridPart().communicate
451 ( handle, GridPartType::indexSetInterfaceType, ForwardCommunication );
454 catch(
const Exception &e )
456 std::cerr << e << std::endl;
457 std::cerr <<
"Exception thrown in: " << __FILE__ <<
" line:" << __LINE__ << std::endl;
470 template<
class EntityType >
473 typedef typename DiscreteFunctionSpaceType :: GridPartType
GridPartType;
475 typedef typename GridPartType :: IntersectionIteratorType
476 IntersectionIteratorType;
481 bool hasDirichletBoundary =
false;
484 std::vector< size_t> globalBlockDofs(
space_.blockMapper().numDofs(entity));
485 space_.blockMapper().map(entity,globalBlockDofs);
487 std::vector< bool> globalBlockDofsFilter(
space_.blockMapper().numDofs(entity));
489 IntersectionIteratorType it = gridPart.ibegin( entity );
490 const IntersectionIteratorType endit = gridPart.iend( entity );
491 for( ; it != endit; ++it )
493 typedef typename IntersectionIteratorType :: Intersection IntersectionType;
494 const IntersectionType& intersection = *it;
497 if( intersection.boundary() )
502 const bool isDirichletIntersection = model.isDirichletIntersection( intersection, block );
503 if (isDirichletIntersection)
506 const int face = intersection.indexInInside();
507 space_.blockMapper().onSubEntity(entity,face,1,globalBlockDofsFilter);
508 for(
unsigned int i=0;i<globalBlockDofs.size();++i)
510 if ( !globalBlockDofsFilter[i] )
continue;
516 hasDirichletBoundary = true ;
522 return hasDirichletBoundary;
531 class DirichletBuilder;
534 template <
class Model,
class Space >
536 :
public CommDataHandleIF< DirichletBuilder, int >
542 enum { nCodim = SpaceType :: GridType :: dimension + 1 };
556 static const int blockSize = SpaceType::localBlockSize;
562 : myRank_( space.gridPart().comm().rank() ),
563 mySize_( space.gridPart().comm().size() ),
564 dirichlet_( dirichlet ),
571 return mapper_.contains( codim );
580 template<
class MessageBuffer,
class Entity >
581 inline void gather ( MessageBuffer &buffer,
582 const Entity &entity )
const
584 unsigned int localBlocks = mapper_.numEntityDofs( entity );
585 std::vector<std::size_t> globalBlockDofs(localBlocks);
586 mapper_.mapEntityDofs( entity, globalBlockDofs );
587 assert( size(entity) == globalBlockDofs.size()*blockSize );
588 for(
unsigned int localBlock = 0 ; localBlock < globalBlockDofs.size(); ++ localBlock )
590 int global = globalBlockDofs[localBlock];
591 for (
int r=0;r<blockSize;++r)
603 template<
class MessageBuffer,
class EntityType >
605 const EntityType &entity,
608 unsigned int localBlocks = mapper_.numEntityDofs( entity );
609 std::vector<std::size_t> globalBlockDofs(localBlocks);
610 mapper_.mapEntityDofs( entity, globalBlockDofs );
611 assert( n == globalBlockDofs.size()*blockSize );
612 assert( n == size(entity) );
613 for(
unsigned int localBlock = 0 ; localBlock < globalBlockDofs.size(); ++ localBlock )
615 int global = globalBlockDofs[localBlock];
616 for (
int r=0;r<blockSize;++r)
626 template<
class Entity >
627 size_t size (
const Entity &entity )
const
629 return blockSize * mapper_.numEntityDofs( entity );
Definition: bindguard.hh:11
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:14
typename Impl::ConstLocalFunction< GridFunction >::Type ConstLocalFunction
Definition: const.hh:517
static auto bindGuard(Object &object, Args &&... args) -> std::enable_if_t< isBindable< Object, Args... >::value, BindGuard< Object > >
Definition: bindguard.hh:67
static constexpr T sub(T a)
Definition: utility.hh:61
Definition: common/localcontribution.hh:14
A local matrix with a small array as storage.
Definition: temporarylocalmatrix.hh:100
Definition: dirichletconstraints.hh:58
std::array< int, localBlockSize > DirichletBlock
Definition: dirichletconstraints.hh:77
DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: dirichletconstraints.hh:65
Operation
Definition: dirichletconstraints.hh:60
@ set
Definition: dirichletconstraints.hh:60
@ sub
Definition: dirichletconstraints.hh:60
DirichletBlockVector dirichletBlocks_
Definition: dirichletconstraints.hh:527
DiscreteFunctionSpaceType::DomainType DomainType
Definition: dirichletconstraints.hh:63
DiscreteFunctionSpaceType::RangeType RangeType
Definition: dirichletconstraints.hh:64
static const int localBlockSize
Definition: dirichletconstraints.hh:75
const DirichletBlockVector & dirichletBlocks() const
Definition: dirichletconstraints.hh:280
void dirichletDofTreatment(LocalFunctionType &wLocal) const
set the dirichlet points to exact values
Definition: dirichletconstraints.hh:334
DiscreteFunctionSpaceType ::GridPartType GridPartType
type of grid partition
Definition: dirichletconstraints.hh:69
void updateDirichletDofs() const
Definition: dirichletconstraints.hh:411
Model ModelType
Definition: dirichletconstraints.hh:61
void applyToOperator(LinearOperator &linearOperator) const
Definition: dirichletconstraints.hh:249
bool hasDirichletDofs_
Definition: dirichletconstraints.hh:528
const DiscreteFunctionSpaceType & space_
Definition: dirichletconstraints.hh:526
std::vector< DirichletBlock > DirichletBlockVector
Definition: dirichletconstraints.hh:79
DiscreteFunctionSpaceType ::GridType GridType
type of grid
Definition: dirichletconstraints.hh:71
ModelType & model_
Definition: dirichletconstraints.hh:525
void operator()(const DiscreteFunctionType &u, DiscreteFunctionType &w) const
Definition: dirichletconstraints.hh:122
int sequence_
Definition: dirichletconstraints.hh:529
void dirichletDofsCorrectOnEntity(const EntityType &entity, LocalMatrix &localMatrix) const
Definition: dirichletconstraints.hh:297
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: dirichletconstraints.hh:62
DirichletConstraints(ModelType &model, const DiscreteFunctionSpaceType &space)
Definition: dirichletconstraints.hh:105
bool searchEntityDirichletDofs(const EntityType &entity, ModelType &model) const
Definition: dirichletconstraints.hh:471
DiscreteFunctionSpaceType::HessianRangeType HessianRangeType
Definition: dirichletconstraints.hh:66
void dirichletDofTreatment(const GridLocalFunctionType &uLocal, LocalFunctionType &wLocal, Operation op) const
Definition: dirichletconstraints.hh:368
Definition: dirichletconstraints.hh:84
DiscreteFunctionSpaceType::DomainType DomainType
Definition: dirichletconstraints.hh:90
DiscreteFunctionSpace::HessianRangeType HessianRangeType
Definition: dirichletconstraints.hh:93
DiscreteFunctionSpace::JacobianRangeType JacobianRangeType
Definition: dirichletconstraints.hh:92
static const int dimRange
Definition: dirichletconstraints.hh:94
DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType
Definition: dirichletconstraints.hh:89
void jacobian(const Point &x, JacobianRangeType &ret) const
Definition: dirichletconstraints.hh:101
void evaluate(const Point &x, RangeType &ret) const
Definition: dirichletconstraints.hh:98
DiscreteFunctionSpace::RangeType RangeType
Definition: dirichletconstraints.hh:91
DiscreteFunctionSpaceType::EntityType EntityType
Definition: dirichletconstraints.hh:88
BoundaryWrapper(const ModelType &impl, int bndId)
Definition: dirichletconstraints.hh:95
Definition: dirichletconstraints.hh:537
DirichletConstraints< Model, Space > DirichletType
Definition: dirichletconstraints.hh:550
void gather(MessageBuffer &buffer, const Entity &entity) const
read buffer and apply operation
Definition: dirichletconstraints.hh:581
const SpaceType & space_
Definition: dirichletconstraints.hh:553
int DataType
Definition: dirichletconstraints.hh:545
DirichletBuilder(const DirichletType &dirichlet, const SpaceType &space, const MapperType &mapper)
Definition: dirichletconstraints.hh:559
bool contains(int dim, int codim) const
Definition: dirichletconstraints.hh:569
bool fixedSize(int dim, int codim) const
Definition: dirichletconstraints.hh:574
const int mySize_
Definition: dirichletconstraints.hh:548
const int myRank_
Definition: dirichletconstraints.hh:547
void scatter(MessageBuffer &buffer, const EntityType &entity, size_t n)
Definition: dirichletconstraints.hh:604
size_t size(const Entity &entity) const
return local dof size to be communicated
Definition: dirichletconstraints.hh:627
Space SpaceType
Definition: dirichletconstraints.hh:539
const MapperType & mapper_
Definition: dirichletconstraints.hh:554
const DirichletType & dirichlet_
Definition: dirichletconstraints.hh:551
SpaceType::BlockMapperType MapperType
Definition: dirichletconstraints.hh:540