diff --git a/src/diagnostics/soilcanopy_compute_methods.jl b/src/diagnostics/soilcanopy_compute_methods.jl index 7ce1ac2582..93d08e965a 100644 --- a/src/diagnostics/soilcanopy_compute_methods.jl +++ b/src/diagnostics/soilcanopy_compute_methods.jl @@ -1,3 +1,81 @@ +macro land_compute(name, model, compute) + functions = Expr[] + function_name = Symbol("compute_", name, "!") + function_body = esc(quote + function $function_name(out, Y, p, t, land_model::$model) + if isnothing(out) + return copy($compute) + else + out .= $compute + end + end + end) + push!(functions, function_body) + return quote + $(functions...) + end +end + +# note: model can be e.g., BucketModel, SoilCanopyModel, or Union{BucketModel, SoilCanopyModel} + +@land_compute "soil_net_radiation" SoilCanopyModel p.soil.R_n +@land_compute "soil_latent_heat_flux" SoilCanopyModel p.soil.turbulent_flux.lhf +@land_compute "soil_aerodynamic_resistance" SoilCanopyModel p.soil.turbulent_fluxes.r_ae +@land_compute "soil_sensible_heat_flux" SoilCanopyModel p.soil.turbulent_fluxes.shf +@land_compute "vapor_flux" SoilCanopyModel p.soil.turbulent_fluxes.vapor_flux +@land_compute "soil_temperature" SoilCanopyModel p.soil.T +@land_compute "soil_water_liquid" SoilCanopyModel top_center_to_surface(p.soil.θ_l) +@land_compute "infiltration" SoilCanopyModel p.soil.infiltration +@land_compute "soilco2_diffusivity" SoilCanopyModel p.soilco2.D +@land_compute "soilco2_source_microbe" SoilCanopyModel p.soilco2.Sm +@land_compute "stomatal_conductance" SoilCanopyModel p.canopy.conductance.gs +@land_compute "medlyn_term" SoilCanopyModel p.canopy.conductance.medlyn_term +@land_compute "canopy_transpiration" SoilCanopyModel p.canopy.transpiration +@land_compute "rainfall" SoilCanopyModel p.drivers.P_liq +@land_compute "snowfall" SoilCanopyModel p.drivers.P_snow +@land_compute "pressure" SoilCanopyModel p.drivers.P +@land_compute "wind_speed" SoilCanopyModel p.drivers.u +@land_compute "specific_humidity" SoilCanopyModel p.drivers.q +@land_compute "air_co2" SoilCanopyModel p.drivers.c_co2 +@land_compute "radiation_shortwave_down" SoilCanopyModel p.drivers.SW_d +@land_compute "radiation_longwave_down" SoilCanopyModel p.drivers.LW_d +@land_compute "photosynthesis_net_leaf" SoilCanopyModel p.canopy.photosynthesis.An +@land_compute "photosynthesis_net_canopy" SoilCanopyModel p.canopy.photosynthesis.GPP +@land_compute "respiration_leaf" SoilCanopyModel p.canopy.photosynthesis.Rd +@land_compute "vcmax25" SoilCanopyModel p.canopy.photosynthesis.vcmax25 +@land_compute "photosynthetically_active_radiation" SoilCanopyModel p.canopy.radiative_transfer.par +@land_compute "photosynthetically_active_radiation_absorbed" SoilCanopyModel p.canopy.radiative_transfer.apar +@land_compute "photosynthetically_active_radiation_reflected" SoilCanopyModel p.canopy.radiative_transfer.rpar +@land_compute "photosynthetically_active_radiation_transmitted" SoilCanopyModel p.canopy.radiative_transfer.tpar +@land_compute "near_infrared_radiation" SoilCanopyModel p.canopy.radiative_transfer.nir +@land_compute "near_infrared_radiation_absorbed" SoilCanopyModel p.canopy.radiative_transfer.anir +@land_compute "near_infrared_radiation_reflected" SoilCanopyModel p.canopy.radiative_transfer.rnir +@land_compute "near_infrared_radiation_transmitted" SoilCanopyModel p.canopy.radiative_transfer.tnir +@land_compute "radiation_shortwave_net" SoilCanopyModel p.canopy.radiative_transfer.SW_n +@land_compute "radiation_longwave_net" SoilCanopyModel p.canopy.radiative_transfer.LW_n +@land_compute "autotrophic_respiration" SoilCanopyModel p.canopy.autotrophic_respiration.Ra +@land_compute "soilco2" SoilCanopyModel Y.soilco2.C +@land_compute "heterotrophic_respiration" SoilCanopyModel p.soilco2.top_bc +@land_compute "soil_hydraulic_conductivity" SoilCanopyModel p.soil.K +@land_compute "soil_water_potential" SoilCanopyModel p.soil.ψ +@land_compute "soil_thermal_conductivity" SoilCanopyModel p.soil.κ +@land_compute "solar_zenith_angle" SoilCanopyModel p.drivers.θs +@land_compute "moisture_stress_factor" SoilCanopyModel p.canopy.hydraulics.β +@land_compute "canopy_water_potential" SoilCanopyModel p.canopy.hydraulics.ψ +@land_compute "cross_section" SoilCanopyModel p.canopy.hydraulics +@land_compute "cross_section_roots" SoilCanopyModel p.canopy.hydraulics.fa_roots +@land_compute "area_index" SoilCanopyModel p.canopy.hydraulics.area_index.leaf +@land_compute "canopy_latent_heat_flux" SoilCanopyModel p.canopy.energy.lhf +@land_compute "canopy_sensible_heat_flux" SoilCanopyModel p.canopy.energy.shf +@land_compute "canopy_aerodynamic_resistance" SoilCanopyModel p.canopy.energy.r_ae +@land_compute "canopy_temperature" SoilCanopyModel Y.canopy.energy.T +@land_compute "soil_ice" SoilCanopyModel Y.soil.θ_i + + + + +#= + # stored in p function compute_soil_net_radiation!(out, Y, p, t, land_model::SoilCanopyModel) @@ -577,3 +655,6 @@ function compute_soil_ice!(out, Y, p, t, land_model::SoilCanopyModel) out .= top_center_to_surface(Y.soil.θ_i) end end + +=# +