DUNE-FEM (unstable)

tuplelocalrestrictprolong.hh
1#ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLELOCALRESTIRCTPROLONG_HH
2#define DUNE_FEM_SPACE_COMBINEDSPACE_TUPLELOCALRESTIRCTPROLONG_HH
3
4#include <algorithm>
5#include <array>
6#include <tuple>
7#include <vector>
8#include <utility>
9
11#include <dune/common/hybridutilities.hh>
12
13#include <dune/fem/common/forloop.hh>
14#include <dune/fem/common/utility.hh>
15#include <dune/fem/function/localfunction/const.hh>
16#include <dune/fem/function/localfunction/localfunction.hh>
17#include <dune/fem/space/common/localrestrictprolong.hh>
18#include <dune/fem/storage/subvector.hh>
19
20namespace Dune
21{
22
23 namespace Fem
24 {
25
26 // TupleLocalRestricProlong
27 // ------------------------
28
29 template< class ... DiscreteFunctionSpaces >
30 class TupleLocalRestrictProlong
31 {
32 typedef TupleLocalRestrictProlong< DiscreteFunctionSpaces ... > ThisType;
33
34 typedef std::tuple< DefaultLocalRestrictProlong< DiscreteFunctionSpaces > ... > LocalRestrictProlongTupleType;
35
36 static const int setSize = sizeof...( DiscreteFunctionSpaces )-1;
37
38 // helper structs
39 template< int > struct RestrictLocal;
40 template< int > struct RestrictFinalize;
41 template< int > struct ProlongLocal;
42
43 template< std::size_t ... i >
44 static LocalRestrictProlongTupleType localRestrictProlongTuple ( std::tuple< const DiscreteFunctionSpaces &... > tuple, std::index_sequence< i ... > )
45 {
46 return std::make_tuple( typename std::tuple_element< i, LocalRestrictProlongTupleType >::type( std::get< i >( tuple ) ) ...);
47 }
48
49 public:
50 static_assert( Std::are_all_same< typename DiscreteFunctionSpaces::DomainFieldType ... >::value,
51 "TupleLocalRestrictProlong needs common DomainFieldType in the Spaces!" );
52
53 typedef std::tuple_element_t< 0, std::tuple< typename DiscreteFunctionSpaces::DomainFieldType... > > DomainFieldType;
54
55 TupleLocalRestrictProlong ( std::tuple< const DiscreteFunctionSpaces & ... > tuple )
56 : localRestrictProlongTuple_( localRestrictProlongTuple( tuple, std::index_sequence_for< DiscreteFunctionSpaces ... >() ) )
57 {}
58
59 void setFatherChildWeight ( const DomainFieldType &weight )
60 {
61 Hybrid::forEach( std::make_index_sequence< sizeof ... ( DiscreteFunctionSpaces ) >{},
62 [ & ]( auto i ){ std::get< i >( localRestrictProlongTuple_ ).setFatherChildWeight( weight ); } );
63 }
64
66 template< class LFFather, class LFSon, class LocalGeometry >
67 void restrictLocal ( LFFather &lfFather, const LFSon &lfSon,
68 const LocalGeometry &geometryInFather, bool initialize ) const
69 {
70 Fem::ForLoop< RestrictLocal, 0, setSize >::apply( lfFather, lfSon, geometryInFather, initialize, localRestrictProlongTuple_ );
71 }
72 template< class LFFather >
73 void restrictFinalize ( LFFather &lfFather ) const
74 {
75 Fem::ForLoop< RestrictFinalize, 0, setSize >::apply( lfFather, localRestrictProlongTuple_ );
76 }
77
78 template< class LFFather, class LFSon, class LocalGeometry >
79 void prolongLocal ( const LFFather &lfFather, LFSon &lfSon,
80 const LocalGeometry &geometryInFather, bool initialize ) const
81 {
82 Fem::ForLoop< ProlongLocal, 0, setSize >::apply( lfFather, lfSon, geometryInFather, initialize, localRestrictProlongTuple_ );
83 }
84
85 bool needCommunication () const
86 {
87 return needCommunication( std::index_sequence_for< DiscreteFunctionSpaces ... >() );
88 }
89
90 protected:
91 template< std::size_t ... i >
92 bool needCommunication ( std::index_sequence< i...> ) const
93 {
94 return Std::Or( std::get< i >( localRestrictProlongTuple_ ).needCommunication() ... );
95 }
96
97 private:
98 LocalRestrictProlongTupleType localRestrictProlongTuple_;
99 };
100
101
102
103 // ProlongLocal
104 // ------------
105
106 template< class ... DiscreteFunctionSpaces >
107 template< int i >
108 struct TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >::
109 ProlongLocal
110 {
111 template< class LFFather, class LFSon, class LocalGeometry, class Tuple >
112 static void apply ( const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize,
113 const Tuple &tuple )
114 {
115 typedef SubVector< const typename LFFather::LocalDofVectorType, OffsetSubMapper > SubDofVectorTypeFather;
116 typedef SubVector< typename LFSon::LocalDofVectorType, OffsetSubMapper > SubDofVectorTypeSon;
117
118 typedef typename LFFather::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubFatherBasisFunctionSetType;
119 typedef typename LFSon::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubSonBasisFunctionSetType;
120
121 SubFatherBasisFunctionSetType subFatherBasisFunctionSet = lfFather.basisFunctionSet().template subBasisFunctionSet< i >();
122 SubSonBasisFunctionSetType subSonBasisFunctionSet = lfSon.basisFunctionSet().template subBasisFunctionSet< i >();
123
124 std::size_t fatherBasisSetOffset = lfFather.basisFunctionSet().offset( i );
125 std::size_t sonBasisSetOffset = lfSon.basisFunctionSet().offset(i);
126
127 SubDofVectorTypeSon sonSubDofVector( lfSon.localDofVector(), OffsetSubMapper( subSonBasisFunctionSet.size(), sonBasisSetOffset ) );
128 SubDofVectorTypeFather fatherSubDofVector( lfFather.localDofVector(), OffsetSubMapper( subFatherBasisFunctionSet.size(),
129 fatherBasisSetOffset ) );
130
131 BasicConstLocalFunction< SubFatherBasisFunctionSetType, SubDofVectorTypeFather > subLFFather( subFatherBasisFunctionSet,
132 fatherSubDofVector );
133 LocalFunction< SubSonBasisFunctionSetType, SubDofVectorTypeSon > subLFSon( subSonBasisFunctionSet, sonSubDofVector );
134
135 std::get< i >( tuple ).prolongLocal( subLFFather, subLFSon, geometryInFather, initialize );
136 }
137 };
138
139
140 // RestrictFinalize
141 // ----------------
142
143 template< class ... DiscreteFunctionSpaces >
144 template< int i >
145 struct TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >::
146 RestrictFinalize
147 {
148 template< class LFFather, class Tuple >
149 static void apply ( LFFather &lfFather,
150 const Tuple &tuple )
151 {
152 typedef SubVector< typename LFFather::LocalDofVectorType, OffsetSubMapper > SubDofVectorTypeFather;
153
154 typedef typename LFFather::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubFatherBasisFunctionSetType;
155
156 SubFatherBasisFunctionSetType subFatherBasisFunctionSet = lfFather.basisFunctionSet().template subBasisFunctionSet< i >();
157
158 std::size_t fatherBasisSetOffset = lfFather.basisFunctionSet().offset(i);
159
160 SubDofVectorTypeFather fatherSubDofVector( lfFather.localDofVector(), OffsetSubMapper( subFatherBasisFunctionSet.size(),
161 fatherBasisSetOffset ) );
162 LocalFunction< SubFatherBasisFunctionSetType, SubDofVectorTypeFather > subLFFather( subFatherBasisFunctionSet, fatherSubDofVector );
163
164 std::get< i >( tuple ).restrictFinalize( subLFFather );
165 }
166 };
167
168
169 // RestrictLocal
170 // -------------
171
172 template< class ... DiscreteFunctionSpaces >
173 template< int i >
174 struct TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >::
175 RestrictLocal
176 {
177 template< class LFFather, class LFSon, class LocalGeometry, class Tuple >
178 static void apply ( LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize,
179 const Tuple &tuple )
180 {
181 typedef SubVector< typename LFFather::LocalDofVectorType, OffsetSubMapper > SubDofVectorTypeFather;
182 typedef SubVector< const typename LFSon::LocalDofVectorType, OffsetSubMapper > SubDofVectorTypeSon;
183
184 typedef typename LFFather::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubFatherBasisFunctionSetType;
185 typedef typename LFSon::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubSonBasisFunctionSetType;
186
187 SubFatherBasisFunctionSetType subFatherBasisFunctionSet = lfFather.basisFunctionSet().template subBasisFunctionSet< i >();
188 SubSonBasisFunctionSetType subSonBasisFunctionSet = lfSon.basisFunctionSet().template subBasisFunctionSet< i >();
189
190 std::size_t fatherBasisSetOffset = lfFather.basisFunctionSet().offset(i);
191 std::size_t sonBasisSetOffset = lfSon.basisFunctionSet().offset(i);
192
193 SubDofVectorTypeSon sonSubDofVector( lfSon.localDofVector(), OffsetSubMapper( subSonBasisFunctionSet.size(), sonBasisSetOffset ) );
194 SubDofVectorTypeFather fatherSubDofVector( lfFather.localDofVector(), OffsetSubMapper( subFatherBasisFunctionSet.size(),
195 fatherBasisSetOffset ) );
196
197 LocalFunction< SubFatherBasisFunctionSetType, SubDofVectorTypeFather > subLFFather( subFatherBasisFunctionSet, fatherSubDofVector );
198 BasicConstLocalFunction< SubSonBasisFunctionSetType, SubDofVectorTypeSon > subLFSon( subSonBasisFunctionSet, sonSubDofVector );
199
200 std::get< i >( tuple ).restrictLocal( subLFFather, subLFSon, geometryInFather, initialize );
201 }
202 };
203
204
205 } // namespace Fem
206
207} // namespace Dune
208
209#endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLELOCALRESTIRCTPROLONG_HH
A few common exception classes.
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)