Skip to content

Commit c7321d1

Browse files
committed
Merge branch 'master' of https://github.com/fgerick/SHTns.jl
2 parents 9548ca0 + 7d8788d commit c7321d1

File tree

14 files changed

+365
-306
lines changed

14 files changed

+365
-306
lines changed

.github/workflows/TagBot.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: TagBot
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
workflow_dispatch:
7+
inputs:
8+
lookback:
9+
default: "3"
10+
permissions:
11+
actions: read
12+
checks: read
13+
contents: write
14+
deployments: read
15+
issues: read
16+
discussions: read
17+
packages: read
18+
pages: read
19+
pull-requests: read
20+
repository-projects: read
21+
security-events: read
22+
statuses: read
23+
jobs:
24+
TagBot:
25+
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: JuliaRegistries/TagBot@v1
29+
with:
30+
token: ${{ secrets.GITHUB_TOKEN }}
31+
# Edit the following line to reflect the actual name of the GitHub Secret containing your private key
32+
ssh: ${{ secrets.DOCUMENTER_KEY }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*.jl.mem
44
.DS_Store
55
/Manifest.toml
6+
/test/Manifest.toml
67
/dev/
78
/docs/build/
89
/docs/site/
10+
/docs/Manifest.toml

docs/Manifest.toml

Lines changed: 0 additions & 159 deletions
This file was deleted.

docs/src/index.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
# SHTns.jl
22

3-
[SHTns](https://bitbucket.org/nschaeff/shtns/src/master/) is a high performance library for Spherical Harmonic Transform written in C, aimed at numerical simulation (fluid flows, mhd, ...) in spherical geometries.
3+
[SHTns](https://bitbucket.org/nschaeff/shtns/src/master/) is a high performance library for Spherical Harmonic Transform written in C, aimed at numerical simulation (fluid flows, MHD, ...) in spherical geometries.
4+
5+
## Installation
6+
7+
In your project environment run
8+
9+
```julia
10+
import Pkg; Pkg.add("SHTns")
11+
```
12+
13+
If you have installed SHTns separately (and compiled it into a shared library!) and you would like `SHTns.jl` to use this installation instead of the binaries shipped through `SHTns_jll`, you can set the `SHTNS_PATH` environment variable before `using SHTns`:
14+
15+
```julia
16+
ENV["SHTNS_PATH"] = "/path/to/libshtns.so"
17+
using SHTns
18+
```

src/SHTns.jl

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
module SHTns
22

33
using SHTns_jll
4-
export SHTns_jll
4+
#to use system build SHTns library (needs to be a shared library)
5+
# e.g. using
6+
# gcc -lfftw3 -lfftw3_omp -fopenmp -shared libshtns.so *.o
7+
const libshtns = Ref{String}()
8+
9+
function __init__()
10+
if haskey(ENV, "SHTNS_PATH")
11+
libshtns[] = ENV["SHTNS_PATH"]
12+
else
13+
libshtns[] = SHTns_jll.LibSHTns
14+
end
15+
end
516

6-
import Base: convert, show, propertynames, getproperty
717

8-
const libshtns = SHTns_jll.LibSHTns
18+
import Base: convert, show, propertynames, getproperty
919

1020

1121
const shtns_norm = UInt32
@@ -89,10 +99,10 @@ end
8999

90100
function _init_checks(shtype, lmax, mmax, mres, nlat, nphi)
91101
@assert lmax > 1
92-
@assert nphi > 2lmax
93102
@assert mmax*mres <= lmax
94103
@assert mres > 0
95-
@assert nlat >= 32 #shtns wants nlat > 4*VSIZE2
104+
@assert nlat >= 16 # shtns wants nlat > 4*VSIZE2
105+
@assert nphi > 2mmax # sampling theorem
96106
if typeof(shtype) <: Union{Gauss, GaussFly, QuickInit}
97107
@assert nlat > lmax
98108
else
@@ -110,6 +120,20 @@ mutable struct SHTnsCfg{N<:SHTnsNorm, T<:SHTnsType}
110120
norm::N
111121
shtype::T
112122
robert_form::Bool
123+
nlm::Int
124+
lmax::Int
125+
mmax::Int
126+
mres::Int
127+
nlat_2::Int
128+
nlat::Int
129+
nphi::Int
130+
nspat::Int
131+
li::Vector{Int}
132+
mi::Vector{Int}
133+
ct::Vector{Float64}
134+
st::Vector{Float64}
135+
nlat_padded::Int
136+
nlm_cplx::Int
113137
function SHTnsCfg(lmax, mmax, mres, nlat, nphi;
114138
shtype::T=QuickInit(),
115139
norm::N=Orthonormal(),
@@ -120,9 +144,13 @@ mutable struct SHTnsCfg{N<:SHTnsNorm, T<:SHTnsType}
120144
_init_checks(shtype, lmax, mmax, mres, nlat, nphi)
121145
cfg = shtns_create(lmax, mmax, mres, norm)
122146
robert_form && shtns_robert_form(cfg,1)
123-
124147
shtns_set_grid(cfg, shtype, eps, nlat, nphi)
125-
stream = new{N,T}(cfg, norm, shtype, robert_form)
148+
info = unsafe_load(cfg)
149+
li = Vector{Int}(unsafe_wrap(Vector{Cushort},info.li,Int(info.nlm)))
150+
mi = Vector{Int}(unsafe_wrap(Vector{Cushort},info.mi,Int(info.nlm)))
151+
ct = Vector{Float64}(unsafe_wrap(Vector{Cdouble},info.ct,Int(info.nlat)))
152+
st = Vector{Float64}(unsafe_wrap(Vector{Cdouble},info.st,Int(info.nlat)))
153+
stream = new{N,T}(cfg, norm, shtype, robert_form, info.nlm, info.lmax, info.mmax, info.mres, info.nlat_2, info.nlat, info.nphi, info.nspat, li, mi, ct, st, info.nlat_padded, info.nlm_cplx)
126154
finalizer(x->shtns_destroy(x.cfg), stream)
127155
return stream
128156
end
@@ -142,43 +170,29 @@ mutable struct SHTnsCfg{N<:SHTnsNorm, T<:SHTnsType}
142170
robert_form && shtns_robert_form(cfg,1)
143171
info = unsafe_load(cfg)
144172
shtns_set_grid_auto(cfg, shtype, eps, nl_order, Ref(info.nlat), Ref(info.nphi))
145-
stream = new{N,T}(cfg, norm, shtype, robert_form)
173+
info = unsafe_load(cfg)
174+
li = Vector{Int}(unsafe_wrap(Vector{Cushort},info.li,Int(info.nlm)))
175+
mi = Vector{Int}(unsafe_wrap(Vector{Cushort},info.mi,Int(info.nlm)))
176+
ct = Vector{Float64}(unsafe_wrap(Vector{Cdouble},info.ct,Int(info.nlat)))
177+
st = Vector{Float64}(unsafe_wrap(Vector{Cdouble},info.st,Int(info.nlat)))
178+
stream = new{N,T}(cfg, norm, shtype, robert_form, info.nlm, info.lmax, info.mmax, info.mres, info.nlat_2, info.nlat, info.nphi, info.nspat, li, mi, ct, st, info.nlat_padded, info.nlm_cplx)
146179
finalizer(x->shtns_destroy(x.cfg), stream)
147180
return stream
148181
end
149182

150183
end
151184

152185

153-
function Base.propertynames(::SHTnsCfg, private::Bool=false)
154-
publicnames = (:nlm, :lmax, :mmax, :mres, :nlat_2, :nlat, :nphi,
155-
:nspat, :li, :mi, :ct, :st, :nlat_padded, :nlm_cplx, :norm, :type, :csphase, :robert_form)
156-
privatenames = (:cfg, )
157-
if private
158-
return (publicnames..., privatenames...)
159-
else
160-
return publicnames
161-
end
162-
end
163-
164-
function Base.getproperty(cfg::SHTnsCfg, p::Symbol)
165-
if p (:nlm, :lmax, :mmax, :mres, :nlat_2, :nlat, :nphi,
166-
:nspat, :nlat_padded, :nlm_cplx)
167-
return Int(getproperty(unsafe_load(cfg.cfg),p))
168-
elseif p (:li, :mi)
169-
info = unsafe_load(cfg.cfg)
170-
u = Vector{Int}(unsafe_wrap(Vector{Cushort},getproperty(info,p),Int(info.nlm)))
171-
return u
172-
elseif p (:ct, :st)
173-
info = unsafe_load(cfg.cfg)
174-
u = Vector{Float64}(unsafe_wrap(Vector{Cdouble},getproperty(info,p),Int(info.nlat)))
175-
return u
176-
elseif p (:norm, :type)
177-
return getfield(cfg, p)
178-
else
179-
return getfield(cfg, p)
180-
end
181-
end
186+
# function Base.propertynames(::SHTnsCfg, private::Bool=false)
187+
# publicnames = (:nlm, :lmax, :mmax, :mres, :nlat_2, :nlat, :nphi,
188+
# :nspat, :li, :mi, :ct, :st, :nlat_padded, :nlm_cplx, :norm, :type, :robert_form)
189+
# privatenames = (:cfg, )
190+
# if private
191+
# return (publicnames..., privatenames...)
192+
# else
193+
# return publicnames
194+
# end
195+
# end
182196

183197
function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, cfg::SHTnsCfg)
184198
summary(io, cfg); println(io)

0 commit comments

Comments
 (0)