From 73e1d18190938e1479725ab5b027e998bc9a38ec Mon Sep 17 00:00:00 2001 From: valeriabarra Date: Tue, 8 Dec 2020 16:25:12 -0800 Subject: [PATCH] Addition of polynomial degrees CL option --- src/Driver/Driver.jl | 23 ++++++--- src/Driver/driver_configs.jl | 94 ++++++++++++++++++++++++------------ src/Driver/solver_configs.jl | 2 + 3 files changed, 81 insertions(+), 38 deletions(-) diff --git a/src/Driver/Driver.jl b/src/Driver/Driver.jl index f09aa421e52..176a675a44e 100644 --- a/src/Driver/Driver.jl +++ b/src/Driver/Driver.jl @@ -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() @@ -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) @@ -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 @@ -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}, @@ -290,6 +294,11 @@ function parse_commandline( metavar = "" 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) @@ -298,7 +307,6 @@ function parse_commandline( return parse_args(s) end - """ ClimateMachine.init(; parse_clargs::Bool = false, @@ -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. @@ -460,7 +470,6 @@ function init(; return cl_args end - """ init_runtime(settings::ClimateMachine_Settings) @@ -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 diff --git a/src/Driver/driver_configs.jl b/src/Driver/driver_configs.jl index bd29cd43523..2666cf62e58 100644 --- a/src/Driver/driver_configs.jl +++ b/src/Driver/driver_configs.jl @@ -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 @@ -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) @@ -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, @@ -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) @@ -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, @@ -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 = Nˣ + 1, stop = model.problem.Lˣ), @@ -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) @@ -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, diff --git a/src/Driver/solver_configs.jl b/src/Driver/solver_configs.jl index e4596946d95..575d18bad34 100644 --- a/src/Driver/solver_configs.jl +++ b/src/Driver/solver_configs.jl @@ -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`.