Skip to content

Commit eee41bc

Browse files
committed
mv Base to BEPS
1 parent e39d9ca commit eee41bc

13 files changed

+147
-135
lines changed

src/BEPS.jl

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ libbeps = path_proj("deps/libbeps.dll")
2121
# include("DataFrames.jl")
2222
# include("Ipaper.jl")
2323
# include("c2julia.jl")
24+
include("SPAC/SPAC.jl")
2425
include("DataType/DataType.jl")
2526
include("BEPS_modules.jl")
2627

src/BEPS_modules.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include("Base/Base.jl")
1+
# include("Base/Base.jl")
22
include("Param/Parameter.jl")
33

44
include("Soil/Soil.jl")

src/Base/Base.jl

-15
This file was deleted.

src/Base/helpers.jl

-75
This file was deleted.

src/DataType/DataType.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ nzero(n) = tuple(zeros(n)...) # n double zero
1111

1212

1313
include("Constant.jl")
14-
include("Leaf.jl")
14+
# include("Leaf.jl")
1515
include("CanopyLayer.jl")
1616
include("Soil.jl")
1717

src/SPAC/BEPS_helper.jl

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
## BEPS modules
3+
function update_Gw!(Gw::Leaf, Gs_new::Leaf, Ga_o, Ga_u, Gb_o, Gb_u)
4+
Gw.o_sunlit = 1.0 / (1.0 / Ga_o + 1.0 / Gb_o + 1.0 / Gs_new.o_sunlit) #conductance for water
5+
Gw.o_shaded = 1.0 / (1.0 / Ga_o + 1.0 / Gb_o + 1.0 / Gs_new.o_shaded)
6+
Gw.u_sunlit = 1.0 / (1.0 / Ga_u + 1.0 / Gb_u + 1.0 / Gs_new.u_sunlit)
7+
Gw.u_shaded = 1.0 / (1.0 / Ga_u + 1.0 / Gb_u + 1.0 / Gs_new.u_shaded)
8+
end
9+
10+
function update_Gc!(Gc::Leaf, Gs_new::Leaf, Ga_o, Ga_u, Gb_o, Gb_u)
11+
Gc.o_sunlit = 1.0 / (1.0 / Ga_o + 1.4 / Gb_o + 1.6 / Gs_new.o_sunlit) # conductance for CO2
12+
Gc.o_shaded = 1.0 / (1.0 / Ga_o + 1.4 / Gb_o + 1.6 / Gs_new.o_shaded)
13+
Gc.u_sunlit = 1.0 / (1.0 / Ga_u + 1.4 / Gb_u + 1.6 / Gs_new.u_sunlit)
14+
Gc.u_shaded = 1.0 / (1.0 / Ga_u + 1.4 / Gb_u + 1.6 / Gs_new.u_shaded)
15+
end
16+

src/DataType/Leaf.jl renamed to src/SPAC/Leaf.jl

-15
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,3 @@ function multiply!(Z::Leaf, X::Leaf, Y::Leaf)
6363
Z.u_sunlit = X.u_sunlit * Y.u_sunlit
6464
Z.u_shaded = X.u_shaded * Y.u_shaded
6565
end
66-
67-
68-
function update_Gw!(Gw::Leaf, Gs_new::Leaf, Ga_o, Ga_u, Gb_o, Gb_u)
69-
Gw.o_sunlit = 1.0 / (1.0 / Ga_o + 1.0 / Gb_o + 1.0 / Gs_new.o_sunlit) #conductance for water
70-
Gw.o_shaded = 1.0 / (1.0 / Ga_o + 1.0 / Gb_o + 1.0 / Gs_new.o_shaded)
71-
Gw.u_sunlit = 1.0 / (1.0 / Ga_u + 1.0 / Gb_u + 1.0 / Gs_new.u_sunlit)
72-
Gw.u_shaded = 1.0 / (1.0 / Ga_u + 1.0 / Gb_u + 1.0 / Gs_new.u_shaded)
73-
end
74-
75-
function update_Gc!(Gc::Leaf, Gs_new::Leaf, Ga_o, Ga_u, Gb_o, Gb_u)
76-
Gc.o_sunlit = 1.0 / (1.0 / Ga_o + 1.4 / Gb_o + 1.6 / Gs_new.o_sunlit) # conductance for CO2
77-
Gc.o_shaded = 1.0 / (1.0 / Ga_o + 1.4 / Gb_o + 1.6 / Gs_new.o_shaded)
78-
Gc.u_sunlit = 1.0 / (1.0 / Ga_u + 1.4 / Gb_u + 1.6 / Gs_new.u_sunlit)
79-
Gc.u_shaded = 1.0 / (1.0 / Ga_u + 1.4 / Gb_u + 1.6 / Gs_new.u_shaded)
80-
end

