1#ifndef DUNE_FEM_SPACE_COMMON_AUXILIARYDOFS_HH
2#define DUNE_FEM_SPACE_COMMON_AUXILIARYDOFS_HH
19#include <dune/grid/common/gridenums.hh>
22#include <dune/fem/storage/singletonlist.hh>
23#include <dune/fem/misc/mpimanager.hh>
24#include <dune/fem/space/common/commindexmap.hh>
25#include <dune/fem/storage/envelope.hh>
44 template<
class Gr
idPart,
class Mapper >
59 typedef Fem :: CommunicationIndexMap IndexMapType;
65 IndexMapType auxiliarys_;
68 typedef typename IndexMapType :: IndexType IndexType;
72 typedef std::forward_iterator_tag iterator_category;
73 typedef const IndexType value_type;
74 typedef IndexType difference_type;
75 typedef IndexType* pointer;
76 typedef IndexType& reference;
78 ConstIterator () =
default;
79 ConstIterator (
const IndexMapType &auxiliarys, IndexType index ) : auxiliarys_( &auxiliarys ), index_( index ) {}
81 const IndexType &operator* ()
const {
return (*auxiliarys_)[ index_ ]; }
82 const IndexType *operator-> ()
const {
return &(*auxiliarys_)[ index_ ]; }
84 const IndexType &
operator[] ( IndexType n )
const noexcept {
return (*auxiliarys_)[ index_ + n ]; }
86 bool operator== (
const ConstIterator &other )
const {
return (index_ == other.index_); }
87 bool operator!= (
const ConstIterator &other )
const {
return (index_ != other.index_); }
89 ConstIterator &operator++ () { ++index_;
return *
this; }
90 ConstIterator operator++ (
int ) { ConstIterator copy( *
this ); ++(*this);
return copy; }
92 ThisType &operator-- ()
noexcept { --index_;
return *
this; }
93 ThisType operator-- (
int )
noexcept {
ThisType copy( *
this ); --(*this);
return copy; }
95 ThisType &operator+= ( IndexType n )
noexcept { index_ += n;
return *
this; }
96 ThisType &operator-= ( IndexType n )
noexcept { index_ -= n;
return *
this; }
98 ThisType operator+ ( IndexType n )
const noexcept {
return ThisType( index_ + n ); }
99 ThisType operator- ( IndexType n )
const noexcept {
return ThisType( index_ - n ); }
101 friend ThisType operator+ ( IndexType n,
const ThisType &i )
noexcept {
return i + n; }
103 IndexType operator- (
const ThisType &other )
const noexcept {
return (index_ - other.index_); }
105 bool operator< (
const ThisType &other )
const noexcept {
return (index_ < other.index_); }
106 bool operator<= (
const ThisType &other )
const noexcept {
return (index_ <= other.index_); }
107 bool operator>= (
const ThisType &other )
const noexcept {
return (index_ >= other.index_); }
108 bool operator> (
const ThisType &other )
const noexcept {
return (index_ > other.index_); }
111 const IndexMapType *auxiliarys_ =
nullptr;
112 IndexType index_ = 0;
116 : gridPart_( gridPart ), mapper_( mapper )
119 AuxiliaryDofs (
const AuxiliaryDofs& ) =
delete;
124 return auxiliarys_[ index ];
130 return auxiliarys_.size();
136 const IndexType last = auxiliarys_.size() - 1;
139 return auxiliarys_[ last ] - last ;
142 ConstIterator begin ()
const {
return ConstIterator( auxiliarys_, 0 ); }
143 ConstIterator end ()
const { assert(
size() > 0 );
return ConstIterator( auxiliarys_,
size()-1 ); }
146 bool contains ( IndexType index )
const {
return std::binary_search( begin(), end(), index ); }
148 [[deprecated(
"Use contains instead")]]
149 bool isSlave ( IndexType index )
const {
return contains( index ); }
153 std::set< IndexType > auxiliarySet;
154 buildMaps( auxiliarySet );
156 auxiliarys_.set( auxiliarySet );
159 const GridPartType &gridPart ()
const {
return gridPart_; }
162 void buildMaps ( std::set< IndexType > &auxiliarySet )
165 for(
int codim = 1; codim <= GridPartType::dimension; ++codim )
168 return buildCommunicatedMaps( auxiliarySet );
170 return buildDiscontinuousMaps( auxiliarySet );
173 void buildDiscontinuousMaps ( std::set< IndexType > &auxiliarySet )
176 const auto idxpitype = GridPartType::indexSetPartitionType;
177 for(
auto it = gridPart().
template begin< 0, idxpitype >(), end = gridPart().
template end< 0, idxpitype >(); it != end; ++it )
179 const auto& entity = *it;
181 mapper_.mapEachEntityDof( entity, [ &auxiliarySet ] ( IndexType, IndexType value ) { auxiliarySet.insert( value ); } );
184 auxiliarySet.insert( mapper_.
size() );
187 void buildCommunicatedMaps ( std::set< IndexType > &auxiliarySet )
191 if( gridPart().comm().
size() > 1 )
195 LinkBuilder handle( auxiliarySet, gridPart(), mapper_ );
198 catch(
const Exception &e )
200 std::cerr << e << std::endl <<
"Exception thrown in: " << __FILE__ <<
" line:" << __LINE__ << std::endl;
205 auxiliarySet.insert( mapper_.
size() );
214 template<
class Gr
idPart,
class Mapper >
215 class AuxiliaryDofs< GridPart, Mapper >::LinkBuilder
216 :
public CommDataHandleIF< LinkBuilder, int >
219 LinkBuilder( std::set< IndexType > &auxiliarySet,
const GridPartType &gridPart,
const MapperType &mapper )
220 : myRank_( gridPart.comm().rank() ), mySize_( gridPart.comm().
size() ),
221 auxiliarySet_( auxiliarySet ), mapper_( mapper )
224 bool contains (
int dim,
int codim )
const {
return mapper_.
contains( codim ); }
225 bool fixedSize (
int dim,
int codim )
const {
return false; }
228 template<
class MessageBuffer,
class Entity >
232 if( sendRank( entity ) )
233 buffer.write( myRank_ );
240 template<
class MessageBuffer,
class EntityType >
241 void scatter ( MessageBuffer &buffer,
const EntityType &entity, std::size_t n )
248 assert( (rank >= 0) && (rank < mySize_) );
251 if ( rank < myRank_ || ! sendRank( entity ) )
252 mapper_.mapEachEntityDof( entity, [
this](
const int ,
const auto& value ){auxiliarySet_.insert( value );} );
257 template<
class Entity >
260 return (sendRank( entity )) ? 1 : 0;
264 template <
class Entity>
265 bool sendRank(
const Entity& entity)
const
272 int myRank_, mySize_;
273 std::set< IndexType > &auxiliarySet_;
284 template <
class AuxiliaryDofs,
class F>
288 const size_t auxiliarySize = auxiliaryDofs.size() - 1;
289 for(
size_t auxiliary = 0; auxiliary<auxiliarySize; ++auxiliary)
292 f( auxiliaryDofs[auxiliary] );
302 template <
class AuxiliaryDofs,
class F>
305 const size_t numAuxiliarys = auxiliaryDofs.size();
306 for(
size_t auxiliary = 0, dof = 0 ; auxiliary < numAuxiliarys; ++auxiliary, ++dof )
308 const size_t nextAuxiliary = auxiliaryDofs[ auxiliary ];
309 for(; dof < nextAuxiliary; ++dof )
327 template<
class AuxiliaryDofs >
330 template<
class Gr
idPart,
class Mapper >
334 typedef typename AuxiliaryDofsType :: IndexType IndexType;
338 typedef std::forward_iterator_tag iterator_category;
339 typedef IndexType value_type;
340 typedef std::ptrdiff_t difference_type;
341 typedef Envelope< IndexType > pointer;
342 typedef IndexType reference;
344 ConstIterator () =
default;
346 ConstIterator ( IndexType index, IndexType auxiliary )
347 : index_( index ), auxiliary_( auxiliary )
350 ConstIterator (
const AuxiliaryDofsType &auxiliaryDofs, IndexType index, IndexType auxiliary )
351 : auxiliaryDofs_( &auxiliaryDofs ), index_( index ), auxiliary_( auxiliary )
356 IndexType operator* ()
const {
return index_; }
357 Envelope< IndexType > operator-> ()
const {
return Envelope< IndexType >( index_ ); }
359 bool operator== (
const ConstIterator &other )
const {
return (index_ == other.index_); }
360 bool operator!= (
const ConstIterator &other )
const {
return (index_ != other.index_); }
362 ConstIterator &operator++ () { ++index_; skipAuxiliarys();
return *
this; }
363 ConstIterator operator++ (
int ) { ConstIterator copy( *
this ); ++(*this);
return copy; }
365 const AuxiliaryDofsType &auxiliaryDofs ()
const { assert( auxiliaryDofs_ );
return *auxiliaryDofs_; }
367 bool contains(
const IndexType index )
const {
return ! auxiliaryDofs().contains( index ); }
370 void skipAuxiliarys ()
372 const IndexType aSize = auxiliaryDofs().size();
373 assert( auxiliary_ < aSize );
374 for( ; (index_ == auxiliaryDofs()[ auxiliary_ ]) && (++auxiliary_ != aSize); ++index_ )
378 const AuxiliaryDofsType *auxiliaryDofs_ =
nullptr;
379 IndexType index_ = 0, auxiliary_ = 0;
382 [[deprecated(
"Use forEachPrimaryDof instead!")]]
383 explicit PrimaryDofs (
const AuxiliaryDofsType &auxiliaryDofs )
384 : auxiliaryDofs_( auxiliaryDofs )
387 ConstIterator begin ()
const {
return ConstIterator( auxiliaryDofs_, 0, 0 ); }
388 ConstIterator end ()
const {
return ConstIterator( auxiliaryDofs_[ auxiliaryDofs_.size()-1 ], auxiliaryDofs_.size() ); }
390 IndexType
size ()
const {
return auxiliaryDofs_[ auxiliaryDofs_.size()-1 ] - (auxiliaryDofs_.size()-1); }
393 const AuxiliaryDofsType &auxiliaryDofs_;
401 template<
class AuxiliaryDofs >
402 [[deprecated(
"Use forEachPrimaryDof instead!" )]]
403 inline static PrimaryDofs< AuxiliaryDofs > primaryDofs (
const AuxiliaryDofs &auxiliaryDofs )
405 return PrimaryDofs< AuxiliaryDofs >( auxiliaryDofs );
408 template<
class AuxiliaryDofs >
409 [[deprecated(
"Use primaryDofs instead!" )]]
410 inline static PrimaryDofs< AuxiliaryDofs > masterDofs (
const AuxiliaryDofs &auxiliaryDofs )
412 return PrimaryDofs< AuxiliaryDofs >( auxiliaryDofs );
Wrapper class for entities.
Definition: entity.hh:66
PartitionType partitionType() const
Partition type of this entity.
Definition: entity.hh:127
In parallel computations the dofs of a discrete function are made up by all primary dofs....
Definition: auxiliarydofs.hh:46
Mapper interface.
Definition: mapper.hh:110
auto size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mapper.hh:152
bool contains(const EntityType &e, IndexType &result) const
Returns true if the entity is contained in the index set and at the same time the array index is retu...
Definition: mapper.hh:167
Describes the parallel communication interface class for MessageBuffers and DataHandles.
A few common exception classes.
Type traits to determine the type of reals (when working with complex numbers)
Implements a generic iterator class for writing stl conformant iterators.
GridPart GridPartType
type of grid part
Definition: auxiliarydofs.hh:53
static void forEachAuxiliaryDof(const AuxiliaryDofs &auxiliaryDofs, F &&f)
Apply action encoded in Functor f to all auxiliary dofs.
Definition: auxiliarydofs.hh:285
bool contains(IndexType index) const
return true if index is contained, meaning it is a auxiliary dof
Definition: auxiliarydofs.hh:146
IndexType operator[](const IndexType index) const
return dof number of auxiliary for index
Definition: auxiliarydofs.hh:122
IndexType size() const
return number of auxiliary dofs
Definition: auxiliarydofs.hh:128
std::size_t size(const Entity &entity) const
return local dof size to be communicated
Definition: auxiliarydofs.hh:258
Mapper MapperType
type of used mapper
Definition: auxiliarydofs.hh:56
void scatter(MessageBuffer &buffer, const EntityType &entity, std::size_t n)
Definition: auxiliarydofs.hh:241
IndexType primarySize() const
return number of primaryDofs
Definition: auxiliarydofs.hh:134
static void forEachPrimaryDof(const AuxiliaryDofs &auxiliaryDofs, F &&f)
Apply action encoded in Functor f to all primary dofs.
Definition: auxiliarydofs.hh:303
void gather(MessageBuffer &buffer, const Entity &entity) const
read buffer and apply operation
Definition: auxiliarydofs.hh:229
EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:638
EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:684
EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:661
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:238
EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:706
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:260
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
constexpr std::bool_constant<((II==value)||...)> contains(std::integer_sequence< T, II... >, std::integral_constant< T, value >)
Checks whether or not a given sequence contains a value.
Definition: integersequence.hh:137
In parallel computations the dofs of a discrete function are made up by all primary dofs....
Definition: auxiliarydofs.hh:328
Traits for type conversions and type information.
std::size_t fixedSize
The number of data items per index if it is fixed, 0 otherwise.
Definition: variablesizecommunicator.hh:264