DUNE-FEM (unstable)

fem.hh
1#ifndef DUNE_FEM_SOLVER_COMMUNICATION_FEM_HH
2#define DUNE_FEM_SOLVER_COMMUNICATION_FEM_HH
3
4#include <memory>
5#include <type_traits>
6#include <utility>
7
9#include <dune/common/hybridutilities.hh>
10
11#include <dune/istl/solvercategory.hh>
12
13#include <dune/fem/space/common/commoperations.hh>
14
15namespace Dune
16{
17
18 namespace Fem
19 {
20
21 namespace ISTL
22 {
23
24 // FemCommunicationVector
25 // ----------------------
26
27 template< class DiscreteFunctionSpace, class DofVector >
28 class FemCommunicationVector
29 {
30 typedef FemCommunicationVector< DiscreteFunctionSpace, DofVector > ThisType;
31
32 public:
33 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
34
35 typedef typename DiscreteFunctionSpaceType::LocalBlockIndices BlockIndices;
36
37 static constexpr std::size_t blockSize = Hybrid::size( BlockIndices() );
38
39 typedef typename DofVector::field_type DofType;
40
41 template< class Operation >
42 struct CommDataHandle
43 {
44 typedef typename DiscreteFunctionSpaceType::template CommDataHandle< ThisType, Operation >::Type Type;
45 };
46
47 FemCommunicationVector ( const DiscreteFunctionSpace &dfSpace, DofVector &dofVector )
48 : dfSpace_( dfSpace ), dofVector_( dofVector )
49 {}
50
51 template< class Operation >
52 typename CommDataHandle< Operation >::Type dataHandle ( const Operation &operation )
53 {
54 return space().createDataHandle( *this, operation );
55 }
56
57 const DofVector &dofVector () const { return dofVector_; }
58 DofVector &dofVector () { return dofVector_; }
59
60 const DiscreteFunctionSpaceType &space () const { return dfSpace_; }
61
62 private:
63 const DiscreteFunctionSpace &dfSpace_;
64 DofVector &dofVector_;
65 };
66
67
68
69 // FemCommunication
70 // ----------------
71
72 template< class DiscreteFunctionSpace >
73 class FemCommunication
74 {
75 typedef FemCommunication< DiscreteFunctionSpace > ThisType;
76
77 public:
78 typedef DiscreteFunctionSpace DiscreteFunctionSpaceType;
79
80 explicit FemCommunication ( const DiscreteFunctionSpaceType &dfSpace, Dune::SolverCategory::Category solverCategory = Dune::SolverCategory::sequential )
81 : dfSpace_( dfSpace ), solverCategory_( solverCategory )
82 {}
83
84 const typename DiscreteFunctionSpace::GridPartType::CommunicationType &communicator () const { return dfSpace_.gridPart().comm(); }
85
86 template< class T >
87 void copyOwnerToAll ( const T &x, T &y ) const
88 {
89 y = x;
90 project( y );
91 FemCommunicationVector< DiscreteFunctionSpaceType, T > z( dfSpace_, y );
92 dfSpace_.communicator().exchange( z, DFCommunicationOperation::Add() );
93 }
94
95 template< class T >
96 void project ( T &x ) const
97 {
98 typedef typename T::field_type field_type;
99
100 // clear auxiliary DoFs
101 for( int i : dfSpace_.auxiliaryDofs() )
102 x[ i ] = field_type( 0 );
103 }
104
105 template< class T, class F >
106 void dot ( const T &x, const T &y, F &scp ) const
107 {
108 const auto &auxiliaryDofs = dfSpace_.auxiliaryDofs();
109
110 const int numAuxiliarys = auxiliaryDofs.size();
111 for( int auxiliary = 0, i = 0; auxiliary < numAuxiliarys; ++auxiliary, ++i )
112 {
113 const int nextAuxiliary = auxiliaryDofs[ auxiliary ];
114 for( ; i < nextAuxiliary; ++i )
115 scp += x[ i ] * y[ i ];
116 }
117
118 scp = communicator().sum( scp );
119 }
120
121 template< class T >
122 typename Dune::FieldTraits< typename T::field_type >::real_type norm ( const T &x ) const
123 {
124 using std::sqrt;
125 typename Dune::FieldTraits< typename T::field_type >::real_type norm2( 0 );
126 dot( x, x, norm2 );
127 return sqrt( norm2 );
128 }
129
130 Dune::SolverCategory::Category getSolverCategory () const { return solverCategory_; }
131
132 private:
133 const DiscreteFunctionSpaceType &dfSpace_;
134 Dune::SolverCategory::Category solverCategory_;
135 };
136
137
138
139 // buildCommunication
140 // ------------------
141
142 template< class DiscreteFunctionSpace >
143 void buildCommunication ( const DiscreteFunctionSpace &dfSpace,
144 Dune::SolverCategory::Category solverCategory,
145 std::shared_ptr< FemCommunication< DiscreteFunctionSpace > > &communication )
146 {
147 communication.reset( new FemCommunication< DiscreteFunctionSpace >( dfSpace, solverCategory ) );
148 }
149
150
151
152 // SupportsAMG for FemCommunication
153 // --------------------------------
154
155 template< class T >
156 struct SupportsAMG;
157
158 template< class DiscreteFunctionSpace >
159 struct SupportsAMG< FemCommunication< DiscreteFunctionSpace > >
160 : public std::false_type
161 {};
162
163 } // namespace ISTL
164
165 } // namespace Fem
166
167} // namespace Dune
168
169#endif // #ifndef DUNE_FEM_SOLVER_COMMUNICATION_FEM_HH
discrete function space
Traits::CommunicationType CommunicationType
Collective communication.
Definition: gridpart.hh:97
Type traits to determine the type of reals (when working with complex numbers)
auto dot(const A &a, const B &b) -> typename std::enable_if< IsNumber< A >::value &&!IsVector< A >::value &&!std::is_same< typename FieldTraits< A >::field_type, typename FieldTraits< A >::real_type > ::value, decltype(conj(a) *b)>::type
computes the dot product for fundamental data types according to Petsc's VectDot function: dot(a,...
Definition: dotproduct.hh:42
Dune namespace.
Definition: alignedallocator.hh:13
Category
Definition: solvercategory.hh:23
@ sequential
Category for sequential solvers.
Definition: solvercategory.hh:25
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)