bessel.hh

Go to the documentation of this file.
1 
9 #ifndef besselFormula_hh
10 #define besselFormula_hh
11 
12 #include "toolbox/sequence.hh"
13 #include "formula.hh"
14 // Integrated from git clone https://github.com/valandil/complex_bessel.git
15 #ifdef HAS_COMPLEX_BESSEL
16 #include "basics/warnings/push.h"
18 #include "complex_bessel.h"
19 #include "basics/warnings/pop.h"
20 #endif
21 
22 namespace concepts {
23 
24  // ************************************************************** besselJ0 **
25 
26  Real besselJ0(const Real x);
27 
28  // ************************************************************** besselY0 **
29 
30  Real besselY0(const Real x);
31 
32  // ************************************************************** besselJ1 **
33 
34  Real besselJ1(const Real x);
35 
36  // ************************************************************** besselY1 **
37 
38  Real besselY1(const Real x);
39 
40  // ************************************************************** besselJn **
41 
43  Real besselJn(const Real x, const int n);
44 
47 
48  // ************************************************************** besselYn **
49 
51  Real besselYn(const Real x, const int n);
52 
54  Sequence<Real> besselJn(const Real x, const Sequence<int>& n);
55 
56  // ************************************************************ hankel_1_n **
57 
61  Cmplx hankel_1_n(const Real x, const int n);
62 
64 
65  // ************************************************************ hankel_2_n **
66 
70  Cmplx hankel_2_n(const Real x, const int n);
71 
73 
74  // ****************************************************** hankel_1_deriv_n **
75 
79  Cmplx hankel_1_deriv_n(const Real x, const int n);
80 
82 
83  // ****************************************************** hankel_2_deriv_n **
84 
88  Cmplx hankel_2_deriv_n(const Real x, const int n);
89 
91 
92 #ifdef HAS_COMPLEX_BESSEL
93 
94  // ************************************************************* besselJnu **
95 
97  Cmplx besselJnu(const Real x, const Real nu);
98 
100  Cmplx besselJnu_deriv(const Real x, const Real nu);
101 
102  // ************************************************************* besselYnu **
103 
105  Cmplx besselYnu(const Real x, const Real nu);
106 
108  Cmplx besselYnu_deriv(const Real x, const Real nu);
109 
110 #endif
111 
112  // *************************************************************** BesselJ **
113 
123  template<int n>
124  class BesselJ : public Formula<Real> {
125  public:
127  BesselJ(const Real m = 1.0, const Real r0 = 0.0)
128  : m_(m), r0_(r0, 0.0, 0.0) {}
129  BesselJ(const Real m, const Real3d r0)
130  : m_(m), r0_(r0) {}
132  virtual Real operator() (const Real p, const Real t = 0.0) const;
133  virtual Real operator() (const Real2d& p, const Real t = 0.0) const;
134  virtual Real operator() (const Real3d& p, const Real t = 0.0) const;
136  Real derivative(const Real p);
137  Real derivative(const Real2d& p);
138  Real derivative(const Real3d& p);
139 
140  virtual BesselJ<n>* clone() const {
141  return new BesselJ<n>(m_, r0_);
142  }
143  protected:
144  virtual std::ostream& info(std::ostream& os) const;
145  private:
147  const Real m_;
149  const Real3d r0_;
150  };
151 
152  template<int n>
153  Real BesselJ<n>::operator() (const Real p, const Real t) const {
154  return besselJn(m_*std::abs(p - r0_[0]),n);
155  }
156 
157  template<int n>
158  Real BesselJ<n>::operator() (const Real2d& p, const Real t) const {
159  return besselJn(m_*(p - Real2d(r0_)).l2(),n);
160  }
161 
162  template<int n>
163  Real BesselJ<n>::operator() (const Real3d& p, const Real t) const {
164  return besselJn(m_*(p - r0_).l2(),n);
165  }
166 
167  template<int n>
169  Real x = m_*std::abs(p - r0_[0]);
170  return -n/x*besselJn(x,n)+besselJn(x,n-1);
171  }
172 
173  template<int n>
175  Real x = m_*(p - Real2d(r0_)).l2();
176  return -n/x*besselJn(x,n)+besselJn(x,n-1);
177  }
178 
179  template<int n>
181  Real x = m_*(p - r0_).l2();
182  return -n/x*besselJn(x,n)+besselJn(x,n-1);
183  }
184 
185  template<int n>
186  std::ostream& BesselJ<n>::info(std::ostream& os) const {
187  os << concepts::typeOf(*this)<< "(";
188  if (m_ != 1) os << m_ << "*";
189  if (r0_.l2() > 0)
190  os << "(r - " << r0_ << ")";
191  else
192  os << "r";
193  return os << ")";
194  }
195 
196  // ************************************************************** BesselY **
197 
207  template<int n>
208  class BesselY : public Formula<Real> {
209  public:
211  BesselY(const Real m = 1.0, const Real r0 = 0.0)
212  : m_(m), r0_(r0, 0.0, 0.0) {}
213  BesselY(const Real m, const Real3d r0)
214  : m_(m), r0_(r0) {}
216  virtual Real operator() (const Real p, const Real t = 0.0) const;
217  virtual Real operator() (const Real2d& p, const Real t = 0.0) const;
218  virtual Real operator() (const Real3d& p, const Real t = 0.0) const;
220  Real derivative(const Real p);
221  Real derivative(const Real2d& p);
222  Real derivative(const Real3d& p);
223 
224  virtual BesselY<n>* clone() const {
225  return new BesselY<n>(m_, r0_);
226  }
227  protected:
228  virtual std::ostream& info(std::ostream& os) const;
229  private:
231  const Real m_;
233  const Real3d r0_;
234  };
235 
236  template<int n>
237  Real BesselY<n>::operator() (const Real p, const Real t) const {
238  return besselYn(m_*std::abs(p - r0_[0]),n);
239  }
240 
241  template<int n>
242  Real BesselY<n>::operator() (const Real2d& p, const Real t) const {
243  return besselYn(m_*(p - Real2d(r0_)).l2(),n);
244  }
245 
246  template<int n>
247  Real BesselY<n>::operator() (const Real3d& p, const Real t) const {
248  return besselYn(m_*(p - r0_).l2(),n);
249  }
250 
251  template<int n>
253  Real x = m_*std::abs(p - r0_[0]);
254  return -n/x*besselYn(x,n)+besselYn(x,n-1);
255  }
256 
257  template<int n>
259  Real x = m_*(p - Real2d(r0_)).l2();
260  return -n/x*besselYn(x,n)+besselYn(x,n-1);
261  }
262 
263  template<int n>
265  Real x = m_*(p - r0_).l2();
266  return -n/x*besselYn(x,n)+besselYn(x,n-1);
267  }
268 
269  template<int n>
270  std::ostream& BesselY<n>::info(std::ostream& os) const {
271  os << concepts::typeOf(*this)<< "(";
272  if (m_ != 1) os << m_ << "*";
273  if (r0_.l2() > 0)
274  os << "(r - " << r0_ << ")";
275  else
276  os << "r";
277  return os << ")";
278  }
279 
280 } // namespace concepts
281 
282 #endif // besselFormula_hh
283 
Class for evaluating the Bessel function of first kind.
Definition: bessel.hh:124
Cmplx hankel_1_n(const Real x, const int n)
Evaluates the Hankel function .
Real derivative(const Real p)
Derivative of Bessel function.
Definition: bessel.hh:252
virtual BesselY< n > * clone() const
Definition: bessel.hh:224
Real besselJ1(const Real x)
Cmplx hankel_2_n(const Real x, const int n)
Evaluates the Hankel function .
Real besselY0(const Real x)
const Real m_
Factor in the argument.
Definition: bessel.hh:147
Point< Real, 2 > Real2d
virtual std::ostream & info(std::ostream &os) const
Definition: bessel.hh:186
Interface for a formula.
Definition: lform.hh:18
BesselY(const Real m=1.0, const Real r0=0.0)
Constructor.
Definition: bessel.hh:211
const Real3d r0_
Center of the Bessel function.
Definition: bessel.hh:149
BesselJ(const Real m=1.0, const Real r0=0.0)
Constructor.
Definition: bessel.hh:127
Real derivative(const Real p)
Derivative of Bessel function.
Definition: bessel.hh:168
Class for evaluating the Bessel function of second kind.
Definition: bessel.hh:208
Real besselY1(const Real x)
Real besselJn(const Real x, const int n)
Evaluates the Bessel function .
BesselJ(const Real m, const Real3d r0)
Definition: bessel.hh:129
Cmplx hankel_1_deriv_n(const Real x, const int n)
Evaluates the derivative of the Hankel function .
Real besselYn(const Real x, const int n)
Evaluates the Bessel function .
BesselY(const Real m, const Real3d r0)
Definition: bessel.hh:213
Cmplx hankel_2_deriv_n(const Real x, const int n)
Evaluates the derivative of the Hankel function .
std::complex< Real > Cmplx
Type for a complex number. It also depends on the setting of Real.
Definition: typedefs.hh:39
uint abs(const uint &v)
Definition: operations.hh:95
const Real m_
Factor.
Definition: bessel.hh:231
virtual Real operator()(const Real p, const Real t=0.0) const
Bessel function.
Definition: bessel.hh:153
Real besselJ0(const Real x)
virtual std::ostream & info(std::ostream &os) const
Definition: bessel.hh:270
const Real3d r0_
Center of the Bessel function.
Definition: bessel.hh:233
virtual BesselJ< n > * clone() const
Definition: bessel.hh:140
std::string typeOf(const T &t)
Return the typeid name of a class object.
Definition: output.hh:43
virtual Real operator()(const Real p, const Real t=0.0) const
Bessel function.
Definition: bessel.hh:237
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