Skip to content

Commit

Permalink
Add command-line argument changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailmints committed Jul 2, 2023
1 parent 4e5e146 commit 8b0c706
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ steps:
command: "julia --color=yes --project=test test/experiments/KiD_driver/KiD_driver.jl --moisture_choice=NonEquilibriumMoisture --prognostic_vars=RhodTQ --precipitation_choice=Precipitation1M"
artifact_paths: "test/experiments/KiD_driver/Output_NonEquilibriumMoisture_RhodTQ_Precipitation1M_CliMA_1M/figures/*"

- label: ":crystal_ball: Experiments: equil (fixed rhod and T) + KK2000 "
command: "julia --color=yes --project=test test/experiments/KiD_driver/KiD_driver.jl --moisture_choice=EquilibriumMoisture --prognostic_vars=RhodTQ --precipitation_choice=Precipitation1M --rain_formation_scheme_choice KK2000 --prescribed_Nd 1e8"
- label: ":crystal_ball: Experiments: equil (fixed rhod and T) + KK2000 + Float32 "
command: "julia --color=yes --project=test test/experiments/KiD_driver/KiD_driver.jl --FLOAT_TYPE=Float32 --moisture_choice=EquilibriumMoisture --prognostic_vars=RhodTQ --precipitation_choice=Precipitation1M --rain_formation_scheme_choice KK2000 --prescribed_Nd 1e8"
artifact_paths: "test/experiments/KiD_driver/Output_EquilibriumMoisture_RhodTQ_Precipitation1M_KK2000/figures/*"

- label: ":crystal_ball: Experiments: equil (fixed rhod and T) + B1994 "
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.8.1'
- '1.8.5'
os:
- ubuntu-latest
- macOS-latest
Expand Down
12 changes: 11 additions & 1 deletion test/experiments/KiD_driver/KiD_driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
include("parse_commandline.jl")
opts = parse_commandline()

ft_choice = opts["FLOAT_TYPE"]

if ft_choice == "Float64"
const FT = Float64
elseif ft_choice == "Float32"
const FT = Float32
else
error("Invalid float type: $ft_choice")
end

include("run_KiD_simulation.jl")

run_KiD_simulation(opts)
run_KiD_simulation(FT, opts)
52 changes: 28 additions & 24 deletions test/experiments/KiD_driver/parse_commandline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ function parse_commandline()
s = AP.ArgParseSettings()

AP.@add_arg_table! s begin
"--FLOAT_TYPE"
help = "Float type. Can be set to Float64 or Float32"
arg_type = String
default = "Float64"
"--moisture_choice"
help = "Mositure model choice: EquilibriumMoisture, NonEquilibriumMoisture"
arg_type = String
Expand Down Expand Up @@ -47,56 +51,56 @@ function parse_commandline()
default = false
"--z_min"
help = "Bottom of the computational domain [m]"
arg_type = Real
default = 0.0
arg_type = Float64
default = Float64(0.0)
"--z_max"
help = "Top of the computational domain [m]"
arg_type = Real
default = 2000.0
arg_type = Float64
default = Float64(2000)
"--n_elem"
help = "Number of computational elements"
arg_type = Int
default = 256
"--dt"
help = "Simulation time step [s]"
arg_type = Real
default = 1.0
arg_type = Float64
default = Float64(1)
"--dt_output"
help = "Output time step [s]"
arg_type = Real
default = 30.0
arg_type = Float64
default = Float64(30)
"--t_ini"
help = "Time at the beginning of the simulation [s]"
arg_type = Real
default = 0.0
arg_type = Float64
default = Float64(0)
"--t_end"
help = "Time at the end of the simulation [s]"
arg_type = Real
default = 3600.0
arg_type = Float64
default = Float64(3600)
"--w1"
help = "Maximum prescribed updraft momentum flux [m/s * kg/m3]"
arg_type = Real
default = 2.0
arg_type = Float64
default = Float64(2)
"--t1"
help = "Oscillation time of the prescribed momentum flux [s]"
arg_type = Real
default = 600.0
arg_type = Float64
default = Float64(600)
"--p0"
help = "Pressure at the surface [pa]"
arg_type = Real
default = 100000.0
arg_type = Float64
default = Float64(100000)
"--r_dry"
help = "aerosol distribution mean radius for aerosol activation calculations in 2M schemes [m]"
arg_type = Real
default = 0.04 * 1e-6
arg_type = Float64
default = Float64(0.04 * 1e-6)
"--std_dry"
help = "aerosol distribution standard deviation for aerosol activation calucaulations in 2M schemes"
arg_type = Real
default = 1.4
arg_type = Float64
default = Float64(1.4)
"--kappa"
help = "hygroscopicity of aerosols for aerosol activation calucaulations in 2M schemes"
arg_type = Real
default = 0.9
arg_type = Float64
default = Float64(0.9)
end