src/SPAC/SPAC.jl

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using DocStringExtensions: TYPEDFIELDS
2+
using DataFrames: DataFrame
3+
4+
# include("../SPAC/SPAC.jl")
5+
6+
export s_coszs, lai2, VCmax
7+
export fill_meteo!, meteo_pack_jl
8+
export snow_density
9+
10+
include("Leaf.jl")
11+
include("list.jl")
12+
include("lai2.jl")
13+
include("VCmax.jl")
14+
include("snow_density.jl")
15+
include("helper.jl")
16+
include("BEPS_helper.jl")
17+
18+
"""
19+
s_coszs(jday::Int, j::Int, lat::Float64, lon::Float64)
20+
21+
# Example
22+
```julia
23+
jday, hour, lat, lon = 20, 12, 20., 120.
24+
s_coszs(jday, hour, lat, lon)
25+
```
26+
"""
27+
function s_coszs(jday::Int, hour::Int, lat::Float64, lon::Float64)
28+
Delta = 0.006918 - 0.399912 * cos(jday * 2π / 365.0) + 0.070257 * sin(jday * 2π / 365.0) -
29+
0.006758 * cos(jday * 4π / 365.0) + 0.000907 * sin(jday * 4π / 365.0)
30+
# delta is the declination angle of sun.
31+
32+
hr = hour + lon / 15.0 # UTC time
33+
# hr =j*24.0/RTIMES; # local time
34+
hr > 24 && (hr = hr - 24)
35+
hr < 0 && (hr = 24 + hr)
36+
37+
Lat_arc = π * lat / 180.0
38+
Hsolar1 = (hr - 12.0) * 2.0 * π / 24.0 # local hour angle in arc.
39+
40+
# sin(h)
41+
CosZs = cos(Delta) * cos(Lat_arc) * cos(Hsolar1) + sin(Delta) * sin(Lat_arc)
42+
return CosZs
43+
end
44+
45+
function meteo_pack_jl(Ta::FT, RH::FT) where {FT<:Real}
46+
ρₐ::FT = 1.292 # ρ_air, kg/m3
47+
es::FT = cal_es(Ta)
48+
ea::FT = es * RH / 100
49+
VPD::FT = es - ea
50+
51+
q::FT = ea2q(ea)
52+
cp::FT = cal_cp(q)
53+
54+
λ::FT = cal_lambda(Ta)
55+
Δ::FT = cal_slope(Ta) # slope of es
56+
γ::FT = 0.066 # kPa/K,
57+
# lambda = cal_lambda(Ta) # J kg-1
58+
# psy = cp * 101.13 / (0.622 * lambda)
59+
(; ρₐ, cp, VPD, λ, Δ, γ, es, ea, q)
60+
end

src/Base/VCmax.jl renamed to src/SPAC/VCmax.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# VCmax25 = 62.5 # maximum capacity of Rubisco at 25C-VCmax
44
# N_leaf = 3.10 + 1.35 # leaf Nitrogen content mean value + 1 SD g/m2
55
# slope = 20.72 / 62.5 # slope of VCmax-N curve
6-
function VCmax(lai::FT, Ω::FT, CosZs::FT, VCmax25::FT, N_leaf::FT, slope::FT)
6+
function VCmax(lai::FT, Ω::FT, CosZs::FT, VCmax25::FT, N_leaf::FT, slope::FT) where {FT<:Real}
77
CosZs <= 0 && return 0.0, 0.0 # 光合仅发生在白天
88
K = 0.5 * Ω / CosZs # assuming a spherical leaf angle distribution
99
Kn = 0.3 # 0.713/2.4

