Dune Core Modules (2.6.0)

interpolation.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
4#define DUNE_LAGRANGEBASIS_INTERPOLATION_HH
5
6#include <vector>
7#include <dune/geometry/topologyfactory.hh>
8#include <dune/localfunctions/lagrange/lagrangecoefficients.hh>
9
10namespace Dune
11{
12
13 template< template <class,unsigned int> class LP,
14 unsigned int dim, class F >
15 struct LagrangeInterpolationFactory;
16
17 // LocalLagrangeInterpolation
18 // --------------------------
19
20 template< template <class,unsigned int> class LP,
21 unsigned int dim, class F >
22 class LocalLagrangeInterpolation
23 {
24 typedef LocalLagrangeInterpolation< LP,dim,F > This;
25
26 public:
27 typedef LP<F,dim> LagrangePointSet;
28 typedef typename LagrangePointSet::Field Field;
29
30 static const unsigned int dimension = LagrangePointSet::dimension;
31
32 private:
33 friend struct LagrangeInterpolationFactory<LP,dim,F>;
34 const LagrangePointSet &lagrangePoints_;
35
36 explicit LocalLagrangeInterpolation ( const LagrangePointSet &lagrangePoints )
37 : lagrangePoints_( lagrangePoints )
38 {}
39 const LagrangePointSet *points () const
40 {
41 return &lagrangePoints_;
42 }
43
44 public:
45 template< class Function, class Fy >
46 void interpolate ( const Function &function, std::vector< Fy > &coefficients ) const
47 {
48 typedef typename LagrangePointSet::iterator Iterator;
49
50 coefficients.resize( lagrangePoints_.size() );
51
52 unsigned int index = 0;
53 const Iterator end = lagrangePoints_.end();
54 for( Iterator it = lagrangePoints_.begin(); it != end; ++it )
55 {
56 typename Function::RangeType val;
57 function.evaluate( field_cast<typename Function::DomainType::field_type>(it->point()), val );
58 field_cast( val, coefficients[ index++ ] );
59 }
60 }
61
62 template< class Matrix, class Basis >
63 void interpolate ( const Basis &basis, Matrix &coefficients ) const
64 {
65 typedef typename LagrangePointSet::iterator Iterator;
66
67 coefficients.resize( lagrangePoints_.size(), basis.size( ) );
68
69 unsigned int index = 0;
70 const Iterator end = lagrangePoints_.end();
71 for( Iterator it = lagrangePoints_.begin(); it != end; ++it )
72 basis.template evaluate<0>( it->point(), coefficients.rowPtr( index++ ) );
73 }
74
75 const LagrangePointSet &lagrangePoints () const
76 {
77 return lagrangePoints_;
78 }
79 };
80
81
82
83 // LocalLagrangeInterpolationFactory
84 // ---------------------------------
85 template< template <class,unsigned int> class LP,
86 unsigned int dim, class F >
87 struct LagrangeInterpolationFactoryTraits
88 {
89 typedef LagrangeCoefficientsFactory<LP,dim,F> LagrangePointSetFactory;
90 typedef typename LagrangePointSetFactory::Object LagrangePointSet;
91
92 typedef typename LagrangePointSetFactory::Key Key;
93 typedef const LocalLagrangeInterpolation< LP,dim,F > Object;
94 typedef LagrangeInterpolationFactory<LP,dim,F> Factory;
95
96 static const unsigned int dimension = dim;
97 };
98
99 template< template <class,unsigned int> class LP,
100 unsigned int dim, class F >
101 struct LagrangeInterpolationFactory :
102 public TopologyFactory< LagrangeInterpolationFactoryTraits< LP,dim,F > >
103 {
104 typedef LagrangeInterpolationFactoryTraits< LP,dim,F > Traits;
105 typedef typename Traits::Key Key;
106 typedef typename Traits::Object Object;
107
108 template< class Topology >
109 static Object *createObject ( const Key &key )
110 {
111 const typename Traits::LagrangePointSet *lagrangeCoeff
112 = Traits::LagrangePointSetFactory::template create< Topology >( key );
113 if ( lagrangeCoeff == 0 )
114 return 0;
115 else
116 return new Object( *lagrangeCoeff );
117 }
118 template< class Topology >
119 static bool supports ( const typename Traits::Key &key )
120 {
121 return true;
122 }
123 static void release( Object *object)
124 {
125 Traits::LagrangePointSetFactory::release( object->points() );
126 delete object;
127 }
128 };
129
130}
131
132#endif // #ifndef DUNE_LAGRANGEBASIS_INTERPOLATION_HH
RawRangeType RangeType
Raw type of input variable with removed reference and constness.
Definition: function.hh:36
Dune namespace.
Definition: alignedallocator.hh:10
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:60
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)