Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing transport equilibrium workflow #47

Merged
merged 27 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9a8a1d5
add IMASDD to install and update
TimSlendebroek Mar 9, 2022
0598bea
conflict
TimSlendebroek Mar 10, 2022
d10ebe9
conflict
TimSlendebroek Mar 23, 2022
8d844e4
Merge branch 'master' of github.com:ProjectTorreyPines/FUSE.jl
TimSlendebroek Mar 24, 2022
8234fc5
Merge branch 'master' of github.com:ProjectTorreyPines/FUSE.jl
TimSlendebroek Mar 24, 2022
95a7daf
Merge branch 'master' of github.com:ProjectTorreyPines/FUSE.jl
TimSlendebroek Mar 25, 2022
064b29b
Merge branch 'master' of github.com:ProjectTorreyPines/FUSE.jl
TimSlendebroek Mar 25, 2022
c9cdfc8
bug fix ohmic power for validation database
TimSlendebroek Mar 31, 2022
4948caa
merge conflict and save failed database
TimSlendebroek Mar 31, 2022
0d0857f
take out janky ohmic power
TimSlendebroek Apr 4, 2022
a6401ab
Merge branch 'master' of github.com:ProjectTorreyPines/FUSE.jl into f…
TimSlendebroek Apr 5, 2022
6d2fe18
check if dd.X in the ods that you are loading
TimSlendebroek Apr 5, 2022
fa60420
equilibrium init fix , ohmic_power fix
TimSlendebroek Apr 5, 2022
d3e8c3b
xpoint and symmetric added to validation cases
TimSlendebroek Apr 6, 2022
81b604c
allow passing of xpoint to SolovevEquilibriumActor
TimSlendebroek Apr 6, 2022
4735137
conflict merge
TimSlendebroek Apr 7, 2022
b2d83b3
merge conflict
TimSlendebroek Apr 7, 2022
e802f46
Symmetric and x_point resolution
TimSlendebroek Apr 7, 2022
261aa37
merge conflict bugs....
TimSlendebroek Apr 7, 2022
30fe577
Merge branch 'master' of github.com:ProjectTorreyPines/FUSE.jl into f…
TimSlendebroek Apr 7, 2022
206d799
j_ohmic_steady_state! function changed
TimSlendebroek Apr 7, 2022
c4abab5
Merge branch 'master' of github.com:ProjectTorreyPines/FUSE.jl into f…
TimSlendebroek Apr 7, 2022
f0cd286
!ismissing mistake fixed
TimSlendebroek Apr 7, 2022
6e1536b
better finding of x-points
orso82 Apr 8, 2022
0106b30
init_workflow --> init
orso82 Apr 8, 2022
843b716
recalculate flux_surfaces when loading from ODS
orso82 Apr 8, 2022
ad7f714
minor renaming of sources
orso82 Apr 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions cases/HDB5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function Parameters(data_row::DataFrames.DataFrameRow)
par.equilibrium.area = data_row[:AREA]
par.equilibrium.volume = data_row[:VOL]
par.equilibrium.ip = abs(data_row[:IP])
par.equilibrium.x_point = contains("SN", data_row[:CONFIG]) || contains("DN", data_row[:CONFIG])
par.equilibrium.symmetric = !par.equilibrium.x_point || !contains("SN", data_row[:CONFIG])
par.equilibrium.x_point = false
par.equilibrium.symmetric = true
TimSlendebroek marked this conversation as resolved.
Show resolved Hide resolved

# Core_profiles parameters
par.core_profiles.ne_ped = data_row[:NEL] / 1.3
Expand All @@ -38,17 +38,23 @@ function Parameters(data_row::DataFrames.DataFrameRow)
par.core_profiles.impurity = :C

# nbi
if data_row[:PNBI] + data_row[:POHM] > 0.0
par.nbi.power_launched = data_row[:PNBI] + data_row[:POHM]
if data_row[:PNBI] == 0.0
par.nbi.beam_energy = 1e9
else
if data_row[:PNBI] > 0
par.nbi.power_launched = data_row[:PNBI]
if data_row[:ENBI] > 0
par.nbi.beam_energy = data_row[:ENBI]
else
par.nbi.beam_energy = 100e3
end
par.nbi.beam_mass = 2
par.nbi.toroidal_angle = 0.0
end