return AP.parse_args(s)
Expand Down
16 changes: 7 additions & 9 deletions test/experiments/KiD_driver/run_KiD_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import Kinematic1D as KID
const kid_dir = pkgdir(KID)
include(joinpath(kid_dir, "test", "create_parameters.jl"))


const FT = Float64

include("../../plotting_utils.jl")

function run_KiD_simulation(opts)

function run_KiD_simulation(::Type{FT}, opts) where {FT}

# Equations to solve for mositure and precipitation variables
moisture_choice = opts["moisture_choice"]
Expand Down Expand Up @@ -68,7 +66,7 @@ function run_KiD_simulation(opts)
TS = KID.TimeStepping(FT(opts["dt"]), FT(opts["dt_output"]), FT(opts["t_end"]))

# Create the coordinates
space, face_space = KID.make_function_space(FT, opts["z_min"], opts["z_max"], opts["n_elem"])
space, face_space = KID.make_function_space(FT, FT(opts["z_min"]), FT(opts["z_max"]), opts["n_elem"])
coord = CC.Fields.coordinate_field(space)
face_coord = CC.Fields.coordinate_field(face_space)

Expand All @@ -91,9 +89,9 @@ function run_KiD_simulation(opts)
path,
toml_dict,
FT,
opts["w1"],
opts["t1"],
opts["p0"],
FT(opts["w1"]),
FT(opts["t1"]),
FT(opts["p0"]),
Int(opts["precip_sources"]),
Int(opts["precip_sinks"]),
Int(opts["qtot_flux_correction"]),
Expand Down Expand Up @@ -126,7 +124,7 @@ function run_KiD_simulation(opts)
ode_rhs! = KID.make_rhs_function(moisture, precip)

# Solve the ODE operator
problem = ODE.ODEProblem(ode_rhs!, Y, (opts["t_ini"], opts["t_end"]), aux)
problem = ODE.ODEProblem(ode_rhs!, Y, (FT(opts["t_ini"]), FT(opts["t_end"])), aux)
solver = ODE.solve(
problem,
ODE.SSPRK33(),
Expand Down
6 changes: 4 additions & 2 deletions test/precip_production_tests/test_precip_production.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ include("../experiments/KiD_driver/run_KiD_simulation.jl")
path = joinpath(@__DIR__, "Output_test_precip_production")
mkpath(path)

const FT = Float64

"""
This is a very simple metric of precipitation production that is calculated
by summing the ρq_rai at a height corresponding to the cloud base over time.
Expand All @@ -31,7 +33,7 @@ function total_precipitation_production(Nd)

println(opts["prescribed_Nd"])

solver = run_KiD_simulation(opts)
solver = run_KiD_simulation(FT, opts)

precip = sum([parent(u.ρq_rai)[cloud_base] for u in solver.u])

Expand All @@ -40,7 +42,7 @@ function total_precipitation_production(Nd)
return precip
end

Nd_range = FT.(range(1e5, 1e8, 50))
Nd_range = FT.(range(1e5, 1e8, 10))

# p = Plots.plot(Nd_range, total_precipitation_production.(Nd_range), yscale = :log10,
# xlabel = "Prescribed Nd", ylabel = "Precipitation Production Metric")
Expand Down

0 comments on commit 8b0c706

Please sign in to comment.