dune-fem  2.4.1-rc
errordisplay.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_ERRORDISPLAY_HH
2 #define DUNE_FEM_ERRORDISPLAY_HH
3 
4 #include <dune/common/exceptions.hh>
5 
8 
9 namespace Dune
10 {
11 
12  template< class DiscreteFunction, class SolutionType, bool withTime = true >
14 
15 
16  template< class DiscreteFunction, class SolutionType >
17  class DisplayErrorFunction< DiscreteFunction, SolutionType, true >
18  {
20 
21  public:
22  typedef DiscreteFunction DiscreteFunctionType;
23 
24  typedef typename DiscreteFunctionType :: LocalFunctionType LocalFunctionType;
25 
26  typedef typename DiscreteFunctionType :: DiscreteFunctionSpaceType
28 
29  typedef typename DiscreteFunctionSpaceType :: GridPartType GridPartType;
30 
31  protected:
32  struct Error;
33 
35 
36  public:
37  template< class GrapeDispType >
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
67  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  {
134 
135  public:
136  typedef DiscreteFunction DiscreteFunctionType;
137 
138  typedef typename DiscreteFunctionType :: LocalFunctionType LocalFunctionType;
139 
140  typedef typename DiscreteFunctionType :: 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
152  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  };
213 
214  protected:
215  const GridPartType &gridPart_;
217  Error error_;
218  ErrorFunctionType errorFunction_;
219 
220  public:
221  template< class GrapeDispType >
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
Fem::LocalFunctionAdapter< Error > ErrorFunctionType
Definition: errordisplay.hh:210
Fem::GridFunctionAdapter< SolutionType, GridPartType > GridSolutionType
Definition: errordisplay.hh:212
DiscreteFunction DiscreteFunctionType
Definition: errordisplay.hh:22
GridSolutionType gridSolution_
Definition: errordisplay.hh:216
DiscreteFunction DiscreteFunctionType
Definition: errordisplay.hh:136
Fem::LocalFunctionAdapter< Error > ErrorFunctionType
Definition: errordisplay.hh:32
const GridPartType & gridPart_
Definition: errordisplay.hh:215
Definition: errordisplay.hh:13
DiscreteFunctionType::LocalFunctionType LocalFunctionType
Definition: errordisplay.hh:138
Definition: coordinate.hh:4
ErrorFunctionType errorFunction_
Definition: errordisplay.hh:218
DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: errordisplay.hh:143
DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: errordisplay.hh:29
DisplayErrorFunction(GrapeDispType &disp, const DiscreteFunctionType &Uh, const SolutionType &solution, const double time=0)
Definition: errordisplay.hh:38
DisplayErrorFunction(GrapeDispType &disp, const DiscreteFunctionType &Uh, const SolutionType &solution)
Definition: errordisplay.hh:222
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: errordisplay.hh:27
GrapeDataDisplay< GR_GridType > GrapeDispType
type of GrapeDisplay
Definition: readiotupledata.cc:22
DiscreteFunctionType::LocalFunctionType LocalFunctionType
Definition: errordisplay.hh:24
const GridPartType & gridPart_
Definition: errordisplay.hh:54
ErrorFunctionType errorFunction_
Definition: errordisplay.hh:56
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: errordisplay.hh:141
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:11