Skip to content

Commit

Permalink
Addition of polynomial degrees CL option
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriabarra committed Dec 17, 2020
1 parent 19da615 commit 73e1d18
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 38 deletions.
23 changes: 15 additions & 8 deletions src/Driver/Driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ Base.@kwdef mutable struct ClimateMachine_Settings
array_type::Type = Array
sim_time::Float64 = NaN
fixed_number_of_steps::Int = -1
degree::NTuple{2, Int} = (-1, -1)
end

const Settings = ClimateMachine_Settings()


"""
ClimateMachine.array_type()
Expand All @@ -90,7 +90,6 @@ line, from an environment variable, or from experiment code) after
"""
array_type() = Settings.array_type


"""
get_setting(setting_name::Symbol, settings, defaults)
Expand All @@ -110,7 +109,13 @@ function get_setting(setting_name::Symbol, settings, defaults)
return convert(setting_type, settings[setting_name])
elseif haskey(ENV, setting_env)
env_val = ENV[setting_env]
v = setting_type == String ? env_val : tryparse(setting_type, env_val)
if setting_type == String
v = env_val
elseif setting_type == NTuple{2, Int}
v = ArgParse.parse_item(setting_type, env_val)
else
v = tryparse(setting_type, env_val)
end
if isnothing(v)
error("cannot parse ENV $setting_env value $env_val, to setting type $setting_type")
end
Expand All @@ -134,7 +139,6 @@ function get_gpu_setting(setting_name::Symbol, settings, defaults)
return get_setting(setting_name, settings, defaults)
end


"""
parse_commandline(
defaults::Dict{Symbol, Any},
Expand Down Expand Up @@ -290,6 +294,11 @@ function parse_commandline(
metavar = "<number>"
arg_type = Int
default = get_setting(:fixed_number_of_steps, defaults, global_defaults)
"--degree"
help = "tuple of horizontal and vertical polynomial degrees for spatial discretization order (no space before/after comma)"
metavar = "horizontal,vertical"
arg_type = NTuple{2, Int}
default = get_setting(:degree, defaults, global_defaults)
end
# add custom cli argparse settings if provided
if !isnothing(custom_clargs)
Expand All @@ -298,7 +307,6 @@ function parse_commandline(
return parse_args(s)
end


"""
ClimateMachine.init(;
parse_clargs::Bool = false,
Expand Down Expand Up @@ -366,6 +374,8 @@ Recognized keyword arguments are:
run for the specified time (in simulation seconds)
- `fixed_number_of_steps::Int = -1`:
if `≥0` perform specified number of steps
- `degree::NTuple{2, Int} = (-1, -1)`:
tuple of horizontal and vertical polynomial degrees for spatial discretization order
Returns `nothing`, or if `parse_clargs = true`, returns parsed command line
arguments.
Expand Down Expand Up @@ -460,7 +470,6 @@ function init(;
return cl_args
end


"""
init_runtime(settings::ClimateMachine_Settings)
Expand Down Expand Up @@ -521,12 +530,10 @@ function init_runtime(settings::ClimateMachine_Settings)
return
end


include("driver_configs.jl")
include("solver_configs.jl")
include("diagnostics_configs.jl")


"""
ClimateMachine.ConservationCheck
Expand Down
94 changes: 64 additions & 30 deletions src/Driver/driver_configs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,40 @@ struct SingleStackSpecificInfo <: ConfigSpecificInfo end

include("SolverTypes/SolverTypes.jl")

"""
ArgParse.parse_item
Parses custom command line option for tuples of two integers.
"""
function ArgParse.parse_item(::Type{NTuple{2, Int}}, s::AbstractString)

str_array = split(s, ",")
horizontal = parse(Int, str_array[1])
vertical = parse(Int, str_array[2])

return (horizontal, vertical)
end

"""
get_polyorders
Utility functions that gets the polynomial orders for the given configuration
either passed from command line or as default values
"""
function get_polyorders(N)

(polyorder_horz, polyorder_vert) = isa(N, Int) ? (N, N) : N

# Check if polynomial degree was passed as a CL option
if ClimateMachine.Settings.degree != (-1, -1)
ClimateMachine.Settings.degree
elseif N isa Int
(N, N)
else
N
end
end

"""
ClimateMachine.DriverConfiguration
Expand Down Expand Up @@ -135,7 +169,7 @@ function AtmosLESConfiguration(
numerical_flux_gradient = CentralNumericalFluxGradient(),
) where {FT <: AbstractFloat}

(polyorder_horz, polyorder_vert) = isa(N, Int) ? (N, N) : N
(polyorder_horz, polyorder_vert) = get_polyorders(N)

print_model_info(model)

Expand All @@ -162,14 +196,14 @@ function AtmosLESConfiguration(
@info @sprintf(
"""
Establishing Atmos LES configuration for %s
precision = %s
horiz polynomial order = %d
vert polynomial order = %d
domain = %.2f m x%.2f m x%.2f m
resolution = %dx%dx%d
MPI ranks = %d
min(Δ_horz) = %.2f m
min(Δ_vert) = %.2f m""",
precision = %s
horiz polynomial order = %d
vert polynomial order = %d
domain = %.2f m x%.2f m x%.2f m
resolution = %dx%dx%d
MPI ranks = %d
min(Δ_horz) = %.2f m
min(Δ_vert) = %.2f m""",
name,
FT,
polyorder_horz,
Expand Down Expand Up @@ -224,7 +258,7 @@ function AtmosGCMConfiguration(
numerical_flux_gradient = CentralNumericalFluxGradient(),
) where {FT <: AbstractFloat}

(polyorder_horz, polyorder_vert) = isa(N, Int) ? (N, N) : N
(polyorder_horz, polyorder_vert) = get_polyorders(N)

print_model_info(model)

Expand Down Expand Up @@ -253,15 +287,15 @@ function AtmosGCMConfiguration(
@info @sprintf(
"""
Establishing Atmos GCM configuration for %s
precision = %s
horiz polynomial order = %d
vert polynomial order = %d
# horiz elem = %d
# vert elems = %d
domain height = %.2e m
MPI ranks = %d
min(Δ_horz) = %.2f m
min(Δ_vert) = %.2f m""",
precision = %s
horiz polynomial order = %d
vert polynomial order = %d
# horiz elem = %d
# vert elems = %d
domain height = %.2e m
MPI ranks = %d
min(Δ_horz) = %.2f m
min(Δ_vert) = %.2f m""",
name,
FT,
polyorder_horz,
Expand Down Expand Up @@ -311,7 +345,7 @@ function OceanBoxGCMConfiguration(
boundary = ((1, 1), (1, 1), (2, 3)),
)

(polyorder_horz, polyorder_vert) = isa(N, Int) ? (N, N) : N
(polyorder_horz, polyorder_vert) = get_polyorders(N)

brickrange = (
range(FT(0); length =+ 1, stop = model.problem.Lˣ),
Expand Down Expand Up @@ -371,7 +405,7 @@ function SingleStackConfiguration(
numerical_flux_gradient = CentralNumericalFluxGradient(),
) where {FT <: AbstractFloat}

(polyorder_horz, polyorder_vert) = isa(N, Int) ? (N, N) : N
(polyorder_horz, polyorder_vert) = get_polyorders(N)

print_model_info(model)

Expand Down Expand Up @@ -400,15 +434,15 @@ function SingleStackConfiguration(
@info @sprintf(
"""
Establishing single stack configuration for %s
precision = %s
horiz polynomial order = %d
vert polynomial order = %d
domain_min = %.2f m x%.2f m x%.2f m
domain_max = %.2f m x%.2f m x%.2f m
# vert elems = %d
MPI ranks = %d
min(Δ_horz) = %.2f m
min(Δ_vert) = %.2f m""",
precision = %s
horiz polynomial order = %d
vert polynomial order = %d
domain_min = %.2f m x%.2f m x%.2f m
domain_max = %.2f m x%.2f m x%.2f m
# vert elems = %d
MPI ranks = %d
min(Δ_horz) = %.2f m
min(Δ_vert) = %.2f m""",
name,
FT,
polyorder_horz,
Expand Down
2 changes: 2 additions & 0 deletions src/Driver/solver_configs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ the ODE solver, and return a `SolverConfiguration` to be used with
# - `direction=EveryDirection()`: restrict diffusivity direction.
# - `timeend_dt_adjust=true`: should `dt` be adjusted to hit `timeend` exactly
# - `CFL_direction=EveryDirection()`: direction for `calculate_dt`
# - `sim_time`: run for the specified time (in simulation seconds).
# - `fixed_number_of_steps`: if `≥0` perform specified number of steps.
Note that `diffdir`, `direction`, and `CFL_direction` are `VerticalDirection()`
when `driver_config.config_type isa SingleStackConfigType`.
Expand Down

0 comments on commit 73e1d18

Please sign in to comment.