Skip to content

Commit

Permalink
add InterTempLeafs
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Jan 16, 2024
1 parent db6c78c commit b929e96
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 33 deletions.
71 changes: 69 additions & 2 deletions src/DataType/InterTempVars.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@
export InterTempLeafs

@with_kw mutable struct InterTempLeafs
x0::Float64 = 0.0
Cc_new::Leaf = Leaf(x0)
Cs_old::Leaf = Leaf(x0)
Cs_new::Leaf = Leaf(x0)
Ci_old::Leaf = Leaf(x0)
Tc_old::Leaf = Leaf(x0)
Tc_new::Leaf = Leaf(x0)
Gs_old::Leaf = Leaf(x0)

# to the reference height above the canopy
Gc::Leaf = Leaf(x0) # total conductance for CO2 from the intercellular space of the leaves
Gh::Leaf = Leaf(x0) # total conductance for heat transfer from the leaf surface
Gw::Leaf = Leaf(x0) # total conductance for water from the intercellular space of the leaves
Gww::Leaf = Leaf(x0) # total conductance for water from the surface of the leaves

Gs_new::Leaf = Leaf(x0)
Ac::Leaf = Leaf(x0)
Ci_new::Leaf = Leaf(x0)

Rn::Leaf = Leaf(x0)
Rns::Leaf = Leaf(x0)
Rnl::Leaf = Leaf(x0)

leleaf::Leaf = Leaf(x0)
GPP::Leaf = Leaf(x0)
LAI::Leaf = Leaf(x0)
PAI::Leaf = Leaf(x0)
end

InterTempLeafs(x0) = InterTempLeafs(; x0)

function reset!(l::InterTempLeafs)
# reset!(l.Cc_new)
# reset!(l.Cs_old)
# reset!(l.Cs_new)
# reset!(l.Ci_old)
# reset!(l.Tc_old)
# reset!(l.Tc_new)
# reset!(l.Gs_old)
# reset!(l.Gc)
# reset!(l.Gh)
# reset!(l.Gw)
# reset!(l.Gww)
# reset!(l.Gs_new)
# reset!(l.Ac)
# reset!(l.Ci_new)
# reset!(l.Rn)
# reset!(l.Rns)
# reset!(l.Rnl)
# reset!(l.leleaf)
# reset!(l.GPP)
# reset!(l.LAI)
# reset!(l.PAI)

# names = fieldnames(InterTempLeafs)[2:end]
# for name in names
# x = getfield(l, name)
# reset(x)
# end
end



@with_kw mutable struct InterTempVars
Tc_u::Vector{FT} = zeros(MAX_Loop)
Ts0::Vector{FT} = zeros(MAX_Loop)
Expand Down Expand Up @@ -36,10 +102,12 @@
lambda_snow::Vector{FT} = zeros(MAX_Loop)

# 记录土壤温度

Cs::Matrix{FT} = zeros(layer + 2, MAX_Loop)
Tm::Matrix{FT} = zeros(layer + 2, MAX_Loop)
G::Matrix{FT} = zeros(layer + 2, MAX_Loop)

# Leafs
TempLeafs::InterTempLeafs = InterTempLeafs(0.0)
end

function init_vars!(x::InterTempVars)
Expand All @@ -66,7 +134,6 @@ function init_vars!(x::InterTempVars)

# x.Ac_snow_o .= 0.
# x.Ac_snow_u .= 0.

# x.alpha_v_sw .= 0.
# x.alpha_n_sw .= 0.
# x.r_rain_g .= 0.
Expand Down
10 changes: 10 additions & 0 deletions src/DataType/Leaf.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export @reset, reset!
macro reset(x)
quote
reset!($(esc(x)))
end
end

@with_kw mutable struct Leaf
o_sunlit::Cdouble = 0.0
o_shaded::Cdouble = 0.0
Expand Down Expand Up @@ -26,6 +33,8 @@ for (m, f) in Base_ops
end


