rgsl/
coupling_coefficients.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5/*!
6The Wigner 3-j, 6-j and 9-j symbols give the coupling coefficients for combined angular momentum vectors.
7Since the arguments of the standard coupling coefficient functions are integer or half-integer, the arguments of the following functions
8are, by convention, integers equal to twice the actual spin value.
9!*/
10
11use crate::{types, Value};
12use std::mem::MaybeUninit;
13
14/// This routine computes the Wigner 3-j coefficient,
15///
16/// (ja jb jc
17///  ma mb mc)
18///
19/// where the arguments are given in half-integer units, ja = two_ja/2, ma = two_ma/2, etc.
20#[doc(alias = "gsl_sf_coupling_3j")]
21pub fn _3j(two_ja: i32, two_jb: i32, two_jc: i32, two_ma: i32, two_mb: i32, two_mc: i32) -> f64 {
22    unsafe { ::sys::gsl_sf_coupling_3j(two_ja, two_jb, two_jc, two_ma, two_mb, two_mc) }
23}
24
25/// This routine computes the Wigner 3-j coefficient,
26///
27/// (ja jb jc
28///  ma mb mc)
29///
30/// where the arguments are given in half-integer units, ja = two_ja/2, ma = two_ma/2, etc.
31#[doc(alias = "gsl_sf_coupling_3j_e")]
32pub fn _3j_e(
33    two_ja: i32,
34    two_jb: i32,
35    two_jc: i32,
36    two_ma: i32,
37    two_mb: i32,
38    two_mc: i32,
39) -> Result<types::Result, Value> {
40    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
41    let ret = unsafe {
42        ::sys::gsl_sf_coupling_3j_e(
43            two_ja,
44            two_jb,
45            two_jc,
46            two_ma,
47            two_mb,
48            two_mc,
49            result.as_mut_ptr(),
50        )
51    };
52
53    result_handler!(ret, unsafe { result.assume_init() }.into())
54}
55
56/// This routine computes the Wigner 6-j coefficient,
57///
58/// {ja jb jc
59/// jd je jf}
60///
61/// where the arguments are given in half-integer units, ja = two_ja/2, ma = two_ma/2, etc.
62#[doc(alias = "gsl_sf_coupling_6j")]
63pub fn _6j(two_ja: i32, two_jb: i32, two_jc: i32, two_jd: i32, two_je: i32, two_jf: i32) -> f64 {
64    unsafe { ::sys::gsl_sf_coupling_6j(two_ja, two_jb, two_jc, two_jd, two_je, two_jf) }
65}
66
67/// This routine computes the Wigner 6-j coefficient,
68///
69/// {ja jb jc
70/// jd je jf}
71///
72/// where the arguments are given in half-integer units, ja = two_ja/2, ma = two_ma/2, etc.
73#[doc(alias = "gsl_sf_coupling_6j_e")]
74pub fn _6j_e(
75    two_ja: i32,
76    two_jb: i32,
77    two_jc: i32,
78    two_jd: i32,
79    two_je: i32,
80    two_jf: i32,
81) -> Result<types::Result, Value> {
82    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
83    let ret = unsafe {
84        ::sys::gsl_sf_coupling_6j_e(
85            two_ja,
86            two_jb,
87            two_jc,
88            two_jd,
89            two_je,
90            two_jf,
91            result.as_mut_ptr(),
92        )
93    };
94
95    result_handler!(ret, unsafe { result.assume_init() }.into())
96}
97
98/// This routine computes the Wigner 9-j coefficient,
99///
100/// {ja jb jc
101/// jd je jf
102/// jg jh ji}
103/// where the arguments are given in half-integer units, ja = two_ja/2, ma = two_ma/2, etc.
104#[doc(alias = "gsl_sf_coupling_9j")]
105pub fn _9j(
106    two_ja: i32,
107    two_jb: i32,
108    two_jc: i32,
109    two_jd: i32,
110    two_je: i32,
111    two_jf: i32,
112    two_jg: i32,
113    two_jh: i32,
114    two_ji: i32,
115) -> f64 {
116    unsafe {
117        ::sys::gsl_sf_coupling_9j(
118            two_ja, two_jb, two_jc, two_jd, two_je, two_jf, two_jg, two_jh, two_ji,
119        )
120    }
121}
122
123/// This routine computes the Wigner 9-j coefficient,
124///
125/// {ja jb jc
126/// jd je jf
127/// jg jh ji}
128/// where the arguments are given in half-integer units, ja = two_ja/2, ma = two_ma/2, etc.
129#[doc(alias = "gsl_sf_coupling_9j_e")]
130pub fn _9j_e(
131    two_ja: i32,
132    two_jb: i32,
133    two_jc: i32,
134    two_jd: i32,
135    two_je: i32,
136    two_jf: i32,
137    two_jg: i32,
138    two_jh: i32,
139    two_ji: i32,
140) -> Result<types::Result, Value> {
141    let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
142    let ret = unsafe {
143        ::sys::gsl_sf_coupling_9j_e(
144            two_ja,
145            two_jb,
146            two_jc,
147            two_jd,
148            two_je,
149            two_jf,
150            two_jg,
151            two_jh,
152            two_ji,
153            result.as_mut_ptr(),
154        )
155    };
156
157    result_handler!(ret, unsafe { result.assume_init() }.into())
158}