Skip to content

Commit

Permalink
photosynthesis_jl passed test
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Oct 13, 2024
1 parent 9e9ef75 commit 31e2d08
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BEPS"
uuid = "28258c4d-138d-4793-867a-264e32c782b1"
authors = ["Dongdong Kong <[email protected]>"]
version = "0.1.3"
version = "0.1.5"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
11 changes: 10 additions & 1 deletion src/photosynthesis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ since transfer is going on only one side of a leaf.
(2PPFD < 1) && (PPFD = 0.0)
T_leaf_K = T_leaf + 273.13

λ = LAMBDA(T_leaf_p) # [J kg-1], ~2.5MJ kg-1
λ = leaf_lambda(T_leaf_p) # [J kg-1], ~2.5MJ kg-1
rᵥ = 1.0 / gb_w

ρₐ = cal_rho_a(T_leaf, ea) # [kg m-3]
Expand Down Expand Up @@ -133,6 +133,15 @@ end
exp(tprime * eact / (tref * rugc * t_lk))
end

function leaf_lambda(TK::T)::T where {T<:Real}
y = 3149_000.0 - 2370.0 * TK # J kg-1
# add heat of fusion for melting ice
if TK < 273.0
y += 333.0 # TODO: unit error, `y += 333_000.0`
end
return y
end

"""
If `Wj` or `Wc` are less than Rd then A would probably be less than 0. This
would yield a negative stomatal conductance.
Expand Down
9 changes: 0 additions & 9 deletions src/photosynthesis_helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ end
return rh
end

function LAMBDA(TK::T)::T where {T<:Real}
y = 3149000.0 - 2370.0 * TK # J kg-1
# add heat of fusion for melting ice
if TK < 273.0
y += 333.0 # TODO: unit error, `y += 333_000.0`
end
return y
end

# Function to calculate saturation vapor pressure function in mb
@fastmath function ES(t::T)::T where {T<:Real}
if t > 0.0
Expand Down
18 changes: 0 additions & 18 deletions test/debug-photo.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@

```{julia}
using Test
temp_leaf_p = 16.0
rad_leaf = 378.15760935295305
e_air = 0.9879918003910609
g_lb_w = 0.025
vc_opt = 124.13532190023277
f_soilwater = 0.9514687124755321
b_h2o = 0.0175
m_h2o = 8.0
cii = 266.0
temp_leaf_c = 16.5
LH_leaf = 68.04830184404008
r1 = photosynthesis_c(temp_leaf_p, rad_leaf, e_air, g_lb_w, vc_opt, f_soilwater, b_h2o, m_h2o, cii, temp_leaf_c, LH_leaf)
r2 = photosynthesis_jl(temp_leaf_p, rad_leaf, e_air, g_lb_w, vc_opt, f_soilwater, b_h2o, m_h2o, cii, temp_leaf_c, LH_leaf)
@test maximum(abs.(r1 .- r2)) <= 1e-10
```

# `sensible_heat`
Expand Down
30 changes: 30 additions & 0 deletions test/modules/test-photosynthesis.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@testset "photosynthesis_jl" begin
ea = 0.9879918003910609 # kPa
gb_w = 0.60 # m s-1
VCmax25 = 124.13532190023277 # μmol m-2 s-1

β_soil = 0.9514687124755321
g0_w = 0.0175
g1_w = 8.0

cii = 266.0
LH_leaf = 68.04830184404008

## 白天
Tleaf = 16.0
Tleaf_c = 16.5
Rs_leaf = 378.15760935295305

r1 = clang.photosynthesis_c(Tleaf, Rs_leaf, ea, gb_w, VCmax25, β_soil, g0_w, g1_w, cii, temp_leaf_c, LH_leaf)
r2 = photosynthesis_jl(Tleaf, Rs_leaf, ea, gb_w, VCmax25, β_soil, g0_w, g1_w, cii, temp_leaf_c, LH_leaf)
@test all(isapprox.(r1, r2, rtol=1e-7))

## 夜间
Tleaf = 16.0
Tleaf_c = 16.5
Rs_leaf = 0.0

r1 = clang.photosynthesis_c(Tleaf, Rs_leaf, ea, gb_w, VCmax25, β_soil, g0_w, g1_w, cii, temp_leaf_c, LH_leaf)
r2 = photosynthesis_jl(Tleaf, Rs_leaf, ea, gb_w, VCmax25, β_soil, g0_w, g1_w, cii, temp_leaf_c, LH_leaf)
@test maximum(abs.(r1 .- r2)) <= 1e-6
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using BEPS
using BEPS: path_proj

include("modules/test-snowpack.jl")
include("modules/test-photosynthesis.jl")

# include("test-beps_main.jl")
include("test-clang.jl")
include("test-soil.jl")

0 comments on commit 31e2d08

Please sign in to comment.