# ohmic

if data_row[:POHM] > 0
par.oh.ohmic_heating = data_row[:POHM]
end

if data_row[:PECRH] > 0
par.ec.power_launched = data_row[:PECRH]
end
Expand Down Expand Up @@ -76,4 +82,4 @@ function load_hdb5(tokamak::T=:all, extra_signal_names=T[]) where {T<:Union{Stri
run_df = run_df[run_df.TOK.==String(tokamak), :]
end
return run_df
end
end
3 changes: 3 additions & 0 deletions src/actors/transport_actor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function TauennActor(dd::IMAS.dd, par::Parameters; do_plot = false, verbose = fa
if do_plot
display(plot!(dd.core_profiles))
end
if verbose
display(actor.tauenn_parameters)
end
return dd
end

Expand Down
20 changes: 14 additions & 6 deletions src/ddinit/init.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
"""
init(dd::IMAS.dd, par::Parameters; do_plot = false)

Initialize all IDSs
Initialize all IDSs if there are parameters for it or is initialized from ods
"""
function init(dd::IMAS.dd, par::Parameters; do_plot=false)
ods_items = []
# Check what is in the ods to load
if par.general.init_from == :ods
ods_items = keys(IMAS.json2imas(par.ods.filename))
end

# initialize equilibrium
init_equilibrium(dd, par)
if !ismissing(par.equilibrium.B0) || :equilibrium ∈ ods_items
init_equilibrium(dd, par)
end
if do_plot
plot(dd.equilibrium.time_slice[end])
display(plot!(dd.equilibrium.time_slice[1].boundary.outline.r, dd.equilibrium.time_slice[1].boundary.outline.z))
end

# initialize build
if !ismissing(par.build, :vessel) || !ismissing(par.build, :layers)
if !ismissing(par.build, :vessel) || !ismissing(par.build, :layers) || :build ∈ ods_items
init_build(dd, par)
if do_plot
plot(dd.equilibrium, color=:gray)
Expand All @@ -22,7 +30,7 @@ function init(dd::IMAS.dd, par::Parameters; do_plot=false)
end

# initialize oh and pf coils
if !ismissing(par.pf_active, :n_oh_coils)
if !ismissing(par.pf_active, :n_oh_coils) || :pf_active ∈ ods_items
init_pf_active(dd, par)
if do_plot
plot(dd.equilibrium, color=:gray)
Expand All @@ -33,15 +41,15 @@ function init(dd::IMAS.dd, par::Parameters; do_plot=false)
end

# initialize core profiles
if !ismissing(par.core_profiles, :bulk)
if !ismissing(par.core_profiles, :bulk) || :core_profiles ∈ ods_items
init_core_profiles(dd, par)
if do_plot
display(plot(dd.core_profiles))
end
end

# initialize core sources
if !ismissing(par.ec, :power_launched) || !ismissing(par.ic, :power_launched) || !ismissing(par.lh, :power_launched) || !ismissing(par.nbi, :power_launched)
if !ismissing(par.ec, :power_launched) || !ismissing(par.ic, :power_launched) || !ismissing(par.lh, :power_launched) || !ismissing(par.nbi, :power_launched) || :core_sources ∈ ods_items
init_core_sources(dd, par)
if do_plot
display(plot(dd.core_sources))
Expand Down
2 changes: 1 addition & 1 deletion src/parameters_list.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ function Parameters(::Type{Val{:coil_technology}})
coil_tech.fraction_void = Entry(Real, "", "Fraction of `void` in the coil cross-sectional area. Void is everything (like coolant) that is not structural nor conductor.")
coil_tech.ratio_SC_to_copper = Entry(Real, "", "Fraction of superconductor to copper cross-sectional areas")
return coil_tech
end
end
27 changes: 19 additions & 8 deletions src/workflows/DB5_validation_workflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import ProgressMeter

Initializes and runs simple equilibrium, core_sources and transport actors and stores the resulting dd in <save_directory>
"""
function simple_equilibrium_transport_workflow(dd::IMAS.dd, par::Parameters; save_directory::String="", do_plot::Bool=false, warn_nn_train_bounds=true)
function simple_equilibrium_transport_workflow(dd::IMAS.dd, par::Parameters; save_directory::String="", do_plot::Bool=false, warn_nn_train_bounds=true, transport_model=:tglfnn)
FUSE.init_equilibrium(dd, par) # already solves the equilibrium once
FUSE.init_core_profiles(dd, par)
FUSE.init_core_sources(dd, par)

# Add ohmic power to core_sources
IMAS.ohmic_power_steady_state!(dd)

# run transport actor
FUSE.TauennActor(dd, par; transport_model=:tglfnn, warn_nn_train_bounds, verbose=false)
FUSE.TauennActor(dd, par; transport_model=transport_model, warn_nn_train_bounds, verbose=false)

# Set beta_normal from equilbrium to the kinetic beta_n
if !isempty(dd.core_profiles.profiles_1d)
Expand Down Expand Up @@ -61,21 +64,23 @@ function transport_validation_workflow(;
n_samples_per_tokamak::Union{Integer,Symbol}=10,
save_directory::String="",
show_dd_plots=false,
plot_database=true)
plot_database=true,
verbose=false)

# load HDB5 database
run_df = load_hdb5(tokamak)

# pick cases at random
if n_samples_per_tokamak !== :all
tok_list = unique(run_df[:, "TOK"])
display(@show tok_list)
TimSlendebroek marked this conversation as resolved.
Show resolved Hide resolved
run_df = DataFrames.reduce(
vcat, [run_df[run_df.TOK.==tok, :][Random.shuffle(1:DataFrames.nrow(run_df[run_df.TOK.==tok, :]))[1:minimum([n_samples_per_tokamak, length(run_df[run_df.TOK.==tok, :][:, "TOK"])])], :] for tok in tok_list]
)
end

# Run simple_equilibrium_transport_workflow on each of the selected cases
run_df[!, "TAUTH_fuse"] = tau_FUSE = Float64[NaN for k in 1:length(run_df[:, "TOK"])]
tau_FUSE = zeros(length(run_df[:,"TOK"]))
tbl = DataFrames.Tables.rowtable(run_df)
failed_runs_ids = Int[]
p = ProgressMeter.Progress(length(DataFrames.Tables.rows(tbl)); showspeed=true)
Expand All @@ -85,21 +90,27 @@ function transport_validation_workflow(;
par = Parameters(run_df[idx, :])
simple_equilibrium_transport_workflow(dd, par; save_directory, do_plot=show_dd_plots, warn_nn_train_bounds=false)
tau_FUSE[idx] = @ddtime(dd.summary.global_quantities.tau_energy.value)
catch
if verbose
display(println("τ_fuse = $(@ddtime(dd.summary.global_quantities.tau_energy.value)) τ_hdb5 = $(run_df[idx, :TAUTH])"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
display(println("τ_fuse = $(@ddtime(dd.summary.global_quantities.tau_energy.value)) τ_hdb5 = $(run_df[idx, :TAUTH])"))
display(println("τ_fuse = $(tau_FUSE[idx]) τ_hdb5 = $(run_df[idx, :TAUTH])"))

end
catch e
push!(failed_runs_ids, idx)
display(@show e)
TimSlendebroek marked this conversation as resolved.
Show resolved Hide resolved
end
ProgressMeter.next!(p)
end
println("Failed runs: $(length(failed_runs_ids)) out of $(length(run_df[:,"TOK"]))")
run_df[:,"TAUTH_fuse"] = tau_FUSE

failed_df = run_df[failed_runs_ids, :]

# save all input data as well as predicted tau to CSV file
if !isempty(save_directory)
CSV.write(joinpath(save_directory, "dataframe.csv"), run_df)
CSV.write(joinpath(save_directory, "failed_runs_dataframe.csv"), failed_df)
end

failed_df = run_df[failed_runs_ids, :]
goof_runs_ids = [k for (k,v) in enumerate(tau_FUSE) if !isnan(v)]
run_df = run_df[goof_runs_ids, :]


if plot_database
plot_x_y_regression(run_df, "TAUTH")
Expand Down