dune-fem  2.8-git
tuplelocalrestrictprolong.hh
Go to the documentation of this file.
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 
10 #include <dune/common/exceptions.hh>
11 #include <dune/common/hybridutilities.hh>
12 
19 
20 namespace Dune
21 {
22 
23  namespace Fem
24  {
25 
26  // TupleLocalRestricProlong
27  // ------------------------
28 
29  template< class ... DiscreteFunctionSpaces >
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:
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
Definition: bindguard.hh:11
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
static constexpr bool Or()
Definition: utility.hh:110
static DUNE_PRIVATE void apply(Args &&... args)
Definition: forloop.hh:23
Definition: utility.hh:147
Definition: tuplelocalrestrictprolong.hh:31
std::tuple_element_t< 0, std::tuple< typename DiscreteFunctionSpaces::DomainFieldType... > > DomainFieldType
Definition: tuplelocalrestrictprolong.hh:51
void prolongLocal(const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
Definition: tuplelocalrestrictprolong.hh:79
TupleLocalRestrictProlong(std::tuple< const DiscreteFunctionSpaces &... > tuple)
Definition: tuplelocalrestrictprolong.hh:55
bool needCommunication(std::index_sequence< i... >) const
Definition: tuplelocalrestrictprolong.hh:92
bool needCommunication() const
Definition: tuplelocalrestrictprolong.hh:85
void restrictFinalize(LFFather &lfFather) const
Definition: tuplelocalrestrictprolong.hh:73
void restrictLocal(LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: tuplelocalrestrictprolong.hh:67
void setFatherChildWeight(const DomainFieldType &weight)
Definition: tuplelocalrestrictprolong.hh:59