|
| 1 | +""" |
| 2 | +`FastTransforms` submodule for the computation of some elliptic integrals and functions. |
| 3 | +
|
| 4 | +Complete elliptic integrals of the first and second kinds: |
| 5 | +```math |
| 6 | +K(k) = \\int_0^{\\frac{\\pi}{2}} \\frac{{\\rm d}\\theta}{\\sqrt{1-k^2\\sin^2\\theta}},\\quad{\\rm and}, |
| 7 | +``` |
| 8 | +```math |
| 9 | +E(k) = \\int_0^{\\frac{\\pi}{2}} \\sqrt{1-k^2\\sin^2\\theta} {\\rm\\,d}\\theta. |
| 10 | +``` |
| 11 | +
|
| 12 | +Jacobian elliptic functions: |
| 13 | +```math |
| 14 | +x = \\int_0^{\\operatorname{sn}(x,k)} \\frac{{\\rm d}t}{\\sqrt{(1-t^2)(1-k^2t^2)}}, |
| 15 | +``` |
| 16 | +```math |
| 17 | +x = \\int_{\\operatorname{cn}(x,k)}^1 \\frac{{\\rm d}t}{\\sqrt{(1-t^2)[1-k^2(1-t^2)]}}, |
| 18 | +``` |
| 19 | +```math |
| 20 | +x = \\int_{\\operatorname{dn}(x,k)}^1 \\frac{{\\rm d}t}{\\sqrt{(1-t^2)(t^2-1+k^2)}}, |
| 21 | +``` |
| 22 | +and the remaining nine are defined by: |
| 23 | +```math |
| 24 | +\\operatorname{pq}(x,k) = \\frac{\\operatorname{pr}(x,k)}{\\operatorname{qr}(x,k)} = \\frac{1}{\\operatorname{qp}(x,k)}. |
| 25 | +``` |
| 26 | +""" |
| 27 | +module Elliptic |
| 28 | + |
| 29 | +import FastTransforms: libfasttransforms |
| 30 | + |
| 31 | +export K, E, |
| 32 | + sn, cn, dn, ns, nc, nd, |
| 33 | + sc, cs, sd, ds, cd, dc |
| 34 | + |
| 35 | +for (fC, elty) in ((:ft_complete_elliptic_integralf, :Float32), (:ft_complete_elliptic_integral, :Float64)) |
| 36 | + @eval begin |
| 37 | + function K(k::$elty) |
| 38 | + return ccall(($(string(fC)), libfasttransforms), $elty, (Cint, $elty), '1', k) |
| 39 | + end |
| 40 | + function E(k::$elty) |
| 41 | + return ccall(($(string(fC)), libfasttransforms), $elty, (Cint, $elty), '2', k) |
| 42 | + end |
| 43 | + end |
| 44 | +end |
| 45 | + |
| 46 | +const SN = UInt(1) |
| 47 | +const CN = UInt(2) |
| 48 | +const DN = UInt(4) |
| 49 | + |
| 50 | +for (fC, elty) in ((:ft_jacobian_elliptic_functionsf, :Float32), (:ft_jacobian_elliptic_functions, :Float64)) |
| 51 | + @eval begin |
| 52 | + function sn(x::$elty, k::$elty) |
| 53 | + retsn = Ref{$elty}() |
| 54 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, retsn, C_NULL, C_NULL, SN) |
| 55 | + retsn[] |
| 56 | + end |
| 57 | + function cn(x::$elty, k::$elty) |
| 58 | + retcn = Ref{$elty}() |
| 59 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, C_NULL, retcn, C_NULL, CN) |
| 60 | + retcn[] |
| 61 | + end |
| 62 | + function dn(x::$elty, k::$elty) |
| 63 | + retdn = Ref{$elty}() |
| 64 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, C_NULL, C_NULL, retdn, DN) |
| 65 | + retdn[] |
| 66 | + end |
| 67 | + function ns(x::$elty, k::$elty) |
| 68 | + retsn = Ref{$elty}() |
| 69 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, retsn, C_NULL, C_NULL, SN) |
| 70 | + inv(retsn[]) |
| 71 | + end |
| 72 | + function nc(x::$elty, k::$elty) |
| 73 | + retcn = Ref{$elty}() |
| 74 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, C_NULL, retcn, C_NULL, CN) |
| 75 | + inv(retcn[]) |
| 76 | + end |
| 77 | + function nd(x::$elty, k::$elty) |
| 78 | + retdn = Ref{$elty}() |
| 79 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, C_NULL, C_NULL, retdn, DN) |
| 80 | + inv(retdn[]) |
| 81 | + end |
| 82 | + function sc(x::$elty, k::$elty) |
| 83 | + retsn = Ref{$elty}() |
| 84 | + retcn = Ref{$elty}() |
| 85 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, retsn, retcn, C_NULL, SN & CN) |
| 86 | + retsn[]/retcn[] |
| 87 | + end |
| 88 | + function cs(x::$elty, k::$elty) |
| 89 | + retsn = Ref{$elty}() |
| 90 | + retcn = Ref{$elty}() |
| 91 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, retsn, retcn, C_NULL, SN & CN) |
| 92 | + retcn[]/retsn[] |
| 93 | + end |
| 94 | + function sd(x::$elty, k::$elty) |
| 95 | + retsn = Ref{$elty}() |
| 96 | + retdn = Ref{$elty}() |
| 97 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, retsn, C_NULL, retdn, SN & DN) |
| 98 | + retsn[]/retdn[] |
| 99 | + end |
| 100 | + function ds(x::$elty, k::$elty) |
| 101 | + retsn = Ref{$elty}() |
| 102 | + retdn = Ref{$elty}() |
| 103 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, retsn, C_NULL, retdn, SN & DN) |
| 104 | + retdn[]/retsn[] |
| 105 | + end |
| 106 | + function cd(x::$elty, k::$elty) |
| 107 | + retcn = Ref{$elty}() |
| 108 | + retdn = Ref{$elty}() |
| 109 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, C_NULL, retcn, retdn, CN & DN) |
| 110 | + retcn[]/retdn[] |
| 111 | + end |
| 112 | + function dc(x::$elty, k::$elty) |
| 113 | + retcn = Ref{$elty}() |
| 114 | + retdn = Ref{$elty}() |
| 115 | + ccall(($(string(fC)), libfasttransforms), Cvoid, ($elty, $elty, Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, UInt), x, k, C_NULL, retcn, retdn, CN & DN) |
| 116 | + retdn[]/retcn[] |
| 117 | + end |
| 118 | + end |
| 119 | +end |
| 120 | + |
| 121 | +end # module |
0 commit comments