function.hh

Go to the documentation of this file.
1 
6 #ifndef spcFunction_hh
7 #define spcFunction_hh
8 
9 #include <cstring>
10 #include "basics/outputOperator.hh"
12 #include "toolbox/array.hh"
13 #include "element.hh"
14 
15 namespace concepts {
16 
17  // ****************************************************** ElementFunction **
18 
23  template<class F, class G = typename Realtype<F>::type>
24  class ElementFunction : public virtual OutputOperator {
25  public:
27  virtual uint n() const = 0;
34  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
35  Array<F>& val, const uint *i) const = 0;
43  virtual void operator() (const Element<G>& elm, const uint* j,
44  Array<F>& val, const uint* i) const = 0;
46 
54  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
55  Array<F>& val, const Real p,
56  const Real t = 0.0) const = 0;
57  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
58  Array<F>& val, const Real2d& p,
59  const Real t = 0.0) const = 0;
60  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
61  Array<F>& val, const Real3d& p,
62  const Real t = 0.0) const = 0;
64 
65  virtual ElementFunction<F,G>* clone() const = 0;
66  protected:
67  virtual std::ostream& info(std::ostream& os) const {
68  return os << concepts::typeOf(*this)<<"()";
69  }
70  };
71 
72  // *************************************************************** Squared **
73 
77  template<class F, class G = typename Realtype<F>::type>
78  class Squared : public ElementFunction<F, G> {
79  public:
82  virtual ~Squared() {}
83  virtual uint n() const { return fun_.n(); }
84 
85  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
86  Array<F>& val, const uint *i) const;
87  virtual void operator() (const Element<G>& elm, const uint* j,
88  Array<F>& val, const uint* i) const;
89  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
90  Array<F>& val, const Real p,
91  const Real t = 0.0) const;
92  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
93  Array<F>& val, const Real2d& p,
94  const Real t = 0.0) const;
95  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
96  Array<F>& val, const Real3d& p,
97  const Real t = 0.0) const;
98 
99  virtual Squared<F,G>* clone() const { return new Squared(fun_); }
100  protected:
101  virtual std::ostream& info(std::ostream& os) const;
102  private:
106  template<class H>
107  void square_(Array<H>& val) const {
108  conceptsAssert(val.size() <= n(), Assertion());
109  for(uint j=0; j < n(); ++j)
110  val[j] = val[j]*val[j];
111  }
112  };
113 
114  // ********************************************************** AbsoluteComp **
115 
124  template<class F, class G = typename Realtype<F>::type>
125  class AbsoluteComp : public ElementFunction<F, G> {
126  public:
129  virtual ~AbsoluteComp() {}
130  virtual uint n() const { return fun_.n(); }
131 
132  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
133  Array<F>& val, const uint *i) const;
134  virtual void operator() (const Element<G>& elm, const uint* j,
135  Array<F>& val, const uint* i) const;
136  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
137  Array<F>& val, const Real p,
138  const Real t = 0.0) const;
139  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
140  Array<F>& val, const Real2d& p,
141  const Real t = 0.0) const;
142  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
143  Array<F>& val, const Real3d& p,
144  const Real t = 0.0) const;
145  virtual AbsoluteComp<F,G>* clone() const { return new AbsoluteComp(fun_); }
146  protected:
147  virtual std::ostream& info(std::ostream& os) const;
148  private:
152  void absolute_(Array<F>& val) const;
153  };
154 
155  // ************************************************************** Absolute **
156 
165  template<class F, class G = typename Realtype<F>::type>
166  class Absolute : public ElementFunction<F, G> {
167  public:
170  virtual ~Absolute() {}
171  virtual uint n() const { return 1; }
172 
173  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
174  Array<F>& val, const uint *i) const;
175  virtual void operator() (const Element<G>& elm, const uint* j,
176  Array<F>& val, const uint* i) const;
177  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
178  Array<F>& val, const Real p,
179  const Real t = 0.0) const;
180  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
181  Array<F>& val, const Real2d& p,
182  const Real t = 0.0) const;
183  virtual void operator() (const Element<G>& elm, const Array<F>& coeff,
184  Array<F>& val, const Real3d& p,
185  const Real t = 0.0) const;
186  virtual Absolute<F,G>* clone() const { return new Absolute(fun_); }
187  protected:
188  virtual std::ostream& info(std::ostream& os) const;
189  private:
193  F absolute_(const Array<F>& val) const;
194  };
195 
196 } // namespace concepts
197 
198 #endif // spcFunction_hh
uint size() const
Returns the requested size of the array.
Definition: array.hh:259
The square of a element function (componentwise)
Definition: function.hh:78
An abstract class for a function in a FE space.
virtual ~Absolute()
Definition: function.hh:170
virtual ~Squared()
Definition: function.hh:82
virtual uint n() const
Definition: function.hh:83
void square_(Array< H > &val) const
Method for the square.
Definition: function.hh:107
virtual void operator()(const Element< G > &elm, const Array< F > &coeff, Array< F > &val, const uint *i) const =0
Evaluates the function on precalculated quadrature points.
Absolute(ElementFunction< F, G > &fun)
Constructor.
Definition: function.hh:169
virtual Squared< F, G > * clone() const
Definition: function.hh:99
ElementFunction< F, G > & fun_
FE Function for which the square is to taken.
Definition: function.hh:150
Squared(ElementFunction< F, G > &fun)
Constructor.
Definition: function.hh:81
ElementFunction< F, G > & fun_
FE Function for which the square is to taken.
Definition: function.hh:191
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
AbsoluteComp(ElementFunction< F, G > &fun)
Constructor.
Definition: function.hh:128
virtual std::ostream & info(std::ostream &os) const
virtual uint n() const
Definition: function.hh:171
F absolute_(const Array< F > &val) const
Method for the absolute value.
virtual AbsoluteComp< F, G > * clone() const
Definition: function.hh:145
virtual uint n() const =0
Number of components.
An array of objects.
Definition: bilinearForm.hh:23
Exception class for assertions.
Definition: exceptions.hh:258
virtual Absolute< F, G > * clone() const
Definition: function.hh:186
virtual void operator()(const Element< G > &elm, const Array< F > &coeff, Array< F > &val, const uint *i) const
virtual std::ostream & info(std::ostream &os) const
virtual uint n() const
Definition: function.hh:130
virtual std::ostream & info(std::ostream &os) const
Definition: function.hh:67
virtual ElementFunction< F, G > * clone() const =0
The component wise absolute value of a element function.
Definition: function.hh:125
virtual void operator()(const Element< G > &elm, const Array< F > &coeff, Array< F > &val, const uint *i) const
The absolute value of a element function.
Definition: function.hh:166
virtual std::ostream & info(std::ostream &os) const
virtual ~AbsoluteComp()
Definition: function.hh:129
ElementFunction< F, G > & fun_
FE Function for which the square is to taken.
Definition: function.hh:104
std::string typeOf(const T &t)
Return the typeid name of a class object.
Definition: output.hh:43
void absolute_(Array< F > &val) const
Method for the absolute value.
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
virtual void operator()(const Element< G > &elm, const Array< F > &coeff, Array< F > &val, const uint *i) const
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich