diff --git a/NEWS.md b/NEWS.md index d155678b175..51f86e288e4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,16 +5,29 @@ Main ------- ### Features -### DYAMOND-summer initial conditions +### Read initial conditions from NetCDF files -Added functionality to allow initial conditions to be overwritten by -interpolated datasets. Currently supports equilibrium moisture models -for DYAMOND runs, assuming a simulation start date of 1 August 2016. +Added functionality to allow initial conditions to be overwritten by +interpolated NetCDF datasets. + +To use this feature from the YAML interface, just pass the path of the file. +We expect the file to contain the following variables: +- `p`, for pressure, +- `t`, for temperature, +- `q`, for humidity, +- `u, v, w`, for velocity, +- `cswc, crwc` for snow and rain water content (for 1 moment microphysics). + +For example, to use the DYAMONDSummer initial condition, set +``` +initial_condition: "artifact\"DYAMONDSummer\"/DYAMOND_SUMMER_ICS_p98deg.nc" +``` +in your configuration file. ### Write diagnostics to text files Added functionality to write diagnostics in DictWriter to text files. -This is useful for outputing scalar diagnostics, such as total mass of +This is useful for outputting scalar diagnostics, such as total mass of the atmosphere. PR [3476](https://github.com/CliMA/ClimaAtmos.jl/pull/3476) v0.28.0 diff --git a/config/default_configs/default_config.yml b/config/default_configs/default_config.yml index 9bdcedc4af6..69d4a30d3aa 100644 --- a/config/default_configs/default_config.yml +++ b/config/default_configs/default_config.yml @@ -182,7 +182,7 @@ surface_temperature: help: "Prescribed surface temperature functional form ['ZonallySymmetric' (default), 'ZonallyAsymmetric', 'RCEMIPII']" value: "ZonallySymmetric" initial_condition: - help: "Initial condition [`DryBaroclinicWave`, `MoistBaroclinicWave`, `DecayingProfile`, `IsothermalProfile`, `Bomex`, `DryDensityCurrentProfile`, `AgnesiHProfile`, `ScharProfile`, `RisingThermalBubbleProfile`, `ISDAC`, `DYAMONDSummer`]" + help: "Initial condition [`DryBaroclinicWave`, `MoistBaroclinicWave`, `DecayingProfile`, `IsothermalProfile`, `Bomex`, `DryDensityCurrentProfile`, `AgnesiHProfile`, `ScharProfile`, `RisingThermalBubbleProfile`, `ISDAC`], or a file path for a NetCDF file (read documentation about requirements)." value: "DecayingProfile" perturb_initstate: help: "Add a perturbation to the initial condition [`false`, `true` (default)]" diff --git a/config/gpu_configs/gpu_aquaplanet_dyamond_summer.yml b/config/gpu_configs/gpu_aquaplanet_dyamond_summer.yml index 471df5a147d..705e3aec9f3 100644 --- a/config/gpu_configs/gpu_aquaplanet_dyamond_summer.yml +++ b/config/gpu_configs/gpu_aquaplanet_dyamond_summer.yml @@ -23,7 +23,7 @@ toml: [toml/longrun_aquaplanet.toml] prescribe_ozone: true aerosol_radiation: true prescribed_aerosols: ["CB1", "CB2", "DST01", "OC1", "OC2", "SO4", "SSLT01"] -initial_condition: "DYAMONDSummer" +initial_condition: "artifact\"DYAMONDSummer\"/DYAMOND_SUMMER_ICS_p98deg.nc" topography: "Earth" diagnostics: - short_name: [ts, ta, thetaa, ha, pfull, rhoa, ua, va, wa, hur, hus, cl, clw, cli, hussfc, evspsbl, pr, rv] diff --git a/src/initial_conditions/initial_conditions.jl b/src/initial_conditions/initial_conditions.jl index 0bb0f352889..9fbddeb7adc 100644 --- a/src/initial_conditions/initial_conditions.jl +++ b/src/initial_conditions/initial_conditions.jl @@ -161,15 +161,16 @@ function (initial_condition::DecayingProfile)(params) end """ - DYAMONDSummer() + MoistFromFile(file_path) -This function assigns a default initial condition, populating the `LocalState` -with `NaN`, prior to applying the `overwrite_initial_conditions` method, which -interpolates values from NetCDF data onto the `ExtrudedFiniteDifferenceSpace`. +This function assigns an empty initial condition for , populating the `LocalState` with +`NaN`, and later overwriting it with the content of the given file """ -struct DYAMONDSummer <: InitialCondition end +struct MoistFromFile <: InitialCondition + file_path::String +end -function (initial_condition::DYAMONDSummer)(params) +function (initial_condition::MoistFromFile)(params) function local_state(local_geometry) FT = eltype(params) grav = CAP.grav(params) @@ -379,28 +380,41 @@ end """ overwrite_initial_conditions!(initial_condition, args...) + Do-nothing fallback method for the operation overwriting initial conditions (this functionality required in instances where we interpolate initial conditions from NetCDF files). Future work may revisit this design choice. """ -overwrite_initial_conditions!(initial_condition::InitialCondition, args...) = - (return nothing) +function overwrite_initial_conditions!( + initial_condition::InitialCondition, + args..., +) + return nothing +end """ - overwrite_initial_conditions!(initial_condition, Y, thermo_params, config) -Given a prognostic state `Y`, an `initial condition` (specifically, where -initial values are assigned from interpolations of existing datasets), a `thermo_state`, this function overwrites the default initial condition -and populates prognostic variables with interpolated values using the `SpaceVaryingInputs` -tool. To mitigate issues related to unbalanced states following the interpolation operation, -we recompute vertical pressure levels assuming hydrostatic balance, given the surface pressure + overwrite_initial_conditions!(initial_condition::MoistFromFile, Y, thermo_params, config) + +Given a prognostic state `Y`, an `initial condition` (specifically, where initial values are +assigned from interpolations of existing datasets), a `thermo_state`, this function +overwrites the default initial condition and populates prognostic variables with +interpolated values using the `SpaceVaryingInputs` tool. To mitigate issues related to +unbalanced states following the interpolation operation, we recompute vertical pressure +levels assuming hydrostatic balance, given the surface pressure. + +We expect the file to contain the following variables: +- `p`, for pressure, +- `t`, for temperature, +- `q`, for humidity, +- `u, v, w`, for velocity, +- `cswc, crwc` for snow and rain water content (for 1 moment microphysics). """ function overwrite_initial_conditions!( - initial_condition::DYAMONDSummer, + initial_conditions::MoistFromFile, Y, thermo_params, ) - # Get file from AtmosArtifacts - file_path = AA.dyamond_summer_artifact_path(; context = config.comms_ctx) + file_path = isfile(file_path) || error("$(file_path) is not a file") center_space = Fields.axes(Y.c) face_space = Fields.axes(Y.f) # Using surface pressure, air temperature and specific humidity diff --git a/src/solver/type_getters.jl b/src/solver/type_getters.jl index 43e9521f7ae..c5dfde132fa 100644 --- a/src/solver/type_getters.jl +++ b/src/solver/type_getters.jl @@ -294,9 +294,10 @@ function get_initial_condition(parsed_args) "RisingThermalBubbleProfile", "ScharProfile", "PrecipitatingColumn", - "DYAMONDSummer", ] return getproperty(ICs, Symbol(parsed_args["initial_condition"]))() + elseif isfile(parsed_args["initial_condition"]) + return ICs.MoistFromFile(parsed_args["initial_condition"]) elseif parsed_args["initial_condition"] == "GCM" @assert parsed_args["prognostic_tke"] == true return ICs.GCMDriven( @@ -663,22 +664,21 @@ function get_simulation(config::AtmosConfig) t_start = Spaces.undertype(axes(Y.c))(0) end @info "Allocating Y: $s" + + # In instances where we wish to interpolate existing datasets, e.g. + # NetCDF files containing spatially varying thermodynamic properties, + # this call to `overwrite_initial_conditions` accesses rewrite the + # variable in `Y` (specific to `initial_condition`) with those computed + # using the `SpaceVaryingInputs` tool. + CA.InitialConditions.overwrite_initial_conditions!( + initial_condition, + Y, + params.thermodynamics_params, + ) end tracers = get_tracers(config.parsed_args) - # In instances where we wish to interpolate existing datasets, - # e.g. NetCDF files containing spatially varying thermodynamic properties, - # this call to `overwrite_initial_conditions` - # accesses the appropriate artifact for a given `initial_condition` - # and then updates some predetermined state `Y` (specific to `initial_condition`) - # with those computed using the `SpaceVaryingInputs` tool. - CA.InitialConditions.overwrite_initial_conditions!( - initial_condition, - Y, - params.thermodynamics_params, - ) - s = @timed_str begin p = build_cache( Y, diff --git a/src/utils/AtmosArtifacts.jl b/src/utils/AtmosArtifacts.jl index 039859da449..2a3092406c4 100644 --- a/src/utils/AtmosArtifacts.jl +++ b/src/utils/AtmosArtifacts.jl @@ -82,19 +82,4 @@ function earth_orography_file_path(; context = nothing) ) end -""" - dyamond_summer_artifact_path(; context = nothing) - -Construct the file path for the 0.98deg DYAMOND initial conditions: -the artifact contains initial conditions for DYAMOND simulations -beginning on 1 August 2016. -""" -function dyamond_summer_artifact_path(; context = nothing) - filename = "DYAMOND_SUMMER_ICS_p98deg.nc" - return joinpath( - @clima_artifact("DYAMOND_SUMMER_ICS_p98deg", context), - filename, - ) -end - end