Skip to content

Commit e3d0422

Browse files
committed
Merge branch 'main' of github.com:EarthyScience/Bigleaf.jl
2 parents 37c5b51 + dafc166 commit e3d0422

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/surface_roughness.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,26 @@ rp = roughness_parameters(Roughness_wind_profile(),df;zh,zr=40,d=0.8*zh)
146146
≈(rp.z0m, 0.55, rtol=0.1)
147147
# output
148148
true
149-
```
150-
"""
151-
function roughness_parameters(::RoughnessCanopyHeight, zh; frac_d=0.7, frac_z0m=0.1)
149+
```
150+
"""
151+
function roughness_parameters(::RoughnessCanopyHeight, zh::FT;
152+
frac_d=FT(0.7), frac_z0m=FT(0.1)) where FT
152153
d = frac_d*zh
153154
z0m = frac_z0m*zh
154155
z0m_se = missing
155156
(;d, z0m, z0m_se)
156157
end
157158

158-
function roughness_parameters(::RoughnessCanopyHeightLAI, zh, LAI;
159-
cd=0.2, hs=0.01)
159+
function roughness_parameters(::RoughnessCanopyHeightLAI, zh::FT, LAI;
160+
cd=FT(0.2), hs=FT(0.01)) where FT
160161
X = cd * LAI
161-
d = 1.1 * zh * log(1 + X^(1/4))
162-
z0m = ifelse(0 <= X <= 0.2, hs + 0.3 * X^(1/2), 0.3 * zh * (1 - d/zh))
162+
d = FT(1.1) * zh * log(1 + X^FT(1/4))
163+
z0m = ifelse(0 <= X <= FT(0.2), hs + FT(0.3) * X^(1/2), FT(0.3) * zh * (1 - d/zh))
163164
z0m_se = missing
164165
(;d, z0m, z0m_se)
165166
end
166167

167-
function roughness_parameters(::Roughness_wind_profile, ustar::AbstractVector{FT}, wind, psi_m;
168+
function roughness_parameters(::Roughness_wind_profile, ustar::AbstractVector{FT}, wind, psi_m;
168169
zh, zr, d = 0.7*zh, constants=BigleafConstants()
169170
) where FT
170171
FT == Missing && return((d = d, z0m = missing, z0m_se = missing))

src/unit_conversions.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ function Esat_slope(Tair::Number; Esat_formula=Sonntag1990(), constants=BigleafC
6060
Delta = Esat_from_Tair_deriv(Tair; Esat_formula, constants)
6161
Esat, Delta
6262
end,
63-
function Esat_from_Tair(Tair; Esat_formula=Sonntag1990(), constants=BigleafConstants())
64-
a,b,c = get_EsatCoef(Esat_formula)
65-
Esat = a * exp((b * Tair) / (c + Tair)) * constants.Pa2kPa
63+
function Esat_from_Tair(Tair::FT; Esat_formula=Sonntag1990(), constants=BigleafConstants()) where FT
64+
a,b,c = map(x -> convert(FT,x), get_EsatCoef(Esat_formula))
65+
Esat = a * exp((b * Tair) / (c + Tair)) * FT(constants.Pa2kPa)
6666
end,
67-
function Esat_from_Tair_deriv(Tair; Esat_formula=Sonntag1990(), constants=BigleafConstants())
67+
function Esat_from_Tair_deriv(Tair::FT; Esat_formula=Sonntag1990(), constants=BigleafConstants()) where FT
6868
# slope of the saturation vapor pressure curve
6969
#Delta = eval(D(expression(a * exp((b * Tair) / (c + Tair))),name="Tair"))
70-
a,b,c = get_EsatCoef(Esat_formula)
70+
a,b,c = map(x -> convert(FT,x), get_EsatCoef(Esat_formula))
7171
#Delta_Pa = @. a*(b / (Tair + c) + (-Tair*b) / ((Tair + c)^2))*exp((Tair*b) / (Tair + c))
72-
Delta_Pa = @. a * (exp((b * Tair)/(c + Tair)) * (b/(c + Tair) - (b * Tair)/(c + Tair)^2))
73-
Delta = Delta_Pa .* constants.Pa2kPa
72+
Delta_Pa = a * (exp((b * Tair)/(c + Tair)) * (b/(c + Tair) - (b * Tair)/(c + Tair)^2))
73+
Delta = Delta_Pa .* FT(constants.Pa2kPa)
7474
end
7575

7676
get_EsatCoef(::Sonntag1990) = (a=611.2,b=17.62,c=243.12)
@@ -145,12 +145,12 @@ true
145145
"""
146146
function ms_to_mol(G_ms,Tair,pressure; constants=BigleafConstants())
147147
Tair = Tair + oftype(Tair,constants.Kelvin)
148-
pressure = pressure * constants.kPa2Pa
148+
pressure = pressure * oftype(Tair, constants.kPa2Pa)
149149
G_mol = G_ms * pressure / (oftype(Tair, constants.Rgas) * Tair)
150150
end,
151151
function mol_to_ms(G_mol,Tair,pressure; constants=BigleafConstants())
152152
Tair = Tair + oftype(Tair,constants.Kelvin)
153-
pressure = pressure * constants.kPa2Pa
153+
pressure = pressure * oftype(Tair, constants.kPa2Pa)
154154
G_ms = G_mol * (oftype(Tair, constants.Rgas) * Tair) / (pressure)
155155
end
156156

test/unit_conversions_test.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Bigleaf, Test
22

33
@testset "Esat_from_Tair" begin
4-
Tair = 15
4+
Tair = 15.0
55
Esat_formula=Sonntag1990()
66
constants=BigleafConstants()
77
eSat = Esat_from_Tair(Tair; Esat_formula, constants)
@@ -25,7 +25,7 @@ end
2525
constants=BigleafConstants()
2626
Esat = Esat_from_Tair.(Tair)
2727
delta = Esat_from_Tair_deriv.(Tair)
28-
delta2 = diff(Esat)/step
28+
delta2 = diff(Esat)/step
2929
@test all(isapprox.(delta[2:end] - delta2, 0, atol=1e-3))
3030
Esat3, delta3 = Esat_slope(Tair[1])
3131
@test Esat3 Esat[1]

0 commit comments

Comments
 (0)