Skip to content

Commit

Permalink
Save and load evolve_density and evolve_upar
Browse files Browse the repository at this point in the history
These can be useful for post-processing.
  • Loading branch information
johnomotani committed Sep 13, 2022
1 parent d05c931 commit 88c4435
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
27 changes: 21 additions & 6 deletions src/file_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ end
open the necessary output files
"""
function setup_file_io(output_dir, run_name, vpa, z, r, composition,
collisions, evolve_ppar)
collisions, evolve_density, evolve_upar, evolve_ppar)
begin_serial_region()
@serial_region begin
# Only read/write from first process in each 'block'
Expand All @@ -69,7 +69,7 @@ function setup_file_io(output_dir, run_name, vpa, z, r, composition,
mom_io = open_output_file(out_prefix, "moments_vs_t")
fields_io = open_output_file(out_prefix, "fields_vs_t")
cdf = setup_netcdf_io(out_prefix, r, z, vpa, composition, collisions,
evolve_ppar)
evolve_density, evolve_upar, evolve_ppar)
#return ios(ff_io, mom_io, fields_io), cdf
return ios(mom_io, fields_io), cdf
end
Expand Down Expand Up @@ -110,11 +110,11 @@ function define_dimensions!(fid, nvpa, nz, nr, n_species, n_ion_species=nothing,
end

"""
define_static_variables!(vpa,vperp,z,r,composition,collisions,evolve_ppar)
define_static_variables!(vpa,vperp,z,r,composition,collisions,evolve_density,evolve_upar,evolve_ppar)
Define static (i.e. time-independent) variables for an output file.
"""
function define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_ppar)
function define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_density,evolve_upar,evolve_ppar)
# create and write the "r" variable to file
varname = "r"
attributes = Dict("description" => "radial coordinate")
Expand Down Expand Up @@ -168,6 +168,20 @@ function define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_ppar
vartype = mk_float
var = defVar(fid, varname, vartype, dims, attrib=attributes)
var[:] = collisions.charge_exchange
# create and write the "evolve_density" variable to file
varname = "evolve_density"
attributes = Dict("description" => "flag indicating if the density is separately evolved")
vartype = mk_int
dims = ("n_species",)
var = defVar(fid, varname, vartype, dims, attrib=attributes)
var[:] = evolve_density
# create and write the "evolve_upar" variable to file
varname = "evolve_upar"
attributes = Dict("description" => "flag indicating if the parallel flow is separately evolved")
vartype = mk_int
dims = ("n_species",)
var = defVar(fid, varname, vartype, dims, attrib=attributes)
var[:] = evolve_upar
# create and write the "evolve_ppar" variable to file
varname = "evolve_ppar"
attributes = Dict("description" => "flag indicating if the parallel pressure is separately evolved")
Expand Down Expand Up @@ -240,7 +254,8 @@ end
"""
setup file i/o for netcdf
"""
function setup_netcdf_io(prefix, r, z, vpa, composition, collisions, evolve_ppar)
function setup_netcdf_io(prefix, r, z, vpa, composition, collisions, evolve_density,
evolve_upar, evolve_ppar)
# the netcdf file will be given by output_dir/run_name with .cdf appended
filename = string(prefix,".cdf")
# if a netcdf file with the requested name already exists, remove it
Expand All @@ -253,7 +268,7 @@ function setup_netcdf_io(prefix, r, z, vpa, composition, collisions, evolve_ppar
define_dimensions!(fid, vpa.n, z.n, r.n, composition.n_species,
composition.n_ion_species, composition.n_neutral_species)
### create and write static variables to file ###
define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_ppar)
define_static_variables!(fid,vpa,z,r,composition,collisions,evolve_density,evolve_upar,evolve_ppar)
### create variables for time-dependent quantities and store them ###
### in a struct for later access ###
cdf_time, cdf_f, cdf_phi, cdf_density, cdf_upar, cdf_ppar, cdf_qpar, cdf_vth =
Expand Down
21 changes: 20 additions & 1 deletion src/load_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ function load_moments_data(fid)
thermal_speed = cdfvar.var[:,:,:,:]
# define the number of species
n_species = size(cdfvar,3)
# define a handle for the flag indicating if the density should be separately advanced
cdfvar = fid["evolve_density"]
# load the parallel pressure evolution flag
evolve_density_int = cdfvar.var[:]
if evolve_density_int[1] == 1
evolve_density = true
else
evolve_density = false
end
# define a handle for the flag indicating if the parallel pressure should be separately advanced
cdfvar = fid["evolve_upar"]
# load the parallel pressure evolution flag
evolve_upar_int = cdfvar.var[:]
if evolve_upar_int[1] == 1
evolve_upar = true
else
evolve_upar = false
end
# define a handle for the flag indicating if the parallel pressure should be separately advanced
cdfvar = fid["evolve_ppar"]
# load the parallel pressure evolution flag
Expand All @@ -122,7 +140,8 @@ function load_moments_data(fid)
evolve_ppar = false
end
println("done.")
return density, parallel_flow, parallel_pressure, parallel_heat_flux, thermal_speed, n_species, evolve_ppar
return density, parallel_flow, parallel_pressure, parallel_heat_flux, thermal_speed,
n_species, evolve_density, evolve_upar, evolve_ppar
end

"""
Expand Down
1 change: 1 addition & 0 deletions src/moment_kinetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ function setup_moment_kinetics(input_dict::Dict; backup_filename=nothing,

# setup i/o
io, cdf = setup_file_io(output_dir, run_name, vpa, z, r, composition, collisions,
moments.evolve_density, moments.evolve_upar,
moments.evolve_ppar)
# write initial data to ascii files
write_data_to_ascii(pdf.norm, moments, fields, vpa, z, r, code_time, composition.n_species, io)
Expand Down
3 changes: 2 additions & 1 deletion src/post_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function analyze_and_plot_data(path)
phi = load_fields_data(fid)
# load full (z,r,species,t) velocity moments data
density, parallel_flow, parallel_pressure, parallel_heat_flux,
thermal_speed, n_species, evolve_ppar = load_moments_data(fid)
thermal_speed, n_species, evolve_density, evolve_upar, evolve_ppar =
load_moments_data(fid)
# load full (vpa,z,r,species,t) particle distribution function (pdf) data
ff = load_pdf_data(fid)

Expand Down

0 comments on commit 88c4435

Please sign in to comment.