Skip to content

Commit

Permalink
try bucket update
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Feb 3, 2024
1 parent 07af9cb commit 4c71623
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 119 deletions.
122 changes: 7 additions & 115 deletions experiments/AMIP/components/land/bucket_init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ 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
include(joinpath(pkgdir(ClimaLSM), "parameters", "create_parameters.jl"))

import ClimaCoupler.Interfacer: LandModelSimulation, get_field, update_field!, name
Expand All @@ -31,117 +37,6 @@ 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}
# 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
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)
Expand All @@ -155,9 +50,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)
Expand Down
8 changes: 4 additions & 4 deletions experiments/AMIP/components/land/bucket_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.lhf) .= 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)
parent(sim.integrator.p.bucket.turbulent_fluxes.vapor_flux) .= parent(field ./ ρ_liq)
end
function update_field!(sim::BucketSimulation, ::Val{:radiative_energy_flux}, field)
parent(sim.integrator.p.bucket.R_n) .= parent(field)
Expand All @@ -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.lhf[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
Expand Down

0 comments on commit 4c71623

Please sign in to comment.