-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function to print some dimensional parameters of a simulation
- Loading branch information
1 parent
fdac38e
commit df1bd5b
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
`utils` | ||
=============== | ||
|
||
```@autodocs | ||
Modules = [moment_kinetics.utils] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
""" | ||
Utility functions | ||
""" | ||
module utils | ||
|
||
export get_unnormalized_parameters, print_unnormalized_parameters | ||
|
||
using ..moment_kinetics_input: mk_input | ||
|
||
using OrderedCollections | ||
using TOML | ||
using Unitful | ||
|
||
Unitful.@unit eV "eV" "electron volt" 1.602176634e-19*Unitful.J true | ||
|
||
function __init__() | ||
Unitful.register(utils) | ||
end | ||
|
||
""" | ||
get_unnormalized_parameters(input::Dict) | ||
get_unnormalized_parameters(input_filename::String) | ||
Get many parameters for the simulation setup given by `input` or in the file | ||
`input_filename`, in SI units and eV, returned as an OrderedDict. | ||
""" | ||
function get_unnormalized_parameters end | ||
function get_unnormalized_parameters(input::Dict) | ||
io_input, evolve_moments, t_input, z, z_spectral, r, r_spectral, vpa, vpa_spectral, | ||
vperp, vperp_spectral, gyrophase, gyrophase_spectral, vz, vz_spectral, vr, | ||
vr_spectral, vzeta, vzeta_spectral, composition, species, collisions, geometry, | ||
drive_input, external_source_settings, num_diss_params, manufactured_solns_input, | ||
reference_parameters = mk_input(input) | ||
|
||
Nnorm = reference_parameters.Nref * Unitful.m^(-3) | ||
Tnorm = reference_parameters.Tref * eV | ||
Lnorm = reference_parameters.Lref * Unitful.m | ||
Bnorm = reference_parameters.Bref * Unitful.T | ||
cnorm = reference_parameters.cref * Unitful.m / Unitful.s | ||
timenorm = reference_parameters.timeref * Unitful.s | ||
|
||
# Assume single ion species so normalised ion mass is always 1 | ||
mi = reference_parameters.mnorm * Unitful.kg | ||
|
||
parameters = OrderedDict{String,Any}() | ||
parameters["run_name"] = run_name | ||
|
||
parameters["Nnorm"] = Nnorm | ||
parameters["Tnorm"] = Tnorm | ||
parameters["Lnorm"] = Lnorm | ||
|
||
parameters["Lz"] = Lnorm * z_input.L | ||
|
||
parameters["cs0"] = cnorm | ||
|
||
dt = t_input.dt * timenorm | ||
parameters["dt"] = dt | ||
parameters["output time step"] = dt * t_input.nwrite | ||
parameters["total simulated time"] = dt * t_input.nstep | ||
|
||
parameters["T_e"] = Tnorm * composition.T_e | ||
parameters["T_wall"] = Tnorm * composition.T_wall | ||
|
||
parameters["CX_rate_coefficient"] = collisions.charge_exchange / Nnorm / timenorm | ||
parameters["ionization_rate_coefficient"] = collisions.ionization / Nnorm / timenorm | ||
|
||
return parameters | ||
end | ||
function get_unnormalized_parameters(input_filename::String, args...; kwargs...) | ||
return get_unnormalized_parameters(TOML.parsefile(input_filename), args...; | ||
kwargs...) | ||
end | ||
|
||
""" | ||
print_unnormalized_parameters(input) | ||
Print many parameters for the simulation setup given by `input` (a Dict of parameters or | ||
a String giving a filename), in SI units and eV. | ||
""" | ||
function print_unnormalized_parameters(args...; kwargs...) | ||
|
||
parameters = get_unnormalized_parameters(args...; kwargs...) | ||
|
||
println("Dimensional parameters for '$(parameters["run_name"])'") | ||
|
||
for (k,v) ∈ parameters | ||
println("$k = $v") | ||
end | ||
|
||
return nothing | ||
end | ||
|
||
end #utils |