DUNE-FEM (unstable)

petsc.hh
1#ifndef DUNE_FEM_SPACE_MAPPER_PETSC_HH
2#define DUNE_FEM_SPACE_MAPPER_PETSC_HH
3
4#include <cassert>
5
6#include <memory>
7#include <tuple>
8#include <utility>
9
10#include <dune/fem/space/mapper/ghost.hh>
11#include <dune/fem/space/mapper/parallel.hh>
12#include <dune/fem/storage/singletonlist.hh>
13
14namespace Dune
15{
16
17 namespace Fem
18 {
19
20 // PetscMappers
21 // ------------
22
23#if HAVE_PETSC
24 template< class DiscreteFunctionSpace >
25 class PetscMappers
26 {
27 typedef PetscMappers< DiscreteFunctionSpace > PetscMappersType;
28
29 public:
30 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
31
32 typedef typename DiscreteFunctionSpaceType::BlockMapperType BlockMapperType;
33 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
34
35 typedef GhostDofMapper< GridPartType, BlockMapperType, PetscInt > GhostMapperType;
36 typedef ParallelDofMapper< GridPartType, GhostMapperType, PetscInt > ParallelMapperType;
37
38 private:
39 template< class Mapper >
40 struct MapperFactory
41 {
42 static std::pair< Mapper, int > *createObject ( std::pair< GridPartType *, typename Mapper::BaseMapperType * > key, int sequence )
43 {
44 return new std::pair< Mapper, int >( std::piecewise_construct, std::tie( *key.first, *key.second ), std::make_tuple( sequence ) );
45 }
46
47 static void deleteObject ( std::pair< Mapper, int > *object ) { delete object; }
48 };
49
50 template< class Mapper >
51 using MapperProvider = SingletonList< std::pair< GridPartType *, typename Mapper::BaseMapperType * >, std::pair< Mapper, int >, MapperFactory< Mapper > >;
52
53 typedef MapperProvider< GhostMapperType > GhostMapperProviderType;
54 typedef MapperProvider< ParallelMapperType > ParallelMapperProviderType;
55
56 public:
58 PetscMappers ( const DiscreteFunctionSpaceType &space )
59 : space_( space )
60 {
61 const int sequence = space_.sequence();
62
63 ghostMapper_.reset( &GhostMapperProviderType::getObject( std::make_pair( &space_.gridPart(), &space_.blockMapper() ), sequence-1 ) );
64 // update anyway here because of comm interface for Lagrange spaces
65 update( *ghostMapper_, sequence, space );
66
67 parallelMapper_.reset( &ParallelMapperProviderType::getObject( std::make_pair( &space_.gridPart(), &ghostMapper_->first ), sequence-1 ) );
68 // update anyway here because of comm interface for Lagrange spaces
69 update( *parallelMapper_, sequence, space );
70 }
71
73 PetscMappers ( const PetscMappers &other )
74 : space_( other.space_ )
75 {
76 const int sequence = space_.sequence();
77
78 ghostMapper_.reset( &GhostMapperProviderType::getObject( std::make_pair( &space_.gridPart(), &space_.blockMapper() ), sequence ) );
79 parallelMapper_.reset( &ParallelMapperProviderType::getObject( std::make_pair( &space_.gridPart(), &ghostMapper_->first ), sequence ) );
80 }
81
82 const DiscreteFunctionSpaceType &space () const { return space_; }
83
84 const GhostMapperType &ghostMapper () const { assert( ghostMapper_ ); return ghostMapper_->first; }
85 const ParallelMapperType &parallelMapper () const { assert( parallelMapper_ ); return parallelMapper_->first; }
86
87 PetscInt ghostIndex ( const typename BlockMapperType::GlobalKeyType &index ) const
88 {
89 assert( static_cast< std::size_t >( index ) < size() );
90 return ghostMapper().mapping()[ index ];
91 }
92
93 PetscInt parallelIndex ( const typename BlockMapperType::GlobalKeyType &index ) const
94 {
95 return parallelMapper().mapping()[ ghostIndex( index ) ];
96 }
97
98 std::size_t size () const { return ghostMapper().mapping().size(); }
99
100 void update ()
101 {
102 const int sequence = space().sequence();
103
104 assert( ghostMapper_ );
105 update( *ghostMapper_, sequence, space() );
106
107 assert( parallelMapper_ );
108 update( *parallelMapper_, sequence, space() );
109 }
110
111 private:
112 template< class Mapper >
113 static void update ( std::pair< Mapper, int > &mapper, int sequence, const DiscreteFunctionSpaceType& space )
114 {
115 if( mapper.second != sequence )
116 {
117 // TODO: For Lagrange spaces the comm interface needs to be InteriorBorder_InteriorBorder_Interface
118 // otherwise the petsc solvers don't work.
119 // This is only a temporary fix and need further investigation.
120 const InterfaceType commIf =
121 space.continuous() ? InteriorBorder_InteriorBorder_Interface : space.communicationInterface();
122
123 mapper.first.update( commIf );
124 mapper.second = sequence;
125 }
126 }
127
128 const DiscreteFunctionSpaceType &space_;
129 std::unique_ptr< std::pair< GhostMapperType, int >, typename GhostMapperProviderType::Deleter > ghostMapper_;
130 std::unique_ptr< std::pair< ParallelMapperType, int >, typename ParallelMapperProviderType::Deleter > parallelMapper_;
131 };
132#endif // #if HAVE_PETSC
133
134 } // namespace Fem
135
136} // namespace Dune
137
138#endif // #ifndef DUNE_FEM_SPACE_MAPPER_PETSC_HH
discrete function space
mapper allocating one DoF per subentity of a given codimension
Definition: codimensionmapper.hh:357
InterfaceType
Parameter to be used for the communication functions.
Definition: gridenums.hh:86
@ InteriorBorder_InteriorBorder_Interface
send/receive interior and border entities
Definition: gridenums.hh:87
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)