DUNE-FEM (unstable)

restrictprolongfunction.hh
1 #ifndef DUNE_FEM_RESTRICTPROLONGFUNCTION_HH
2 #define DUNE_FEM_RESTRICTPROLONGFUNCTION_HH
3 
5 
7 #include <dune/fem/function/localfunction/const.hh>
8 
9 namespace Dune
10 {
11 
12  namespace Fem
13  {
14 
22  template< class LRP >
24  {
26  typedef LRP LocalRestrictProlong;
27 
35  template< class CoarseFunction, class FineFunction >
36  void operator() ( const CoarseFunction &coarseFunction,
37  FineFunction &fineFunction ) const
38  {
39  typedef typename CoarseFunction::DiscreteFunctionSpaceType CoarseSpace;
40 
41  ConstLocalFunction< CoarseFunction > coarseLocalFunction( coarseFunction );
42  MutableLocalFunction< FineFunction > fineLocalFunction( fineFunction );
43 
44  const CoarseSpace &coarseSpace = coarseFunction.space();
45  for( const auto& entity : coarseSpace )
46  {
47  auto cg = bindGuard( coarseLocalFunction, entity );
48 
49  if( isDefinedOn( fineFunction, entity ) )
50  {
51  auto fg = bindGuard( fineLocalFunction, entity );
52  fineLocalFunction.assign( coarseLocalFunction );
53  }
54  else
55  hierarchicProlong( coarseLocalFunction, fineLocalFunction );
56  }
57  }
58 
59  private:
60  template< class CoarseLocalFunction, class FineLocalFunction >
61  void hierarchicProlong ( const CoarseLocalFunction &coarseLocalFunction,
62  FineLocalFunction &fineLocalFunction ) const
63  {
64  typedef typename CoarseLocalFunction::EntityType Entity;
65  typedef typename Entity::HierarchicIterator HierarchicIterator;
66 
67  const Entity &parent = coarseLocalFunction.entity();
68  const int childLevel = parent.level()+1;
69 
70  const HierarchicIterator hend = parent.hend( childLevel );
71  for( HierarchicIterator hit = parent.hbegin( childLevel ); hit != hend; ++hit )
72  {
73  const Entity &child = *hit;
74  if( isDefinedOn( fineLocalFunction.discreteFunction(), child ) )
75  {
76  auto guard = bindGuard( fineLocalFunction, child );
77  localRestrictProlong_.prolongLocal( coarseLocalFunction, fineLocalFunction, child.geometryInFather(), true );
78  }
79  else
80  DUNE_THROW( GridError, "Cannot prolong over more than one level." );
81  }
82  }
83 
84  template< class Function >
85  static bool isDefinedOn ( const Function &function, const typename Function::GridPartType::template Codim< 0 >::EntityType &entity )
86  {
87  typedef typename Function::GridPartType::IndexSetType IndexSet;
88  const IndexSet &indexSet = function.gridPart().indexSet();
89  return indexSet.contains( entity );
90  }
91 
92  private:
93  LocalRestrictProlong localRestrictProlong_;
94  };
95 
96 
97 
105  template< class LRP >
107  {
109  typedef LRP LocalRestrictProlong;
110 
111  public:
119  template< class FineFunction, class CoarseFunction >
120  void operator() ( const FineFunction &fineFunction,
121  CoarseFunction &coarseFunction ) const
122  {
123  typedef typename CoarseFunction::DiscreteFunctionSpaceType CoarseSpace;
124 
125  ConstLocalFunction< FineFunction > fineLocalFunction( fineFunction );
126  MutableLocalFunction< CoarseFunction > coarseLocalFunction( coarseFunction );
127 
128  const CoarseSpace &coarseSpace = coarseFunction.space();
129  for( const auto& entity : coarseSpace )
130  {
131  auto cg = bindGuard( coarseLocalFunction, entity );
132 
133  if( isDefinedOn( fineFunction, entity ) )
134  {
135  auto fg = bindGuard( fineLocalFunction, entity );
136  coarseLocalFunction.assign( fineLocalFunction );
137  }
138  else
139  hierarchicRestrict( fineLocalFunction, coarseLocalFunction );
140  }
141  }
142 
143  private:
144  template< class FineLocalFunction, class CoarseLocalFunction >
145  void hierarchicRestrict ( FineLocalFunction &fineLocalFunction,
146  CoarseLocalFunction &coarseLocalFunction ) const
147  {
148  typedef typename CoarseLocalFunction::EntityType Entity;
149  typedef typename Entity::HierarchicIterator HierarchicIterator;
150 
151  const Entity &parent = coarseLocalFunction.entity();
152  const int childLevel = parent.level()+1;
153 
154  bool initialize = true;
155  const HierarchicIterator hend = parent.hend( childLevel );
156  for( HierarchicIterator hit = parent.hbegin( childLevel ); hit != hend; ++hit )
157  {
158  const Entity &child = *hit;
159  if( isDefinedOn( fineLocalFunction.discreteFunction(), child ) )
160  {
161  auto guard = bindGuard( fineLocalFunction, child );
162  localRestrictProlong_.restrictLocal( coarseLocalFunction, fineLocalFunction, child.geometryInFather(), initialize );
163  }
164  else
165  DUNE_THROW( GridError, "Cannot restrict over more than one level." );
166  initialize = false;
167  }
168  localRestrictProlong_.restrictFinalize(parent);
169  }
170 
171  template< class Function >
172  static bool isDefinedOn ( const Function &function, const typename Function::GridPartType::template Codim< 0 >::EntityType &entity )
173  {
174  typedef typename Function::GridPartType::IndexSetType IndexSet;
175  const IndexSet &indexSet = function.gridPart().indexSet();
176  return indexSet.contains( entity );
177  }
178 
179  private:
180  LocalRestrictProlong localRestrictProlong_;
181  };
182 
183  } // namespace Fem
184 
185 } // namespace Dune
186 
187 #endif // #ifndef DUNE_FEM_RESTRICTPROLONGFUNCTION_HH
Wrapper class for entities.
Definition: entity.hh:66
int level() const
The level of this entity.
Definition: entity.hh:124
void assign(const LocalFunction< BasisFunctionSet, T > &other)
assign all DoFs of this local function
Definition: localfunction.hh:189
Definition: mutable.hh:31
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:20
Different resources needed by all grid implementations.
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
concept Entity
Model of a grid entity.
Definition: entity.hh:107
concept IndexSet
Model of an index set.
Definition: indexidset.hh:44
Dune namespace.
Definition: alignedallocator.hh:13
prolong discrete functions between grid levels
Definition: restrictprolongfunction.hh:24
void operator()(const CoarseFunction &coarseFunction, FineFunction &fineFunction) const
prolong a discrete function to finer grid level
Definition: restrictprolongfunction.hh:36
LRP LocalRestrictProlong
type of the local restriction and prolongation operator
Definition: restrictprolongfunction.hh:26
restrict discrete functions between grid levels
Definition: restrictprolongfunction.hh:107
void operator()(const FineFunction &fineFunction, CoarseFunction &coarseFunction) const
restrict a discrete function to coarser grid level
Definition: restrictprolongfunction.hh:120
LRP LocalRestrictProlong
type of the local restriction and prolongation operator
Definition: restrictprolongfunction.hh:109
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 14, 22:30, 2024)