DOpE
dwrdatacontainer.h
Go to the documentation of this file.
1 
24 #ifndef DWRDATACONTAINER_H_
25 #define DWRDATACONTAINER_H_
26 
27 #include "constraintvector.h"
28 #include "controlvector.h"
29 #include "statevector.h"
30 #include "dopetypes.h"
31 #include "parameterreader.h"
32 #include "dopetypes.h"
33 
34 namespace DOpE
35 {
36 
49  template<typename VECTOR>
51  {
52  public:
55  : ee_terms_(ee_terms)
56  {
57  lock_ = true;
58  switch (this->GetEETerms())
59  {
61  n_error_comps_ = 2;
62  break;
64  n_error_comps_ = 2;
65  break;
66  case DOpEtypes::mixed:
67  n_error_comps_ = 2;
68  break;
70  n_error_comps_ = 3;
71  break;
72  default:
73  throw DOpEException("Unknown DOpEtypes::EEterms.",
74  "DWRDataContainer::ReleaseLock");
75  break;
76  }
77  }
78 
79  virtual
81  {
82  }
83 
84  virtual std::string
85  GetName() const = 0;
86 
92  virtual void
93  ReInit(unsigned int n_elements);
94 
101  void
103  {
104  lock_ = false;
105 
106  switch (this->GetEETerms())
107  {
109  error_ind_ = GetPrimalErrorIndicators();
110  break;
112  error_ind_ = GetDualErrorIndicators();
113  break;
114  case DOpEtypes::mixed:
115  error_ind_.equ(0.5, GetPrimalErrorIndicators());
116  error_ind_.add(0.5, GetDualErrorIndicators());
117  break;
119  error_ind_.equ(0.5, GetPrimalErrorIndicators());
120  error_ind_.add(0.5, GetDualErrorIndicators());
121  error_ind_.add(0.5, GetControlErrorIndicators());
122  break;
123  default:
124  throw DOpEException("Unknown DOpEtypes::EEterms.",
125  "DWRDataContainer::ReleaseLock");
126  break;
127  }
128  }
129 
138  double
139  GetError() const
140  {
141  double error = 0;
142  for (unsigned int i = 0; i < GetErrorIndicators().size(); ++i)
143  {
144  error += GetErrorIndicators()(i);
145  }
146  return error;
147  }
148 
157  double
159  {
160  double error = 0;
161  for (unsigned int i = 0; i < GetAllErrorIndicators()[1]->size(); ++i)
162  {
163  error += GetAllErrorIndicators()[1]->operator()(i);
164  }
165  return error;
166  }
167 
176  double
177  GetDualError() const
178  {
179  double error = 0;
180  for (unsigned int i = 0; i < GetAllErrorIndicators()[2]->size(); ++i)
181  {
182  error += GetAllErrorIndicators()[2]->operator()(i);
183  }
184  return error;
185  }
186 
195  double
197  {
198  double error = 0;
199  for (unsigned int i = 0; i < GetAllErrorIndicators()[3]->size(); ++i)
200  {
201  error += GetAllErrorIndicators()[3]->operator()(i);
202  }
203  return error;
204  }
205 
212  const Vector<double>&
214  {
215  if (lock_)
216  {
217  throw DOpEException("Error indicators are still locked.",
218  "DWRDataContainer::GetErrorIndicators");
219  }
220  else
221  {
222  return error_ind_;
223  }
224  }
225 
232  Vector<double>&
234  {
235  return error_ind_primal_;
236  }
237 
238  const Vector<double>&
240  {
241  return error_ind_primal_;
242  }
243 
250  Vector<double>&
252  {
253  return error_ind_dual_;
254  }
255 
256  const Vector<double>&
258  {
259  return error_ind_dual_;
260  }
261 
268  Vector<double>&
270  {
271  return error_ind_control_;
272  }
273 
274  const Vector<double>&
276  {
277  return error_ind_control_;
278  }
279 
287  Vector<double>&
288  GetErrorIndicators(unsigned int i)
289  {
290  if( i == 0)
291  return error_ind_primal_;
292  else
293  if (i == 1)
294  return error_ind_dual_;
295  else
296  if (i == 2)
297  return error_ind_control_;
298  else
299  throw DOpEException("Unknown Indicator","DWRDataContainer::GetErrorIndicators");
300  }
301 
302  const Vector<double>&
303  GetErrorIndicators(unsigned int i) const
304  {
305  if( i == 0)
306  return error_ind_primal_;
307  else
308  if (i == 1)
309  return error_ind_dual_;
310  else
311  if (i == 2)
312  return error_ind_control_;
313  else
314  throw DOpEException("Unknown Indicator","DWRDataContainer::GetErrorIndicators");
315  }
316 
317  unsigned int GetNErrorComps() const
318  {
319  //number of error components...
320  return n_error_comps_;
321  }
322 
330  std::vector<const Vector<double>*>
332  {
333  std::vector<const Vector<double>*> res;
334  if (lock_)
335  {
336  throw DOpEException("Error indicators are still locked.",
337  "DWRDataContainer::GetErrorIndicators");
338  }
339  else
340  {
341  res.push_back(&error_ind_);
342  res.push_back(&this->GetPrimalErrorIndicators());
343  res.push_back(&this->GetDualErrorIndicators());
344  res.push_back(&this->GetControlErrorIndicators());
345  }
346  return res;
347  }
348 
353  GetWeightComputation() const = 0;
354 
359  GetResidualEvaluation() const =0;
360 
365  GetEETerms() const
366  {
367  return ee_terms_;
368  }
369 
375  template<class PROBLEM, class INTEGRATOR>
376  void
377  ComputeRefinementIndicators(PROBLEM& problem, INTEGRATOR& integrator)
378  {
379  integrator.ComputeRefinementIndicators(problem, *this);
380  }
381 
388  virtual bool
389  NeedDual() const = 0;
390 
397  const std::map<std::string, const VECTOR*>&
399  {
400  return weight_data_;
401  }
402 
406  void
408  {
409  weight_data_.clear();
410  }
411 
419  void
421  {
422  //Dependend on the GetEETerms we let the dwrc compute the primal and/or dual weights
423  switch (GetEETerms())
424  {
426  PreparePI_h_z(z);
427  AddWeightData("weight_for_primal_residual",
428  &(GetPI_h_z().GetSpacialVector()));
429  break;
431  PreparePI_h_u(u);
432  AddWeightData("weight_for_dual_residual",
433  &(GetPI_h_u().GetSpacialVector()));
434  break;
435  case DOpEtypes::mixed:
436  PreparePI_h_u(u);
437  AddWeightData("weight_for_dual_residual",
438  &(GetPI_h_u().GetSpacialVector()));
439  PreparePI_h_z(z);
440  AddWeightData("weight_for_primal_residual",
441  &(GetPI_h_z().GetSpacialVector()));
442  break;
444  PreparePI_h_u(u);
445  AddWeightData("weight_for_dual_residual",
446  &(GetPI_h_u().GetSpacialVector()));
447  PreparePI_h_z(z);
448  AddWeightData("weight_for_primal_residual",
449  &(GetPI_h_z().GetSpacialVector()));
450  break;
451  default:
452  throw DOpEException("Unknown DOpEtypes::EETerms!",
453  "DWRDataContainerBase::PrepareWeights");
454  break;
455  }
456  }
463  void
465  {
466  //Dependend on the GetEETerms we let the dwrc compute the primal and/or dual weights
467  switch (GetEETerms())
468  {
470  PreparePI_h_q(q);
471  AddWeightData("weight_for_control_residual",
472  &(GetPI_h_q().GetSpacialVector()));
473  break;
475  //Do nothing to be compatible with residual estimators not using the control!
476  break;
477  default:
478  throw DOpEException("Unknown DOpEtypes::EETerms!",
479  "DWRDataContainerBase::PrepareWeights");
480  break;
481  }
482  }
483 
484  protected:
485  //TODO PI_h_u and PI_h_z are probably not the best names.
486  //Basically, one could replace them with 'primalweight' and 'dualweight',
487  //but i found them a little bit misleading. ~cg
488  virtual StateVector<VECTOR>&
489  GetPI_h_u() = 0;
490 
491  virtual StateVector<VECTOR>&
492  GetPI_h_z() = 0;
493 
494  virtual ControlVector<VECTOR>&
495  GetPI_h_q() = 0;
496 
497  virtual void
498  PreparePI_h_u(const StateVector<VECTOR>& u) = 0;
499 
500  virtual void
501  PreparePI_h_z(const StateVector<VECTOR>& z) = 0;
502 
503  virtual void
504  PreparePI_h_q(const ControlVector<VECTOR>& q) = 0;
505 
506  void
507  AddWeightData(std::string name, const VECTOR* new_data)
508  {
509  if (weight_data_.find(name) != weight_data_.end())
510  {
511  throw DOpEException(
512  "Adding multiple Data with name " + name + " is prohibited!",
513  "Integrator::AddDomainData");
514  }
515  weight_data_.insert(
516  std::pair<std::string, const VECTOR*>(name, new_data));
517  }
518 
519  private:
520  DOpEtypes::EETerms ee_terms_;
521  bool lock_;
522  unsigned int n_error_comps_;
523  std::map<std::string, const VECTOR*> weight_data_;
524  Vector<double> error_ind_, error_ind_primal_, error_ind_dual_, error_ind_control_;
525  }
526  ;
527 
528  template<typename VECTOR>
529  void
530  DWRDataContainerBase<VECTOR>::ReInit(unsigned int n_elements)
531  {
532  error_ind_.reinit(n_elements);
533  GetPrimalErrorIndicators().reinit(n_elements);
534  GetDualErrorIndicators().reinit(n_elements);
535  GetControlErrorIndicators().reinit(n_elements);
536  lock_ = true;
537  }
538 
544  template<class STH, class IDC, class EDC, class FDC, typename VECTOR>
545  class DWRDataContainer : public DWRDataContainerBase<VECTOR>
546  {
547  public:
550  : DWRDataContainerBase<VECTOR>(ee_terms)
551  {
552  }
553  ;
554  virtual
556  {
557  }
558  ;
559 
564  virtual EDC&
565  GetElementWeight() const = 0;
566 
571  virtual FDC&
572  GetFaceWeight() const = 0;
573 
574  virtual STH&
575  GetWeightSTH() = 0;
576  virtual const STH&
577  GetWeightSTH() const = 0;
578 
579  virtual IDC&
580  GetWeightIDC() = 0;
581  virtual const IDC&
582  GetWeightIDC() const = 0;
583  };
584 
590  template<class EDC, class STH, class IDC, class FDC, typename VECTOR>
591  EDC*
593  {
594  return &dwrc.GetElementWeight();
595  }
596  template<class FDC, class STH, class IDC, class EDC, typename VECTOR>
597  FDC*
599  {
600  return &dwrc.GetFaceWeight();
601  }
602 
603 } //end of namespace
604 #endif /* DWRDATACONTAINER_H_ */
virtual ~DWRDataContainerBase()
Definition: dwrdatacontainer.h:80
Definition: dopetypes.h:68
virtual bool NeedDual() const =0
const std::map< std::string, const VECTOR * > & GetWeightData() const
Definition: dwrdatacontainer.h:398
DWRDataContainerBase(DOpEtypes::EETerms ee_terms=DOpEtypes::EETerms::mixed)
Definition: dwrdatacontainer.h:53
Vector< double > & GetErrorIndicators(unsigned int i)
Definition: dwrdatacontainer.h:288
virtual EDC & GetElementWeight() const =0
virtual StateVector< VECTOR > & GetPI_h_z()=0
const Vector< double > & GetErrorIndicators(unsigned int i) const
Definition: dwrdatacontainer.h:303
virtual DOpEtypes::ResidualEvaluation GetResidualEvaluation() const =0
Vector< double > & GetPrimalErrorIndicators()
Definition: dwrdatacontainer.h:233
virtual void PreparePI_h_q(const ControlVector< VECTOR > &q)=0
void AddWeightData(std::string name, const VECTOR *new_data)
Definition: dwrdatacontainer.h:507
void PrepareWeights(const StateVector< VECTOR > &u, const StateVector< VECTOR > &z)
Definition: dwrdatacontainer.h:420
Definition: dopetypes.h:68
double GetDualError() const
Definition: dwrdatacontainer.h:177
virtual void PreparePI_h_u(const StateVector< VECTOR > &u)=0
const Vector< double > & GetErrorIndicators() const
Definition: dwrdatacontainer.h:213
double GetError() const
Definition: dwrdatacontainer.h:139
Definition: controlvector.h:49
EDC * ExtractEDC(const DWRDataContainer< STH, IDC, EDC, FDC, VECTOR > &dwrc)
Definition: dwrdatacontainer.h:592
const Vector< double > & GetDualErrorIndicators() const
Definition: dwrdatacontainer.h:257
Definition: dopetypes.h:68
virtual std::string GetName() const =0
const Vector< double > & GetControlErrorIndicators() const
Definition: dwrdatacontainer.h:275
Vector< double > & GetDualErrorIndicators()
Definition: dwrdatacontainer.h:251
DOpEtypes::EETerms GetEETerms() const
Definition: dwrdatacontainer.h:365
virtual STH & GetWeightSTH()=0
EETerms
Definition: dopetypes.h:66
Definition: dopetypes.h:68
void ComputeRefinementIndicators(PROBLEM &problem, INTEGRATOR &integrator)
Definition: dwrdatacontainer.h:377
Definition: statevector.h:50
const Vector< double > & GetPrimalErrorIndicators() const
Definition: dwrdatacontainer.h:239
double GetPrimalError() const
Definition: dwrdatacontainer.h:158
virtual DOpEtypes::WeightComputation GetWeightComputation() const =0
ResidualEvaluation
Definition: dopetypes.h:91
void ClearWeightData()
Definition: dwrdatacontainer.h:407
double GetControlError() const
Definition: dwrdatacontainer.h:196
WeightComputation
Definition: dopetypes.h:80
Vector< double > & GetControlErrorIndicators()
Definition: dwrdatacontainer.h:269
FDC * ExtractFDC(const DWRDataContainer< STH, IDC, EDC, FDC, VECTOR > &dwrc)
Definition: dwrdatacontainer.h:598
virtual FDC & GetFaceWeight() const =0
Definition: dwrdatacontainer.h:50
virtual void ReInit(unsigned int n_elements)
Definition: dwrdatacontainer.h:530
virtual ControlVector< VECTOR > & GetPI_h_q()=0
unsigned int GetNErrorComps() const
Definition: dwrdatacontainer.h:317
virtual StateVector< VECTOR > & GetPI_h_u()=0
virtual IDC & GetWeightIDC()=0
void PrepareWeights(const ControlVector< VECTOR > &q)
Definition: dwrdatacontainer.h:464
Definition: dopeexception.h:35
virtual ~DWRDataContainer()
Definition: dwrdatacontainer.h:555
DWRDataContainer(DOpEtypes::EETerms ee_terms=DOpEtypes::EETerms::mixed)
Definition: dwrdatacontainer.h:548
std::vector< const Vector< double > * > GetAllErrorIndicators() const
Definition: dwrdatacontainer.h:331
Definition: dwrdatacontainer.h:545
virtual void PreparePI_h_z(const StateVector< VECTOR > &z)=0
void ReleaseLock()
Definition: dwrdatacontainer.h:102