DOpE
residualestimator.h
Go to the documentation of this file.
1 
24 #ifndef RESIDUAL_ERROR_H_
25 #define RESIDUAL_ERROR_H_
26 
27 #include "dwrdatacontainer.h"
28 #include <deal.II/fe/fe_tools.h>
29 
30 namespace DOpE
31 {
37  template<typename VECTOR>
39  {
40  public:
43  DWRDataContainerBase<VECTOR>(ee_terms)
44  {
45  }
46  virtual void
47  InitFace(double /*h*/) = 0;
48  virtual void
49  InitElement(double /*h*/) = 0;
50 
51  };
52 
60  template<class EDC, typename VECTOR>
61  EDC*
63  {
64  return NULL;
65  }
66  template<class FDC, typename VECTOR>
67  FDC*
69  {
70  return NULL;
71  }
77  template<class STH, typename VECTOR, int dim>
79  {
80  public:
82  ParameterReader &param_reader, DOpEtypes::EETerms ee_terms =
84  ResidualErrorContainer<VECTOR>(ee_terms), sth_(sth), PI_h_u_(NULL), PI_h_z_(
85  NULL)
86  {
87  if (this->GetEETerms() == DOpEtypes::primal_only
88  || this->GetEETerms() == DOpEtypes::mixed)
89  {
90  PI_h_z_ = new StateVector<VECTOR>(&GetSTH(), state_behavior,
91  param_reader);
92  }
93  if (this->GetEETerms() == DOpEtypes::dual_only
94  || this->GetEETerms() == DOpEtypes::mixed)
95  {
96  PI_h_u_ = new StateVector<VECTOR>(&GetSTH(), state_behavior,
97  param_reader);
98  }
99  weight_ = 0.;
100  }
101 
102  virtual
104  {
105  if (PI_h_z_ != NULL)
106  delete PI_h_z_;
107  if (PI_h_u_ != NULL)
108  delete PI_h_u_;
109 
110  }
111 
112  std::string
113  GetName() const
114  {
115  return "L2-Residual-Estimator";
116  }
117 
118  void
119  Initialize(unsigned int state_n_blocks,
120  std::vector<unsigned int>& state_block_component)
121  {
122  state_n_blocks_ = state_n_blocks;
123  state_block_component_ = &state_block_component;
124  }
125 
130  void
131  ReInit(unsigned int n_elements);
132 
135  {
136  return *PI_h_u_;
137  }
138 
141  {
142  return *PI_h_z_;
143  }
146  {
147  throw DOpEException("There is no Control in PDE Problems!",
148  "L2ResidualErrorContainer::PreparePI_h_q");
149  }
150 
156  void
158  {
159  BuildConstantWeight(&(GetSTH().GetStateDoFHandler()),
160  GetPI_h_u().GetSpacialVector());
161  }
162 
168  void
170  {
171  BuildConstantWeight(&(GetSTH().GetStateDoFHandler()),
172  GetPI_h_z().GetSpacialVector());
173  }
179  void
181  {
182  throw DOpEException("There is no Control in PDE Problems!",
183  "HigherOrderDWRContainer::PreparePI_h_q");
184 
185  }
186 
190  bool
191  NeedDual() const
192  {
193  return false;
194  }
195 
201  {
203  }
204 
210  {
212  }
213 
218  inline void
219  ResidualModifier(double& res)
220  {
221  res = res * res * weight_;
222  }
223 
224  inline void
225  VectorResidualModifier(dealii::Vector<double>& res)
226  {
227  for (unsigned int i = 0; i < res.size(); i++)
228  res(i) = res(i) * res(i) * weight_;
229  }
230 
231  void
232  InitFace(double h)
233  {
234  weight_ = h * h * h;
235  }
236  void
237  InitElement(double h)
238  {
239  weight_ = h * h * h * h;
240  }
241 
242  protected:
243  STH&
245  {
246  return sth_;
247  }
248 
249  template<template<int, int> class DH>
250  void
252  VECTOR& vals)
253  {
254  VectorTools::interpolate(sth_.GetMapping(),
255  *(static_cast<const DH<dim, dim>*>(dofh)),
256  ConstantFunction<dim>(1., dofh->get_fe().n_components()), vals);
257  }
258 
259  private:
260  unsigned int state_n_blocks_;
261  std::vector<unsigned int>* state_block_component_;
262  double weight_;
263 
264  STH& sth_;
265 
266  StateVector<VECTOR> * PI_h_u_, *PI_h_z_;
267  };
268 
269  template<class STH, typename VECTOR, int dim>
270  void
272  {
274 
275  if (this->GetEETerms() == DOpEtypes::primal_only
276  || this->GetEETerms() == DOpEtypes::mixed)
277  {
278  GetPI_h_z().ReInit();
279  }
280  if (this->GetEETerms() == DOpEtypes::dual_only
281  || this->GetEETerms() == DOpEtypes::mixed)
282  {
283  GetPI_h_u().ReInit();
284  }
285  }
286 
287  /**************************************************************************/
293  template<class STH, typename VECTOR, int dim>
295  {
296  public:
298  ParameterReader &param_reader, DOpEtypes::EETerms ee_terms =
300  ResidualErrorContainer<VECTOR>(ee_terms), sth_(sth), PI_h_u_(NULL), PI_h_z_(
301  NULL)
302  {
303  if (this->GetEETerms() == DOpEtypes::primal_only
304  || this->GetEETerms() == DOpEtypes::mixed)
305  {
306  PI_h_z_ = new StateVector<VECTOR>(&GetSTH(), state_behavior,
307  param_reader);
308  }
309  if (this->GetEETerms() == DOpEtypes::dual_only
310  || this->GetEETerms() == DOpEtypes::mixed)
311  {
312  PI_h_u_ = new StateVector<VECTOR>(&GetSTH(), state_behavior,
313  param_reader);
314  }
315  }
316 
317  virtual
319  {
320  if (PI_h_z_ != NULL)
321  delete PI_h_z_;
322  if (PI_h_u_ != NULL)
323  delete PI_h_u_;
324 
325  }
326 
327  std::string
328  GetName() const
329  {
330  return "H1-Residual-Estimator";
331  }
332 
333  void
334  Initialize(unsigned int state_n_blocks,
335  std::vector<unsigned int>& state_block_component)
336  {
337  state_n_blocks_ = state_n_blocks;
338  state_block_component_ = &state_block_component;
339  }
340 
345  void
346  ReInit(unsigned int n_elements);
347 
350  {
351  return *PI_h_u_;
352  }
353 
356  {
357  return *PI_h_z_;
358  }
361  {
362  throw DOpEException("There is no Control in PDE Problems!",
363  "H1ResidualErrorContainer::PreparePI_h_q");
364  }
365 
371  void
373  {
374  BuildConstantWeight(&(GetSTH().GetStateDoFHandler()),
375  GetPI_h_u().GetSpacialVector());
376  }
377 
383  void
385  {
386  BuildConstantWeight(&(GetSTH().GetStateDoFHandler()),
387  GetPI_h_z().GetSpacialVector());
388  }
394  void
396  {
397  throw DOpEException("There is no Control in PDE Problems!",
398  "HigherOrderDWRContainer::PreparePI_h_q");
399 
400  }
401 
405  bool
406  NeedDual() const
407  {
408  return false;
409  }
410 
416  {
418  }
419 
425  {
427  }
428 
433  inline void
434  ResidualModifier(double& res)
435  {
436  res = res * res * weight_;
437  }
438  inline void
439  VectorResidualModifier(dealii::Vector<double>& res)
440  {
441  for (unsigned int i = 0; i < res.size(); i++)
442  res(i) = res(i) * res(i) * weight_;
443  }
444 
445  void
446  InitFace(double h)
447  {
448  weight_ = h;
449  }
450  void
451  InitElement(double h)
452  {
453  weight_ = h * h;
454  }
455 
456  protected:
457  STH&
459  {
460  return sth_;
461  }
462 
463  template<template<int, int> class DH>
464  void
466  VECTOR& vals)
467  {
468  VectorTools::interpolate(sth_.GetMapping(),
469  dofh->GetDEALDoFHandler(),
470  ConstantFunction<dim>(1., dofh->get_fe().n_components()), vals);
471  }
472 
473  private:
474  unsigned int state_n_blocks_;
475  std::vector<unsigned int>* state_block_component_;
476  double weight_;
477 
478  STH& sth_;
479 
480  StateVector<VECTOR> * PI_h_u_, *PI_h_z_;
481  };
482 
483  template<class STH, typename VECTOR, int dim>
484  void
486  {
488 
489  if (this->GetEETerms() == DOpEtypes::primal_only
490  || this->GetEETerms() == DOpEtypes::mixed)
491  {
492  GetPI_h_z().ReInit();
493  }
494  if (this->GetEETerms() == DOpEtypes::dual_only
495  || this->GetEETerms() == DOpEtypes::mixed)
496  {
497  GetPI_h_u().ReInit();
498  }
499  }
500 
501 }
502 
503 #endif /* RESIDUAL_ERROR */
Definition: dopetypes.h:68
void Initialize(unsigned int state_n_blocks, std::vector< unsigned int > &state_block_component)
Definition: residualestimator.h:119
void BuildConstantWeight(const DOpEWrapper::DoFHandler< dim, DH > *dofh, VECTOR &vals)
Definition: residualestimator.h:465
H1ResidualErrorContainer(STH &sth, DOpEtypes::VectorStorageType state_behavior, ParameterReader &param_reader, DOpEtypes::EETerms ee_terms=DOpEtypes::EETerms::mixed)
Definition: residualestimator.h:297
ResidualErrorContainer(DOpEtypes::EETerms ee_terms=DOpEtypes::EETerms::mixed)
Definition: residualestimator.h:41
bool NeedDual() const
Definition: residualestimator.h:406
void InitElement(double h)
Definition: residualestimator.h:451
StateVector< VECTOR > & GetPI_h_u()
Definition: residualestimator.h:134
std::string GetName() const
Definition: residualestimator.h:328
Definition: parameterreader.h:36
void PreparePI_h_z(const StateVector< VECTOR > &)
Definition: residualestimator.h:384
StateVector< VECTOR > & GetPI_h_z()
Definition: residualestimator.h:355
void InitElement(double h)
Definition: residualestimator.h:237
virtual DOpEtypes::ResidualEvaluation GetResidualEvaluation() const
Definition: residualestimator.h:209
Definition: residualestimator.h:294
Definition: dopetypes.h:68
virtual DOpEtypes::WeightComputation GetWeightComputation() const
Definition: residualestimator.h:200
const DOFHANDLER< dim, dim > & GetDEALDoFHandler() const
Definition: dofhandler_wrapper.h:69
std::string GetName() const
Definition: residualestimator.h:113
void ReInit(unsigned int n_elements)
Definition: residualestimator.h:271
void PreparePI_h_z(const StateVector< VECTOR > &)
Definition: residualestimator.h:169
Definition: dopetypes.h:82
void PreparePI_h_q(const ControlVector< VECTOR > &)
Definition: residualestimator.h:395
Definition: controlvector.h:49
void VectorResidualModifier(dealii::Vector< double > &res)
Definition: residualestimator.h:225
EDC * ExtractEDC(const DWRDataContainer< STH, IDC, EDC, FDC, VECTOR > &dwrc)
Definition: dwrdatacontainer.h:592
virtual DOpEtypes::ResidualEvaluation GetResidualEvaluation() const
Definition: residualestimator.h:424
void PreparePI_h_q(const ControlVector< VECTOR > &)
Definition: residualestimator.h:180
void InitFace(double h)
Definition: residualestimator.h:232
void InitFace(double h)
Definition: residualestimator.h:446
Definition: dopetypes.h:93
L2ResidualErrorContainer(STH &sth, DOpEtypes::VectorStorageType state_behavior, ParameterReader &param_reader, DOpEtypes::EETerms ee_terms=DOpEtypes::EETerms::mixed)
Definition: residualestimator.h:81
void ReInit(unsigned int n_elements)
Definition: residualestimator.h:485
DOpEtypes::EETerms GetEETerms() const
Definition: dwrdatacontainer.h:365
void BuildConstantWeight(const DOpEWrapper::DoFHandler< dim, DH > *dofh, VECTOR &vals)
Definition: residualestimator.h:251
EETerms
Definition: dopetypes.h:66
Definition: dopetypes.h:68
virtual ~L2ResidualErrorContainer()
Definition: residualestimator.h:103
STH & GetSTH()
Definition: residualestimator.h:458
Definition: statevector.h:50
virtual ~H1ResidualErrorContainer()
Definition: residualestimator.h:318
ControlVector< VECTOR > & GetPI_h_q()
Definition: residualestimator.h:145
ResidualEvaluation
Definition: dopetypes.h:91
STH & GetSTH()
Definition: residualestimator.h:244
void VectorResidualModifier(dealii::Vector< double > &res)
Definition: residualestimator.h:439
void Initialize(unsigned int state_n_blocks, std::vector< unsigned int > &state_block_component)
Definition: residualestimator.h:334
VectorStorageType
Definition: dopetypes.h:120
void PreparePI_h_u(const StateVector< VECTOR > &)
Definition: residualestimator.h:157
Definition: residualestimator.h:38
WeightComputation
Definition: dopetypes.h:80
FDC * ExtractFDC(const DWRDataContainer< STH, IDC, EDC, FDC, VECTOR > &dwrc)
Definition: dwrdatacontainer.h:598
StateVector< VECTOR > & GetPI_h_u()
Definition: residualestimator.h:349
void ResidualModifier(double &res)
Definition: residualestimator.h:434
Definition: dwrdatacontainer.h:50
virtual void ReInit(unsigned int n_elements)
Definition: dwrdatacontainer.h:530
virtual void InitFace(double)=0
void ResidualModifier(double &res)
Definition: residualestimator.h:219
ControlVector< VECTOR > & GetPI_h_q()
Definition: residualestimator.h:360
bool NeedDual() const
Definition: residualestimator.h:191
virtual DOpEtypes::WeightComputation GetWeightComputation() const
Definition: residualestimator.h:415
Definition: dopeexception.h:35
Definition: residualestimator.h:78
StateVector< VECTOR > & GetPI_h_z()
Definition: residualestimator.h:140
virtual void InitElement(double)=0
void PreparePI_h_u(const StateVector< VECTOR > &)
Definition: residualestimator.h:372