Skip to content

Commit

Permalink
move land_components into bc type
Browse files Browse the repository at this point in the history
  • Loading branch information
kmdeck committed Sep 19, 2024
1 parent ee63ecc commit b6583cc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 33 deletions.
17 changes: 12 additions & 5 deletions src/integrated/soil_canopy_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,20 @@ function SoilCanopyModel{FT}(;
(; atmos, radiation, soil_organic_carbon) = land_args
# These should always be set by the constructor.
sources = (RootExtraction{FT}(), Soil.PhaseChange{FT}())
prognostic_land_components = (:canopy, :soil, :soilco2)
if :runoff propertynames(land_args)
top_bc = ClimaLand.AtmosDrivenFluxBC(atmos, radiation, land_args.runoff)
top_bc = ClimaLand.AtmosDrivenFluxBC(
atmos,
radiation,
land_args.runoff,
prognostic_land_components,
)
else #no runoff model
top_bc = ClimaLand.AtmosDrivenFluxBC(
atmos,
radiation,
ClimaLand.Soil.Runoff.NoRunoff(),
prognostic_land_components,
)
end
zero_flux = Soil.HeatFluxBC((p, t) -> 0.0)
Expand All @@ -97,7 +104,6 @@ function SoilCanopyModel{FT}(;
boundary_conditions = boundary_conditions,
sources = sources,
soil_args...,
land_components = (:canopy, :soil, :soilco2),
)

transpiration = Canopy.PlantHydraulics.DiagnosticTranspiration{FT}()
Expand Down Expand Up @@ -383,7 +389,7 @@ end
"""
soil_boundary_fluxes!(
bc::AtmosDrivenFluxBC{<:PrescribedAtmosphere, <:PrescribedRadiativeFluxes},
land_components::Val{(:canopy, :soil,:soilco2,)},
prognostic_land_components::Val{(:canopy, :soil,:soilco2,)},
soil::EnergyHydrology{FT},
Y,
p,
Expand All @@ -393,11 +399,12 @@ end
A method of `ClimaLand.Soil.soil_boundary_fluxes!` which is used for
integrated land surface models; this computes and returns the net
energy and water flux at the surface of the soil for use as boundary
conditions.
conditions when a canopy and Soil CO2 model is also included, though only
the presence of the canopy modifies the soil BC.
"""
function soil_boundary_fluxes!(
bc::AtmosDrivenFluxBC{<:PrescribedAtmosphere, <:PrescribedRadiativeFluxes},
land_components::Val{(:canopy, :soil, :soilco2)},
prognostic_land_components::Val{(:canopy, :soil, :soilco2)},
soil::EnergyHydrology{FT},
Y,
p,
Expand Down
16 changes: 11 additions & 5 deletions src/integrated/soil_snow_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,20 @@ function LandHydrologyModel{FT}(;
soil_args::NamedTuple = (;),
) where {FT, SnM <: Snow.SnowModel, SoM <: Soil.EnergyHydrology{FT}}
(; atmos, radiation) = land_args
prognostic_land_components = (:snow, :soil)
if :runoff propertynames(land_args)
top_bc = ClimaLand.AtmosDrivenFluxBC(atmos, radiation, land_args.runoff)
top_bc = ClimaLand.AtmosDrivenFluxBC(
atmos,
radiation,
land_args.runoff,
prognostic_land_components,
)
else #no runoff model
top_bc = AtmosDrivenFluxBC(
atmos,
radiation,
ClimaLand.Soil.Runoff.NoRunoff(),
prognostic_land_components,
)
end
sources = (Soil.PhaseChange{FT}(),)
Expand All @@ -79,7 +86,6 @@ function LandHydrologyModel{FT}(;
boundary_conditions = boundary_conditions,
sources = sources,
soil_args...,
land_components = (:snow, :soil),
)
snow = snow_model_type(; atmos = atmos, radiation = radiation, snow_args...)

Expand Down Expand Up @@ -179,7 +185,7 @@ end
"""
soil_boundary_fluxes!(
bc::AtmosDrivenFluxBC{<:PrescribedAtmosphere, <:PrescribedRadiativeFluxes},
land_components::Val{(:snow, :soil)},
prognostic_land_components::Val{(:snow, :soil)},
soil::EnergyHydrology{FT},
Y,
p,
Expand All @@ -189,11 +195,11 @@ end
A method of `ClimaLand.Soil.soil_boundary_fluxes!` which is used for
integrated land surface models; this computes and returns the net
energy and water flux at the surface of the soil for use as boundary
conditions.
conditions, taking into account the presence of snow on the surface.
"""
function soil_boundary_fluxes!(
bc::AtmosDrivenFluxBC{<:PrescribedAtmosphere, <:PrescribedRadiativeFluxes},
land_components::Val{(:snow, :soil)},
prognostic_land_components::Val{(:snow, :soil)},
soil::EnergyHydrology{FT},
Y,
p,
Expand Down
59 changes: 46 additions & 13 deletions src/standalone/Soil/boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ end
A <: AbstractAtmosphericDrivers,
B <: AbstractRadiativeDrivers,
R <: AbstractRunoffModel,
C::Tuple
} <: AbstractEnergyHydrologyBC
A concrete type of soil boundary condition for use at the top
Expand All @@ -576,27 +577,40 @@ to simulate surface and subsurface runoff and this is accounted
for when setting boundary conditions. The default is to have no runoff
accounted for.
Finally, because this same boundary condition type is used for the soil
in integrated land surface models, we also provide a tuple
indicating the prognostic land components present, as these affect how the boundary
conditions are computed. The default is
a tuple containing only (:soil,), indicating a standalone soil run.
$(DocStringExtensions.FIELDS)
"""
struct AtmosDrivenFluxBC{
A <: AbstractAtmosphericDrivers,
B <: AbstractRadiativeDrivers,
R <: AbstractRunoffModel,
C <: Tuple,
} <: AbstractEnergyHydrologyBC
"The atmospheric conditions driving the model"
atmos::A
"The radiative fluxes driving the model"
radiation::B
"The runoff model. The default is no runoff."
runoff::R
"Prognostic land components present"
prognostic_land_components::C
end


function AtmosDrivenFluxBC(atmos, radiation; runoff = NoRunoff())
function AtmosDrivenFluxBC(
atmos,
radiation;
runoff = NoRunoff(),
prognostic_land_components = (:soil,),
)
if typeof(runoff) <: NoRunoff
@info("Warning: No runoff model was provided; zero runoff generated.")
end
args = (atmos, radiation, runoff)
args = (atmos, radiation, runoff, prognostic_land_components)
return AtmosDrivenFluxBC{typeof.(args)...}(args...)
end

Expand Down Expand Up @@ -701,6 +715,31 @@ boundary_var_types(
Runoff.runoff_var_types(bc.runoff, FT)...,
)

"""
soil_boundary_fluxes!(
bc::AtmosDrivenFluxBC{
<:PrescribedAtmosphere,
<:PrescribedRadiativeFluxes,
},
boundary::ClimaLand.TopBoundary,
model::EnergyHydrology,
Δz,
Y,
p,
t,
)
Returns the net volumetric water flux (m/s) and net energy
flux (W/m^2) for the soil `EnergyHydrology` model at the top
of the soil domain.
This function calls the `turbulent_fluxes` and `net_radiation`
functions, which use the soil surface conditions as well as
the atmos and radiation conditions in order to
compute the surface fluxes using Monin Obukhov Surface Theory.
It also accounts for the presence of other components, if run as
part of an integrated land model, and their affect on boundary conditions.
"""
function soil_boundary_fluxes!(
bc::AtmosDrivenFluxBC,
boundary::ClimaLand.TopBoundary,
Expand All @@ -710,7 +749,7 @@ function soil_boundary_fluxes!(
p,
t,
) where {FT}
soil_boundary_fluxes!(bc, Val(soil.land_components), soil, Y, p, t)
soil_boundary_fluxes!(bc, Val(bc.prognostic_land_components), soil, Y, p, t)
end


Expand All @@ -720,7 +759,7 @@ end
<:PrescribedAtmosphere,
<:PrescribedRadiativeFluxes,
},
land_components::Val{(:soil,)},
prognostic_land_components::Val{(:soil,)},
model::EnergyHydrology,
Y,
p,
Expand All @@ -731,18 +770,12 @@ Returns the net volumetric water flux (m/s) and net energy
flux (W/m^2) for the soil `EnergyHydrology` model at the top
of the soil domain.
If you wish to compute surface fluxes taking into account the
presence of a canopy, snow, etc, as in a land surface model,
this is not the correct method to be using.
This function calls the `turbulent_fluxes` and `net_radiation`
functions, which use the soil surface conditions as well as
the atmos and radiation conditions in order to
compute the surface fluxes using Monin Obukhov Surface Theory.
Here, the soil boundary fluxes are computed as if the soil is run
in standalone mode.
"""
function soil_boundary_fluxes!(
bc::AtmosDrivenFluxBC{<:PrescribedAtmosphere, <:PrescribedRadiativeFluxes},
land_components::Val{(:soil,)},
prognostic_land_components::Val{(:soil,)},
model::EnergyHydrology,
Y,
p,
Expand Down
13 changes: 3 additions & 10 deletions src/standalone/Soil/energy_hydrology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ struct EnergyHydrology{FT, PS, D, BCRH, S} <: AbstractSoilModel{FT}
sources::S
"A boolean flag which, when false, turns off the horizontal flow of water and heat"
lateral_flow::Bool
"Components"
land_components::Tuple
end

"""
Expand All @@ -119,7 +117,6 @@ end
boundary_conditions::NamedTuple,
sources::Tuple,
lateral_flow::Bool = false,
land_components = (:soil,)
) where {FT, D, PS}
A constructor for a `EnergyHydrology` model, which sets the default value
Expand All @@ -131,24 +128,20 @@ function EnergyHydrology{FT}(;
boundary_conditions::NamedTuple,
sources::Tuple,
lateral_flow::Bool = false,
land_components = (:soil,),
) where {FT, D, PSE}
@assert !lateral_flow
top_bc = boundary_conditions.top
if typeof(top_bc) <: AtmosDrivenFluxBC
# If the top BC indicates atmospheric conditions are driving the model
# add baseflow as a sink term, add sublimation as a sink term
subl_source = sublimation_source(Val(land_components), FT)
subl_source =
sublimation_source(Val(top_bc.prognostic_land_components), FT)
subsurface_source = subsurface_runoff_source(top_bc.runoff)
sources = append_source(subsurface_source, sources)
sources = append_source(subl_source, sources)
end
args = (parameters, domain, boundary_conditions, sources)
EnergyHydrology{FT, typeof.(args)...}(
args...,
lateral_flow,
land_components,
)
EnergyHydrology{FT, typeof.(args)...}(args..., lateral_flow)
end

function make_update_boundary_fluxes(model::EnergyHydrology)
Expand Down

0 comments on commit b6583cc

Please sign in to comment.