From 401a495c47b99685f6a3aba39cdf46d96619473d Mon Sep 17 00:00:00 2001 From: Zhaoyi Shen <11598433+szy21@users.noreply.github.com> Date: Fri, 23 Aug 2024 23:12:53 -0700 Subject: [PATCH] update rrtmgp --- Project.toml | 2 +- ...uaplanet_rhoe_equilmoist_allsky_gw_res.yml | 2 +- examples/Manifest.toml | 4 +- src/callbacks/callbacks.jl | 37 ++++++-- .../radiation/RRTMGPInterface.jl | 85 +++++++++++++------ .../radiation/radiation.jl | 18 +++- .../radiation/radiation_utilities.jl | 18 +--- 7 files changed, 104 insertions(+), 62 deletions(-) diff --git a/Project.toml b/Project.toml index 90148cb1a88..d767275abd4 100644 --- a/Project.toml +++ b/Project.toml @@ -68,7 +68,7 @@ NCDatasets = "0.14.2" NVTX = "0.3" Pkg = "1.8" Printf = "1" -RRTMGP = "0.17" +RRTMGP = "0.18" Random = "1" RootSolvers = "0.2, 0.3, 0.4" SciMLBase = "1, 2" diff --git a/config/model_configs/sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res.yml b/config/model_configs/sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res.yml index 3ced2aaf4f2..6b2a5950fdb 100644 --- a/config/model_configs/sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res.yml +++ b/config/model_configs/sphere_aquaplanet_rhoe_equilmoist_allsky_gw_res.yml @@ -2,7 +2,7 @@ z_elem: 25 z_max: 55000.0 dz_bottom: 300.0 dt: "400secs" -t_end: "1days" +t_end: "1hours" dt_save_state_to_disk: "24hours" vert_diff: "FriersonDiffusion" implicit_diffusion: true diff --git a/examples/Manifest.toml b/examples/Manifest.toml index 76fc36bbeb7..b11b6d46cf4 100644 --- a/examples/Manifest.toml +++ b/examples/Manifest.toml @@ -2137,9 +2137,9 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" [[deps.RRTMGP]] deps = ["Adapt", "Artifacts", "ClimaComms", "DocStringExtensions", "Random"] -git-tree-sha1 = "866d94b4cf46fe3a0ffd35d1414a3a4181c9db08" +git-tree-sha1 = "c2311d511058db1fb2db61e0d60710471b102504" uuid = "a01a1ee8-cea4-48fc-987c-fc7878d79da1" -version = "0.17.0" +version = "0.18.0" weakdeps = ["CUDA", "ClimaParams"] [deps.RRTMGP.extensions] diff --git a/src/callbacks/callbacks.jl b/src/callbacks/callbacks.jl index df4a2cd0c2e..46e8dfa31aa 100644 --- a/src/callbacks/callbacks.jl +++ b/src/callbacks/callbacks.jl @@ -168,15 +168,34 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator) if !(radiation_mode isa RRTMGPI.GrayRadiation) if radiation_mode.aerosol_radiation ᶜΔz = Fields.Δz_field(Y.c) - ᶜaero_type = - Fields.array2field(rrtmgp_model.center_aerosol_type, axes(Y.c)) - @. ᶜaero_type = - set_aerosol_type(p.tracers.prescribed_aerosols_field) - ᶜaero_conc = Fields.array2field( - rrtmgp_model.center_aerosol_column_mass_density, - axes(Y.c), - ) - @. ᶜaero_conc = maximum(p.tracers.prescribed_aerosols_field) * ᶜΔz + + aerosol_names_pair = [ + (:center_dust_column_mass_density, :DST01), + (:center_ss_column_mass_density, :SSLT01), + (:center_so4_column_mass_density, :SO4), + (:center_bcpi_column_mass_density, :CB2), + (:center_bcpo_column_mass_density, :CB1), + (:center_ocpi_column_mass_density, :OC2), + (:center_ocpo_column_mass_density, :OC1), + ] + + for (aerosol_name, prescribed_aerosol_name) in aerosol_names_pair + ᶜaero_conc = Fields.array2field( + getproperty(rrtmgp_model, aerosol_name), + axes(Y.c), + ) + if prescribed_aerosol_name in + propertynames(p.tracers.prescribed_aerosols_field) + @. ᶜaero_conc = + getproperty( + p.tracers.prescribed_aerosols_field, + prescribed_aerosol_name, + ) * ᶜΔz + else + @. ᶜaero_conc = 0 + end + end + end if :o3 in propertynames(p.tracers) ᶜvmr_o3 = Fields.array2field( diff --git a/src/parameterized_tendencies/radiation/RRTMGPInterface.jl b/src/parameterized_tendencies/radiation/RRTMGPInterface.jl index 4046a692096..8466e397128 100644 --- a/src/parameterized_tendencies/radiation/RRTMGPInterface.jl +++ b/src/parameterized_tendencies/radiation/RRTMGPInterface.jl @@ -500,7 +500,9 @@ function RRTMGPModel( nbnd_lw = 1 else local lookup_lw, idx_gases - data_loader("rrtmgp-gas-lw-g256.nc") do ds + data_loader( + RRTMGP.ArtifactPaths.get_lookup_filename(:gas, :lw), + ) do ds lookup_lw, idx_gases = RRTMGP.LookUpTables.LookUpLW(ds, FT, DA) end lookups = (; lookups..., lookup_lw, idx_gases) @@ -510,7 +512,9 @@ function RRTMGPModel( if !(radiation_mode isa ClearSkyRadiation) local lookup_lw_cld - data_loader(joinpath("rrtmgp-clouds-lw.nc")) do ds + data_loader( + RRTMGP.ArtifactPaths.get_lookup_filename(:cloud, :lw), + ) do ds lookup_lw_cld = use_pade_cloud_optics_mode ? RRTMGP.LookUpTables.PadeCld(ds, FT, DA) : @@ -519,9 +523,11 @@ function RRTMGPModel( lookups = (; lookups..., lookup_lw_cld) end if radiation_mode.aerosol_radiation - local lookup_lw_aero - data_loader(joinpath("rrtmgp-aerosols-merra-lw.nc")) do ds - lookup_lw_aero = + local lookup_lw_aero, idx_aerosol, idx_aerosize + data_loader( + RRTMGP.ArtifactPaths.get_lookup_filename(:aerosol, :lw), + ) do ds + lookup_lw_aero, idx_aerosol, idx_aerosize = RRTMGP.LookUpTables.LookUpAerosolMerra(ds, FT, DA) end else @@ -571,7 +577,9 @@ function RRTMGPModel( nbnd_sw = 1 else local lookup_sw, idx_gases - data_loader("rrtmgp-gas-sw-g224.nc") do ds + data_loader( + RRTMGP.ArtifactPaths.get_lookup_filename(:gas, :sw), + ) do ds lookup_sw, idx_gases = RRTMGP.LookUpTables.LookUpSW(ds, FT, DA) end lookups = (; lookups..., lookup_sw, idx_gases) @@ -581,7 +589,9 @@ function RRTMGPModel( if !(radiation_mode isa ClearSkyRadiation) local lookup_sw_cld - data_loader(joinpath("rrtmgp-clouds-sw.nc")) do ds + data_loader( + RRTMGP.ArtifactPaths.get_lookup_filename(:cloud, :sw), + ) do ds lookup_sw_cld = use_pade_cloud_optics_mode ? RRTMGP.LookUpTables.PadeCld(ds, FT, DA) : @@ -591,9 +601,11 @@ function RRTMGPModel( end if radiation_mode.aerosol_radiation - local lookup_sw_aero - data_loader(joinpath("rrtmgp-aerosols-merra-sw.nc")) do ds - lookup_sw_aero = + local lookup_sw_aero, idx_aerosol, idx_aerosize + data_loader( + RRTMGP.ArtifactPaths.get_lookup_filename(:aerosol, :sw), + ) do ds + lookup_sw_aero, idx_aerosol, idx_aerosize = RRTMGP.LookUpTables.LookUpAerosolMerra(ds, FT, DA) end else @@ -805,17 +817,35 @@ function RRTMGPModel( end if radiation_mode.aerosol_radiation - aero_type = DA{Int}(undef, nlay, ncol) - name = "center_aerosol_type" - set_and_save!(aero_type, name, t..., dict) - aero_size = DA{FT}(undef, nlay, ncol) - name = "center_aerosol_radius" - set_and_save!(aero_size, name, t..., dict) - aero_mass = DA{FT}(undef, nlay, ncol) - name = "center_aerosol_column_mass_density" - set_and_save!(aero_mass, name, t..., dict) + n_aerosol_sizes = maximum(values(idx_aerosize)) + n_aerosols = length(idx_aerosol) + + aero_mask = DA{Bool}(undef, nlay, ncol) + set_and_save!(aero_mask, "center_aerosol_mask", t..., dict) + + aero_size = DA{FT}(undef, n_aerosol_sizes, nlay, ncol) + aero_mass = DA{FT}(undef, n_aerosols, nlay, ncol) + aerosol_size_names = ["dust", "ss"] + aerosol_names = + ["dust", "ss", "so4", "bcpi", "bcpo", "ocpi", "ocpo"] + for (i, name) in enumerate(aerosol_size_names) + set_and_save!( + view(aero_size, i, :, :), + "center_$(name)_radius", + t..., + dict, + ) + end + for (i, name) in enumerate(aerosol_names) + set_and_save!( + view(aero_mass, i, :, :), + "center_$(name)_column_mass_density", + t..., + dict, + ) + end aerosol_state = RRTMGP.AtmosphericStates.AerosolState( - aero_type, + aero_mask, aero_size, aero_mass, ) @@ -835,6 +865,7 @@ function RRTMGPModel( cloud_state, aerosol_state, ) + end if use_one_scalar_mode @@ -1127,12 +1158,12 @@ update_boundary_layer_aerosol!(::Nothing) = nothing function update_boundary_layer_aerosol!( aerosol_state::RRTMGP.AtmosphericStates.AerosolState, ) - @views aerosol_state.aero_type[end, :] .= - aerosol_state.aero_type[end - 1, :] - @views aerosol_state.aero_size[end, :] .= - aerosol_state.aero_size[end - 1, :] - @views aerosol_state.aero_mass[end, :] .= - aerosol_state.aero_mass[end - 1, :] + @views aerosol_state.aero_mask[end, :] .= + aerosol_state.aero_mask[end - 1, :] + @views aerosol_state.aero_size[:, end, :] .= + aerosol_state.aero_size[:, end - 1, :] + @views aerosol_state.aero_mass[:, end, :] .= + aerosol_state.aero_mass[:, end - 1, :] end function clip_values!(model) @@ -1245,12 +1276,10 @@ NVTX.@annotate function update_sw_fluxes!( end function update_net_fluxes!(_, model) - FT = eltype(model.face_flux) model.face_flux .= model.face_lw_flux .+ model.face_sw_flux end function update_net_fluxes!(::AllSkyRadiationWithClearSkyDiagnostics, model) - FT = eltype(model.face_flux) model.face_clear_flux .= model.face_clear_lw_flux .+ model.face_clear_sw_flux model.face_flux .= model.face_lw_flux .+ model.face_sw_flux diff --git a/src/parameterized_tendencies/radiation/radiation.jl b/src/parameterized_tendencies/radiation/radiation.jl index bbb90d8f53e..d4c983a65bb 100644 --- a/src/parameterized_tendencies/radiation/radiation.jl +++ b/src/parameterized_tendencies/radiation/radiation.jl @@ -70,7 +70,9 @@ function radiation_model_cache( "inputs", "multiple_input4MIPs_radiation_RFMIP_UColorado-RFMIP-1-2_none.nc", ) - data_loader(file_name) do input_data + data_loader( + RRTMGP.ArtifactPaths.get_input_filename(:gas, :lw), + ) do input_data if radiation_mode isa RRTMGPI.GrayRadiation kwargs = (; lapse_rate = 3.5, @@ -206,9 +208,17 @@ function radiation_model_cache( if aerosol_radiation kwargs = (; kwargs..., - center_aerosol_type = 0, # initialized in callback - center_aerosol_radius = 0.2, # assuming fixed aerosol radius - center_aerosol_column_mass_density = NaN, # initialized in callback + center_aerosol_mask = true, # initialized in callback + # assuming fixed aerosol radius + center_dust_radius = 0.2, + center_ss_radius = 0.2, + center_dust_column_mass_density = NaN, # initialized in callback + center_ss_column_mass_density = NaN, # initialized in callback + center_so4_column_mass_density = NaN, # initialized in callback + center_bcpi_column_mass_density = NaN, # initialized in callback + center_bcpo_column_mass_density = NaN, # initialized in callback + center_ocpi_column_mass_density = NaN, # initialized in callback + center_ocpo_column_mass_density = NaN, # initialized in callback ) end end diff --git a/src/parameterized_tendencies/radiation/radiation_utilities.jl b/src/parameterized_tendencies/radiation/radiation_utilities.jl index 117b2280a96..5277e3c6bd5 100644 --- a/src/parameterized_tendencies/radiation/radiation_utilities.jl +++ b/src/parameterized_tendencies/radiation/radiation_utilities.jl @@ -6,22 +6,6 @@ import RRTMGP ##### RRTMGP ##### -""" - rrtmgp_artifact(file_name) - -Returns the filename of an artifact stored in -`RRTMGPReferenceData/`. -""" -function rrtmgp_artifact(file_name) - artifact_name = "rrtmgp-data" - artifacts_file = joinpath(pkgdir(RRTMGP), "test", "Artifacts.toml") - data_folder = joinpath( - Pkg.Artifacts.ensure_artifact_installed(artifact_name, artifacts_file), - "rrtmgp-data-1.8.1", - ) - return joinpath(data_folder, file_name) -end - """ data_loader(fn, file_name) @@ -30,7 +14,7 @@ Loads data from an `NCDataset` from the `RRTMGP.jl` artifact stored in dataset. """ function rrtmgp_data_loader(fn, file_name) - NC.Dataset(rrtmgp_artifact(file_name), "r") do ds + NC.Dataset(file_name, "r") do ds fn(ds) end end