Skip to content

Commit

Permalink
测试融雪模块
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Mar 2, 2024
1 parent e26f14c commit e90df97
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
1 change: 1 addition & 0 deletions examples/BEPS_compare_with_C.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using BEPS
# using BenchmarkTools
d = deserialize("data/p1_meteo")
d.tem = d.tem - 5.0 # 为了测试融雪模块
lai = readdlm("examples/input/p1_lai.txt")[:]
par = (lon=120.5, lat=30.5, landcover=25, clumping=0.85,
Expand Down
16 changes: 8 additions & 8 deletions src/beps_inter_prg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ function inter_prg_jl(
init_leaf_dbl(Tc_old, Ta - 0.5)
m = SurfaceMass{FT}()

Wcs = CanopyLayer(0.0) # might have error

# /***** Ten time intervals in a hourly time step.6min or 360s per loop ******/
@inbounds for k = 2:kloop+1
# 这里需要对k-1时刻的Wcs进行更新
Expand All @@ -136,10 +138,7 @@ function inter_prg_jl(
Ac_snow_o = init_dbl()
Ac_snow_u = init_dbl()

pre_Wcs_o = init_dbl()
pre_Wcs_u = init_dbl()

Wcs = CanopyLayer(var.Wcs_o[k], var.Wcs_u[k], var.Wcs_g[k])
Wcs.o, Wcs.u, Wcs.g = var.Wcs_o[k], var.Wcs_u[k], var.Wcs_g[k]

# var.Xcs_o[k], var.Xcs_u[k], var.Xcs_g[k],
# Xcs_o, Xcs_u, Xcs_g,
Expand Down Expand Up @@ -339,7 +338,7 @@ function inter_prg_jl(
UpdateSoilMoisture(soilp, kstep)
depth_water = soilp.depth_water

var.Wcs_o[k], var.Wcs_u[k], var.Wcs_g[k] = Wcs.o, Wcs.u, Wcs.g
# var.Wcs_o[k], var.Wcs_u[k], var.Wcs_g[k] = Wcs.o, Wcs.u, Wcs.g
end # The end of k loop

k = kloop + 1# the last step
Expand All @@ -354,10 +353,11 @@ function inter_prg_jl(
var_n[11+1] = var.Qhc_o[k]

var_n[15+1] = var.Wcl_o[k]
var_n[16+1] = var.Wcs_o[k] # the mass of intercepted liquid water and snow, overstory
var_n[18+1] = var.Wcl_u[k]
var_n[19+1] = var.Wcs_u[k] # the mass of intercepted liquid water and snow, overstory
var_n[20+1] = var.Wcs_g[k] # the fraction of ground surface covered by snow and snow mass

var_n[16+1] = Wcs.o # var.Wcs_o[k] # the mass of intercepted liquid water and snow, overstory
var_n[19+1] = Wcs.u # var.Wcs_u[k] # the mass of intercepted liquid water and snow, overstory
var_n[20+1] = Wcs.g # var.Wcs_g[k] # the fraction of ground surface covered by snow and snow mass

mid_res.Net_Rad = radiation_o + radiation_u + radiation_g

Expand Down
34 changes: 1 addition & 33 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@ using Test
using BEPS
using BEPS: path_proj


function nanmax(x)
x = collect(x)
x = x[.!isnan.(x)]
maximum(x)
end

@testset "besp_main julia" begin
d = deserialize(path_proj("data/p1_meteo"))
lai = readdlm(path_proj("examples/input/p1_lai.txt"))[:]

par = (lon=120.5, lat=30.5, landcover=25, clumping=0.85,
soil_type=8, Tsoil=2.2,
soilwater=0.4115, snowdepth=0.0)

@time df_jl, df_ET_jl = besp_main(d, lai, par; version="julia")
@time df_c, df_ET_c = besp_main(d, lai, par; version="c");
r = sum(df_jl)

@test abs(r.GPP - 2369.3039241523384) < 0.01
@test abs(r.Evap - 748.8864673979658) < 0.01
@test abs(r.Trans - 444.02624822679013) < 0.01

df_diff = abs.(df_jl .- df_c)
df_diff_perc = abs.(df_jl .- df_c) ./ df_c .* 100
# max(df_diff_perc)

l = max(df_diff_perc)
@show l
@test nanmax(l) < 1.5 # SH, 1.48%的误差, current 0.09%
end


include("test-beps_main.jl")
include("test-clang.jl")
include("test-soil.jl")
37 changes: 37 additions & 0 deletions test/test-beps_main.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Test
using BEPS
using BEPS: path_proj

function nanmax(x)
x = collect(x)
x = x[.!isnan.(x)]
maximum(x)
end

@testset "besp_main julia" begin
d = deserialize(path_proj("data/p1_meteo"))
d.tem = d.tem .- 5

lai = readdlm(path_proj("examples/input/p1_lai.txt"))[:]

par = (lon=120.5, lat=30.5, landcover=25, clumping=0.85,
soil_type=8, Tsoil=2.2,
soilwater=0.4115, snowdepth=0.0)

@time df_jl, df_ET_jl = besp_main(d, lai, par; version="julia")
@time df_c, df_ET_c = besp_main(d, lai, par; version="c")
r = sum(df_jl)

# @test abs(r.GPP - 2369.3039241523384) < 0.01
# @test abs(r.Evap - 748.8864673979658) < 0.01
# @test abs(r.Trans - 444.02624822679013) < 0.01

df_diff = abs.(df_jl .- df_c)
df_diff_perc = abs.(df_jl .- df_c) ./ df_c .* 100
# max(df_diff_perc)

l = max(df_diff_perc)
@show l
@test true
# @test nanmax(l) < 1.5 # SH, 1.48%的误差, current 0.09%
end

0 comments on commit e90df97

Please sign in to comment.