dune-fem 2.8.0
Loading...
Searching...
No Matches
fem.hh
Go to the documentation of this file.
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
8#include <dune/common/ftraits.hh>
9#include <dune/common/hybridutilities.hh>
10
11#include <dune/istl/solvercategory.hh>
12
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 >
29 {
31
32 public:
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 >
43 {
44 typedef typename DiscreteFunctionSpaceType::template CommDataHandle< ThisType, Operation >::Type Type;
45 };
46
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 >
74 {
76
77 public:
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::CollectiveCommunicationType &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 );
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 >
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 >
157
158 template< class 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
double sqrt(const Dune::Fem::Double &v)
Definition: double.hh:977
Definition: bindguard.hh:11
static double sqrt(const Double &v)
Definition: double.hh:886
void buildCommunication(const DiscreteFunctionSpace &dfSpace, Dune::SolverCategory::Category solverCategory, std::shared_ptr< FemCommunication< DiscreteFunctionSpace > > &communication)
Definition: fem.hh:143
const DiscreteFunctionSpaceType & space() const
Definition: fem.hh:60
static constexpr std::size_t blockSize
Definition: fem.hh:37
CommDataHandle< Operation >::Type dataHandle(const Operation &operation)
Definition: fem.hh:52
DiscreteFunctionSpaceType::LocalBlockIndices BlockIndices
Definition: fem.hh:35
FemCommunicationVector(const DiscreteFunctionSpace &dfSpace, DofVector &dofVector)
Definition: fem.hh:47
DofVector::field_type DofType
Definition: fem.hh:39
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: fem.hh:33
const DofVector & dofVector() const
Definition: fem.hh:57
DofVector & dofVector()
Definition: fem.hh:58
DiscreteFunctionSpaceType::template CommDataHandle< ThisType, Operation >::Type Type
Definition: fem.hh:44
FemCommunication(const DiscreteFunctionSpaceType &dfSpace, Dune::SolverCategory::Category solverCategory=Dune::SolverCategory::sequential)
Definition: fem.hh:80
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: fem.hh:78
void dot(const T &x, const T &y, F &scp) const
Definition: fem.hh:106
const DiscreteFunctionSpace::GridPartType::CollectiveCommunicationType & communicator() const
Definition: fem.hh:84
Dune::FieldTraits< typenameT::field_type >::real_type norm(const T &x) const
Definition: fem.hh:122
void project(T &x) const
Definition: fem.hh:96
Dune::SolverCategory::Category getSolverCategory() const
Definition: fem.hh:130
void copyOwnerToAll(const T &x, T &y) const
Definition: fem.hh:87
Definition: fem.hh:156
sum up data
Definition: commoperations.hh:144
discrete function space