Skip to content

Commit

Permalink
remove PrescribedSOC and use new driver
Browse files Browse the repository at this point in the history
  • Loading branch information
kmdeck committed Jul 7, 2024
1 parent f8ee54b commit 0166bd4
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 167 deletions.
1 change: 0 additions & 1 deletion docs/src/APIs/SoilBiogeochemistry.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ ClimaLand.Soil.Biogeochemistry.AtmosCO2StateBC
ClimaLand.Soil.Biogeochemistry.AbstractSoilDriver
ClimaLand.Soil.Biogeochemistry.SoilDrivers
ClimaLand.Soil.Biogeochemistry.PrescribedMet
ClimaLand.Soil.Biogeochemistry.PrescribedSOC
```

## Functions of State
Expand Down
1 change: 1 addition & 0 deletions docs/src/APIs/shared_utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ClimaLand.get_drivers
ClimaLand.PrescribedAtmosphere
ClimaLand.PrescribedPrecipitation
ClimaLand.PrescribedRadiativeFluxes
ClimaLand.PrescribedSoilOrganicCarbon
ClimaLand.CoupledAtmosphere
ClimaLand.CoupledRadiativeFluxes
ClimaLand.AbstractAtmosphericDrivers
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/integrated/soil_canopy_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}
soilco2_ps = SoilCO2ModelParameters(FT; ν = soil_ν);

# soil microbes args
Csom = (z, t) -> eltype(z)(5); # kg C m⁻³, this is a guess, not measured at the site
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
soilco2_bot_bc = Soil.Biogeochemistry.SoilCO2StateBC((p, t) -> 0.0);
Expand All @@ -187,7 +187,7 @@ soilco2_boundary_conditions = (; top = soilco2_top_bc, bottom = soilco2_bot_bc);

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
);

Expand Down
4 changes: 2 additions & 2 deletions experiments/benchmarks/land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function setup_prob(t0, tf, Δt; nelements = (101, 15))
soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

# Set the soil CO2 BC to being atmospheric CO2
soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
Expand All @@ -424,7 +424,7 @@ function setup_prob(t0, tf, Δt; nelements = (101, 15))

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
)

Expand Down
5 changes: 2 additions & 3 deletions experiments/integrated/fluxnet/ozark_pft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ soilco2_ps = SoilCO2ModelParameters(
ν = soil_ν, # same as soil
)

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

# Set the soil CO2 BC to being atmospheric CO2
soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
Expand All @@ -152,7 +151,7 @@ soilco2_boundary_conditions = (; top = soilco2_top_bc, bottom = soilco2_bot_bc)

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
)

Expand Down
5 changes: 2 additions & 3 deletions experiments/integrated/fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ soilco2_ps = SoilCO2ModelParameters(
ν = soil_ν, # same as soil
)

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

# Set the soil CO2 BC to being atmospheric CO2
soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
Expand All @@ -111,7 +110,7 @@ soilco2_boundary_conditions = (; top = soilco2_top_bc, bottom = soilco2_bot_bc)

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
)

Expand Down
4 changes: 2 additions & 2 deletions experiments/integrated/global/global_soil_canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ soil_model_type = Soil.EnergyHydrology{FT}
soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

# Set the soil CO2 BC to being atmospheric CO2
soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
Expand All @@ -192,7 +192,7 @@ soilco2_boundary_conditions = (; top = soilco2_top_bc, bottom = soilco2_bot_bc)

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}
soilco2_ps = SoilCO2ModelParameters(FT; ν = soil_ν)

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

# Set the soil CO2 BC to being atmospheric CO2
soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
Expand All @@ -93,7 +93,7 @@ soilco2_boundary_conditions = (; top = soilco2_top_bc, bottom = soilco2_bot_bc)

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
)

Expand Down
4 changes: 2 additions & 2 deletions experiments/integrated/performance/profile_allocations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ soilco2_type = Soil.Biogeochemistry.SoilCO2Model{FT}
soilco2_ps = SoilCO2ModelParameters(FT; ν = soil_ν)

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

# Set the soil CO2 BC to being atmospheric CO2
soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
Expand All @@ -240,7 +240,7 @@ soilco2_boundary_conditions = (; top = soilco2_top_bc, bottom = soilco2_bot_bc)

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
)

Expand Down
4 changes: 2 additions & 2 deletions experiments/standalone/Biogeochemistry/experiment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ for (FT, tf) in ((Float32, 2 * dt), (Float64, tf))
)

# Make biogeochemistry model args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

co2_parameters = Soil.Biogeochemistry.SoilCO2ModelParameters(FT; ν = 0.556)
C = FT(100)
Expand Down Expand Up @@ -105,7 +105,7 @@ for (FT, tf) in ((Float32, 2 * dt), (Float64, tf))

soil_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
atmos,
)

Expand Down
4 changes: 2 additions & 2 deletions lib/ClimaLandSimulations/src/Fluxnet/run_fluxnet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function run_fluxnet(
)

# soil microbes args
Csom = (z, t) -> eltype(z)(5.0)
Csom = ClimaLand.PrescribedSoilOrganicCarbon{FT}(TimeVaryingInput((t) -> 5))

soilco2_top_bc = Soil.Biogeochemistry.AtmosCO2StateBC()
soilco2_bot_bc = Soil.Biogeochemistry.SoilCO2FluxBC((p, t) -> 0.0) # no flux
Expand All @@ -74,7 +74,7 @@ function run_fluxnet(

soilco2_drivers = Soil.Biogeochemistry.SoilDrivers(
Soil.Biogeochemistry.PrognosticMet{FT}(),
Soil.Biogeochemistry.PrescribedSOC{FT}(Csom),
Csom,
drivers.atmos,
)

Expand Down
6 changes: 5 additions & 1 deletion src/integrated/soil_canopy_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -590,5 +590,9 @@ end


function ClimaLand.get_drivers(model::SoilCanopyModel)
return (model.canopy.atmos, model.canopy.radiation)
return (
model.canopy.atmos,
model.canopy.radiation,
model.soilco2.driver.soc,
)
end
4 changes: 2 additions & 2 deletions src/integrated/soil_energy_hydrology_biogeochemistry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ function ClimaLand.get_drivers(model::LandSoilBiogeochemistry)
<:AbstractRadiativeDrivers,
<:Soil.AbstractRunoffModel,
}
return (bc.atmos, bc.radiation)
return (bc.atmos, bc.radiation, model.soilco2.driver.soc)
else
return (model.soilco2.driver.atmos, nothing)
return (model.soilco2.driver.atmos, model.soilco2.driver.soc)
end
end
50 changes: 50 additions & 0 deletions src/shared_utilities/drivers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export AbstractAtmosphericDrivers,
AbstractRadiativeDrivers,
PrescribedAtmosphere,
PrescribedPrecipitation,
PrescribedSoilOrganicCarbon,
CoupledAtmosphere,
PrescribedRadiativeFluxes,
CoupledRadiativeFluxes,
Expand Down Expand Up @@ -48,6 +49,21 @@ An abstract type of radiative drivers of land models.
abstract type AbstractRadiativeDrivers{FT} <: AbstractClimaLandDrivers{FT} end


"""
PrescribedSoilOrganicCarbon{FT}
A type for prescribing soil organic carbon.
$(DocStringExtensions.FIELDS)
"""
struct PrescribedSoilOrganicCarbon{FT, SOC <: AbstractTimeVaryingInput} <:
AbstractClimaLandDrivers{FT}
"Soil organic carbon, function of time and space: kg C/m^3"
soc::SOC
end

PrescribedSoilOrganicCarbon{FT}(soc) where {FT} =
PrescribedSoilOrganicCarbon{FT, typeof(soc)}(soc)

"""
PrescribedAtmosphere{FT, CA, DT} <: AbstractAtmosphericDrivers{FT}
Expand Down Expand Up @@ -766,6 +782,28 @@ function initialize_drivers(r::PrescribedRadiativeFluxes{FT}, coords) where {FT}
return vars.drivers
end

"""
initialize_drivers(r::PrescribedSoilOrganicCarbon{FT}, coords) where {FT}
Creates and returns a NamedTuple for the `PrescribedSoilOrganicCarbon` driver,
with variable `soc`.
"""
function initialize_drivers(
r::PrescribedSoilOrganicCarbon{FT},
coords,
) where {FT}
keys = (:soc,)
types = (FT,)
domain_names = (:subsurface,)
model_name = :drivers
# intialize_vars packages the variables as a named tuple,
# as part of a named tuple with `model_name` as the key.
# Here we just want the variable named tuple itself
vars =
ClimaLand.initialize_vars(keys, types, domain_names, coords, model_name)
return vars.drivers
end

"""
initialize_drivers(d::Union{AbstractClimaLandDrivers, Nothing}, coords)
Expand Down Expand Up @@ -869,3 +907,15 @@ function make_update_drivers(r::PrescribedRadiativeFluxes{FT}) where {FT}
end
return update_drivers!
end

"""
make_update_drivers(a::PrescribedSoilOrganicCarbon{FT}) where {FT}
Creates and returns a function which updates the driver variables
in the case of a PrescribedSoilOrganicCarbon.
"""
function make_update_drivers(a::PrescribedSoilOrganicCarbon{FT}) where {FT}
function update_drivers!(p, t)
evaluate!(p.drivers.soc, a.soc, t)
end
return update_drivers!
end
36 changes: 4 additions & 32 deletions src/standalone/Soil/Biogeochemistry/Biogeochemistry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ClimaLand:
export SoilCO2ModelParameters,
SoilCO2Model,
PrescribedMet,
PrescribedSOC,
PrescribedSoilOrganicCarbon,
MicrobeProduction,
SoilCO2FluxBC,
AtmosCO2StateBC,
Expand Down Expand Up @@ -290,7 +290,7 @@ $(DocStringExtensions.FIELDS)
struct SoilDrivers{
FT,
MET <: AbstractSoilDriver,
SOC <: AbstractSoilDriver,
SOC <: PrescribedSoilOrganicCarbon{FT},
ATM <: PrescribedAtmosphere{FT},
}
"Soil temperature and moisture drivers - Prescribed or Prognostic"
Expand Down Expand Up @@ -334,24 +334,6 @@ function PrescribedMet{FT}(
end


"""
PrescribedSOC <: AbstractSoilDriver
A container which holds the prescribed function for soil organic carbon
This is meant for use when running the biogeochemistry model without a soil
organic carbon model.
$(DocStringExtensions.FIELDS)
"""
struct PrescribedSOC{FT, F <: Function} <: AbstractSoilDriver
"Carbon content of soil organic matter, of the form f(z::FT, t) where FT <: AbstractFloat"
soil_organic_carbon::F
end

function PrescribedSOC{FT}(Csom) where {FT <: AbstractFloat}
return PrescribedSOC{FT, typeof(Csom)}(Csom)
end

"""
soil_temperature(driver::PrescribedMet, p, Y, t, z)
Expand All @@ -373,16 +355,6 @@ function soil_moisture(driver::PrescribedMet, p, Y, t, z)
return driver.volumetric_liquid_fraction.(z, t)
end

"""
soil_som_C(driver::PrescribedSOC, p, Y, t, z)
Returns the carbon soil organic matter (SOM) at location (z) and time (t) for the prescribed
soil case.
"""
function soil_SOM_C(driver::PrescribedSOC, p, Y, t, z)
return driver.soil_organic_carbon.(z, t)
end

"""
air_pressure(driver::PrescribedAtmosphere, t)
Expand All @@ -406,7 +378,7 @@ function ClimaLand.make_update_aux(model::SoilCO2Model)
z = model.domain.fields.z
T_soil = soil_temperature(model.driver.met, p, Y, t, z)
θ_l = soil_moisture(model.driver.met, p, Y, t, z)
Csom = soil_SOM_C(model.driver.soc, p, Y, t, z)
Csom = p.drivers.soc
P_sfc = air_pressure(model.driver.atmos, p, Y, t)
θ_w = θ_l

Expand Down Expand Up @@ -581,7 +553,7 @@ function ClimaLand.boundary_flux(
end

function ClimaLand.get_drivers(model::SoilCO2Model)
return (model.driver.atmos, nothing)
return (model.driver.atmos, model.driver.soc)
end

include("./co2_parameterizations.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/standalone/Soil/energy_hydrology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,6 @@ function ClimaLand.get_drivers(model::EnergyHydrology)
}
return (bc.atmos, bc.radiation)
else
return (nothing, nothing)
return (nothing,)
end
end
4 changes: 2 additions & 2 deletions src/standalone/Soil/rre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ function ClimaLand.get_drivers(model::RichardsModel)
<:PrescribedPrecipitation,
<:AbstractRunoffModel,
}
return (bc.precip, nothing)
return (bc.precip,)
else
return (nothing, nothing)
return (nothing,)
end
end
Loading

0 comments on commit 0166bd4

Please sign in to comment.