From 21b7441a36e1c4f2e8aaffe6c452de5edb2559a4 Mon Sep 17 00:00:00 2001 From: Dongdong Kong Date: Tue, 16 Jan 2024 16:58:04 +0800 Subject: [PATCH] `Leaf_Temperature` passed --- src/BEPS/BEPS.jl | 2 ++ src/BEPS/Leaf_Temperature.jl | 29 +++++++++++++++++++++++++++++ src/beps_inter_prg.jl | 2 +- src/clang/BEPS_c.jl | 26 +++++++++++++------------- src/clang/module.jl | 17 ++++++++--------- 5 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 src/BEPS/Leaf_Temperature.jl diff --git a/src/BEPS/BEPS.jl b/src/BEPS/BEPS.jl index 8f61830..e9bce71 100644 --- a/src/BEPS/BEPS.jl +++ b/src/BEPS/BEPS.jl @@ -8,6 +8,7 @@ include("soil_thermal_regime.jl") include("latent_heat.jl") include("aerodynamic_conductance.jl") include("sensible_heat.jl") +include("Leaf_Temperature.jl") include("surface_temperature.jl") include("transpiration.jl") include("evaporation_soil.jl") @@ -19,6 +20,7 @@ export s_coszs, lai2, readparam, readcoef export aerodynamic_conductance_jl, sensible_heat_jl, latent_heat!, + Leaf_Temperatures_jl, surface_temperature_jl, transpiration_jl, evaporation_soil_jl, diff --git a/src/BEPS/Leaf_Temperature.jl b/src/BEPS/Leaf_Temperature.jl new file mode 100644 index 0000000..8ef0f83 --- /dev/null +++ b/src/BEPS/Leaf_Temperature.jl @@ -0,0 +1,29 @@ +function Leaf_Temperature_jl(Tair::Float64, Δ::Float64, γ::Float64, VPD::Float64, cp::Float64, + Gw::Float64, Gww::Float64, Gh::Float64, Xc_sl::Float64, radiation::Float64, constrain::Bool) + + ρ_a = 1.292 # ρ_air, kg/m3 + p_star = (Gw + Gww * Xc_sl) / γ + Tc = Tair + (radiation - VPD * ρ_a * cp * p_star) / (ρ_a * cp * (Gh + Δ * p_star)) + + constrain && (Tc = clamp(Tc, Tair - 3.0, Tair + 5.0)) + return Tc +end + + +function Leaf_Temperatures_jl(Tair::Float64, slope::Float64, psychrometer::Float64, VPD_air::Float64, Cp_ca::Float64, + Gw::Leaf, Gww::Leaf, Gh::Leaf, + Xcs_o::Float64, Xcl_o::Float64, Xcs_u::Float64, Xcl_u::Float64, + radiation::Leaf, Tc::Leaf) + + Tc.o_sunlit = Leaf_Temperature_jl(Tair, slope, psychrometer, VPD_air, Cp_ca, + Gw.o_sunlit, Gww.o_sunlit, Gh.o_sunlit, Xcs_o + Xcl_o, radiation.o_sunlit, true) + + Tc.o_shaded = Leaf_Temperature_jl(Tair, slope, psychrometer, VPD_air, Cp_ca, + Gw.o_shaded, Gww.o_shaded, Gh.o_shaded, Xcs_o + Xcl_o, radiation.o_shaded, true) + + Tc.u_sunlit = Leaf_Temperature_jl(Tair, slope, psychrometer, VPD_air, Cp_ca, + Gw.u_sunlit, Gww.u_sunlit, Gh.u_sunlit, Xcs_u + Xcl_u, radiation.u_sunlit, true) + + Tc.u_shaded = Leaf_Temperature_jl(Tair, slope, psychrometer, VPD_air, Cp_ca, + Gw.u_shaded, Gww.u_shaded, Gh.u_shaded, Xcs_u + Xcl_u, radiation.u_shaded, true) +end diff --git a/src/beps_inter_prg.jl b/src/beps_inter_prg.jl index b035882..fb2c78c 100644 --- a/src/beps_inter_prg.jl +++ b/src/beps_inter_prg.jl @@ -295,7 +295,7 @@ function inter_prg_jl( update_Gc!(Gc, Gs_new, Ga_o, Ga_u, Gb_o, Gb_u) # /***** Leaf temperatures module by L. He *****/ - Leaf_Temperatures(Ta, slope, gamma, VPD_air, Cp_ca, + Leaf_Temperatures_jl(Ta, slope, gamma, VPD_air, Cp_ca, Gw, Gww, Gh, var.Xcs_o[kkk], var.Xcl_o[kkk], var.Xcs_u[kkk], var.Xcl_u[kkk], Rn, Tc_new) diff --git a/src/clang/BEPS_c.jl b/src/clang/BEPS_c.jl index 707ad28..9c26975 100644 --- a/src/clang/BEPS_c.jl +++ b/src/clang/BEPS_c.jl @@ -46,6 +46,18 @@ end # function soilresp(Ccd, Cssd, Csmd, Cfsd, Cfmd, Csm, Cm, Cs, Cp, npp_yr, coef, soiltype, soilp, mid_res) # ccall((:soilresp, libbeps), Cvoid, (Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Cfloat, Ptr{Cdouble}, Cint, Ptr{Soil_c}, Ptr{Results}), Ccd, Cssd, Csmd, Cfsd, Cfmd, Csm, Cm, Cs, Cp, npp_yr, coef, soiltype, soilp, mid_res) # end +function readparam(lc::Int=1) + parameter1 = zeros(Cdouble, 48) + # readparam(short lc, double* parameter1) + ccall((:readparam, libbeps), Cvoid, (Cshort, Ptr{Cdouble}), lc, parameter1) + parameter1 +end + +function readcoef(lc::Int=1, stxt::Int=1) + coef = zeros(Cdouble, 48) + ccall((:readcoef, libbeps), Cvoid, (Cshort, Cint, Ptr{Cdouble}), lc, stxt, coef) + coef +end """ s_coszs(jday::Int, j::Int, lat::T, lon::T) where {T<:Real} @@ -80,18 +92,6 @@ function lai2(clumping, CosZs, stem_o, stem_u, lai_o, lai_u, LAI::Leaf, PAI::Lea clumping, CosZs, stem_o, stem_u, lai_o, lai_u, Ref(LAI), Ref(PAI)) end -function Leaf_Temperatures(Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, Xcs_o, Xcl_o, Xcs_u, Xcl_u, radiation::Leaf, Tc::Leaf) - ccall((:Leaf_Temperatures, libbeps), Cvoid, (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Leaf, Leaf, Leaf, Cdouble, Cdouble, Cdouble, Cdouble, Leaf, Ptr{Leaf}), - Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, - Xcs_o, Xcl_o, Xcs_u, Xcl_u, - radiation, Ref(Tc)) -end - -function Leaf_Temperature(Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, Xcs, Xcl, radiation) - ccall((:Leaf_Temperature, libbeps), Cdouble, (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), - Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, Xcs, Xcl, radiation) -end - function evaporation_canopy(tempL, temp_air, rh_air, Gwater, lai, percent_water_o, percent_water_u, percent_snow_o, percent_snow_u, evapo_water_o, evapo_water_u, evapo_snow_o, evapo_snow_u) ccall((:evaporation_canopy, libbeps), Cvoid, (Leaf, Cdouble, Cdouble, Leaf, Leaf, Cdouble, Cdouble, Cdouble, Cdouble, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}), tempL, temp_air, rh_air, Gwater, lai, percent_water_o, percent_water_u, percent_snow_o, percent_snow_u, evapo_water_o, evapo_water_u, evapo_snow_o, evapo_snow_u) end @@ -159,7 +159,7 @@ export inter_prg_c, # readcoef, # lai2, s_coszs, # latent_heat!, - Leaf_Temperatures, + # Leaf_Temperatures, evaporation_canopy, rainfall_stage1, rainfall_stage2, rainfall_stage3, snowpack_stage1, snowpack_stage2, snowpack_stage3 diff --git a/src/clang/module.jl b/src/clang/module.jl index 515d8ee..a367878 100644 --- a/src/clang/module.jl +++ b/src/clang/module.jl @@ -73,17 +73,16 @@ function evaporation_soil_c(temp_air, temp_g, rh_air, netRad_g, Gheat_g, end -function readparam(lc::Int=1) - parameter1 = zeros(Cdouble, 48) - # readparam(short lc, double* parameter1) - ccall((:readparam, libbeps), Cvoid, (Cshort, Ptr{Cdouble}), lc, parameter1) - parameter1 +function Leaf_Temperatures_c(Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, Xcs_o, Xcl_o, Xcs_u, Xcl_u, radiation::Leaf, Tc::Leaf) + ccall((:Leaf_Temperatures, libbeps), Cvoid, (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Leaf, Leaf, Leaf, Cdouble, Cdouble, Cdouble, Cdouble, Leaf, Ptr{Leaf}), + Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, + Xcs_o, Xcl_o, Xcs_u, Xcl_u, + radiation, Ref(Tc)) end -function readcoef(lc::Int=1, stxt::Int=1) - coef = zeros(Cdouble, 48) - ccall((:readcoef, libbeps), Cvoid, (Cshort, Cint, Ptr{Cdouble}), lc, stxt, coef) - coef +function Leaf_Temperature_c(Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, Xcs, Xcl, radiation) + ccall((:Leaf_Temperature, libbeps), Cdouble, (Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble), + Tair, slope, psychrometer, VPD_air, Cp_ca, Gw, Gww, Gh, Xcs, Xcl, radiation) end function aerodynamic_conductance_c(canopy_height_o::T, canopy_height_u::T,