src/SPAC/helper.jl

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# pow = ^
2+
# pow(x::FT, y)::FT where {FT<:Real} = x^y
3+
pow(x, y) = x^y
4+
5+
function blackbody(T::FT) where {FT<:Real}
6+
σ = 5.67 / 100000000 # stephen-boltzman constant
7+
σ * (T + 273.15)^4
8+
end
9+
10+
function cal_Rln(emiss::FT, T::FT) where {FT<:Real}
11+
emiss * blackbody(T)
12+
end
13+
14+
# kPa deg-1
15+
function cal_slope(Ta::FT)::FT where {FT<:Real}
16+
2503.0 / pow((Ta + 237.3), 2) * exp(17.27 * Ta / (Ta + 237.3))
17+
end
18+
19+
# kPa
20+
function cal_es(Ta::FT)::FT where {FT<:Real}
21+
0.61078 * exp(17.3 * Ta / (237.3 + Ta))
22+
end
23+
24+
function cal_ea(Ta::FT, RH::FT)::FT where {FT<:Real}
25+
cal_es(Ta) * RH / 100
26+
end
27+
28+
function cal_lambda(Ta::FT)::FT where {FT<:Real}
29+
(2.501 - 0.00237 * Ta) * 1000000
30+
end
31+
32+
function ea2q(ea::FT, Pa::FT=101.35)::FT where {FT<:Real}
33+
0.622 * ea / (Pa - 0.378 * ea)
34+
end
35+
36+
function RH2q(Ta::FT, RH::FT)::FT where {FT<:Real}
37+
es = cal_es(Ta)
38+
ea = es * RH / 100
39+
ea2q(ea)
40+
end
41+
42+
"""
43+
# Arguments
44+
- `q` : specific humidity, g / kg
45+
- `tem`: air temperature, ℃
46+
"""
47+
function q2RH(q::FT, tem::FT)::FT where {FT<:Real}
48+
# Vapour pressure in mbar
49+
ea = 0.46 * q * (tem + 273.16) / 100
50+
es = 6.1078 * exp((17.269 * tem) / (237.3 + tem))
51+
clamp(ea / es * 100, 0.0, 100.0)
52+
end
53+
54+
55+
function cal_cp(q::FT)::FT where {FT<:Real}
56+
1004.65 * (1 + 0.84 * q)
57+
end
58+
59+
function cal_cp(Ta::FT, RH::FT)::FT where {FT<:Real}
60+
q = RH2q(Ta, RH)
61+
cal_cp(q)
62+
end
63+
64+
export pow, cal_ea, cal_es,
65+
cal_slope, cal_lambda, cal_cp, ea2q, RH2q,
66+
cal_Rln,
67+
blackbody

src/Base/lai2.jl renamed to src/SPAC/lai2.jl

-27
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,3 @@ function partition_lai(lai, Ω, CosZs)
3434
sunlit, shaded
3535
end
3636

37-
38-
"""
39-
s_coszs(jday::Int, j::Int, lat::Float64, lon::Float64)
40-
41-
# Example
42-
```julia
43-
jday, hour, lat, lon = 20, 12, 20., 120.
44-
s_coszs(jday, hour, lat, lon)
45-
```
46-
"""
47-
function s_coszs(jday::Int, hour::Int, lat::Float64, lon::Float64)
48-
Delta = 0.006918 - 0.399912 * cos(jday * 2π / 365.0) + 0.070257 * sin(jday * 2π / 365.0) -
49-
0.006758 * cos(jday * 4π / 365.0) + 0.000907 * sin(jday * 4π / 365.0)
50-
# delta is the declination angle of sun.
51-
52-
hr = hour + lon / 15.0 # UTC time
53-
# hr =j*24.0/RTIMES; # local time
54-
hr > 24 && (hr = hr - 24)
55-
hr < 0 && (hr = 24 + hr)
56-
57-
Lat_arc = π * lat / 180.0
58-
Hsolar1 = (hr - 12.0) * 2.0 * π / 24.0 # local hour angle in arc.
59-
60-
# sin(h)
61-
CosZs = cos(Delta) * cos(Lat_arc) * cos(Hsolar1) + sin(Delta) * sin(Lat_arc)
62-
return CosZs
63-
end
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)