From 4f8d5fa8c031aca798eb07c25b4ac13379d8d771 Mon Sep 17 00:00:00 2001 From: Julia Sloan Date: Fri, 2 Feb 2024 16:59:01 -0800 Subject: [PATCH] bucket updates --- .../AMIP/components/land/bucket_init.jl | 127 +++--------------- .../AMIP/components/land/bucket_utils.jl | 8 +- 2 files changed, 19 insertions(+), 116 deletions(-) diff --git a/experiments/AMIP/components/land/bucket_init.jl b/experiments/AMIP/components/land/bucket_init.jl index 037b329fda..a16b8f2411 100644 --- a/experiments/AMIP/components/land/bucket_init.jl +++ b/experiments/AMIP/components/land/bucket_init.jl @@ -8,7 +8,16 @@ using ClimaComms: AbstractCommsContext import ClimaLSM using ClimaLSM.Bucket: BucketModel, BucketModelParameters, AbstractAtmosphericDrivers, AbstractRadiativeDrivers import ClimaLSM.Bucket: BulkAlbedoTemporal, BulkAlbedoStatic, BulkAlbedoFunction -using ClimaLSM: make_exp_tendency, initialize, make_set_initial_cache, surface_evaporative_scaling +using ClimaLSM: + make_exp_tendency, + initialize, + make_set_initial_cache, + surface_evaporative_scaling, + CoupledRadiativeFluxes, + CoupledAtmosphere + +# TODO remove this import after ClimaLand v0.8 update +import ClimaLSM.Parameters as LSMP include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl")) import ClimaCoupler.Interfacer: LandModelSimulation, get_field, update_field!, name @@ -31,117 +40,14 @@ name(::BucketSimulation) = "BucketSimulation" include("./bucket_utils.jl") -""" - CoupledRadiativeFluxes{FT} <: AbstractRadiativeDrivers{FT} - -To be used when coupling to an atmosphere model; internally, used for -multiple dispatch on `surface_fluxes`. -""" -struct CoupledRadiativeFluxes{FT} <: AbstractRadiativeDrivers{FT} end - -""" - CoupledAtmosphere{FT} <: AbstractAtmosphericDrivers{FT} - -To be used when coupling to an atmosphere model; internally, used for -multiple dispatch on `surface_fluxes`. -""" -struct CoupledAtmosphere{FT} <: AbstractAtmosphericDrivers{FT} end - -""" - ClimaLSM.turbulent_fluxes(atmos::CoupledAtmosphere{FT}, - model::BucketModel{FT}, - Y, - p, - ) where {FT <: AbstractFloat} - -Computes the turbulent surface fluxes terms at the ground for a coupled simulation. -Note that `Ch` is not used with the current implementation of the bucket model, -but will be used once the canopy is incorporated. - -The turbulent energy flux is currently not split up between latent and sensible -heat fluxes. This will be fixed once `lhf` and `shf` are added to the bucket's -cache. -""" -function ClimaLSM.turbulent_fluxes( - atmos::CoupledAtmosphere{FT}, - model::BucketModel{FT}, - Y, - p, - _..., -) where {FT <: AbstractFloat} - space = model.domain.space.surface - return ( - lhf = ClimaCore.Fields.zeros(space), - shf = p.bucket.turbulent_energy_flux, - vapor_flux = p.bucket.evaporation, - Ch = ClimaCore.Fields.similar(p.bucket.evaporation), - ) -end - -""" - ClimaLSM.net_radiation(radiation::CoupledRadiativeFluxes{FT}, - model::BucketModel{FT}, - Y, - p, - _..., - ) where {FT <: AbstractFloat} - -Computes the net radiative flux at the ground for a coupled simulation. -""" -function ClimaLSM.net_radiation( - radiation::CoupledRadiativeFluxes{FT}, - model::BucketModel{FT}, - Y::ClimaCore.Fields.FieldVector, - p::NamedTuple, - _..., -) where {FT <: AbstractFloat} +# TODO remove this function after ClimaLand v0.8.1 update +function ClimaLSM.turbulent_fluxes(atmos::CoupledAtmosphere, model::BucketModel, Y, p, t) # coupler has done its thing behind the scenes already - return p.bucket.R_n -end - - -""" - ClimaLSM.surface_air_density( - atmos::CoupledAtmosphere{FT}, - model::BucketModel{FT}, - Y, - p, - _..., - ) -an extension of the bucket model method which returns the surface air -density in the case of a coupled simulation. -""" -function ClimaLSM.surface_air_density( - atmos::CoupledAtmosphere{FT}, - model::BucketModel{FT}, - Y, - p, - _..., -) where {FT <: AbstractFloat} - return p.bucket.ρ_sfc -end - -""" - ClimaLSM.liquid_precipitation(atmos::CoupledAtmosphere, p, t) - -an extension of the bucket model method which returns the precipitation -(m/s) in the case of a coupled simulation. -""" -function ClimaLSM.liquid_precipitation(atmos::CoupledAtmosphere, p, t) - # coupler has filled this in - return p.drivers.P_liq + model_name = ClimaLSM.name(model) + model_cache = getproperty(p, model_name) + return model_cache.turbulent_fluxes end -""" - ClimaLSM.snow_precipitation(atmos::CoupledAtmosphere, p, t) - -an extension of the bucket model method which returns the precipitation -(m/s) in the case of a coupled simulation. -""" -function ClimaLSM.snow_precipitation(atmos::CoupledAtmosphere, p, t) - # coupler has filled this in - return p.drivers.P_snow -end function ClimaLSM.initialize_drivers(a::CoupledAtmosphere{FT}, coords) where {FT} keys = (:P_liq, :P_snow) @@ -155,9 +61,6 @@ function ClimaLSM.initialize_drivers(a::CoupledAtmosphere{FT}, coords) where {FT return vars.drivers end -function ClimaLSM.initialize_drivers(a::CoupledRadiativeFluxes{FT}, coords) where {FT} - return (;) -end """ temp_anomaly_aquaplanet(coord) diff --git a/experiments/AMIP/components/land/bucket_utils.jl b/experiments/AMIP/components/land/bucket_utils.jl index f25a10c935..e3d310be15 100644 --- a/experiments/AMIP/components/land/bucket_utils.jl +++ b/experiments/AMIP/components/land/bucket_utils.jl @@ -50,11 +50,11 @@ get_field(sim::BucketSimulation, ::Val{:area_fraction}) = sim.area_fraction get_field(sim::BucketSimulation, ::Val{:air_density}) = sim.integrator.p.bucket.ρ_sfc function update_field!(sim::BucketSimulation, ::Val{:turbulent_energy_flux}, field) - parent(sim.integrator.p.bucket.turbulent_energy_flux) .= parent(field) + parent(sim.integrator.p.bucket.turbulent_fluxes.shf) .= parent(field) end function update_field!(sim::BucketSimulation, ::Val{:turbulent_moisture_flux}, field) ρ_liq = (LSMP.ρ_cloud_liq(sim.model.parameters.earth_param_set)) - parent(sim.integrator.p.bucket.evaporation) .= parent(field ./ ρ_liq) # TODO: account for sublimation + parent(sim.integrator.p.bucket.turbulent_fluxes.vapor_flux) .= parent(field ./ ρ_liq) # TODO: account for sublimation end function update_field!(sim::BucketSimulation, ::Val{:radiative_energy_flux}, field) parent(sim.integrator.p.bucket.R_n) .= parent(field) @@ -79,8 +79,8 @@ reinit!(sim::BucketSimulation) = reinit!(sim.integrator) # extensions required by FluxCalculator (partitioned fluxes) function update_turbulent_fluxes_point!(sim::BucketSimulation, fields::NamedTuple, colidx::Fields.ColumnIndex) (; F_turb_energy, F_turb_moisture) = fields - sim.integrator.p.bucket.turbulent_energy_flux[colidx] .= F_turb_energy - sim.integrator.p.bucket.evaporation[colidx] .= + sim.integrator.p.bucket.turbulent_fluxes.shf[colidx] .= F_turb_energy + sim.integrator.p.bucket.turbulent_fluxes.vapor_flux[colidx] .= F_turb_moisture ./ LSMP.ρ_cloud_liq(sim.model.parameters.earth_param_set) return nothing end