Skip to content

Commit

Permalink
update rrtmgp
Browse files Browse the repository at this point in the history
  • Loading branch information
szy21 committed Aug 27, 2024
1 parent 09706c3 commit 401a495
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
37 changes: 28 additions & 9 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
85 changes: 57 additions & 28 deletions src/parameterized_tendencies/radiation/RRTMGPInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) :
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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) :
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
Expand All @@ -835,6 +865,7 @@ function RRTMGPModel(
cloud_state,
aerosol_state,
)

end

if use_one_scalar_mode
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions src/parameterized_tendencies/radiation/radiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
18 changes: 1 addition & 17 deletions src/parameterized_tendencies/radiation/radiation_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@ import RRTMGP
##### RRTMGP
#####

"""
rrtmgp_artifact(file_name)
Returns the filename of an artifact stored in
`RRTMGPReferenceData/<file_name>`.
"""
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)
Expand All @@ -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

0 comments on commit 401a495

Please sign in to comment.