DUNE-FEM (unstable)

owneroverlapcopy.hh
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
13
15
17
18#include <dune/fem/space/mapper/parallel.hh>
19
20
21namespace Dune
22{
23
24 namespace Fem
25 {
26
27 namespace ISTL
28 {
29
30 // OwnerOverlapCopyCommunication
31 // -----------------------------
32
33 template< class DiscreteFunctionSpace >
35
36
37
38 // BuildRemoteIndicesDataHandle
39 // ----------------------------
40
41 template< class Mapper, class GlobalLookup >
42 struct BuildRemoteIndicesDataHandle
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 >
99 void buildCommunication ( const DiscreteFunctionSpace &dfSpace,
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
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
116 Dune::Fem::ParallelDofMapper< GridPartType, LocalMapperType, GlobalId > globalMapper( gridPart, localMapper, dfSpace.communicationInterface() );
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
discrete function space
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:143
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:129
A class setting up standard communication for a two-valued attribute set with owner/overlap/copy sema...
Definition: owneroverlapcopy.hh:174
Describes the parallel communication interface class for MessageBuffers and DataHandles.
Classes providing communication interfaces for overlapping Schwarz methods.
@ ForwardCommunication
communicate as given in InterfaceType
Definition: gridenums.hh:171
@ All_All_Interface
send all and receive all entities
Definition: gridenums.hh:91
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
Classes describing a distributed indexset.
Category
Definition: solvercategory.hh:23
std::size_t fixedSize
The number of data items per index if it is fixed, 0 otherwise.
Definition: variablesizecommunicator.hh:264
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)