explicitResidual.hh

Go to the documentation of this file.
1 
7 #ifndef explicitResidual_hh
8 #define explicitResidual_hh
9 
10 #include "estimator/estimator.hh"
11 
12 //TODO: Precise the includes
13 #include "hp2D.hh"
15 #include "basics/exceptions.hh"
16 
17 
18 namespace concepts{
19 
20  template<class F>
21  class ExplicitResidual: public LocalEstimator<F>{
22 
23  public:
24 
25  virtual ~ExplicitResidual(){};
26 
27  virtual ExplicitResidual<F>* clone() const = 0;
28 
34  frms_.push_back(frm);
35  iNAttrbs_.push_back(nSet);
36  }
37 
41  void addHNData(const Set<uint>& nSet){
42  hNAttrbs_ = hNAttrbs_ || nSet;
43  }
44  void addHNData(uint attrb) {
45  hNAttrbs_.insert(attrb);
46  }
47 
48 
49  protected:
50 
51 
68  LocalEstimator<F>(spc, sol),res_(res){};
69 
70  virtual std::ostream& info(std::ostream& os) const{
71  return os << concepts::typeOf(*this);
72  }
73  //local reference to the residual
75 
76  //Neumann formulas
78  //Neumann Attributes inhomogen
80  //Neumann attributes homogen
82 
83  private:
84 
85  virtual void computeError_(const ElementFormulaContainer<F>& res, HashMap<Real>& jumpResidual) = 0 ;
86  virtual void computeJumpPart_(HashMap<Real>& jumpResidual) const=0;
87  };
88 
89 
90 }
91 
92 
93 
94 
95 
96 namespace hp1D{
97 
98  //So far just a abstract class
99  template<class F>
101 
102  public:
104  const concepts::Vector<F>& sol,
106 
108 
109  protected:
110  virtual std::ostream& info(std::ostream& os) const;
111 
112  private:
114  virtual void computeJumpPart_(concepts::HashMap<Real>& jumpResidual) const;
115  };
116 
117 }
118 
119 
120 namespace hp2D {
168 template<class F>
170 
171 public:
172 
173  // Flag for the chose of the weight
174  // DIAM : default weight is just the diameter of cell :
175  // w_K = diam(K), w_E = diam(E)
176  // DIAM_HP : residual type variant introduced by melenk and wohlmuth with the help of weighted norms
177  //
178  //
179  // DIAM_P: polynomal degree weighted diameter :
180  // w_K = diam(K)/(1+p_K), w_E = diam(E)/2*(1+p_E)
181 
182  // further possible weights :
183  // DIAM_L Diameter devided by eigenvalues lambda_K of the diffusion tensor elementwise.
184  // where the diffussion tensor IK is assumed to be quasi-monoton.
185  // for further details check the Diplomarbeit of Christian Merdon, section 2 and 3.
186  //TODO: RETHINK NAME
188 
207  const concepts::Vector<F>& sol,
210  bool square = false,
211  enum weight w = DIAM,
212  Real alpha = 0);
213 
214 
215  virtual ~ExplicitResidual2D(){};
216 
217  /*
218  * Starts the actual estimation of error.
219  * You may start this routine after setting the Neumann boundary info data.
220  */
221  void compute();
222 
235  class Distance : public concepts::ElementFormula<Real>{
236 
237  public:
238  //Constructor
239  Distance(Real alpha=0) : alpha_(alpha){};
240 
241  virtual F operator() (const concepts::ElementWithCell<typename concepts::Realtype<F>::type>& elm, const concepts::Real p,const concepts::Real t = 0.0) const{
242  throw concepts::MissingFeature("Operator not implemented.");
243  return 0.0;
244  }
245 
246  virtual F operator() (const concepts::ElementWithCell<typename concepts::Realtype<F>::type>& elm, const concepts::Real2d& p,const concepts::Real t = 0.0) const{
247 
248  // __________
249  // | : |
250  // |--x p |
251  // | |
252  // |________|
253  //dist = min(x,y,1-x,1-y)
254  concepts::Real dist = std::min(std::min(p[0],p[1]), std::min(1-p[0],1-p[1]));
255  return std::pow(dist, alpha_);
256 
257  }
258  virtual F operator() (const concepts::ElementWithCell<typename concepts::Realtype<F>::type>& elm, const concepts::Real3d& p,const concepts::Real t = 0.0) const{
259  //just take p0 and p1 since this class applicates for hp2D::IntegrableQuad
260  concepts::Real dist = std::min(std::min(p[0],p[1]), std::min(1-p[0],1-p[1]));
261  return std::pow(dist, alpha_);
262  }
263 
264  virtual Distance* clone() const{return new Distance(*this);}
265 
266  virtual ~Distance(){};
267 
268  protected:
269  virtual std::ostream& info(std::ostream& os) const{
270  return os<<concepts::typeOf(*this) <<"( alpha = "<<alpha_<<")";
271  }
272 
273  private:
274  //representing alpha/2
276  };
277 
278 
279 
292  class EdgeWeight : public concepts::ElementFormula<Real>{
293 
294  public:
295  //Constructor
296  EdgeWeight(Real alpha=0) : alpha_(alpha){};
297 
298  virtual F operator() (const concepts::ElementWithCell<typename concepts::Realtype<F>::type>& elm, const concepts::Real p,const concepts::Real t = 0.0) const{
299  // ((1-x)*x)^(alpha)
300  return std::pow((1-p)*p, alpha_);
301  }
302 
303  //for neumanntracelements
304  virtual F operator() (const concepts::ElementWithCell<typename concepts::Realtype<F>::type>& elm, const concepts::Real2d& p,const concepts::Real t = 0.0) const{
305  //take p[0] since this class applicates on neumanntraceElements which are hp1D::IntegrableElm
306  // ((1-x)*x)^(alpha)
307  return std::pow((1-p[0])*p[0], alpha_);
308 
309  }
310  virtual F operator() (const concepts::ElementWithCell<typename concepts::Realtype<F>::type>& elm, const concepts::Real3d& p,const concepts::Real t = 0.0) const{
311  //take p[0] since this class applicates on neumanntraceElements which are hp1D::IntegrableElm
312  // ((1-x)*x)^(alpha)
313  return std::pow((1-p[0])*p[0], alpha_);
314  }
315 
316  virtual EdgeWeight* clone() const{return new EdgeWeight(*this);}
317 
318  virtual ~EdgeWeight(){};
319 
320  protected:
321  virtual std::ostream& info(std::ostream& os) const{
322  return os << concepts::typeOf(*this) << "( alpha = "<<alpha_<<")";
323  }
324 
325  private:
326  //representing alpha
328  };
329 
330  virtual const Real operator()() const {return 0.;}
331 
332  virtual ExplicitResidual2D<F>* clone() const{return new ExplicitResidual2D<F>(*this);}
333 
334  protected:
335  virtual std::ostream& info(std::ostream& os) const {
336  return os << concepts::typeOf(*this);
337  }
338 
339  private:
340 
341  //flag that marks all elements are squares, then diameter computation is faster.
342  bool square_;
343  //isotropic scalar coefficient function in higest derivative operator
345  //weight type
346  enum weight weight_;
347 
348  //weight function exponent
350 
351  //faster data structure for accessing all neumann boundary attributes
353 
355  virtual void computeJumpPart_(concepts::HashMap<Real>& jumpResidual) const;
356 
357  };
358 
359 
360 
361 
362 
363 
364 
365 
366 
367 
368 
369 
370 } //namespace 2D
371 
372 
373 //namespace hp3D{
374 //
375 //class ExplicitResidual3D: concepts::ExplicitResidual{
376 //public:
377 //
378 // template<typename F>
379 // ExplicitResidual3D(const concepts::SpaceOnCells<F>& spc, const concepts::Vector<F>& sol, const concepts::ElementFormula<F>& res);
380 //
381 //protected:
382 // virtual std::ostream& info(std::ostream& os) const{
383 // return os << "Explicit Residual Error Estimator()";
384 // }
385 //
386 //
387 //private:
388 // virtual void computeError_(const concepts::ElementFormula<F>& res, concepts::HashMap<Real>& jumpResidual);
389 // virtual void computeJumpPart_(concepts::HashMap<Real>& jumpResidual) const;
390 //};
391 //
392 //}
393 
394 #endif // explicitResidual_hh
void addHNData(const Set< uint > &nSet)
Add attributes for homogen neumann boundary conditions.
virtual EdgeWeight * clone() const
Virtual constructor.
Sequence< Set< uint > > iNAttrbs_
virtual F operator()(const concepts::ElementWithCell< typename concepts::Realtype< F >::type > &elm, const concepts::Real p, const concepts::Real t=0.0) const
virtual ExplicitResidual2D< F > * clone() const
Virtual constructor.
Weight class for 1d Elements.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual void computeJumpPart_(HashMap< Real > &jumpResidual) const =0
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual Distance * clone() const
Virtual constructor.
2D hp-FEM for H1-conforming elements.
Element with cell.
ExplicitResidual2D(const concepts::SpaceOnCells< F > &spc, const concepts::Vector< F > &sol, const concepts::ElementFormulaContainer< F > res, const concepts::ElementFormulaContainer< F > *a=0, bool square=false, enum weight w=DIAM, Real alpha=0)
Constructor of the 2d explicit residual a posteriori Error estimator.
virtual void computeError_(const concepts::ElementFormulaContainer< F > &res, concepts::HashMap< Real > &jumpResidual)
const ElementFormulaContainer< F > res_
Sequence< ElementFormulaContainer< F > > frms_
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
const concepts::ElementFormulaContainer< F > * a_
virtual ExplicitResidual< F > * clone() const =0
Virtual constructor.
Interface for a formula defined element by element.
virtual const Real operator()() const
ExplicitResidual1D(const concepts::SpaceOnCells< F > &spc, const concepts::Vector< F > &sol, const concepts::ElementFormulaContainer< F > &res)
ExplicitResidual(const SpaceOnCells< F > &spc, const Vector< F > &sol, const ElementFormulaContainer< F > res)
Constructur of the explicit residual a posteriori error estimator.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Sequence with operations, output operator, and method of the particular element types.
Definition: sequence.hh:39
F min(const concepts::Array< F > &a)
Returns the minimal value in array a.
Definition: arrayOp.hh:67
concepts::Set< uint > allNattrb_
Abstract class for a space.
Definition: space.hh:81
Exception class to express a missing feature.
Definition: exceptions.hh:206
virtual void computeJumpPart_(concepts::HashMap< Real > &jumpResidual) const
virtual void computeError_(const ElementFormulaContainer< F > &res, HashMap< Real > &jumpResidual)=0
Given a elliptic equation:
virtual void computeError_(const concepts::ElementFormulaContainer< F > &res, concepts::HashMap< Real > &jumpResidual)
std::string typeOf(const T &t)
Return the typeid name of a class object.
Definition: output.hh:43
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void addINData(const Set< uint > &nSet, concepts::ElementFormulaContainer< F > frm)
Add inhomogen Neumanndata if exist.
virtual void computeJumpPart_(concepts::HashMap< Real > &jumpResidual) const
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Weight class for 2d Elements.
virtual F operator()(const concepts::ElementWithCell< typename concepts::Realtype< F >::type > &elm, const concepts::Real p, const concepts::Real t=0.0) const
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
1D hp-FEM
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich