dune-fem  2.4.1-rc
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 numDofs = lfFather.numDofs();
59  assert( lfFather.numDofs() == lfSon.numDofs() );
60  if( initialize )
61  {
62  for( int i = 0; i < numDofs; ++i )
63  lfFather[ i ] = weight * lfSon[ i ];
64  }
65  else
66  {
67  for( int i = 0; i < numDofs; ++i )
68  lfFather[ i ] += weight * lfSon[ i ];
69  }
70  }
71 
73  template< class LFFather, class LFSon, class LocalGeometry >
74  void prolongLocal ( const LFFather &lfFather, LFSon &lfSon,
75  const LocalGeometry &geometryInFather, bool initialize ) const
76  {
77  const int numDofs = lfFather.numDofs();
78  assert( lfFather.numDofs() == lfSon.numDofs() );
79  for( int i = 0; i < numDofs; ++i )
80  lfSon[ i ] = lfFather[ i ];
81  }
82 
84  bool needCommunication () const { return true; }
85 
86 
87  template< class Entity >
88  static DomainFieldType calcWeight ( const Entity &father, const Entity &son )
89  {
90  return son.geometry().volume() / father.geometry().volume();
91  }
92 
93  protected:
94  DomainFieldType weight_;
95  };
96 
97 
98 
99  // EmptyLocalRestrictProlong
100  // -------------------------
101 
102  template< class DiscreteFunctionSpace >
104  {
106 
107  public:
109 
110  typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType;
111 
118  void setFatherChildWeight ( const DomainFieldType &weight ) {}
119 
121  template< class LFFather, class LFSon, class LocalGeometry >
122  void restrictLocal ( LFFather &lfFather, const LFSon &lfSon,
123  const LocalGeometry &geometryInFather, bool initialize ) const
124  {}
125 
127  template< class LFFather, class LFSon, class LocalGeometry >
128  void prolongLocal ( const LFFather &lfFather, LFSon &lfSon,
129  const LocalGeometry &geometryInFather, bool initialize ) const
130  {}
131 
133  bool needCommunication () const { return false; }
134  };
135 
136  } // namespace Fem
137 
138 } // namespace Dune
139 
140 #endif // #ifndef DUNE_FEM_LOCALRESTRICTPROLONG_HH
bool needCommunication() const
do discrete functions need a communication after restriction / prolongation?
Definition: common/localrestrictprolong.hh:133
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: common/localrestrictprolong.hh:29
DomainFieldType weight_
Definition: common/localrestrictprolong.hh:94
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
Definition: common/localrestrictprolong.hh:110
void setFatherChildWeight(const DomainFieldType &weight)
explicit set volume ratio of son and father
Definition: common/localrestrictprolong.hh:43
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
Definition: common/localrestrictprolong.hh:31
void prolongLocal(const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: common/localrestrictprolong.hh:74
Definition: common/localrestrictprolong.hh:24
bool needCommunication() const
do discrete functions need a communication after restriction / prolongation?
Definition: common/localrestrictprolong.hh:84
void setFatherChildWeight(const DomainFieldType &weight)
explicit set volume ratio of son and father
Definition: common/localrestrictprolong.hh:118
Definition: coordinate.hh:4
Definition: common/localrestrictprolong.hh:103
static DomainFieldType calcWeight(const Entity &father, const Entity &son)
Definition: common/localrestrictprolong.hh:88
discrete function space
void restrictLocal(LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: common/localrestrictprolong.hh:50
void prolongLocal(const LFFather &lfFather, LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
prolong data to children
Definition: common/localrestrictprolong.hh:128
ConstantLocalRestrictProlong()
Definition: common/localrestrictprolong.hh:33
Definition: common/localrestrictprolong.hh:16
void restrictLocal(LFFather &lfFather, const LFSon &lfSon, const LocalGeometry &geometryInFather, bool initialize) const
restrict data to father
Definition: common/localrestrictprolong.hh:122
DiscreteFunctionSpace DiscreteFunctionSpaceType
Definition: common/localrestrictprolong.hh:108