1 #ifndef DUNE_FEM_RESTRICTPROLONGFUNCTION_HH 2 #define DUNE_FEM_RESTRICTPROLONGFUNCTION_HH 4 #include <dune/common/exceptions.hh> 6 #include <dune/grid/common/grid.hh> 34 template<
class CoarseFunction,
class FineFunction >
36 FineFunction &fineFunction )
const 38 typedef typename CoarseFunction::LocalFunctionType CoarseLocalFunction;
39 typedef typename CoarseFunction::DiscreteFunctionSpaceType CoarseSpace;
41 typedef typename FineFunction::LocalFunctionType FineLocalFunction;
43 const CoarseSpace &coarseSpace = coarseFunction.space();
44 for(
const auto& entity : coarseSpace )
46 CoarseLocalFunction coarseLocalFunction = coarseFunction.localFunction( entity );
48 if( isDefinedOn( fineFunction, entity ) )
50 FineLocalFunction fineLocalFunction = fineFunction.localFunction( entity );
51 fineLocalFunction.assign( coarseLocalFunction );
54 hierarchicProlong( coarseLocalFunction, fineFunction );
59 template<
class CoarseLocalFunction,
class FineFunction >
60 void hierarchicProlong (
const CoarseLocalFunction &coarseLocalFunction,
61 FineFunction &fineFunction )
const 63 typedef typename CoarseLocalFunction::EntityType Entity;
64 typedef typename Entity::HierarchicIterator HierarchicIterator;
65 typedef typename FineFunction::LocalFunctionType FineLocalFunction;
67 const Entity &father = coarseLocalFunction.entity();
68 const int childLevel = father.level()+1;
70 const HierarchicIterator hend = father.hend( childLevel );
71 for( HierarchicIterator hit = father.hbegin( childLevel ); hit != hend; ++hit )
73 const Entity &son = *hit;
74 if( isDefinedOn( fineFunction, son ) )
76 FineLocalFunction fineLocalFunction = fineFunction.localFunction( son );
77 localRestrictProlong_.prolongLocal( coarseLocalFunction, fineLocalFunction, son.geometryInFather(), true );
80 DUNE_THROW( GridError,
"Cannot prolong over more than one level." );
84 template<
class Function >
85 static bool isDefinedOn (
const Function &
function,
const typename Function::GridPartType::template Codim< 0 >::EntityType &entity )
87 typedef typename Function::GridPartType::IndexSetType
IndexSet;
88 const IndexSet &indexSet =
function.gridPart().indexSet();
93 LocalRestrictProlong localRestrictProlong_;
105 template<
class LRP >
119 template<
class FineFunction,
class CoarseFunction >
121 CoarseFunction &coarseFunction )
const 123 typedef typename CoarseFunction::LocalFunctionType CoarseLocalFunction;
124 typedef typename CoarseFunction::DiscreteFunctionSpaceType CoarseSpace;
126 typedef typename FineFunction::LocalFunctionType FineLocalFunction;
128 const CoarseSpace &coarseSpace = coarseFunction.space();
129 for(
const auto& entity : coarseSpace )
131 CoarseLocalFunction coarseLocalFunction = coarseFunction.localFunction( entity );
133 if( isDefinedOn( fineFunction, entity ) )
135 FineLocalFunction fineLocalFunction = fineFunction.localFunction( entity );
136 coarseLocalFunction.assign( fineLocalFunction );
139 hierarchicRestrict( fineFunction, coarseLocalFunction );
144 template<
class FineFunction,
class CoarseLocalFunction >
145 void hierarchicRestrict (
const FineFunction &fineFunction,
146 CoarseLocalFunction &coarseLocalFunction )
const 148 typedef typename CoarseLocalFunction::EntityType Entity;
149 typedef typename Entity::HierarchicIterator HierarchicIterator;
150 typedef typename FineFunction::LocalFunctionType FineLocalFunction;
152 const Entity &father = coarseLocalFunction.entity();
153 const int childLevel = father.level()+1;
155 bool initialize =
true;
156 const HierarchicIterator hend = father.hend( childLevel );
157 for( HierarchicIterator hit = father.hbegin( childLevel ); hit != hend; ++hit )
159 const Entity &son = *hit;
160 if( isDefinedOn( fineFunction, son ) )
162 FineLocalFunction fineLocalFunction = fineFunction.localFunction( son );
163 localRestrictProlong_.restrictLocal( coarseLocalFunction, fineLocalFunction, son.geometryInFather(), initialize );
166 DUNE_THROW( GridError,
"Cannot restrict over more than one level." );
171 template<
class Function >
172 static bool isDefinedOn (
const Function &
function,
const typename Function::GridPartType::template Codim< 0 >::EntityType &entity )
174 typedef typename Function::GridPartType::IndexSetType
IndexSet;
175 const IndexSet &indexSet =
function.gridPart().indexSet();
180 LocalRestrictProlong localRestrictProlong_;
187 #endif // #ifndef DUNE_FEM_RESTRICTPROLONGFUNCTION_HH
interface documentation for (grid part) index sets
Definition: common/indexset.hh:25
bool contains(const Entity &entity) const
return true if entity has index
Definition: common/indexset.hh:147
restrict discrete functions between grid levels
Definition: restrictprolongfunction.hh:106
LRP LocalRestrictProlong
type of the local restriction and prolongation operator
Definition: restrictprolongfunction.hh:109
Definition: coordinate.hh:4
void operator()(const CoarseFunction &coarseFunction, FineFunction &fineFunction) const
prolong a discrete function to finer grid level
Definition: restrictprolongfunction.hh:35
prolong discrete functions between grid levels
Definition: restrictprolongfunction.hh:22
LRP LocalRestrictProlong
type of the local restriction and prolongation operator
Definition: restrictprolongfunction.hh:25
Abstract class representing a function.
Definition: function.hh:43