Skip to content

Commit

Permalink
improve radiation
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Oct 13, 2024
1 parent cee54e9 commit 846bf20
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 52 deletions.
11 changes: 4 additions & 7 deletions src/clang/module.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export
export
evaporation_soil_c,
evaporation_canopy_c,
netRadiation_c,
Expand Down Expand Up @@ -37,11 +37,8 @@ end
function netRadiation_c(shortRad_global, CosZs,
temp_o, temp_u, temp_g,
lai_o, lai_u, lai_os, lai_us, lai::Leaf, Ω, temp_air, rh,
α_snow_v, α_snow_n,
percArea_snow_o, percArea_snow_u, perc_snow_g,
α_v_o, α_n_o, α_v_u, α_n_u, α_v_g, α_n_g,
# netRad_o::TypeRef, netRad_u::TypeRef, netRad_g::TypeRef,
Rn_Leaf::Leaf, Rns_Leaf::Leaf, Rnl_Leaf::Leaf, Ra::Radiation)
α_snow_v, α_snow_n, α_v::Layer3{FT}, α_n::Layer3{FT},
percArea_snow_o, percArea_snow_u, perc_snow_g, Rn_Leaf::Leaf, Rns_Leaf::Leaf, Rnl_Leaf::Leaf, Ra::Radiation)

netRad_o = init_dbl()
netRad_u = init_dbl()
Expand All @@ -51,7 +48,7 @@ function netRadiation_c(shortRad_global, CosZs,
(Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Leaf, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble, Cdouble,
Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Leaf}, Ptr{Leaf}),
shortRad_global, CosZs, temp_o, temp_u, temp_g, lai_o, lai_u, lai_os, lai_us, lai, Ω, temp_air, rh, α_snow_v, α_snow_n, percArea_snow_o, percArea_snow_u, perc_snow_g,
α_v_o, α_n_o, α_v_u, α_n_u, α_v_g, α_n_g,
α_v.o, α_n.o, α_v.u, α_n.u, α_v.g, α_n.g,
netRad_o, netRad_u, netRad_g, Ref(Rn_Leaf), Ref(Rns_Leaf))

