From 88c443580cd7258bdba0a769fe7f56bb6f96a4ac Mon Sep 17 00:00:00 2001 From: John Omotani Date: Fri, 5 Aug 2022 14:53:49 +0100 Subject: [PATCH] Save and load evolve_density and evolve_upar These can be useful for post-processing. --- src/file_io.jl | 27 +++++++++++++++++++++------ src/load_data.jl | 21 ++++++++++++++++++++- src/moment_kinetics.jl | 1 + src/post_processing.jl | 3 ++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/file_io.jl b/src/file_io.jl index 1c78cf7fe7..90ed8154cc 100644 --- a/src/file_io.jl +++ b/src/file_io.jl @@ -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' @@ -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 @@ -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") @@ -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") @@ -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 @@ -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 = diff --git a/src/load_data.jl b/src/load_data.jl index 8587e15af9..f70a100e9b 100644 --- a/src/load_data.jl +++ b/src/load_data.jl @@ -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 @@ -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 """ diff --git a/src/moment_kinetics.jl b/src/moment_kinetics.jl index c9b5a977ae..5fc8969800 100644 --- a/src/moment_kinetics.jl +++ b/src/moment_kinetics.jl @@ -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) diff --git a/src/post_processing.jl b/src/post_processing.jl index 5a8ad89c9e..456c808523 100644 --- a/src/post_processing.jl +++ b/src/post_processing.jl @@ -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)