reset!(x::Leaf) = init_leaf_dbl(x, 0.0)

function init_leaf_struct(x::Leaf, replacement::Leaf)
x.o_sunlit = replacement.o_sunlit
x.o_shaded = replacement.o_shaded
Expand All @@ -39,6 +48,7 @@ function init_leaf_dbl(x::Leaf, replacement::Float64)
x.o_shaded = replacement
x.u_sunlit = replacement
x.u_shaded = replacement
nothing
# ccall((:init_leaf_dbl, libbeps), Cvoid, (Ptr{Leaf}, Cdouble), Ref(x), replacement)
end

Expand Down
40 changes: 9 additions & 31 deletions src/beps_inter_prg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,15 @@ function inter_prg_jl(
# var = var2
# var = InterTempVars()
init_vars!(var)

reset!(var.TempLeafs)

@unpack Cc_new, Cs_old, Cs_new, Ci_old,
Tc_old, Tc_new, Gs_old, Gc, Gh, Gw, Gww,
Gs_new, Ac, Ci_new, Rn, Rns, Rnl,
leleaf, GPP, LAI, PAI = var.TempLeafs
d_soil = zeros(layer + 1)
lambda = zeros(layer + 2)

Cc_new = Leaf()
Cs_old = Leaf()
Cs_new = Leaf()
Ci_old = Leaf()
Tc_old = Leaf()
Tc_new = Leaf()
Gs_old = Leaf()

# to the reference height above the canopy
Gc = Leaf() # total conductance for CO2 from the intercellular space of the leaves
Gh = Leaf() # total conductance for heat transfer from the leaf surface
Gw = Leaf() # total conductance for water from the intercellular space of the leaves
Gww = Leaf() # total conductance for water from the surface of the leaves

Gs_new = Leaf()
Ac = Leaf()
Ci_new = Leaf()

Rn = Leaf()
Rns = Leaf()
Rnl = Leaf()

leleaf = Leaf()
GPP = Leaf()

ra_o = 0.0
ra_u = 0.0
ra_g = 0.0
Expand Down Expand Up @@ -120,8 +100,6 @@ function inter_prg_jl(
stem_u = param[9+1] * 0.2 # parameter[9].LAI max understory

# lai2: separate lai into sunlit and shaded portions
LAI = Leaf()
PAI = Leaf()
lai2(clumping, CosZs, stem_o, stem_u, lai_o, lai_u, LAI, PAI)

# /***** Initialization of this time step *****/
Expand Down Expand Up @@ -210,8 +188,8 @@ function inter_prg_jl(
init_leaf_dbl(Ci_old, 0.7 * CO2_air)
init_leaf_dbl2(Gs_old, 1.0 / 200.0, 1.0 / 300.0)

percentArea_snow_o = var.Ac_snow_o[kkk] / lai_o / 2
percentArea_snow_u = var.Ac_snow_u[kkk] / lai_u / 2
percArea_snow_o = var.Ac_snow_o[kkk] / lai_o / 2
percArea_snow_u = var.Ac_snow_u[kkk] / lai_u / 2

temp_grd = Ta # ground temperature substituted by air temperature

Expand Down Expand Up @@ -239,7 +217,7 @@ function inter_prg_jl(
radiation_o, radiation_u, radiation_g = netRadiation_jl(Ks, CosZs, Tco, Tcu, temp_grd,
lai_o, lai_u, lai_o + stem_o, lai_u + stem_u, PAI,
clumping, Ta, rh_air, var.alpha_v_sw[kkk], var.alpha_n_sw[kkk],
percentArea_snow_o, percentArea_snow_u,
percArea_snow_o, percArea_snow_u,
var.Xg_snow[kkk],
alpha_v_o, alpha_n_o, alpha_v_u, alpha_n_u,
alpha_v_g, alpha_n_g, Rn, Rns, Rnl, Ra)
Expand Down

0 comments on commit b929e96

Please sign in to comment.