rgsl/
coulomb.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5use crate::{types, Value};
6use std::mem::MaybeUninit;
7
8/// This routine computes the lowest-order normalized hydrogenic bound state radial wavefunction R_1 := 2Z \sqrt{Z} \exp(-Z r).
9#[doc(alias = "gsl_sf_hydrogenicR_1")]
10pub fn hydrogenicR_1(Z: f64, r: f64) -> f64 {
11    unsafe { sys::gsl_sf_hydrogenicR_1(Z, r) }
12}
13
14/// This routine computes the lowest-order normalized hydrogenic bound state radial wavefunction R_1 := 2Z \sqrt{Z} \exp(-Z r).
15#[doc(alias = "gsl_sf_hydrogenicR_1_e")]
16pub fn hydrogenicR_1_e(Z: f64, r: f64) -> Result<types::Result, Value> {
17    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
18    let ret = unsafe { sys::gsl_sf_hydrogenicR_1_e(Z, r, result.as_mut_ptr()) };
19
20    result_handler!(ret, unsafe { result.assume_init() }.into())
21}
22
23/// This routine computes the n-th normalized hydrogenic bound state radial wavefunction,
24///
25/// R_n := 2 (Z^{3/2}/n^2) \sqrt{(n-l-1)!/(n+l)!} \exp(-Z r/n) (2Zr/n)^l
26///           L^{2l+1}_{n-l-1}(2Zr/n).  
27///
28/// where L^a_b(x) is the generalized Laguerre polynomial (see [`Laguerre Functions`](http://www.gnu.org/software/gsl/manual/html_node/Laguerre-Functions.html#Laguerre-Functions)).
29/// The normalization is chosen such that the wavefunction \psi is given by \psi(n,l,r) = R_n Y_{lm}.
30#[doc(alias = "gsl_sf_hydrogenicR")]
31pub fn hydrogenicR(n: i32, l: i32, Z: f64, r: f64) -> f64 {
32    unsafe { sys::gsl_sf_hydrogenicR(n, l, Z, r) }
33}
34
35/// This routine computes the n-th normalized hydrogenic bound state radial wavefunction,
36///
37/// R_n := 2 (Z^{3/2}/n^2) \sqrt{(n-l-1)!/(n+l)!} \exp(-Z r/n) (2Zr/n)^l
38///           L^{2l+1}_{n-l-1}(2Zr/n).  
39///
40/// where L^a_b(x) is the generalized Laguerre polynomial (see [`Laguerre Functions`](http://www.gnu.org/software/gsl/manual/html_node/Laguerre-Functions.html#Laguerre-Functions)).
41/// The normalization is chosen such that the wavefunction \psi is given by \psi(n,l,r) = R_n Y_{lm}.
42#[doc(alias = "gsl_sf_hydrogenicR_e")]
43pub fn hydrogenicR_e(n: i32, l: i32, Z: f64, r: f64) -> Result<types::Result, Value> {
44    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
45    let ret = unsafe { sys::gsl_sf_hydrogenicR_e(n, l, Z, r, result.as_mut_ptr()) };
46
47    result_handler!(ret, unsafe { result.assume_init() }.into())
48}
49
50/// This function computes the Coulomb wave functions F_L(\eta,x), G_{L-k}(\eta,x) and their derivatives F'_L(\eta,x), G'_{L-k}(\eta,x) with respect to x. The parameters are restricted to L, L-k > -1/2, x > 0 and integer k. Note that L itself is not restricted to being an integer. The results are stored in the parameters F, G for the function values and Fp, Gp for the derivative values.
51/// If an overflow occurs, GSL_EOVRFLW is returned and scaling exponents are stored in the modifiable parameters exp_F, exp_G.
52///
53/// Returns `(F, Fp, G, Gp)`.
54#[doc(alias = "gsl_sf_coulomb_wave_FG_e")]
55pub fn wave_FG_e(
56    eta: f64,
57    x: f64,
58    L_F: f64,
59    k: i32,
60    exp_F: &mut f64,
61    exp_G: &mut f64,
62) -> Result<
63    (
64        ::types::Result,
65        ::types::Result,
66        ::types::Result,
67        ::types::Result,
68    ),
69    Value,
70> {
71    let mut F = MaybeUninit::<sys::gsl_sf_result>::uninit();
72    let mut Fp = MaybeUninit::<sys::gsl_sf_result>::uninit();
73    let mut G = MaybeUninit::<sys::gsl_sf_result>::uninit();
74    let mut Gp = MaybeUninit::<sys::gsl_sf_result>::uninit();
75    let ret = unsafe {
76        sys::gsl_sf_coulomb_wave_FG_e(
77            eta,
78            x,
79            L_F,
80            k,
81            F.as_mut_ptr(),
82            Fp.as_mut_ptr(),
83            G.as_mut_ptr(),
84            Gp.as_mut_ptr(),
85            exp_F,
86            exp_G,
87        )
88    };
89
90    result_handler!(
91        ret,
92        (
93            unsafe { F.assume_init() }.into(),
94            unsafe { Fp.assume_init() }.into(),
95            unsafe { G.assume_init() }.into(),
96            unsafe { Gp.assume_init() }.into(),
97        )
98    )
99}
100
101/// This function computes the Coulomb wave function F_L(\eta,x) for L = Lmin \dots Lmin + kmax,
102/// storing the results in fc_array. In the case of overflow the exponent is stored in F_exponent.
103///
104/// Returns `F_exponent`.
105#[doc(alias = "gsl_sf_coulomb_wave_F_array")]
106pub fn wave_F_array(L_min: f64, eta: f64, x: f64, fc_array: &mut [f64]) -> Result<f64, Value> {
107    let mut F_exponent = 0.;
108    let ret = unsafe {
109        sys::gsl_sf_coulomb_wave_F_array(
110            L_min,
111            fc_array.len() as i32,
112            eta,
113            x,
114            fc_array.as_mut_ptr(),
115            &mut F_exponent,
116        )
117    };
118    result_handler!(ret, F_exponent)
119}
120
121/// This function computes the functions F_L(\eta,x), G_L(\eta,x) for L = Lmin \dots Lmin + kmax
122/// storing the results in fc_array and gc_array. In the case of overflow the exponents are stored
123/// in F_exponent and G_exponent.
124///
125/// Returns `(F_exponent, G_exponent)`.
126#[doc(alias = "gsl_sf_coulomb_wave_FG_array")]
127pub fn wave_FG_array(
128    L_min: f64,
129    eta: f64,
130    x: f64,
131    fc_array: &mut [f64],
132    gc_array: &mut [f64],
133) -> Result<(f64, f64), Value> {
134    let mut F_exponent = 0.;
135    let mut G_exponent = 0.;
136    let ret = unsafe {
137        sys::gsl_sf_coulomb_wave_FG_array(
138            L_min,
139            fc_array.len() as i32,
140            eta,
141            x,
142            fc_array.as_mut_ptr(),
143            gc_array.as_mut_ptr(),
144            &mut F_exponent,
145            &mut G_exponent,
146        )
147    };
148    result_handler!(ret, (F_exponent, G_exponent))
149}
150
151/// This function computes the functions F_L(\eta,x), G_L(\eta,x) and their derivatives
152/// F'_L(\eta,x), G'_L(\eta,x) for L = Lmin \dots Lmin + kmax storing the results in fc_array,
153/// gc_array, fcp_array and gcp_array. In the case of overflow the exponents are stored in
154/// F_exponent and G_exponent.
155///
156/// Returns `(F_exponent, G_exponent)`.
157#[doc(alias = "gsl_sf_coulomb_wave_FGp_array")]
158pub fn wave_FGp_array(
159    L_min: f64,
160    eta: f64,
161    x: f64,
162    fc_array: &mut [f64],
163    fcp_array: &mut [f64],
164    gc_array: &mut [f64],
165    gcp_array: &mut [f64],
166) -> Result<(f64, f64), Value> {
167    let mut F_exponent = 0.;
168    let mut G_exponent = 0.;
169    let ret = unsafe {
170        sys::gsl_sf_coulomb_wave_FGp_array(
171            L_min,
172            fc_array.len() as i32,
173            eta,
174            x,
175            fc_array.as_mut_ptr(),
176            fcp_array.as_mut_ptr(),
177            gc_array.as_mut_ptr(),
178            gcp_array.as_mut_ptr(),
179            &mut F_exponent,
180            &mut G_exponent,
181        )
182    };
183    result_handler!(ret, (F_exponent, G_exponent))
184}
185
186/// This function computes the Coulomb wave function divided by the argument F_L(\eta, x)/x for
187/// L = Lmin \dots Lmin + kmax, storing the results in fc_array. In the case of overflow the
188/// exponent is stored in F_exponent. This function reduces to spherical Bessel functions in the
189/// limit \eta \to 0.
190///
191/// Returns `F_exponent`.
192#[doc(alias = "gsl_sf_coulomb_wave_sphF_array")]
193pub fn wave_sphF_array(L_min: f64, eta: f64, x: f64, fc_array: &mut [f64]) -> Result<f64, Value> {
194    let mut F_exponent = 0.;
195    let ret = unsafe {
196        sys::gsl_sf_coulomb_wave_sphF_array(
197            L_min,
198            fc_array.len() as i32,
199            eta,
200            x,
201            fc_array.as_mut_ptr(),
202            &mut F_exponent,
203        )
204    };
205    result_handler!(ret, F_exponent)
206}
207
208/// This function computes the Coulomb wave function normalization constant C_L(\eta) for L > -1.
209#[doc(alias = "gsl_sf_coulomb_CL_e")]
210pub fn CL_e(L: f64, eta: f64) -> Result<types::Result, Value> {
211    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
212    let ret = unsafe { sys::gsl_sf_coulomb_CL_e(L, eta, result.as_mut_ptr()) };
213
214    result_handler!(ret, unsafe { result.assume_init() }.into())
215}
216
217/// This function computes the Coulomb wave function normalization constant C_L(\eta) for L = Lmin \dots Lmin + kmax, Lmin > -1.
218#[doc(alias = "gsl_sf_coulomb_CL_array")]
219pub fn CL_array(Lmin: f64, eta: f64, cl: &mut [f64]) -> Result<(), Value> {
220    let ret = unsafe { sys::gsl_sf_coulomb_CL_array(Lmin, cl.len() as i32, eta, cl.as_mut_ptr()) };
221    result_handler!(ret, ())
222}