gsl_specfunc__coulomb_bound.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* specfunc/coulomb_bound.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. /* Author: G. Jungman */
  20. #include "gsl__config.h"
  21. #include "gsl_math.h"
  22. #include "gsl_errno.h"
  23. #include "gsl_sf_exp.h"
  24. #include "gsl_sf_gamma.h"
  25. #include "gsl_sf_pow_int.h"
  26. #include "gsl_sf_laguerre.h"
  27. #include "gsl_sf_coulomb.h"
  28. #include "gsl_specfunc__error.h"
  29. #include "gsl_specfunc__check.h"
  30. /* normalization for hydrogenic wave functions */
  31. static
  32. int
  33. R_norm(const int n, const int l, const double Z, gsl_sf_result * result)
  34. {
  35. double A = 2.0*Z/n;
  36. double pre = sqrt(A*A*A /(2.0*n));
  37. gsl_sf_result ln_a, ln_b;
  38. gsl_sf_result ex;
  39. int stat_a = gsl_sf_lnfact_e(n+l, &ln_a);
  40. int stat_b = gsl_sf_lnfact_e(n-l-1, &ln_b);
  41. double diff_val = 0.5*(ln_b.val - ln_a.val);
  42. double diff_err = 0.5*(ln_b.err + ln_a.err) + GSL_DBL_EPSILON * fabs(diff_val);
  43. int stat_e = gsl_sf_exp_err_e(diff_val, diff_err, &ex);
  44. result->val = pre * ex.val;
  45. result->err = pre * ex.err;
  46. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  47. return GSL_ERROR_SELECT_3(stat_e, stat_a, stat_b);
  48. }
  49. /*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
  50. int
  51. gsl_sf_hydrogenicR_1_e(const double Z, const double r, gsl_sf_result * result)
  52. {
  53. if(Z > 0.0 && r >= 0.0) {
  54. double A = 2.0*Z;
  55. double norm = A*sqrt(Z);
  56. double ea = exp(-Z*r);
  57. result->val = norm*ea;
  58. result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val) * fabs(Z*r);
  59. CHECK_UNDERFLOW(result);
  60. return GSL_SUCCESS;
  61. }
  62. else {
  63. DOMAIN_ERROR(result);
  64. }
  65. }
  66. int
  67. gsl_sf_hydrogenicR_e(const int n, const int l,
  68. const double Z, const double r,
  69. gsl_sf_result * result)
  70. {
  71. if(n < 1 || l > n-1 || Z <= 0.0 || r < 0.0) {
  72. DOMAIN_ERROR(result);
  73. }
  74. else {
  75. double A = 2.0*Z/n;
  76. gsl_sf_result norm;
  77. int stat_norm = R_norm(n, l, Z, &norm);
  78. double rho = A*r;
  79. double ea = exp(-0.5*rho);
  80. double pp = gsl_sf_pow_int(rho, l);
  81. gsl_sf_result lag;
  82. int stat_lag = gsl_sf_laguerre_n_e(n-l-1, 2*l+1, rho, &lag);
  83. double W_val = norm.val * ea * pp;
  84. double W_err = norm.err * ea * pp;
  85. W_err += norm.val * ((0.5*rho + 1.0) * GSL_DBL_EPSILON) * ea * pp;
  86. W_err += norm.val * ea * ((l+1.0) * GSL_DBL_EPSILON) * pp;
  87. result->val = W_val * lag.val;
  88. result->err = W_val * lag.err + W_err * fabs(lag.val);
  89. result->err += 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  90. if ((l == 0 || (r > 0 && l > 0)) && lag.val != 0.0
  91. && stat_lag == GSL_SUCCESS && stat_norm == GSL_SUCCESS) {
  92. CHECK_UNDERFLOW(result);
  93. };
  94. return GSL_ERROR_SELECT_2(stat_lag, stat_norm);
  95. }
  96. }
  97. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  98. #include "gsl_specfunc__eval.h"
  99. double gsl_sf_hydrogenicR_1(const double Z, const double r)
  100. {
  101. EVAL_RESULT(gsl_sf_hydrogenicR_1_e(Z, r, &result));
  102. }
  103. double gsl_sf_hydrogenicR(const int n, const int l, const double Z, const double r)
  104. {
  105. EVAL_RESULT(gsl_sf_hydrogenicR_e(n, l, Z, r, &result));
  106. }