Skip to content

Commit

Permalink
fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kmdeck committed Nov 13, 2024
1 parent 9b73ade commit 35279cc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 37 deletions.
40 changes: 32 additions & 8 deletions src/diagnostics/land_compute_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,38 @@ end
@diagnostic_compute "vcmax25" Union{SoilCanopyModel, LandModel} p.canopy.photosynthesis.Vcmax25

# Canopy - Radiative Transfer
@diagnostic_compute "near_infrared_radiation_down" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.nir_d
@diagnostic_compute "near_infrared_radiation_absorbed" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.nir.abs
@diagnostic_compute "near_infrared_radiation_reflected" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.nir.refl
@diagnostic_compute "near_infrared_radiation_transmitted" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.nir.trans
@diagnostic_compute "photosynthetically_active_radiation_down" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.par_d
@diagnostic_compute "photosynthetically_active_radiation_absorbed" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.par.abs
@diagnostic_compute "photosynthetically_active_radiation_reflected" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.par.refl
@diagnostic_compute "photosynthetically_active_radiation_transmitted" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.par.trans
@diagnostic_compute "near_infrared_radiation_down" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.nir_d
@diagnostic_compute "near_infrared_radiation_absorbed" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.nir.abs
@diagnostic_compute "near_infrared_radiation_reflected" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.nir.refl
@diagnostic_compute "near_infrared_radiation_transmitted" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.nir.trans
@diagnostic_compute "photosynthetically_active_radiation_down" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.par_d
@diagnostic_compute "photosynthetically_active_radiation_absorbed" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.par.abs
@diagnostic_compute "photosynthetically_active_radiation_reflected" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.par.refl
@diagnostic_compute "photosynthetically_active_radiation_transmitted" Union{
SoilCanopyModel,
LandModel,
} p.canopy.radiative_transfer.par.trans
@diagnostic_compute "radiation_longwave_net" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.LW_n
@diagnostic_compute "radiation_shortwave_net" Union{SoilCanopyModel, LandModel} p.canopy.radiative_transfer.SW_n

Expand Down
47 changes: 18 additions & 29 deletions src/integrated/land.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,23 +385,20 @@ function lsm_radiant_energy_fluxes!(
= LP.Stefan(earth_param_set)
LW_d = p.drivers.LW_d
SW_d = p.drivers.SW_d
c = LP.light_speed(earth_param_set)
h = LP.planck_constant(earth_param_set)
N_a = LP.avogadro_constant(earth_param_set)
(; λ_γ_PAR, λ_γ_NIR) = canopy_radiation.parameters
energy_per_photon_PAR = h * c / λ_γ_PAR
energy_per_photon_NIR = h * c / λ_γ_NIR

T_canopy =
ClimaLand.Canopy.canopy_temperature(canopy.energy, canopy, Y, p, t)

α_soil_PAR = p.soil.PAR_albedo
α_soil_NIR = p.soil.NIR_albedo
ϵ_soil = land.soil.parameters.emissivity
T_soil = ClimaLand.Domains.top_center_to_surface(p.soil.T)

α_snow_NIR = land.snow.parameters.α_snow
α_snow_PAR = land.snow.parameters.α_snow
ϵ_snow = land.snow.parameters.ϵ_snow
T_snow = p.snow.T_sfc

# in W/m^2
LW_d_canopy = p.scratch1
LW_u_soil = p.scratch2
Expand All @@ -412,40 +409,32 @@ function lsm_radiant_energy_fluxes!(
R_net_snow = p.snow.R_n
LW_u = p.LW_u
SW_u = p.SW_u
par_d = p.canopy.radiative_transfer.par_d
nir_d = p.canopy.radiative_transfer.nir_d
f_abs_par = p.canopy.radiative_transfer.par.abs
f_abs_nir = p.canopy.radiative_transfer.nir.abs
f_refl_par = p.canopy.radiative_transfer.par.refl
f_refl_nir = p.canopy.radiative_transfer.nir.refl
f_trans_par = p.canopy.radiative_transfer.par.trans
f_trans_nir = p.canopy.radiative_transfer.nir.trans
# in total: d - u = CANOPY_ABS + (1-α_ground)*CANOPY_TRANS
# SW_u = reflected par + reflected nir
@. SW_u =
energy_per_photon_NIR * N_a * p.canopy.radiative_transfer.nir.refl +
energy_per_photon_PAR * N_a * p.canopy.radiative_transfer.par.refl
@. SW_u = par_d * f_refl_par + f_refl_nir * nir_d

# net canopy
@. SW_net_canopy =
energy_per_photon_NIR * N_a * p.canopy.radiative_transfer.nir.abs +
energy_per_photon_PAR * N_a * p.canopy.radiative_transfer.par.abs

@. SW_net_canopy = f_abs_par * par_d + f_abs_nir * nir_d

# net radiative flux for soil = -((1-α)*trans for par and nir)
@. R_net_soil .= -(
energy_per_photon_NIR *
N_a *
p.canopy.radiative_transfer.nir.trans *
(1 - α_soil_NIR) +
energy_per_photon_PAR *
N_a *
p.canopy.radiative_transfer.par.trans *
(1 - α_soil_PAR)
f_trans_nir * nir_d * (1 - α_soil_NIR) +
f_trans_par * par_d * (1 - α_soil_PAR)
)

@. R_net_snow .= -(
energy_per_photon_NIR *
N_a *
p.canopy.radiative_transfer.nir.trans *
(1 - α_snow_NIR) +
energy_per_photon_PAR *
N_a *
p.canopy.radiative_transfer.par.trans *
(1 - α_snow_PAR)
f_trans_nir * nir_d * (1 - α_snow_NIR) +
f_trans_par * par_d * (1 - α_snow_PAR)
)

ϵ_canopy = p.canopy.radiative_transfer.ϵ # this takes into account LAI/SAI

# Working through the math, this satisfies: LW_d - LW_u = LW_c + LW_soil + LW_snow
Expand Down

0 comments on commit 35279cc

Please sign in to comment.