dune-fem 2.8.0
Loading...
Searching...
No Matches
owneroverlapcopy.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SOLVER_COMMUNICATION_OWNEROVERLAPCOPY_HH
2#define DUNE_FEM_SOLVER_COMMUNICATION_OWNEROVERLAPCOPY_HH
3
4#include <cassert>
5
6#include <map>
7#include <memory>
8#include <type_traits>
9#include <utility>
10#include <vector>
11
12#include <dune/common/parallel/remoteindices.hh>
13
14#include <dune/grid/common/datahandleif.hh>
15
16#include <dune/istl/owneroverlapcopy.hh>
17
19
20
21namespace Dune
22{
23
24 namespace Fem
25 {
26
27 namespace ISTL
28 {
29
30 // OwnerOverlapCopyCommunication
31 // -----------------------------
32
33 template< class DiscreteFunctionSpace >
34 using OwnerOverlapCopyCommunication = Dune::OwnerOverlapCopyCommunication< std::size_t, typename DiscreteFunctionSpace::BlockMapperType::GlobalKeyType >;
35
36
37
38 // BuildRemoteIndicesDataHandle
39 // ----------------------------
40
41 template< class Mapper, class GlobalLookup >
43 : public Dune::CommDataHandleIF< BuildRemoteIndicesDataHandle< Mapper, GlobalLookup >, int >
44 {
45 typedef typename GlobalLookup::GlobalIndex GlobalIndexType;
46 typedef typename GlobalLookup::LocalIndex::Attribute AttributeType;
47
48 BuildRemoteIndicesDataHandle ( int rank, const Mapper &mapper, const GlobalLookup &globalLookup )
49 : rank_( rank ), mapper_( mapper ), globalLookup_( globalLookup )
50 {}
51
52 bool contains ( int dim, int codim ) const { return mapper_.contains( codim ); }
53 bool fixedSize( int dim, int codim ) const { return true; }
54
55 template< class Buffer, class Entity >
56 void gather ( Buffer &buffer, const Entity &entity ) const
57 {
58 buffer.write( rank_ );
59 int attribute = -1;
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();
64 } );
65 buffer.write( static_cast< int >( attribute ) );
66 }
67
68 template< class Buffer, class Entity >
69 void scatter ( Buffer &buffer, const Entity &entity, std::size_t n )
70 {
71 int rank, attribute;
72 buffer.read( rank );
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 );
77 assert( pair );
78 remotes[ rank ].emplace_back( static_cast< AttributeType >( attribute ), pair );
79 } );
80 }
81
82 template< class Entity >
83 std::size_t size ( const Entity &entity ) const
84 {
85 return 2;
86 }
87
88 std::map< int, std::vector< Dune::RemoteIndex< GlobalIndexType, AttributeType > > > remotes;
89
90 private:
91 int rank_;
92 const Mapper &mapper_;
93 const GlobalLookup &globalLookup_;
94 };
95
96
97
98 template< class DiscreteFunctionSpace, class GlobalId, class LocalId >
100 Dune::SolverCategory::Category solverCategory,
101 std::shared_ptr< Dune::OwnerOverlapCopyCommunication< GlobalId, LocalId > > &communication )
102 {
103 typedef typename DiscreteFunctionSpace::GridPartType GridPartType;
104 typedef typename DiscreteFunctionSpace::BlockMapperType LocalMapperType;
105
106 typedef typename Dune::OwnerOverlapCopyCommunication< GlobalId, LocalId >::GlobalLookupIndexSet GlobalLookupType;
107
108 typedef typename GlobalLookupType::LocalIndex LocalIndexType;
109
110 communication.reset( new Dune::OwnerOverlapCopyCommunication< GlobalId, LocalId >( solverCategory ) );
111
112 const GridPartType &gridPart = dfSpace.gridPart();
113 LocalMapperType &localMapper = dfSpace.blockMapper();
114
115 // create global index mapping
117
118 // construct local attributes
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;
122
123 // build parallel index set
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();
128
129 // build remote indices
130 communication->buildGlobalLookup();
131 BuildRemoteIndicesDataHandle< LocalMapperType, GlobalLookupType > buildRemoteIndicesDataHandle( gridPart.comm().rank(), localMapper, communication->globalLookup() );
132 gridPart.communicate( buildRemoteIndicesDataHandle, Dune::All_All_Interface, Dune::ForwardCommunication );
133 communication->freeGlobalLookup();
134
135 communication->remoteIndices().setIndexSets( communication->indexSet(), communication->indexSet(), communication->communicator() );
136 if( !buildRemoteIndicesDataHandle.remotes.empty() )
137 {
138 for( auto &remote : buildRemoteIndicesDataHandle.remotes )
139 {
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 );
144 }
145 }
146 else
147 communication->remoteIndices().template getModifier< false, true >( 0 );
148 }
149
150
151
152 // SupportsAMG for OwnerOverlapCopyCommunication
153 // ---------------------------------------------
154
155 template< class T >
156 struct SupportsAMG;
157
158 template< class GlobalId, class LocalId >
159 struct SupportsAMG< Dune::OwnerOverlapCopyCommunication< GlobalId, LocalId > >
160 : public std::true_type
161 {};
162
163 } // namespace ISTL
164
165 } // namespace Fem
166
167} // namespace Dune
168
169#endif // #ifndef DUNE_FEM_SOLVER_COMMUNICATION_OWNEROVERLAPCOPY_HH
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: fem.hh:156
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
discrete function space