DUNE-FEM (unstable)

errordisplay.hh
1#ifndef DUNE_FEM_ERRORDISPLAY_HH
2#define DUNE_FEM_ERRORDISPLAY_HH
3
5
6#include <dune/fem/common/coordinate.hh>
7#include <dune/fem/function/common/gridfunctionadapter.hh>
8
9namespace Dune
10{
11
12 template< class DiscreteFunction, class SolutionType, bool withTime = true >
13 class DisplayErrorFunction;
14
15
16 template< class DiscreteFunction, class SolutionType >
17 class DisplayErrorFunction< DiscreteFunction, SolutionType, true >
18 {
19 typedef DisplayErrorFunction< DiscreteFunction, SolutionType > ThisType;
20
21 public:
22 typedef DiscreteFunction DiscreteFunctionType;
23
24 typedef typename DiscreteFunctionType :: LocalFunctionType LocalFunctionType;
25
27 DiscreteFunctionSpaceType;
28
29 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType;
30
31 protected:
32 struct Error;
33
34 typedef Fem::LocalFunctionAdapter< Error > ErrorFunctionType;
35
36 public:
37 template< class GrapeDispType >
38 DisplayErrorFunction ( GrapeDispType &disp,
39 const DiscreteFunctionType &Uh,
40 const SolutionType &solution,
41 const double time = 0 )
42 : gridPart_( Uh.space().gridPart() ),
43 error_( Uh, solution, time ),
44 errorFunction_( "error", error_, gridPart_ )
45 {
46 disp.addData( errorFunction_, "error", time );
47 }
48
49 private:
50 DisplayErrorFunction ( const ThisType & );
51 ThisType &operator= ( const ThisType & );
52
53 protected:
54 const GridPartType &gridPart_;
55 Error error_;
56 ErrorFunctionType errorFunction_;
57 };
58
59
61 template< class DiscreteFunction, class SolutionType >
62 struct DisplayErrorFunction< DiscreteFunction, SolutionType, true >::Error
63 {
64 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType;
65
66 typedef typename DiscreteFunctionSpaceType :: FunctionSpaceType
68 typedef typename FunctionSpaceType :: DomainType DomainType;
69 typedef typename FunctionSpaceType :: RangeType RangeType;
70 typedef typename FunctionSpaceType :: JacobianRangeType JacobianRangeType;
71
72 static const int dimDomain = DiscreteFunctionSpaceType :: dimDomain;
73 static const int dimRange = DiscreteFunctionSpaceType :: dimRange;
74
75 protected:
76 typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
77 typedef typename GridPartType::template Codim< 0 >::GeometryType GeometryType;
78
79 public:
80 Error ( const DiscreteFunctionType &Uh,
81 const SolutionType &solution,
82 double time = 0 )
83 : lUh_( Uh ),
84 initU0_( solution ),
85 entity_( 0 ),
86 time_( time )
87 {}
88
89 template< class PointType >
90 void evaluate ( const PointType &x, RangeType& ret) const
91 {
92 assert( initialized() );
93 lUh_.evaluate( x, ret );
94 DomainType global = entity().geometry().global( coordinate( x ) );
95 RangeType phi;
96 initU0_.evaluate( time_, global, phi );
97 ret -= phi;
98 }
99
100 template< class PointType >
101 void jacobian ( const PointType &x, JacobianRangeType &ret ) const
102 {
103 DUNE_THROW( NotImplemented, "DisplayErrorFunction::jacobian is not implemented." );
104 }
105
106 void init ( const EntityType &entity )
107 {
108 entity_ = &entity;
109 lUh_.init( entity );
110 }
111
112 protected:
113 const EntityType &entity () const
114 {
115 assert( entity_ );
116 return *entity_;
117 }
118
119 bool initialized () const { return entity_; }
120
121 LocalFunctionType lUh_;
122 const SolutionType &initU0_;
123 const EntityType *entity_;
124 const double time_;
125 };
130 template< class DiscreteFunction, class SolutionType >
131 class DisplayErrorFunction< DiscreteFunction, SolutionType, false >
132 {
133 typedef DisplayErrorFunction< DiscreteFunction, SolutionType > ThisType;
134
135 public:
136 typedef DiscreteFunction DiscreteFunctionType;
137
138 typedef typename DiscreteFunctionType :: LocalFunctionType LocalFunctionType;
139
141 DiscreteFunctionSpaceType;
142
143 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType;
144
145 protected:
147 struct Error
148 {
149 typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType;
150
151 typedef typename DiscreteFunctionSpaceType :: FunctionSpaceType
153 typedef typename FunctionSpaceType :: DomainType DomainType;
154 typedef typename FunctionSpaceType :: RangeType RangeType;
155 typedef typename FunctionSpaceType :: JacobianRangeType JacobianRangeType;
156
157 static const int dimDomain = DiscreteFunctionSpaceType :: dimDomain;
158 static const int dimRange = DiscreteFunctionSpaceType :: dimRange;
159
160 protected:
161 typedef typename GridPartType::template Codim< 0 >::EntityType EntityType;
162 typedef typename GridPartType::template Codim< 0 >::GeometryType GeometryType;
163
164 public:
165 Error ( const DiscreteFunctionType &Uh,
166 const SolutionType &solution )
167 : lUh_( Uh ),
168 initU0_( solution ),
169 entity_( 0 )
170 {}
171
172 template< class PointType >
173 void evaluate ( const PointType &x, RangeType& ret) const
174 {
175 assert( initialized() );
176 lUh_.evaluate( x, ret );
177 DomainType global = entity().geometry().global( coordinate( x ) );
178 RangeType phi;
179 initU0_.evaluate( global, phi );
180 ret -= phi;
181 }
182
183 template< class PointType >
184 void jacobian ( const PointType &x, JacobianRangeType &ret ) const
185 {
186 DUNE_THROW( NotImplemented, "DisplayErrorFunction::jacobian is not implemented." );
187 }
188
189 void init ( const EntityType &entity )
190 {
191 entity_ = &entity;
192 lUh_.init( entity );
193 }
194
195 protected:
196 const EntityType &entity () const
197 {
198 assert( entity_ );
199 return *entity_;
200 }
201
202 bool initialized () const { return entity_; }
203
204 LocalFunctionType lUh_;
205 const SolutionType &initU0_;
206 const EntityType *entity_;
207 };
210 typedef Fem::LocalFunctionAdapter< Error > ErrorFunctionType;
211 typedef Fem::GridFunctionAdapter< SolutionType, GridPartType >
212 GridSolutionType;
213
214 protected:
215 const GridPartType &gridPart_;
216 GridSolutionType gridSolution_;
217 Error error_;
218 ErrorFunctionType errorFunction_;
219
220 public:
221 template< class GrapeDispType >
222 DisplayErrorFunction ( GrapeDispType &disp,
223 const DiscreteFunctionType &Uh,
224 const SolutionType &solution )
225 : gridPart_( Uh.space().gridPart() ),
226 gridSolution_( "exact solution", solution, gridPart_ ),
227 error_( Uh, solution ),
228 errorFunction_( "error", error_, gridPart_ )
229 {
230 disp.addData( errorFunction_ );
231 disp.addData( gridSolution_ );
232 }
233
234 private:
235 DisplayErrorFunction ( const ThisType & );
236 ThisType &operator= ( const ThisType & );
237 };
238
239} // namespace Dune
240
241#endif // DUNE_FEM_ERRORDISPLAY_HH
BaseType::LocalFunctionType LocalFunctionType
type of local functions
Definition: discretefunction.hh:639
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
FunctionSpaceTraits::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:75
FunctionSpaceTraits::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:67
A vector valued function space.
Definition: functionspace.hh:60
forward declaration
Definition: discretefunction.hh:51
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
A few common exception classes.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)