1#ifndef DUNE_FEM_SOLVER_COMMUNICATION_OWNEROVERLAPCOPY_HH
2#define DUNE_FEM_SOLVER_COMMUNICATION_OWNEROVERLAPCOPY_HH
12#include <dune/common/parallel/remoteindices.hh>
14#include <dune/grid/common/datahandleif.hh>
16#include <dune/istl/owneroverlapcopy.hh>
33 template<
class DiscreteFunctionSpace >
34 using OwnerOverlapCopyCommunication = Dune::OwnerOverlapCopyCommunication< std::size_t, typename DiscreteFunctionSpace::BlockMapperType::GlobalKeyType >;
41 template<
class Mapper,
class GlobalLookup >
43 :
public Dune::CommDataHandleIF< BuildRemoteIndicesDataHandle< Mapper, GlobalLookup >, int >
49 : rank_( rank ), mapper_( mapper ), globalLookup_( globalLookup )
52 bool contains (
int dim,
int codim )
const {
return mapper_.contains( codim ); }
53 bool fixedSize(
int dim,
int codim )
const {
return true; }
55 template<
class Buffer,
class Entity >
56 void gather ( Buffer &buffer,
const Entity &entity )
const
58 buffer.write( rank_ );
60 mapper_.mapEachEntityDof( entity, [
this, &attribute ] (
int,
auto index ) {
61 auto *pair = globalLookup_.pair( index );
62 assert( pair && ((attribute == -1) || (attribute == pair->local().attribute())) );
63 attribute = pair->local().attribute();
65 buffer.write(
static_cast< int >( attribute ) );
68 template<
class Buffer,
class Entity >
69 void scatter ( Buffer &buffer,
const Entity &entity, std::size_t n )
73 buffer.read( attribute );
74 assert( (attribute != -1) || (mapper_.numEntityDofs( entity ) == 0) );
75 mapper_.mapEachEntityDof( entity, [
this, rank, attribute ] (
int,
auto index ) {
76 auto *pair = globalLookup_.pair( index );
82 template<
class Entity >
83 std::size_t
size (
const Entity &entity )
const
88 std::map< int, std::vector< Dune::RemoteIndex< GlobalIndexType, AttributeType > > >
remotes;
92 const Mapper &mapper_;
93 const GlobalLookup &globalLookup_;
98 template<
class DiscreteFunctionSpace,
class GlobalId,
class LocalId >
100 Dune::SolverCategory::Category solverCategory,
101 std::shared_ptr< Dune::OwnerOverlapCopyCommunication< GlobalId, LocalId > > &communication )
103 typedef typename DiscreteFunctionSpace::GridPartType GridPartType;
104 typedef typename DiscreteFunctionSpace::BlockMapperType LocalMapperType;
106 typedef typename Dune::OwnerOverlapCopyCommunication< GlobalId, LocalId >::GlobalLookupIndexSet GlobalLookupType;
108 typedef typename GlobalLookupType::LocalIndex LocalIndexType;
110 communication.reset(
new Dune::OwnerOverlapCopyCommunication< GlobalId, LocalId >( solverCategory ) );
112 const GridPartType &gridPart = dfSpace.gridPart();
113 LocalMapperType &localMapper = dfSpace.blockMapper();
119 std::vector< typename LocalIndexType::Attribute > attribute( localMapper.size(), Dune::OwnerOverlapCopyAttributeSet::owner );
120 for(
const auto &auxiliary : dfSpace.auxiliaryDofs() )
121 attribute[ auxiliary ] = Dune::OwnerOverlapCopyAttributeSet::copy;
124 communication->indexSet().beginResize();
125 for( LocalId i = 0, size = localMapper.size(); i < size; ++i )
126 communication->indexSet().add( globalMapper.
mapping()[ i ], LocalIndexType( i, attribute[ i ] ) );
127 communication->indexSet().endResize();
130 communication->buildGlobalLookup();
132 gridPart.communicate( buildRemoteIndicesDataHandle, Dune::All_All_Interface, Dune::ForwardCommunication );
133 communication->freeGlobalLookup();
135 communication->remoteIndices().setIndexSets( communication->indexSet(), communication->indexSet(), communication->communicator() );
136 if( !buildRemoteIndicesDataHandle.
remotes.empty() )
138 for(
auto &remote : buildRemoteIndicesDataHandle.
remotes )
140 std::sort( remote.second.begin(), remote.second.end(), [] (
const auto &a,
const auto &b ) { return (a.localIndexPair().global() < b.localIndexPair().global()); } );
141 auto modifier = communication->remoteIndices().template getModifier< false, true >( remote.first );
142 for(
const auto &remoteIndex : remote.second )
143 modifier.insert( remoteIndex );
147 communication->remoteIndices().template getModifier< false, true >( 0 );
158 template<
class GlobalId,
class LocalId >
160 :
public std::true_type
Definition: bindguard.hh:11
Dune::OwnerOverlapCopyCommunication< std::size_t, typename DiscreteFunctionSpace::BlockMapperType::GlobalKeyType > OwnerOverlapCopyCommunication
Definition: owneroverlapcopy.hh:34
void buildCommunication(const DiscreteFunctionSpace &dfSpace, Dune::SolverCategory::Category solverCategory, std::shared_ptr< FemCommunication< DiscreteFunctionSpace > > &communication)
Definition: fem.hh:143
Definition: owneroverlapcopy.hh:44
GlobalLookup::LocalIndex::Attribute AttributeType
Definition: owneroverlapcopy.hh:46
void gather(Buffer &buffer, const Entity &entity) const
Definition: owneroverlapcopy.hh:56
BuildRemoteIndicesDataHandle(int rank, const Mapper &mapper, const GlobalLookup &globalLookup)
Definition: owneroverlapcopy.hh:48
std::size_t size(const Entity &entity) const
Definition: owneroverlapcopy.hh:83
bool contains(int dim, int codim) const
Definition: owneroverlapcopy.hh:52
std::map< int, std::vector< Dune::RemoteIndex< GlobalIndexType, AttributeType > > > remotes
Definition: owneroverlapcopy.hh:88
GlobalLookup::GlobalIndex GlobalIndexType
Definition: owneroverlapcopy.hh:45
void scatter(Buffer &buffer, const Entity &entity, std::size_t n)
Definition: owneroverlapcopy.hh:69
bool fixedSize(int dim, int codim) const
Definition: owneroverlapcopy.hh:53
Definition: parallel.hh:87
const std::vector< GlobalKeyType > & mapping() const
Definition: parallel.hh:197