sph_bessel.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef _SPH_BESSEL_H
  2. #define _SPH_BESSEL_H
  3. #include <iostream>
  4. #include <complex>
  5. typedef double Real;
  6. typedef std::complex<Real> Complex;
  7. const Complex im1(Real(0),Real(1));
  8. const Real _pi = 3.14159265358979323846;
  9. const Real _pi_2 = 1.57079632679489661923;
  10. const Real _e = 2.71828182845904523536;
  11. const Real _ln10 = 2.30258509299404568402;
  12. const Real _ln2 = 0.693147180559945309417;
  13. const Real _1sq2 = 0.707106781186547524401;
  14. inline Complex get_pow_i1(int p) {
  15. int i = p%4;
  16. if (i == 0) return Real(1);
  17. else if (i == 1) return im1;
  18. else if (i == 2) return Real(-1);
  19. else return -im1;
  20. }
  21. namespace sph_bessel {
  22. inline Complex besj0(Complex z) {if (abs(z) < 1.e-8) return 1.; else return sin(z)/z;};
  23. inline Complex besj1(Complex z) {if (abs(z) < 1.e-15) return z/Real(3); else return (sin(z)-z*cos(z))/z/z;}
  24. inline Complex besj0d(Complex z) {if (abs(z) < 1.e-15) return -z/Real(3); else return (z*cos(z)-sin(z))/z/z;}
  25. inline Complex besj1d(Complex z) {
  26. if (abs(z) < 1.e-8) return Real(1)/Real(3);
  27. else return ((z*z - Real(2))*sin(z) + Real(2)*z*cos(z))/(z*z*z);
  28. }
  29. inline Complex besy0(Complex z) {return -cos(z)/z;}
  30. inline Complex besy1(Complex z) {return (-cos(z) - z*sin(z))/z/z;}
  31. inline Complex besy0d(Complex z) {return (cos(z) + z*sin(z))/z/z;;}
  32. inline Complex besy1d(Complex z) {return -( (z*z - Real(2))*cos(z) - Real(2)*z*sin(z) )/z/z/z;}
  33. inline Complex besh10(Complex z) {return -im1*exp(im1*z)/z;}
  34. inline Complex besh11(Complex z) {return (-z-im1)*exp(im1*z)/z/z;}
  35. inline Complex besh10d(Complex z) {return (z+im1)*exp(im1*z)/z/z;}
  36. inline Complex besh11d(Complex z) {return (-im1 + Real(2)*(z+im1)/z/z )*exp(im1*z)/z;}
  37. inline Complex besh20(Complex z) {return im1*exp(-im1*z)/z;}
  38. inline Complex besh21(Complex z) {return (-z+im1)*exp(-im1*z)/z/z;}
  39. inline Complex besh20d(Complex z) {return (z-im1)*exp(-im1*z)/z/z;}
  40. inline Complex besh21d(Complex z) {return (im1 + Real(2)*(z-im1)/z/z)*exp(-im1*z)/z;}
  41. Complex besj(Complex, int);
  42. Complex besjd(Complex, int);
  43. Complex besy(Complex, int);
  44. Complex besyd(Complex, int);
  45. Complex besh1(Complex, int);
  46. Complex besh2(Complex, int);
  47. Complex besh1d(Complex, int);
  48. Complex besh2d(Complex, int);
  49. inline Complex bes_dzj(Complex z, int n) {return besj(z,n)+z*besjd(z,n);};
  50. inline Complex bes_dzy(Complex z, int n) {return besy(z,n)+z*besyd(z,n);};
  51. inline Complex bes_dzh1(Complex z, int n) {return besh1(z,n)+z*besh1d(z,n);};
  52. inline Complex bes_dzh2(Complex z, int n) {return besh2(z,n)+z*besh2d(z,n);};
  53. }
  54. void get_pitau_m01(Real x, Real *pi1, Real *tau0, Real *tau1, int deg_max);
  55. #endif // _SPH_BESSEL_H