Skip to content

Commit

Permalink
Using readg() with set_time & conformed to IMASDD
Browse files Browse the repository at this point in the history
Using set_time for sample files where description is not in the
standard format.

Changes were made in the code to use ismissing in places to conform to
requirements of IMASDD.

In record_regular_mesh!(), the deepcopy of each element was replaced
with deepcopy of the entire grid subset to improve speed.

The test runtests.jl was updated to reflect the changes.

All tests pass now with following versions:

JuliaFusion/EFIT.jl@8580ca8
ProjectTorreyPines/IMASdd.jl@6a6968a
ProjectTorreyPines/IMASggd.jl@b11ad15
ProjectTorreyPines/SOLPS2imas.jl@f843e6a

Note that EFIT version that was used has not been merged with its
master branch yet at the time of this test.

In conclusion, in future, OMAS can be removed now.
  • Loading branch information
anchal-physics committed Mar 23, 2024
1 parent 3597a61 commit 864319e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion sample/geqdsk_iter_small_sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EFITD 00/00/2008 #002296 0200ms Convert 0 65 65
EFITD 00/00/2008 #002296 0200 0 65 65
0.624390220E+01 0.124878049E+02 0.619999981E+01 0.307804870E+01 0.200000050E+00
0.635000000E+01 0.580000000E+00 0.118000000E+02 0.000000000E+00 0.530000019E+01
0.150229038E+08 0.118000000E+02 0.000000000E+00 0.635000000E+01 0.000000000E+00
Expand Down
13 changes: 10 additions & 3 deletions src/SD4SOLPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,20 @@ end
Transfers the equilibrium reconstruction in an EFIT-style gEQDSK file into
the IMAS DD structure.
"""
function geqdsk_to_imas!(eqdsk_file, dd; time_index=1)
function geqdsk_to_imas!(eqdsk_file, dd; set_time=nothing, time_index=1)
# https://github.com/JuliaFusion/EFIT.jl/blob/master/src/io.jl
g = EFIT.readg(eqdsk_file)
g = EFIT.readg(eqdsk_file; set_time=set_time)
# Copying ideas from OMFIT: omfit/omfit_classes/omfit_eqdsk.py / to_omas()
eq = dd.equilibrium
resize!(eq.time_slice, 1)
if IMASDD.ismissing(eq, :time)
eq.time = Array{Float64}(undef, time_index)
end
eq.time[time_index] = g.time
if length(eq.time_slice) < time_index
resize!(eq.time_slice, time_index)
end
eqt = eq.time_slice[time_index]
eqt.time = g.time

# 0D
gq = eqt.global_quantities
Expand Down
10 changes: 8 additions & 2 deletions src/repair_eq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ function add_rho_to_equilibrium!(dd::IMASDD.dd)
continue
end
end
if length(eqt.profiles_1d.phi) == 0
resize!(eqt.profiles_1d.phi, n)
if (
if IMASDD.ismissing(eqt.profiles_1d, :phi)
true
else
IMASDD.isempty(eqt.profiles_1d.phi)
end
)
eqt.profiles_1d.phi = Array{Float64}(undef, n)
psi2 = eqt.profiles_2d[1].psi
req = collect(eqt.profiles_2d[1].grid.dim1)
zeq = collect(eqt.profiles_2d[1].grid.dim2)
Expand Down
17 changes: 5 additions & 12 deletions src/supersize_profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,9 @@ function fill_in_extrapolated_core_profile!(
).(psi_for_quantity[in_bounds])

# Make sure the output 1D rho grid exists; create it if needed
if length(dd.core_profiles.profiles_1d[it].grid.rho_tor_norm) == 0
resize!(dd.core_profiles.profiles_1d[it].grid.rho_tor_norm, 201)
# If you don't like this default, then you should write grid.rho_tor_norm before
# calling this function.
if IMASDD.ismissing(dd.core_profiles.profiles_1d[it].grid, :rho_tor_norm)
# If you don't like this default, then you should write grid.rho_tor_norm
# before calling this function.
dd.core_profiles.profiles_1d[it].grid.rho_tor_norm =
collect(LinRange(0, 1, 201))
end
Expand Down Expand Up @@ -750,15 +749,9 @@ function record_regular_mesh!(

# Preserve record of standard (non extended) mesh
for i 1:5
std_sub = get_grid_subset(grid_ggd, -i)
orig_sub = get_grid_subset(grid_ggd, i)
resize!(std_sub.element, length(orig_sub.element))
for j 1:length(orig_sub.element)
std_sub.element[j] = deepcopy(orig_sub.element[j])
end
std_sub.identifier.index = -i
std_sub.dimension = deepcopy(orig_sub.dimension)
std_sub.metric = deepcopy(orig_sub.metric)
grid_ggd.grid_subset[n_existing_subsets+i] = deepcopy(orig_sub)
grid_ggd.grid_subset[n_existing_subsets+i].identifier.index = -i
end
all_nodes_sub = get_grid_subset(grid_ggd, 1)
all_edges_sub = get_grid_subset(grid_ggd, 2)
Expand Down
20 changes: 15 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ if args["core_profile_extension"]
@test isfile(b2time)
@test isfile(b2mn)
@test isfile(eqdsk)
eqdsk_time = parse(Float64, split(eqdsk, ".")[end]) / 1000.0
dd = SOLPS2IMAS.solps2imas(b2fgmtry, b2time; b2mn=b2mn)
SD4SOLPS.geqdsk_to_imas!(eqdsk, dd)
SD4SOLPS.geqdsk_to_imas!(eqdsk, dd; set_time=eqdsk_time)
rho = dd.equilibrium.time_slice[1].profiles_1d.rho_tor_norm

if !SD4SOLPS.check_rho_1d(dd; time_slice=1)
Expand Down Expand Up @@ -219,8 +220,9 @@ if args["edge_profile_extension"]
@testset "edge_profile_extension" begin
# Test for getting mesh spacing
b2fgmtry, b2time, b2mn, eqdsk = define_default_sample_set()
eqdsk_time = parse(Float64, split(eqdsk, ".")[end]) / 1000.0
dd = SOLPS2IMAS.solps2imas(b2fgmtry, b2time; b2mn=b2mn)
SD4SOLPS.geqdsk_to_imas!(eqdsk, dd)
SD4SOLPS.geqdsk_to_imas!(eqdsk, dd; set_time=eqdsk_time)
dpsin = SD4SOLPS.mesh_psi_spacing(dd)
@test dpsin > 0.0

Expand Down Expand Up @@ -298,8 +300,6 @@ if args["heavy_utilities"]
resize!(dd.core_profiles.profiles_1d, prof_time_idx)
n = 101
rho_n = Array(LinRange(0, 1.0, n))
resize!(dd.core_profiles.profiles_1d[prof_time_idx].grid.rho_tor_norm, n)
resize!(dd.core_profiles.profiles_1d[prof_time_idx].electrons.density, n)
dd.core_profiles.profiles_1d[prof_time_idx].grid.rho_tor_norm = rho_n
dd.core_profiles.profiles_1d[prof_time_idx].electrons.density =
make_test_profile(rho_n)
Expand Down Expand Up @@ -356,7 +356,17 @@ if args["geqdsk_to_imas"]
for sample_file sample_files
println(sample_file)
dd = IMASDD.dd()
SD4SOLPS.geqdsk_to_imas!(sample_file, dd; time_index=tslice)
if endswith(sample_file, "00")
eqdsk_time = parse(Float64, split(sample_file, ".")[end]) / 1000.0
else
eqdsk_time = nothing
end
SD4SOLPS.geqdsk_to_imas!(
sample_file,
dd;
set_time=eqdsk_time,
time_index=tslice,
)
eqt = dd.equilibrium.time_slice[tslice]

# global
Expand Down

0 comments on commit 864319e

Please sign in to comment.