diff --git a/sample/geqdsk_iter_small_sample b/sample/geqdsk_iter_small_sample index e51be73..a230a97 100644 --- a/sample/geqdsk_iter_small_sample +++ b/sample/geqdsk_iter_small_sample @@ -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 diff --git a/src/SD4SOLPS.jl b/src/SD4SOLPS.jl index 129ce90..8518739 100644 --- a/src/SD4SOLPS.jl +++ b/src/SD4SOLPS.jl @@ -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 diff --git a/src/repair_eq.jl b/src/repair_eq.jl index ead09f8..48e2100 100644 --- a/src/repair_eq.jl +++ b/src/repair_eq.jl @@ -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) diff --git a/src/supersize_profile.jl b/src/supersize_profile.jl index 689d9cb..5079098 100644 --- a/src/supersize_profile.jl +++ b/src/supersize_profile.jl @@ -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 @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index a894f11..3fcb573 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) @@ -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 @@ -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) @@ -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