Skip to content

Commit

Permalink
Leaf_Temperature passed
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Jan 16, 2024
1 parent 1a4b8c4 commit 21b7441
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/BEPS/BEPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions src/BEPS/Leaf_Temperature.jl
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/beps_inter_prg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions src/clang/BEPS_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
17 changes: 8 additions & 9 deletions src/clang/module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 21b7441

Please sign in to comment.