formula.hh

Go to the documentation of this file.
1 
6 #ifndef spcFormula_hh
7 #define spcFormula_hh
8 
10 #include "toolbox/sharedPointer.hh"
11 #include "formula/boundary.hh"
12 #include "formula/formula.hh"
15 #include "space/element.hh"
16 
17 namespace concepts {
18 
19  // forward declaration
20  template<typename F, typename G>
21  class ElementFormula; // defined in formula/elementFormula.hh
22 
23 
24 
25  // **************************************************** ElementFormulaLiCo **
26 
27  /* Linear combination of two element formulas of type \c F and \c G.
28 
29  @param F type of the 1st element formula and the return value
30  @param G type of the 2nd element formula
31  @param H type of the factors in the linear combination
32  @param J type of the element, mostly Real
33 
34  @author Kersten Schmidt, 2004
35  */
36 
37  template<class F = Real, class G = F, class H = F,
38  class J = typename Realtype<F>::type>
39  class ElementFormulaLiCo : public ElementFormula<F,J> {
40  public:
42  const ElementFormula<G,J>& frm2,
43  H a = 1.0, H b = 1.0) :
44  frm1_(frm1.clone()), frm2_(frm2.clone()), a_(a), b_(b) {}
46  frm1_(frm.frm1_->clone()), frm2_(frm.frm2_->clone()),
47  a_(frm.a_), b_(frm.b_) {}
48  virtual ~ElementFormulaLiCo() {
49  frm1_.reset(0); frm2_.reset(0);
50  }
51  virtual F operator() (const ElementWithCell<J>& elm, const Real p,
52  const Real t = 0.0) const {
53  return combine_(elm,p,t);
54  }
55  virtual F operator() (const ElementWithCell<J>& elm, const Real2d& p,
56  const Real t = 0.0) const {
57  return combine_(elm,p,t);
58  }
59  virtual F operator() (const ElementWithCell<J>& elm, const Real3d& p,
60  const Real t = 0.0) const {
61  return combine_(elm,p,t);
62  }
65  }
66  protected:
67  virtual std::ostream& info(std::ostream& os) const;
68  private:
70  std::unique_ptr<const ElementFormula<F,J> > frm1_;
72  std::unique_ptr<const ElementFormula<G,J> > frm2_;
74  const H a_, b_;
76  template<typename P>
77  F combine_(const ElementWithCell<J>& elm, const P& p,
78  const Real t = 0.0) const;
79  };
80 
81  template<typename F, typename G, typename H, typename J>
82  template<typename P>
84  const P& p, const Real t) const {
85  F val1 = (*frm1_)(elm, p, t);
86  G val2 = (*frm2_)(elm, p, t);
87  return val1 * (F)a_ + val2 * (F)b_;
88  }
89 
90  template<typename F, typename G, typename H, typename J>
91  std::ostream& ElementFormulaLiCo<F,G,H,J>::info(std::ostream& os) const {
92  return os << concepts::typeOf(*this)<<"(" << a_ << " * " << *frm1_ << "+ "
93  << b_ << " * " << *frm2_ << ")";
94  }
95 
96 // template<class F, class G>
97 // ElementFormulaLiCo<F,G,Real>
98 // operator+(const ElementFormula<F>& frm1,
99 // const ElementFormula<G>& frm2)
100 // {
101 // return ElementFormulaLiCo<F,G,Real>(frm1, frm2, 1.0, 1.0);
102 // }
103 
104 // template<class F, class G>
105 // ElementFormulaLiCo<F,G,Real>
106 // operator-(const ElementFormula<F>& frm1,
107 // const ElementFormula<G>& frm2)
108 // {
109 // return ElementFormulaLiCo<F,G,Real>(frm1, frm2, 1.0, -1.0);
110 // }
111 
112  // ************************************************* ElementFormulaCompose **
113 
114  /* Composition of two element formulas of type \c H to one of type \c F.
115 
116  \c F has to have a constructor of two \c H, like Real2d.
117 
118  @param F type of the return value, e.g. Real2d
119  @param G type of the element, mostly Real
120  @param H type of one element formula, e.g. Real
121 
122  @author Kersten Schmidt, 2004
123  */
124 
125  template<typename F, typename G, typename H>
126  class ElementFormulaCompose : public ElementFormula<F,G> {
127  public:
129  const ElementFormula<H,G>& frm2) :
130  frm1_(frm1.clone()), frm2_(frm2.clone()) {}
132  frm1_(frm.frm1_->clone()), frm2_(frm.frm2_->clone()) {}
134  frm1_.reset(0); frm2_.reset(0);
135  }
136  virtual F operator() (const ElementWithCell<G>& elm, const Real p,
137  const Real t = 0.0) const {
138  return compose_(elm,p,t);
139  }
140  virtual F operator() (const ElementWithCell<G>& elm, const Real2d& p,
141  const Real t = 0.0) const {
142  return compose_(elm,p,t);
143  }
144  virtual F operator() (const ElementWithCell<G>& elm, const Real3d& p,
145  const Real t = 0.0) const {
146  return compose_(elm,p,t);
147  }
150  }
151  protected:
152  virtual std::ostream& info(std::ostream& os) const;
153  private:
154  std::unique_ptr<const ElementFormula<H,G> > frm1_, frm2_;
155 
156  template<typename P>
157  F compose_(const ElementWithCell<G>& elm, const P& p, const Real t = 0.0) const;
158  };
159 
160  template<typename F, typename G, typename H>
161  template<typename P>
163  const P& p, const Real t) const {
164  return F((*frm1_)(elm,p,t),(*frm2_)(elm,p,t));
165  }
166 
167  template<typename F, typename G, typename H>
168  std::ostream& ElementFormulaCompose<F,G,H>::info(std::ostream& os) const {
169  return os << concepts::typeOf(*this)<<"(" << *frm1_ << ", " << *frm2_ << ")";
170  }
171 
172  // ************************************************ ElementBoundaryFormula **
173 
176  class ElementFormulaBoundary : public ElementFormula<Real> {
177  public:
179  (const BoundaryConditions bc,
186  virtual Real operator() (const ElementWithCell<Real>& elm, const Real p,
187  const Real t = 0.0) const;
188  virtual Real operator() (const ElementWithCell<Real>& elm, const Real2d& p,
189  const Real t = 0.0) const;
190  virtual Real operator() (const ElementWithCell<Real>& elm, const Real3d& p,
191  const Real t = 0.0) const;
193  virtual ElementFormulaBoundary* clone() const;
194  protected:
195  virtual std::ostream& info(std::ostream& os) const;
196  private:
199  };
200 
201 
202  // ************************************************ ElementFormulaRotate2D **
203 
208  template<class F>
209  class ElementFormulaRotate2D : public ElementFormula<Point<F,2> > {
210  public:
213  (const ElementFormulaContainer<Point<F,2> > frm)
214  : frm_(frm) {}
216  const Real p, const Real t = 0.0) const;
218  const Real2d& p, const Real t = 0.0) const;
220  const Real3d& p, const Real t = 0.0) const;
222  virtual ElementFormulaRotate2D<F>* clone() const {
223  return new ElementFormulaRotate2D<F>(this->frm_);
224  }
225  protected:
226  virtual std::ostream& info(std::ostream& os) const;
227  private:
229  };
230 
231 
232  // ***************************************** FrmE_ScalarProductNormalEdge2d **
233 
243  template< class F = Real>
245  {
246  public:
248  (RCP<const ElementFormula< Point<F, 2> > > vf)
249  : vf_(vf)
250  { }
251 
253  return new FrmE_ScalarProductNormalEdge2d(*this);
254  }
255 
258  {
259  return vf_;
260  }
261 
264  {
265  return vf_;
266  }
267 
268  virtual F operator() (const ElementWithCell<Real>& elm,
269  const Real p, const Real t = 0.0) const;
270  virtual F operator() (const ElementWithCell<Real>& elm,
271  const Real2d& p, const Real t = 0.0) const
272  {
273  // In the same manner as for Real3d, albeit not that needed.
274  return (*this)(elm, p[0], t);
275  }
276 
277  virtual F operator() (const ElementWithCell<Real>& elm,
278  const Real3d& p, const Real t = 0.0) const {
279  // This is necessary for general integration routine
280  // (see space/integral.hh)
281  return (*this)(elm, p[0], t);
282  }
283  protected:
284  virtual std::ostream& info(std::ostream& os) const;
285  public:
287  };
288 
289 
290 } // namespace concepts
291 
292 #endif // spcFormula_hh
293 
ElementFormulaRotate2D(const ElementFormulaContainer< Point< F, 2 > > frm)
Constructor.
Definition: formula.hh:213
virtual ElementFormulaCompose< F, G, H > * clone() const
Virtual copy constructor.
Definition: formula.hh:148
virtual F operator()(const ElementWithCell< J > &elm, const Real p, const Real t=0.0) const
Definition: formula.hh:51
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Definition: formula.hh:91
std::unique_ptr< const ElementFormula< G, J > > frm2_
2nd element formulas
Definition: formula.hh:72
virtual Point< F, 2 > operator()(const ElementWithCell< Real > &elm, const Real p, const Real t=0.0) const
ElementFormulaCompose(const ElementFormulaCompose< F, G, H > &frm)
Definition: formula.hh:131
ElementFormulaCompose(const ElementFormula< H, G > &frm1, const ElementFormula< H, G > &frm2)
Definition: formula.hh:128
virtual F operator()(const ElementWithCell< Real > &elm, const Real p, const Real t=0.0) const
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
std::unique_ptr< const ElementFormula< F, J > > frm1_
1st element formulas
Definition: formula.hh:70
Computes the scalar product <n, vf> of the normal n with a vector valued formula vf,...
Definition: formula.hh:245
const BoundaryConditions bc_
Definition: formula.hh:197
FrmE_ScalarProductNormalEdge2d(RCP< const ElementFormula< Point< F, 2 > > > vf)
Definition: formula.hh:248
std::unique_ptr< const ElementFormula< H, G > > frm2_
Definition: formula.hh:154
RCP< const ElementFormula< Point< F, 2 > > > vf_
Definition: formula.hh:286
const H a_
Scalar factors.
Definition: formula.hh:74
Element with cell.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual ElementFormulaRotate2D< F > * clone() const
Virtual copy constructor.
Definition: formula.hh:222
F combine_(const ElementWithCell< J > &elm, const P &p, const Real t=0.0) const
Method for calculating the return value.
Definition: formula.hh:83
Element formula, which gives formula on the boundary.
Definition: formula.hh:176
std::unique_ptr< const ElementFormula< H, G > > frm1_
Definition: formula.hh:154
F compose_(const ElementWithCell< G > &elm, const P &p, const Real t=0.0) const
Definition: formula.hh:162
Interface for a formula defined element by element.
virtual Point< F, 2 > operator()(const ElementWithCell< Real > &elm, const Real3d &p, const Real t=0.0) const
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Definition: formula.hh:168
virtual FrmE_ScalarProductNormalEdge2d * clone() const
Virtual constructor.
Definition: formula.hh:252
boundaryTypes
The different boundary condition types.
Definition: boundary.hh:38
const Boundary::boundaryTypes bType_
Definition: formula.hh:198
RCP< const ElementFormula< Point< F, 2 > > > & frm()
Access to the vectorial formula.
Definition: formula.hh:263
Reference-counting pointer.
Definition: bf_iddiv.hh:15
ElementFormulaBoundary(const BoundaryConditions bc, const Boundary::boundaryTypes bType=Boundary::DIRICHLET)
ElementFormulaLiCo(const ElementFormula< F, J > &frm1, const ElementFormula< G, J > &frm2, H a=1.0, H b=1.0)
Definition: formula.hh:41
const ElementFormulaContainer< Point< F, 2 > > frm_
Definition: formula.hh:228
virtual Point< F, 2 > operator()(const ElementWithCell< Real > &elm, const Real2d &p, const Real t=0.0) const
virtual F operator()(const ElementWithCell< G > &elm, const Real p, const Real t=0.0) const
Evaluates the formula.
Definition: formula.hh:136
ElementFormulaLiCo(const ElementFormulaLiCo< F, G, H, J > &frm)
Definition: formula.hh:45
virtual Real operator()(const ElementWithCell< Real > &elm, const Real p, const Real t=0.0) const
Evaluates the formula.
std::string typeOf(const T &t)
Return the typeid name of a class object.
Definition: output.hh:43
RCP< const ElementFormula< Point< F, 2 > > > frm() const
Returns the vectorial formula.
Definition: formula.hh:257
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual ElementFormulaBoundary * clone() const
Virtual copy constructor.
Rotated element formula of a 2D vector (90� to right).
Definition: formula.hh:209
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
virtual ElementFormulaLiCo< F, G, H, J > * clone() const
Virtual constructor.
Definition: formula.hh:63
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich