dune-fem  2.8-git
common/localrestrictprolong.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_LOCALRESTRICTPROLONG_HH
2 #define DUNE_FEM_LOCALRESTRICTPROLONG_HH
3 
5 
6 namespace Dune
7 {
8 
9  namespace Fem
10  {
11 
12  // DefaultLocalRestrictProlong
13  // ---------------------------
14 
15  template< class DiscreteFunctionSpace >
17 
18 
19 
20  // ConstantLocalRestrictProlong
21  // ----------------------------
22 
23  template< class DiscreteFunctionSpace >
25  {
27 
28  public:
30 
31  typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType;
32 
34  : weight_( -1 )
35  {}
36 
43  void setFatherChildWeight ( const DomainFieldType &weight )
44  {
45  weight_ = weight;
46  }
47 
49  template< class LFFather, class LFSon, class LocalGeometry >
50  void restrictLocal ( LFFather &lfFather, const LFSon &lfSon,
51  const LocalGeometry &geometryInFather, bool initialize ) const
52  {
53  const DomainFieldType weight = (weight_ < DomainFieldType( 0 ) ? calcWeight( lfFather.entity(), lfSon.entity() ) : weight_);
54 
55  assert( weight > 0.0 );
56  //assert( std::abs( geometryInFather.volume() - weight ) < 1e-8 );
57 
58  const int size = lfFather.size();
59  assert( lfFather.size() == lfSon.size() );
60  if( initialize )
61  {
62  for( int i = 0; i < size; ++i )
63  lfFather[ i ] = weight * lfSon[ i ];
64  }
65  else
66  {
67  for( int i = 0; i < size; ++i )
68  lfFather[ i ] += weight * lfSon[ i ];
69  }
70  }
71  template< class LFFather >
72  void restrictFinalize ( LFFather &lfFather ) const
73  {}
74 
76  template< class LFFather, class LFSon, class LocalGeometry >
77  void prolongLocal ( const LFFather &lfFather, LFSon &lfSon,
78  const LocalGeometry &geometryInFather, bool initialize ) const
79  {
80  const int size = lfFather.size();
81  assert( lfFather.size() == lfSon.size() );
82  for( int i = 0; i < size; ++i )
83  lfSon[ i ] = lfFather[ i ];
84  }
85 
87  bool needCommunication () const { return true; }
88 
89 
90  template< class Entity >
91  static DomainFieldType calcWeight ( const Entity &father, const Entity &son )
92  {
93  return son.geometry().volume() / father.geometry().volume();
94  }
95 
96  protected:
98  };
99 
100 
101 
102  // EmptyLocalRestrictProlong
103  // -------------------------
104 
105  template< class DiscreteFunctionSpace >
107  {
109 
110  public:
112 
113  typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType;
114 
121  void setFatherChildWeight ( const DomainFieldType &weight ) {}
122 
124  template< class LFFather, class LFSon, class LocalGeometry >
125  void restrictLocal ( LFFather &lfFather, const LFSon &lfSon,
126  const LocalGeometry &geometryInFather, bool initialize ) const
127  {}
128  template< class LFFather >
129  void restrictFinalize ( LFFather &lfFather ) const
130  {}
131 
133  template< class LFFather, class LFSon, class LocalGeometry >
134  void prolongLocal ( const LFFather &lfFather, LFSon &lfSon,
135  const LocalGeometry &geometryInFather, bool initialize ) const
136  {}
137 
139  bool needCommunication () const { return false; }
140  };
141 
142  } // namespace Fem
143 
144 } // namespace Dune
145 
146 #endif // #ifndef DUNE_FEM_LOCALRESTRICTPROLONG_HH
Definition: bindguard.hh:11
Definition: common/localrestrictprolong.hh:16
Definition: common/localrestrictprolong.hh:25
bool needCommunication() const
do discrete functions need a communication after restriction / prolongation?
Definition: common/localrestrictprolong.hh:87
static DomainFieldType calcWeight(const Entity &father, const Entity &son)
Definition: common/localrestrictprolong.hh:91
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: common/localrestrictprolong.hh:29
void restrictFinalize(LFFather &lfFather) const
Definition: common/localrestrictprolong.hh:72
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
Definition: common/localrestrictprolong.hh:31
void setFatherChildWeight(const DomainFieldType &weight)
explicit set volume ratio of son and father
Definition: common/localrestrictprolong.hh:43
void prolongLocal(const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: common/localrestrictprolong.hh:77
void restrictLocal(LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: common/localrestrictprolong.hh:50
DomainFieldType weight_
Definition: common/localrestrictprolong.hh:97
ConstantLocalRestrictProlong()
Definition: common/localrestrictprolong.hh:33
Definition: common/localrestrictprolong.hh:107
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: common/localrestrictprolong.hh:111
void setFatherChildWeight(const DomainFieldType &weight)
explicit set volume ratio of son and father
Definition: common/localrestrictprolong.hh:121
bool needCommunication() const
do discrete functions need a communication after restriction / prolongation?
Definition: common/localrestrictprolong.hh:139
void restrictLocal(LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: common/localrestrictprolong.hh:125
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
Definition: common/localrestrictprolong.hh:113
void restrictFinalize(LFFather &lfFather) const
Definition: common/localrestrictprolong.hh:129
void prolongLocal(const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: common/localrestrictprolong.hh:134
discrete function space