dune-fem  2.4.1-rc
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 
9 #include <dune/common/exceptions.hh>
10 #include <dune/common/forloop.hh>
11 #include <dune/common/std/utility.hh>
12 #include <dune/common/tuples.hh>
13 
18 
20 
21 
22 namespace Dune
23 {
24 
25  namespace Fem
26  {
27 
28  // TupleLocalRestricProlong
29  // ------------------------
30 
31  template< class ... DiscreteFunctionSpaces >
33  {
34  typedef TupleLocalRestrictProlong< DiscreteFunctionSpaces ... > ThisType;
35 
36  typedef std::tuple< DefaultLocalRestrictProlong< DiscreteFunctionSpaces > ... > LocalRestrictProlongTupleType;
37 
38  static const int setSize = sizeof...( DiscreteFunctionSpaces )-1;
39 
40  // helper structs
41  template< int > struct SetFatherChildWeight;
42  template< int > struct RestrictLocal;
43  template< int > struct ProlongLocal;
44 
45  public:
47  "TupleLocalRestrictProlong needs common DomainFieldType in the Spaces!" );
48 
49  typedef typename std::tuple_element< 0, LocalRestrictProlongTupleType >::type::DomainFieldType DomainFieldType;
50 
51  TupleLocalRestrictProlong ( const DiscreteFunctionSpaces & ...spaces )
52  : localRestrictProlongTuple_( spaces ... )
53  {}
54 
55  void setFatherChildWeight ( const DomainFieldType &weight )
56  {
57  ForLoop< SetFatherChildWeight, 0, setSize >::apply( weight, localRestrictProlongTuple_ );
58  }
59 
61  template< class LFFather, class LFSon, class LocalGeometry >
62  void restrictLocal ( LFFather &lfFather, const LFSon &lfSon,
63  const LocalGeometry &geometryInFather, bool initialize ) const
64  {
65  ForLoop< RestrictLocal, 0, setSize >::apply( lfFather, lfSon, geometryInFather, initialize, localRestrictProlongTuple_ );
66  }
67 
68 
69  template< class LFFather, class LFSon, class LocalGeometry >
70  void prolongLocal ( const LFFather &lfFather, LFSon &lfSon,
71  const LocalGeometry &geometryInFather, bool initialize ) const
72  {
73  ForLoop< ProlongLocal, 0, setSize >::apply( lfFather, lfSon, geometryInFather, initialize, localRestrictProlongTuple_ );
74  }
75 
76  bool needCommunication () const
77  {
78  return needCommunication( Std::index_sequence_for< DiscreteFunctionSpaces ... >() );
79  }
80 
81  protected:
82  template< std::size_t ... i >
83  bool needCommunication ( Std::index_sequence< i...> ) const
84  {
85  return Std::Or( std::get< i >( localRestrictProlongTuple_ ).needCommunication() ... );
86  }
87 
88  private:
89  LocalRestrictProlongTupleType localRestrictProlongTuple_;
90  };
91 
92 
93  // SetFatherChildWeight
94  // --------------------
95 
96  template< class ... DiscreteFunctionSpaces >
97  template< int i >
98  struct TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >::
99  SetFatherChildWeight
100  {
101  template< class Tuple >
102  static void apply( const DomainFieldType &weight, Tuple &tuple )
103  {
104  std::get< i >( tuple ).setFatherChildWeight( weight );
105  }
106  };
107 
108 
109  // ProlongLocal
110  // ------------
111 
112  template< class ... DiscreteFunctionSpaces >
113  template< int i >
114  struct TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >::
115  ProlongLocal
116  {
117  template< class LFFather, class LFSon, class LocalGeometry, class Tuple >
118  static void apply ( const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize,
119  const Tuple &tuple )
120  {
122  typedef DenseSubVector< typename LFSon::LocalDofVectorType > SubDofVectorTypeSon;
123 
124  typedef typename LFFather::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubFatherBasisFunctionSetType;
125  typedef typename LFSon::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubSonBasisFunctionSetType;
126 
127  SubFatherBasisFunctionSetType subFatherBasisFunctionSet = lfFather.basisFunctionSet().template subBasisFunctionSet< i >();
128  SubSonBasisFunctionSetType subSonBasisFunctionSet = lfSon.basisFunctionSet().template subBasisFunctionSet< i >();
129 
130  std::size_t fatherBasisSetOffset = lfFather.basisFunctionSet().offset( i );
131  std::size_t sonBasisSetOffset = lfSon.basisFunctionSet().offset(i);
132 
133  SubDofVectorTypeFather fatherSubDofVector( lfFather.localDofVector(), subFatherBasisFunctionSet.size(), fatherBasisSetOffset );
134  SubDofVectorTypeSon sonSubDofVector( lfSon.localDofVector(), subSonBasisFunctionSet.size(), sonBasisSetOffset );
135 
137  subLFFather( subFatherBasisFunctionSet, fatherSubDofVector );
139  subLFSon( subSonBasisFunctionSet, sonSubDofVector );
140 
141  std::get< i >( tuple ).prolongLocal( subLFFather, subLFSon, geometryInFather, initialize );
142  }
143  };
144 
145 
146  // RestrictLocal
147  // -------------
148 
149  template< class ... DiscreteFunctionSpaces >
150  template< int i >
151  struct TupleLocalRestrictProlong< DiscreteFunctionSpaces ... >::
152  RestrictLocal
153  {
154  template< class LFFather, class LFSon, class LocalGeometry, class Tuple >
155  static void apply ( LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize,
156  const Tuple &tuple )
157  {
158  typedef DenseSubVector< typename LFFather::LocalDofVectorType > SubDofVectorTypeFather;
160 
161  typedef typename LFFather::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubFatherBasisFunctionSetType;
162  typedef typename LFSon::BasisFunctionSetType::template SubBasisFunctionSet< i >::type SubSonBasisFunctionSetType;
163 
164  SubFatherBasisFunctionSetType subFatherBasisFunctionSet = lfFather.basisFunctionSet().template subBasisFunctionSet< i >();
165  SubSonBasisFunctionSetType subSonBasisFunctionSet = lfSon.basisFunctionSet().template subBasisFunctionSet< i >();
166 
167  std::size_t fatherBasisSetOffset = lfFather.basisFunctionSet().offset(i);
168  std::size_t sonBasisSetOffset = lfSon.basisFunctionSet().offset(i);
169 
170  SubDofVectorTypeFather fatherSubDofVector( lfFather.localDofVector(), subFatherBasisFunctionSet.size(), fatherBasisSetOffset );
171  SubDofVectorTypeSon sonSubDofVector( lfSon.localDofVector(), subSonBasisFunctionSet.size(), sonBasisSetOffset );
172 
173  LocalFunction< SubFatherBasisFunctionSetType, SubDofVectorTypeFather > subLFFather( subFatherBasisFunctionSet, fatherSubDofVector );
174  BasicConstLocalFunction< SubSonBasisFunctionSetType, SubDofVectorTypeSon > subLFSon( subSonBasisFunctionSet, sonSubDofVector );
175 
176  std::get< i >( tuple ).restrictLocal( subLFFather, subLFSon, geometryInFather, initialize );
177  }
178  };
179 
180 
181  } // namespace Fem
182 
183 } // namespace Dune
184 
185 #endif // #ifndef DUNE_FEM_SPACE_COMBINEDSPACE_TUPLELOCALRESTIRCTPROLONG_HH
Definition: utility.hh:135
void prolongLocal(const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
Definition: tuplelocalrestrictprolong.hh:70
std::tuple_element< 0, LocalRestrictProlongTupleType >::type::DomainFieldType DomainFieldType
Definition: tuplelocalrestrictprolong.hh:43
interface for local functions
Definition: localfunction.hh:41
void restrictLocal(LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: tuplelocalrestrictprolong.hh:62
Definition: tuplelocalrestrictprolong.hh:32
Definition: coordinate.hh:4
void setFatherChildWeight(const DomainFieldType &weight)
Definition: tuplelocalrestrictprolong.hh:55
Definition: subvector.hh:22
static constexpr bool Or(bool a)
Definition: utility.hh:98
TupleLocalRestrictProlong(const DiscreteFunctionSpaces &...spaces)
Definition: tuplelocalrestrictprolong.hh:51
Definition: const.hh:35
bool needCommunication() const
Definition: tuplelocalrestrictprolong.hh:76
bool needCommunication(Std::index_sequence< i... >) const
Definition: tuplelocalrestrictprolong.hh:83