netRad_o[], netRad_u[], netRad_g[]
Expand Down
34 changes: 13 additions & 21 deletions src/inter_prg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,6 @@ function inter_prg_jl(
g1_w = param[33+1] # to be used for module photosynthesis
g0_w = param[34+1]

if (Rs <= 0)
α_v_o = 0.0
α_n_o = 0.0
α_v_u = 0.0
α_n_u = 0.0
else
α_v_o = param[22+1]
α_n_o = param[23+1]
α_v_u = param[22+1]
α_n_u = param[23+1]
end

init_leaf_dbl(Tc_old, Ta - 0.5)

# Ground surface temperature
Expand All @@ -119,14 +107,22 @@ function inter_prg_jl(

# the evaporation rate of rain and snow--in kg/m^2/s,
# understory the mass of intercepted liquid water and snow, overstory
f_snow = Layer3(0.0) # perc_snow
f_snow = Layer3(0.0) # perc_snow
m_snow = Layer3(0.0) # mass_snow
A_snow = Layer2()

# the mass of intercepted liquid water and snow, overstory
f_water = Layer2() # perc_water
m_water = Layer2() # mass_water

if (Rs <= 0)
α_v = Layer3()
α_n = Layer3()
else
α_v = Layer3(param[22+1])
α_n = Layer3(param[23+1])
end

ρ_snow = init_dbl()
α_v_sw = init_dbl()
α_n_sw = init_dbl()
Expand All @@ -152,8 +148,8 @@ function inter_prg_jl(
α_g = (soil.θ_prev[2] - soil.θ_vwp[2] * 0.5) / (soil.θ_sat[2] - soil.θ_vwp[2] * 0.5) * (α_sat - α_dry) + α_dry
end

α_v_g = 2.0 / 3.0 * α_g
α_n_g = 4.0 / 3.0 * α_g
α_v.g = 2.0 / 3.0 * α_g
α_n.g = 4.0 / 3.0 * α_g

# /***** Soil water factor module by L. He *****/
soil_water_factor_v2(soil)
Expand Down Expand Up @@ -194,12 +190,8 @@ function inter_prg_jl(
radiation_o, radiation_u, radiation_g = netRadiation_jl(Rs, CosZs, Tco, Tcu, temp_grd,
lai_o, lai_u, lai_o + stem_o, lai_u + stem_u, PAI,
Ω, Ta, RH,
α_v_sw[], α_n_sw[],
perc_snow_o, perc_snow_u,
f_snow.g,
α_v_o, α_n_o,
α_v_u, α_n_u,
α_v_g, α_n_g,
α_v_sw[], α_n_sw[], α_v, α_n,
perc_snow_o, perc_snow_o, f_snow.g,
Rn, Rns, Rnl, Ra)

# /***** Photosynthesis module by B. Chen *****/
Expand Down
17 changes: 7 additions & 10 deletions src/netRadiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ function netRadiation_jl(Rs_global::FT, CosZs::FT,
lai_o::FT, lai_u::FT, lai_os::FT, lai_us::FT,
lai::Leaf,
Ω::FT, Tair::FT, RH::FT,
α_snow_v::FT, α_snow_n::FT,
α_snow_v::FT, α_snow_n::FT, α_v::Layer3{FT}, α_n::Layer3{FT},
percArea_snow_o::FT, percArea_snow_u::FT, perc_snow_g::FT,
α_v_o::FT, α_n_o::FT, α_v_u::FT, α_n_u::FT,
α_v_g::FT, α_n_g::FT,
# Rn_o::FT, Rn_u::FT, Rn_g::FT,
Rn_Leaf::Leaf,
Rns_Leaf::Leaf,
Rnl_Leaf::Leaf, Ra::Radiation)

# calculate α of canopy in this step
α_v_os::FT = α_v_o * (1.0 - percArea_snow_o) + α_snow_v * percArea_snow_o # visible, overstory
α_n_os::FT = α_n_o * (1.0 - percArea_snow_o) + α_snow_n * percArea_snow_o # near infrared
α_v_us::FT = α_v_u * (1.0 - percArea_snow_u) + α_snow_v * percArea_snow_u # understory
α_n_us::FT = α_n_u * (1.0 - percArea_snow_u) + α_snow_n * percArea_snow_u
α_v_os::FT = α_v.o * (1.0 - percArea_snow_o) + α_snow_v * percArea_snow_o # visible, overstory
α_n_os::FT = α_n.o * (1.0 - percArea_snow_o) + α_snow_n * percArea_snow_o # near infrared
α_v_us::FT = α_v.u * (1.0 - percArea_snow_u) + α_snow_v * percArea_snow_u # understory
α_n_us::FT = α_n.u * (1.0 - percArea_snow_u) + α_snow_n * percArea_snow_u

α_o::FT = 0.5 * (α_v_os + α_n_os)
α_u::FT = 0.5 * (α_v_us + α_n_us)

# calculate α of ground in this step
α_v_gs::FT = α_v_g * (1.0 - perc_snow_g) + α_snow_v * perc_snow_g
α_n_gs::FT = α_n_g * (1.0 - perc_snow_g) + α_snow_n * perc_snow_g
α_v_gs::FT = α_v.g * (1.0 - perc_snow_g) + α_snow_v * perc_snow_g
α_n_gs::FT = α_n.g * (1.0 - perc_snow_g) + α_snow_n * perc_snow_g
α_g::FT = 0.5 * (α_v_gs + α_n_gs)

# separate global solar radiation into direct and diffuse one
Expand Down
24 changes: 10 additions & 14 deletions test/modules/test-radiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ using Test, BEPS
RH = 0.6 # Relative humidity
α_snow_v = 0.8 # Albedo of snow in visible spectrum
α_snow_n = 0.7 # Albedo of snow in near-infrared spectrum
percArea_snow_o = 0.3 # Percentage area of snow in overstory
percArea_snow_u = 0.2 # Percentage area of snow in understory
perc_snow_o = 0.3 # Percentage area of snow in overstory
perc_snow_u = 0.2 # Percentage area of snow in understory
perc_snow_g = 0.1 # Percentage area of snow on ground
α_v_o = 0.2 # Albedo of overstory in visible spectrum
α_n_o = 0.3 # Albedo of overstory in near-infrared spectrum
α_v_u = 0.25 # Albedo of understory in visible spectrum
α_n_u = 0.35 # Albedo of understory in near-infrared spectrum
α_v_g = 0.15 # Albedo of ground in visible spectrum
α_n_g = 0.25 # Albedo of ground in near-infrared spectrum
α_v = Layer3(0.2, 0.25, 0.15)
α_n = Layer3(0.3, 0.35, 0.25)

Rn_Leaf = Leaf(0.0) # Net radiation for leaf
Rns_Leaf = Leaf(0.0) # Net shortwave radiation for leaf
Rnl_Leaf = Leaf(0.0) # Net longwave radiation for leaf
Expand All @@ -35,17 +32,16 @@ using Test, BEPS
temp_o, temp_u, temp_g,
lai_o, lai_u, lai_os, lai_us, lai, Ω,
Tair, RH,
α_snow_v, α_snow_n,
percArea_snow_o, percArea_snow_u, perc_snow_g,
α_v_o, α_n_o, α_v_u, α_n_u, α_v_g, α_n_g,
α_snow_v, α_snow_n, α_v, α_n,
perc_snow_o, perc_snow_u, perc_snow_g,

Rn_Leaf, Rns_Leaf, Rnl_Leaf, Ra)
r_c = clang.netRadiation_c(Rs_global, CosZs,
temp_o, temp_u, temp_g,
lai_o, lai_u, lai_os, lai_us, lai, Ω,
Tair, RH,
α_snow_v, α_snow_n,
percArea_snow_o, percArea_snow_u, perc_snow_g,
α_v_o, α_n_o, α_v_u, α_n_u, α_v_g, α_n_g,
α_snow_v, α_snow_n, α_v, α_n,
perc_snow_o, perc_snow_u, perc_snow_g,
Rn_Leaf, Rns_Leaf, Rnl_Leaf, Ra)
@test all(isapprox.(r_jl, r_c, rtol=1e-8))
end

0 comments on commit 846bf20

Please sign in to comment.