Class documentation of Concepts

Loading...
Searching...
No Matches
formula.hh
Go to the documentation of this file.
1
6#ifndef spcFormula_hh
7#define spcFormula_hh
8
11#include "formula/boundary.hh"
12#include "formula/formula.hh"
15#include "space/element.hh"
16
17namespace 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:
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 }
64 return new ElementFormulaLiCo<F,G,H,J>(*frm1_, *frm2_);
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>
83 F ElementFormulaLiCo<F,G,H,J>::combine_(const ElementWithCell<J>& elm,
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>
127 public:
129 const ElementFormula<H,G>& frm2) :
130 frm1_(frm1.clone()), frm2_(frm2.clone()) {}
132 frm1_(frm.frm1_->clone()), frm2_(frm.frm2_->clone()) {}
133 virtual ~ElementFormulaCompose() {
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 }
149 return new ElementFormulaCompose<F,G,H>(*frm1_, *frm2_);
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>
162 F ElementFormulaCompose<F,G,H>::compose_(const ElementWithCell<G>& elm,
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
177 public:
179 (const BoundaryConditions bc,
180 const Boundary::boundaryTypes bType = Boundary::DIRICHLET);
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;
194 protected:
195 virtual std::ostream& info(std::ostream& os) const;
196 private:
197 const BoundaryConditions bc_;
198 const Boundary::boundaryTypes bType_;
199 };
200
201
202 // ************************************************ ElementFormulaRotate2D **
203
208 template<class F>
209 class ElementFormulaRotate2D : public ElementFormula<Point<F,2> > {
210 public:
214 : frm_(frm) {}
215 virtual Point<F,2> operator()(const ElementWithCell<Real>& elm,
216 const Real p, const Real t = 0.0) const;
217 virtual Point<F,2> operator()(const ElementWithCell<Real>& elm,
218 const Real2d& p, const Real t = 0.0) const;
219 virtual Point<F,2> operator()(const ElementWithCell<Real>& elm,
220 const Real3d& p, const Real t = 0.0) 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
boundaryTypes
The different boundary condition types.
Definition boundary.hh:38
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual ElementFormulaBoundary * clone() const
Virtual copy constructor.
virtual Real operator()(const ElementWithCell< Real > &elm, const Real p, const Real t=0.0) const
virtual ElementFormulaCompose< F, G, H > * clone() const
Virtual copy constructor.
Definition formula.hh:148
virtual F operator()(const ElementWithCell< G > &elm, const Real p, const Real t=0.0) const
Definition formula.hh:136
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Definition formula.hh:168
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Definition formula.hh:91
virtual ElementFormulaLiCo< F, G, H, J > * clone() const
Virtual copy constructor.
Definition formula.hh:63
ElementFormulaRotate2D(const ElementFormulaContainer< Point< F, 2 > > frm)
Constructor.
Definition formula.hh:213
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
RCP< const ElementFormula< Point< F, 2 > > > frm() const
Returns the vectorial formula.
Definition formula.hh:257
RCP< const ElementFormula< Point< F, 2 > > > & frm()
Access to the vectorial formula.
Definition formula.hh:263
virtual FrmE_ScalarProductNormalEdge2d * clone() const
Virtual copy constructor.
Definition formula.hh:252
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
std::string typeOf(const T &t)
Definition output.hh:43
double Real
Definition typedefs.hh:39
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320