From 499b2237f908f32883e1603a4535c33e1bc5d45e Mon Sep 17 00:00:00 2001 From: Orso Meneghini Date: Fri, 26 Jul 2024 11:23:37 -0700 Subject: [PATCH 1/3] add ion_particle_flux and refactor NEO parsing --- src/NEO.jl | 55 +++++++++++++++++------------------------- src/chang_hinton.jl | 4 ++- src/hirshman_sigmar.jl | 11 +++++---- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/NEO.jl b/src/NEO.jl index e51c879..d7164a8 100644 --- a/src/NEO.jl +++ b/src/NEO.jl @@ -83,50 +83,39 @@ function run_neo(input_neo::InputNEO) run(Cmd(`bash command.sh`; dir=folder)) ### parse outputs ### - fluxes = Float64[] - - tmp = open(joinpath(folder, "out.neo.transport_flux"), "r") do io + tmp_fluxes = Float64[] + open(joinpath(folder, "out.neo.transport_flux"), "r") do io for line in eachline(io) if !startswith(line, "#") for word in split(line) val = tryparse(Float64, word) if val !== nothing - push!(fluxes, val) + push!(tmp_fluxes, val) end end end end end - loc_first_tgyro = (4 * input_neo.N_SPECIES * 2) + 1 - tgyro_fluxes = fluxes[loc_first_tgyro:end] - - flux_solution = NEO.flux_solution() - - for i in range(0, input_neo.N_SPECIES - 1) - species = i + 1 - setfield!(flux_solution, Symbol("PARTICLE_FLUX_$species"), tgyro_fluxes[2+(i*4)]) - setfield!(flux_solution, Symbol("ENERGY_FLUX_$species"), tgyro_fluxes[3+(i*4)]) - setfield!(flux_solution, Symbol("MOMENTUM_FLUX_$species"), tgyro_fluxes[4+(i*4)]) - end - - energy_flux_electrons = getfield(flux_solution, Symbol("ENERGY_FLUX_$(input_neo.N_SPECIES)")) # electrons are always the last species in the list - total_ion_energy_flux = -energy_flux_electrons # exclude electron energy flux from total ion energy flux - particle_flux_electrons = getfield(flux_solution, Symbol("PARTICLE_FLUX_$(input_neo.N_SPECIES)")) - - for field in fieldnames(NEO.flux_solution) - if ismissing(getfield(flux_solution, field)) - setfield!(flux_solution, field, 0.0) - end - - if occursin("ENERGY", string(field)) - total_ion_energy_flux += getfield(flux_solution, field) - end - end - - total_fluxes = IMAS.flux_solution(particle_flux_electrons, 0.0, energy_flux_electrons, total_ion_energy_flux) - - return total_fluxes + tgyro_fluxes = tmp_fluxes[loc_first_tgyro:end] + + # figure out indexes + e_index = [input_neo.N_SPECIES] + i_index = collect(1:input_neo.N_SPECIES-1) + particle_index(index) = 2 .+ ((index .- 1) .* 4) + energy_index(index) = 3 .+ ((index .- 1) .* 4) + momentum_index(index) = 4 .+ ((index .- 1) .* 4) + + # sort fluxes + electrons_energy_flux = tgyro_fluxes[energy_index(e_index)] + electrons_particle_flux = tgyro_fluxes[particle_index(e_index)] + ion_particle_flux = tgyro_fluxes[particle_index(i_index)] + ion_total_energy_flux = sum(tgyro_fluxes[energy_index(i_index)]) + ion_total_momentum_flux = sum(tgyro_fluxes[momentum_index(i_index)]) + + # assign fluxes to flux_solution structure + sol = IMAS.flux_solution(electrons_energy_flux, ion_total_energy_flux, electrons_particle_flux, ion_particle_flux, ion_total_momentum_flux) + return sol end const document = Dict() diff --git a/src/chang_hinton.jl b/src/chang_hinton.jl index 0e2b74c..1725550 100644 --- a/src/chang_hinton.jl +++ b/src/chang_hinton.jl @@ -6,6 +6,7 @@ iion::Integer) Calculates the neoclassical flux using Chang-Hinton model which has been modified assuming Zi = 1, and ni=ne + Ref: C.S. Chang, F.L. Hinton, Phys. Fluids 25, 1493–1494 (1982), https://doi.org/10.1063/1.863934 """ function changhinton( @@ -103,6 +104,7 @@ function changhinton( qneo_gb = neo_rho_star_in^2 - sol = IMAS.flux_solution(0.0, 0.0, 0.0, efluxi / qneo_gb) + # assign fluxes to flux_solution structure + sol = IMAS.flux_solution(0.0, efluxi / qneo_gb, 0.0, Float64[], 0.0) return sol end \ No newline at end of file diff --git a/src/hirshman_sigmar.jl b/src/hirshman_sigmar.jl index abbd112..e184c04 100644 --- a/src/hirshman_sigmar.jl +++ b/src/hirshman_sigmar.jl @@ -411,13 +411,14 @@ function HS_to_GB(HS_solution::Tuple{Vector{Float64},Vector{Float64}}, dd::IMAS. pflux_norm = pflux_multi ./ Gamma_neo_GB eflux_norm = eflux_multi ./ Q_neo_GB - particle_flux_e = pflux_norm[end] energy_flux_e = eflux_norm[end] + energy_flux_i = sum(eflux_norm[1:end-1]) + particle_flux_e = pflux_norm[end] + particle_flux_i = pflux_norm[1:end-1] - energy_flux_i = sum(eflux_norm) - energy_flux_e - - HS_fluxes = IMAS.flux_solution(particle_flux_e, 0.0, energy_flux_e, energy_flux_i) - return HS_fluxes + # assign fluxes to flux_solution structure + sol = IMAS.flux_solution(energy_flux_e, energy_flux_i, particle_flux_e, particle_flux_i, 0.0) + return sol end """ From 45ed6885faf40b0121a463395266502aab81187e Mon Sep 17 00:00:00 2001 From: Orso Meneghini Date: Fri, 26 Jul 2024 16:01:53 -0700 Subject: [PATCH 2/3] Update src/NEO.jl Co-authored-by: adrianaghiozzi <67669644+adrianaghiozzi@users.noreply.github.com> --- src/NEO.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NEO.jl b/src/NEO.jl index d7164a8..b13649b 100644 --- a/src/NEO.jl +++ b/src/NEO.jl @@ -114,7 +114,7 @@ function run_neo(input_neo::InputNEO) ion_total_momentum_flux = sum(tgyro_fluxes[momentum_index(i_index)]) # assign fluxes to flux_solution structure - sol = IMAS.flux_solution(electrons_energy_flux, ion_total_energy_flux, electrons_particle_flux, ion_particle_flux, ion_total_momentum_flux) + sol = IMAS.flux_solution(only(electrons_energy_flux), ion_total_energy_flux, only(electrons_particle_flux), ion_particle_flux, ion_total_momentum_flux) return sol end From 1580fb36af481e0655f6cf3672c7666335a62620 Mon Sep 17 00:00:00 2001 From: Orso Meneghini Date: Fri, 26 Jul 2024 16:03:14 -0700 Subject: [PATCH 3/3] minor --- src/NEO.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NEO.jl b/src/NEO.jl index b13649b..ef72578 100644 --- a/src/NEO.jl +++ b/src/NEO.jl @@ -107,14 +107,14 @@ function run_neo(input_neo::InputNEO) momentum_index(index) = 4 .+ ((index .- 1) .* 4) # sort fluxes - electrons_energy_flux = tgyro_fluxes[energy_index(e_index)] - electrons_particle_flux = tgyro_fluxes[particle_index(e_index)] + electrons_energy_flux = only(tgyro_fluxes[energy_index(e_index)]) + electrons_particle_flux = only(tgyro_fluxes[particle_index(e_index)]) ion_particle_flux = tgyro_fluxes[particle_index(i_index)] ion_total_energy_flux = sum(tgyro_fluxes[energy_index(i_index)]) ion_total_momentum_flux = sum(tgyro_fluxes[momentum_index(i_index)]) # assign fluxes to flux_solution structure - sol = IMAS.flux_solution(only(electrons_energy_flux), ion_total_energy_flux, only(electrons_particle_flux), ion_particle_flux, ion_total_momentum_flux) + sol = IMAS.flux_solution(electrons_energy_flux, ion_total_energy_flux, electrons_particle_flux, ion_particle_flux, ion_total_momentum_flux) return sol end