Skip to content

Commit 0960bd9

Browse files
committed
test surface_temperature
1 parent 5b50d7b commit 0960bd9

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

Diff for: src/surface_temperature.jl

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
"""
2+
- cp: capacity_heat, [J kg-1 K-1]
3+
"""
14
function surface_temperature_jl(T_air::FT, rh_air::FT, depth_snow::FT, depth_water::FT,
2-
capacity_heat_soil1::FT, capacity_heat_soil0::FT, Gheat_g::FT,
5+
cp_soil1::FT, cp_soil0::FT, Gheat_g::FT,
36
depth_soil1::FT, ρ_snow::FT, tempL_u::FT, Rn_g::FT,
47
E_soil::FT, E_water_g::FT, E_snow_g::FT, λ_soil1::FT,
58
perc_snow_g::FT, G_soil1::FT,
@@ -30,7 +33,7 @@ function surface_temperature_jl(T_air::FT, rh_air::FT, depth_snow::FT, depth_wat
3033
G::FT = 0.0
3134

3235
if depth_snow <= 0.02
33-
ttt = capacity_heat_soil1 * 0.02 / length_step
36+
ttt = cp_soil1 * 0.02 / length_step
3437
T_ground = (T_ground_last * ttt * ra_g * depth_soil1 + Gg * ra_g * depth_soil1 + ρₐ * cp * T_air * depth_soil1 + ra_g * λ_soil1 * T_soil1_last) /
3538
(ρₐ * cp * depth_soil1 + ra_g * λ_soil1 + ttt * ra_g * depth_soil1)
3639
T_ground = clamp(T_ground, T_ground_last - 25, T_ground_last + 25)
@@ -45,7 +48,7 @@ function surface_temperature_jl(T_air::FT, rh_air::FT, depth_snow::FT, depth_wat
4548
G = clamp(G, -100.0, 100.0)
4649

4750
elseif depth_snow > 0.02 && depth_snow <= 0.05
48-
ttt = capacity_heat_soil1 * 0.02 / length_step # for soil fraction part
51+
ttt = cp_soil1 * 0.02 / length_step # for soil fraction part
4952

5053
T_soil0 = (T_soil0_last * ttt * ra_g * depth_soil1 + Gg * ra_g * depth_soil1 + ρₐ * cp * T_air * depth_soil1 + 2 * ra_g * λ_soil1 * T_soil1_last) /
5154
(ρₐ * cp * depth_soil1 + 2 * ra_g * λ_soil1 + ttt * ra_g * depth_soil1)
@@ -58,8 +61,8 @@ function surface_temperature_jl(T_air::FT, rh_air::FT, depth_snow::FT, depth_wat
5861

5962
T_snow = clamp(T_snow, T_air - 25.0, T_air + 25.0)
6063

61-
ttt = (λ_soil1 * T_soil1_last / depth_soil1 + T_snow * κ_snow + 0.02 * capacity_heat_soil1 / length_step * T_any0_last) /
62-
(λ_soil1 / depth_soil1 + κ_snow / depth_snow + 0.02 * capacity_heat_soil1 / length_step)
64+
ttt = (λ_soil1 * T_soil1_last / depth_soil1 + T_snow * κ_snow + 0.02 * cp_soil1 / length_step * T_any0_last) /
65+
(λ_soil1 / depth_soil1 + κ_snow / depth_snow + 0.02 * cp_soil1 / length_step)
6366
T_any0 = T_soil0 * (1 - perc_snow_g) + ttt * perc_snow_g
6467

6568
G_snow = κ_snow / (depth_snow + 0.5 * depth_soil1) * (T_snow - T_soil1_last)
@@ -98,7 +101,7 @@ function surface_temperature_jl(T_air::FT, rh_air::FT, depth_snow::FT, depth_wat
98101
G_snow2 = (T_snow2_last - T_any0_last) / ((0.5 * (depth_snow - 0.04) / κ_snow) + (0.02 / λ_soil1))
99102
T_snow2 = T_snow2_last + ((G_snow1 - G_snow2) / (cp_ice * ρ_snow * (depth_snow - 0.04))) * length_step
100103

101-
T_any0 = T_any0_last + ((G_snow2 - G_soil1) / (capacity_heat_soil0 * 0.02)) * length_step
104+
T_any0 = T_any0_last + ((G_snow2 - G_soil1) / (cp_soil0 * 0.02)) * length_step
102105
T_soil0 = T_any0
103106

104107
if T_snow > 0.0 && T_snow_last <= 0.0 && depth_snow > 0.0

Diff for: test/modules/modules.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
include("test-surface_temperature.jl")
12
include("test-radiation.jl")
23
include("test-snowpack.jl")
34
include("test-photosynthesis.jl")

Diff for: test/modules/test-surface_temperature.jl

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@testset "surface_temperature_jl tests" begin
2+
T_air = 2.0 # Air temperature in Celsius
3+
rh_air = 0.5 # Relative humidity
4+
depth_snow = 0.03 # Depth of snow in meters
5+
depth_water = 0.1 # Depth of water in meters
6+
cp_soil1 = 1000.0 # Heat capacity of soil layer 1
7+
cp_soil0 = 800.0 # Heat capacity of soil layer 0
8+
Gheat_g = 0.1 # Ground heat flux
9+
depth_soil1 = 0.5 # Depth of soil layer 1 in meters
10+
ρ_snow = 300.0 # Density of snow in kg/m^3
11+
tempL_u = 0.0 # Temperature of the lower layer in Celsius
12+
Rn_g = 200.0 # Net radiation on the ground
13+
E_soil = 0.1 # Evaporation from soil
14+
E_water_g = 0.05 # Evaporation from water on the ground
15+
E_snow_g = 0.02 # Evaporation from snow on the ground
16+
λ_soil1 = 0.5 # Thermal conductivity of soil layer 1
17+
perc_snow_g = 0.3 # Percentage of snow cover on the ground
18+
G_soil1 = 0.2 # Soil heat flux in layer 1
19+
T_ground_last = 0.001 # Last ground temperature in Celsius
20+
T_soil1_last = 0.001 # Last soil layer 1 temperature in Celsius
21+
T_any0_last = 0.001 # Last temperature of any layer 0 in Celsius
22+
T_soil0_last = 0.001 # Last soil layer 0 temperature in Celsius
23+
T_snow_last = 0.001 # Last snow temperature in Celsius
24+
T_snow1_last = 0.001 # Last snow layer 1 temperature in Celsius
25+
T_snow2_last = 0.001 # Last snow layer 2 temperature in Celsius
26+
27+
# T_ground, T_any0, T_soil0, T_snow, T_snow1, T_snow2, G
28+
for depth_snow = [0.01, 0.03, 0.06]
29+
r_jl = surface_temperature_jl(
30+
T_air, rh_air,
31+
depth_snow, depth_water,
32+
cp_soil1, cp_soil0, Gheat_g,
33+
depth_soil1, ρ_snow, tempL_u, Rn_g, E_soil, E_water_g, E_snow_g, λ_soil1, perc_snow_g, G_soil1,
34+
T_ground_last, T_soil1_last, T_any0_last, T_soil0_last, T_snow_last, T_snow1_last, T_snow2_last
35+
)
36+
r_c = clang.surface_temperature_c(
37+
T_air, rh_air,
38+
depth_snow, depth_water,
39+
cp_soil1, cp_soil0, Gheat_g,
40+
depth_soil1, ρ_snow, tempL_u, Rn_g, E_soil, E_water_g, E_snow_g, λ_soil1, perc_snow_g, G_soil1,
41+
T_ground_last, T_soil1_last, T_any0_last, T_soil0_last, T_snow_last, T_snow1_last, T_snow2_last
42+
)
43+
# println(r_jl)
44+
# println(r_c)
45+
@test all(isapprox.(r_jl, r_c, rtol=1e-8))
46+
end
47+
end

0 commit comments

Comments
 (0)