complex.hh

Go to the documentation of this file.
1 
7 #ifndef complex_hh
8 #define complex_hh
9 
10 #include <complex>
11 #include "basis.hh"
12 #include "basics/exceptions.hh"
13 #include "basics/typedefs.hh"
14 
15 namespace concepts {
16 
17  // ************************************************************* CmplxPart **
18 
25  class CmplxPart : public Function<Real> {
26  public:
28  inline CmplxPart(const Function<Cmplx>& fnc) :
29  Function<Real>(fnc.dim()), cfnc_(&fnc), fnc_(0) {}
30  inline CmplxPart(Function<Cmplx>& fnc) :
31  Function<Real>(fnc.dim()), cfnc_(0), fnc_(&fnc) {}
32 
34  virtual Function<Real>& operator=(const Function<Real>& fnc) {
35  throw conceptsException(MissingFeature("not implemented"));
36  return *this;
37  }
38  protected:
39  virtual std::ostream& info(std::ostream& os) const;
42  };
43 
44  // ************************************************************** RealPart **
45 
50  class RealPart : public CmplxPart {
51  public:
53  inline RealPart(const Function<Cmplx>& fnc) : CmplxPart(fnc) {}
54  inline RealPart(Function<Cmplx>& fnc) : CmplxPart(fnc) {}
55 
57  virtual Real& operator()(uint i) {
58  conceptsAssert(this->fnc_, Assertion());
59  return *(Real*)&(*this->fnc_)(i);
60  }
62  virtual Real operator()(uint i) const {
63  if (this->fnc_)
64  return std::real((*this->fnc_)(i));
65  return std::real((*this->cfnc_)(i));
66  }
67  protected:
68  virtual std::ostream& info(std::ostream& os) const;
69  };
70 
71  // ************************************************************** ImagPart **
72 
77  class ImagPart : public CmplxPart {
78  public:
80  inline ImagPart(const Function<Cmplx>& fnc) : CmplxPart(fnc) {}
81  inline ImagPart(Function<Cmplx>& fnc) : CmplxPart(fnc) {}
82 
84  virtual Real& operator()(uint i) {
85  conceptsAssert(this->fnc_, Assertion());
86  return *((Real*)&(*this->fnc_)(i)+1);
87  }
89  virtual Real operator()(uint i) const {
90  if (this->fnc_)
91  return std::imag((*this->fnc_)(i));
92  return std::imag((*this->cfnc_)(i));
93  }
94  protected:
95  virtual std::ostream& info(std::ostream& os) const;
96  };
97 
98  // ******************************************************* ComplexFunction **
99 
104  class ComplexFunction : public Function<Cmplx> {
105  public:
107  inline ComplexFunction(const Function<Real>& fnc) :
108  Function<Cmplx>(fnc.dim()), cfnc_(fnc) {}
111  throw conceptsException(MissingFeature("not assignable"));
112  return *this;
113  }
114 
116  virtual Cmplx& operator()(uint i) {
117  throw conceptsException(MissingFeature("not assignable"));
118  return dummy_;
119  }
121  virtual Cmplx operator()(uint i) const {
122  return cfnc_(i);
123  }
124  protected:
125  virtual std::ostream& info(std::ostream& os) const;
126  private:
129  };
130 
131 } // namespace concepts
132 
133 #endif // complex_hh
virtual Real operator()(uint i) const
Index operator.
Definition: complex.hh:62
RealPart(const Function< Cmplx > &fnc)
Constructor.
Definition: complex.hh:53
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
#define conceptsException(exc)
Prepares an exception for throwing.
Definition: exceptions.hh:344
Function as real part of an complex function.
Definition: complex.hh:50
CmplxPart(Function< Cmplx > &fnc)
Definition: complex.hh:30
virtual Cmplx operator()(uint i) const
Index operator.
Definition: complex.hh:121
Abstract class for a function.
Definition: basis.hh:21
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
virtual Real & operator()(uint i)
Index operator.
Definition: complex.hh:57
virtual Function< Real > & operator=(const Function< Real > &fnc)
Assignment operator.
Definition: complex.hh:34
ComplexFunction(const Function< Real > &fnc)
Constructor.
Definition: complex.hh:107
virtual Real & operator()(uint i)
Index operator.
Definition: complex.hh:84
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual Cmplx & operator()(uint i)
Index operator.
Definition: complex.hh:116
Function< Cmplx > * fnc_
Definition: complex.hh:41
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Exception class for assertions.
Definition: exceptions.hh:258
RealPart(Function< Cmplx > &fnc)
Definition: complex.hh:54
const Function< Cmplx > * cfnc_
Definition: complex.hh:40
virtual Function< Cmplx > & operator=(const Function< Cmplx > &fnc)
Assignment operator.
Definition: complex.hh:110
std::complex< Real > Cmplx
Type for a complex number. It also depends on the setting of Real.
Definition: typedefs.hh:39
ImagPart(Function< Cmplx > &fnc)
Definition: complex.hh:81
Complex function based on a real function (casting).
Definition: complex.hh:104
const Function< Real > & cfnc_
Definition: complex.hh:127
uint dim() const
Returns the dimension of the function.
Definition: basis.hh:53
Abstract class for a function, which is one part of an complex function.
Definition: complex.hh:25
Exception class to express a missing feature.
Definition: exceptions.hh:206
Function as imaginary part of an complex function.
Definition: complex.hh:77
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
ImagPart(const Function< Cmplx > &fnc)
Constructor.
Definition: complex.hh:80
virtual Real operator()(uint i) const
Index operator.
Definition: complex.hh:89
CmplxPart(const Function< Cmplx > &fnc)
Constructor.
Definition: complex.hh:28
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
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