dune-fem  2.4.1-rc
lagrangeinterpolation.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_LAGRANGEINTERPOLATION_HH
2 #define DUNE_FEM_LAGRANGEINTERPOLATION_HH
3 
4 #include <type_traits>
5 
6 #include <dune/common/typetraits.hh>
7 
10 
11 namespace Dune
12 {
13 
14  namespace Fem
15  {
16 
20  template< class Function, class DiscreteFunction >
21  class LagrangeInterpolation : public Operator< Function, DiscreteFunction >
22  {
24 
25  public:
27  typedef DiscreteFunction DiscreteFunctionType;
28 
30  typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType
33  typedef typename DiscreteFunctionType::LocalFunctionType
35 
37  typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
38 
40  typedef typename DiscreteFunctionSpaceType::LagrangePointSetType
43  typedef typename DiscreteFunctionSpaceType::DomainType DomainType;
45  typedef typename DiscreteFunctionSpaceType::RangeType RangeType;
46 
47  public:
50 
52  virtual ~LagrangeInterpolation () {}
53 
65  void operator () ( const Function &function,
66  DiscreteFunctionType &discreteFunction ) const
67  {
68  interpolateFunction( function, discreteFunction );
69  }
70 
82  static void interpolateFunction ( const Function &function, DiscreteFunctionType &discreteFunction )
83  {
84  const bool hasLocalFunction = Conversion< Function, HasLocalFunction >::exists;
85  interpolateFunction( function, discreteFunction, std::integral_constant< bool, hasLocalFunction >() );
86  }
87 
89  //- make interface equal to DGL2Projection
90  static void apply ( const Function &function, DiscreteFunctionType &discreteFunction )
91  {
92  interpolateFunction( function, discreteFunction );
93  }
94 
95  private:
96  static void interpolateFunction ( const Function &function, DiscreteFunctionType &discreteFunction, std::integral_constant< bool, true > )
97  {
98  interpolateDiscreteFunction( function, discreteFunction );
99  }
100 
101  static void interpolateFunction ( const Function &function, DiscreteFunctionType &discreteFunction, std::integral_constant< bool, false > )
102  {
103  typedef GridFunctionAdapter< Function, GridPartType > GridFunctionType;
104 
105  const DiscreteFunctionSpaceType &dfSpace = discreteFunction.space();
106  GridFunctionType dfAdapter( "function", function, dfSpace.gridPart() );
107  interpolateDiscreteFunction( dfAdapter, discreteFunction );
108  }
109 
110  template< class GridFunction >
111  static void interpolateDiscreteFunction ( const GridFunction &function, DiscreteFunctionType &discreteFunction );
112  };
113 
114 
115 
116  template< class Function, class DiscreteFunction >
117  template< class GridFunction >
119  ::interpolateDiscreteFunction ( const GridFunction &function,
120  DiscreteFunctionType &discreteFunction )
121  {
122  typedef typename DiscreteFunctionType::DofType DofType;
123  typedef typename DiscreteFunctionType::DofIteratorType DofIteratorType;
124  static const int dimRange = DiscreteFunctionSpaceType::dimRange;
125 
126  typedef typename GridFunction::LocalFunctionType FunctionLocalFunctionType;
127 
128  // set all DoFs to infinity
129  const DofIteratorType dend = discreteFunction.dend();
130  for( DofIteratorType dit = discreteFunction.dbegin(); dit != dend; ++dit )
131  *dit = std::numeric_limits< DofType >::infinity();
132 
133  const DiscreteFunctionSpaceType &dfSpace = discreteFunction.space();
134  for( const typename DiscreteFunctionSpaceType::EntityType &entity : dfSpace )
135  {
136  const LagrangePointSetType &lagrangePointSet
137  = dfSpace.lagrangePointSet( entity );
138 
139  FunctionLocalFunctionType f_local = function.localFunction( entity );
140  LocalFunctionType df_local = discreteFunction.localFunction( entity );
141 
142  // assume point based local dofs
143  const int nop = lagrangePointSet.nop();
144  int k = 0;
145  for( int qp = 0; qp < nop; ++qp )
146  {
147  // if the first DoF for this point is already valid, continue
148  if( df_local[ k ] == std::numeric_limits< DofType >::infinity() )
149  {
150  // evaluate the function in the Lagrange point
151  RangeType phi;
152  f_local.evaluate( lagrangePointSet[ qp ], phi );
153 
154  // assign the appropriate values to the DoFs
155  for( int i = 0; i < dimRange; ++i, ++k )
156  df_local[ k ] = phi[ i ];
157  }
158  else
159  k += dimRange;
160  }
161  }
162  }
163 
164  } // namespace Fem
165 
166 } // namespace Dune
167 
168 #endif // #ifndef DUNE_FEM_LAGRANGEINTERPOLATION_HH
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: lagrangeinterpolation.hh:31
LagrangeInterpolation()
empty contructor
Definition: lagrangeinterpolation.hh:49
void operator()(const Function &function, DiscreteFunctionType &discreteFunction) const
Definition: lagrangeinterpolation.hh:65
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: gridfunctionadapter.hh:171
DiscreteFunction DiscreteFunctionType
type of discrete functions
Definition: lagrangeinterpolation.hh:27
DiscreteFunctionSpaceType::DomainType DomainType
type of vectors in function&#39;s domain
Definition: lagrangeinterpolation.hh:43
virtual ~LagrangeInterpolation()
virtual destructor because of inheritance from Operator
Definition: lagrangeinterpolation.hh:52
abstract operator
Definition: operator.hh:25
DiscreteFunctionSpaceType::RangeType RangeType
type of vectors in function&#39;s range
Definition: lagrangeinterpolation.hh:45
Definition: coordinate.hh:4
DiscreteFunctionType::LocalFunctionType LocalFunctionType
type of local functions
Definition: lagrangeinterpolation.hh:34
DiscreteFunctionSpaceType::LagrangePointSetType LagrangePointSetType
type of Lagrange point set
Definition: lagrangeinterpolation.hh:41
GridFunctionAdapter provides local functions for a Function.
Definition: gridfunctionadapter.hh:36
Abstract class representing a function.
Definition: function.hh:43
static void interpolateFunction(const Function &function, DiscreteFunctionType &discreteFunction)
Definition: lagrangeinterpolation.hh:82
Generates the Lagrange Interpolation of an analytic function.
Definition: lagrangeinterpolation.hh:21
static void apply(const Function &function, DiscreteFunctionType &discreteFunction)
Definition: lagrangeinterpolation.hh:90
DiscreteFunctionSpaceType::GridPartType GridPartType
type of grid partition
Definition: lagrangeinterpolation.hh:37