DUNE-FEM (unstable)

average.hh
1#ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_AVERAGE_HH
2#define DUNE_FEM_FUNCTION_LOCALFUNCTION_AVERAGE_HH
3
4#include <dune/fem/gridpart/common/capabilities.hh>
5#include <dune/fem/quadrature/cachingquadrature.hh>
6#include <dune/fem/space/common/discretefunctionspace.hh>
7#include <dune/fem/space/discontinuousgalerkin/declaration.hh>
8#include <dune/fem/space/finitevolume/declaration.hh>
9
10namespace Dune
11{
12
13 namespace Fem
14 {
15
16 // Internal forward declaration
17 // ----------------------------
18
19 template< class LocalFunction, class GridPart >
20 class LocalAverage;
21
22
23
24 // LocalAverageHelper
25 // ------------------
26
27 struct LocalAverageHelper
28 {
29 template< class LocalFunction, class Quadrature >
30 static void applyQuadrature ( const LocalFunction &localFunction,
31 const typename LocalFunction::EntityType::Geometry &geometry,
32 const Quadrature &quadrature,
33 typename LocalFunction::RangeType &value )
34 {
35 typedef typename LocalFunction::RangeType RangeType;
36 typedef typename RangeType::value_type RangeFieldType;
37
38 value = RangeType( 0 );
39 RangeFieldType volume( 0 );
40 const int nop = quadrature.nop();
41 for( int qp = 0; qp < nop; ++qp )
42 {
43 RangeType tmp;
44 localFunction.evaluate( quadrature[ qp ], tmp );
45 RangeFieldType weight = quadrature.weight( qp )*geometry.integrationElement( quadrature.point( qp ) );
46 volume += weight;
47 value.axpy( weight, tmp );
48 }
49 value /= volume;
50 }
51 };
52
53
54
55 // LocalAverageImpl
56 // ----------------
57
58 template< class LocalFunction, class GridPart, class DiscreteFunctionSpace >
59 struct LocalAverageImpl
60 {
61 static void apply ( const LocalFunction &localFunction, typename LocalFunction::RangeType &average )
62 {
63 // get entity
64 typedef typename LocalFunction::EntityType EntityType;
65 const EntityType &entity = localFunction.entity();
66
67 // create quadrature
68 typedef CachingQuadrature< GridPart, EntityType::codimension > QuadratureType;
69 QuadratureType quadrature( entity, localFunction.order() );
70 LocalAverageHelper::applyQuadrature( localFunction, entity.geometry(), quadrature, average );
71 }
72 };
73
74
75
76 // LocalAverageImpl for DiscontinuousGalerkinSpace
77 // -----------------------------------------------
78
79 template< class LocalFunction, class GridPart, class FunctionSpace, int order, class Storage >
80 class LocalAverageImpl< LocalFunction, GridPart, DiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage > >
81 {
82 static const bool cartesian = GridPartCapabilities::isCartesian< GridPart >::v;
83
84 static void applyAffine ( const LocalFunction &localFunction, typename LocalFunction::RangeType &average )
85 {
86 // otherwise use direct computation
87 const int dimRange = LocalFunction::dimRange;
88 for( int i = 0; i < dimRange; ++i )
89 average[ i ] = localFunction[ i ];
90
91 const typename LocalFunction::BasisFunctionSetType &basisFunctionSet = localFunction.basisFunctionSet();
92 average /= std::sqrt( basisFunctionSet.referenceElement().volume() );
93 }
94
95 public:
96 static void apply ( const LocalFunction &localFunction, typename LocalFunction::RangeType &average )
97 {
98 if( cartesian )
99 return applyAffine( localFunction, average );
100
101 // get entity and geometry
102 typedef typename LocalFunction::EntityType EntityType;
103 const EntityType &entity = localFunction.entity();
104 const typename EntityType::Geometry geometry = entity.geometry();
105
106 if( geometry.affine() )
107 return applyAffine( localFunction, average );
108
109 // for not affine elements, use quadrature
110 typedef CachingQuadrature< GridPart, EntityType::codimension > QuadratureType;
111 QuadratureType quadrature( entity, localFunction.order() );
112 LocalAverageHelper::applyQuadrature( localFunction, geometry, quadrature, average );
113 }
114 };
115
116
117
118 // LocalAverageImpl for FiniteVolumeSpace
119 // --------------------------------------
120
121 template< class LocalFunction, class GridPart, class FunctionSpace, int codim, class Storage >
122 class LocalAverageImpl< LocalFunction, GridPart, FiniteVolumeSpace< FunctionSpace, GridPart, codim, Storage > >
123 {
124 public:
125 static void apply ( const LocalFunction &localFunction, typename LocalFunction::RangeType &average )
126 {
127 localFunction.evaluate( typename LocalFunction::DomainType( 0 ), average );
128 }
129 };
130
131
132
133 // LocalAverage
134 // ------------
135
136 template< class LocalFunction, class GridPart >
137 class LocalAverage
138 {
139 typedef typename ExportsDiscreteFunctionSpaceType< LocalFunction >::Type DiscreteFunctionSpaceType;
140 typedef LocalAverageImpl< LocalFunction, GridPart, DiscreteFunctionSpaceType > Impl;
141
142 public:
143 static void apply ( const LocalFunction &localFunction, typename LocalFunction::RangeType &average )
144 {
145 Impl::apply( localFunction, average );
146 }
147
148 void operator() ( const LocalFunction &localFunction, typename LocalFunction::RangeType &average ) const
149 {
150 Impl::apply( localFunction, average );
151 }
152 };
153
154 } // namespace Fem
155
156} // namespace Dune
157
158#endif // #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_AVERAGE_HH
GridImp::template Codim< cd >::Geometry Geometry
The corresponding geometry type.
Definition: entity.hh:100
FunctionSpaceType::DomainType DomainType
type of domain vectors, i.e., type of coordinates
Definition: localfunction.hh:108
BasisFunctionSet BasisFunctionSetType
type of basis function set
Definition: localfunction.hh:83
FunctionSpaceType::RangeType RangeType
type of range vectors, i.e., type of function values
Definition: localfunction.hh:110
static const int dimRange
dimension of the range
Definition: localfunction.hh:122
BasisFunctionSetType::EntityType EntityType
type of the entity, the local function lives on is given by the space
Definition: localfunction.hh:95
actual interface class for quadratures
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)