Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Jan 16, 2024
1 parent 084becc commit e78b555
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 128 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MutableNamedTuples = "af6c499f-54b4-48cc-bbd2-094bba7533c7"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Expand All @@ -20,7 +19,6 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
DataFrames = "1.5, 1.6"
DelimitedFiles = "1.9"
LabelledArrays = "1.14"
MutableNamedTuples = "0.1.3"
Parameters = "0.12"
Reexport = "1"
UnPack = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion data/dat_气象驱动.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

- `tem`: Tair, degC

- `hum`: q (specific humidity), kg/kg
- `hum`: q (specific humidity), g/kg

- `pre`: prcp (precipitation), mm

Expand Down
20 changes: 10 additions & 10 deletions src/BEPS/evaporation_canopy.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function evaporation_canopy_jl(tempL::Leaf, Ta::Float64, rh_air::Float64,
function evaporation_canopy_jl(T_leaf::Leaf, Ta::Float64, rh_air::Float64,
Gwater::Leaf, lai::Leaf,
perc_water_o::Float64, perc_water_u::Float64, perc_snow_o::Float64, perc_snow_u::Float64)

Expand All @@ -11,15 +11,15 @@ function evaporation_canopy_jl(tempL::Leaf, Ta::Float64, rh_air::Float64,
latent_snow = 2.83 * 1000000

# leaf level latent heat caused by evaporation or sublimation
LHw_o_sunlit = perc_water_o * latent_heat(Ta, tempL.o_sunlit, Gwater.o_sunlit, met)
LHw_o_shaded = perc_water_o * latent_heat(Ta, tempL.o_shaded, Gwater.o_shaded, met)
LHw_u_sunlit = perc_water_u * latent_heat(Ta, tempL.u_sunlit, Gwater.u_sunlit, met)
LHw_u_shaded = perc_water_u * latent_heat(Ta, tempL.u_shaded, Gwater.u_shaded, met)

LHs_o_sunlit = perc_snow_o * latent_heat(Ta, tempL.o_sunlit, Gwater.o_sunlit, met)
LHs_o_shaded = perc_snow_o * latent_heat(Ta, tempL.o_shaded, Gwater.o_shaded, met)
LHs_u_sunlit = perc_snow_u * latent_heat(Ta, tempL.u_sunlit, Gwater.u_sunlit, met)
LHs_u_shaded = perc_snow_u * latent_heat(Ta, tempL.u_shaded, Gwater.u_shaded, met)
LHw_o_sunlit = perc_water_o * latent_heat(Ta, T_leaf.o_sunlit, Gwater.o_sunlit, met)
LHw_o_shaded = perc_water_o * latent_heat(Ta, T_leaf.o_shaded, Gwater.o_shaded, met)
LHw_u_sunlit = perc_water_u * latent_heat(Ta, T_leaf.u_sunlit, Gwater.u_sunlit, met)
LHw_u_shaded = perc_water_u * latent_heat(Ta, T_leaf.u_shaded, Gwater.u_shaded, met)

LHs_o_sunlit = perc_snow_o * latent_heat(Ta, T_leaf.o_sunlit, Gwater.o_sunlit, met)
LHs_o_shaded = perc_snow_o * latent_heat(Ta, T_leaf.o_shaded, Gwater.o_shaded, met)
LHs_u_sunlit = perc_snow_u * latent_heat(Ta, T_leaf.u_sunlit, Gwater.u_sunlit, met)
LHs_u_shaded = perc_snow_u * latent_heat(Ta, T_leaf.u_shaded, Gwater.u_shaded, met)

evapo_water_o = 1 / (latent_water) * (LHw_o_sunlit * lai.o_sunlit + LHw_o_shaded * lai.o_shaded)
evapo_water_u = 1 / (latent_water) * (LHw_u_sunlit * lai.u_sunlit + LHw_u_shaded * lai.u_shaded)
Expand Down
4 changes: 2 additions & 2 deletions src/BEPS/evaporation_soil.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function evaporation_soil_jl(Tair::FT, Tg::FT, RH::FT, Rn_g::FT, Gheat_g::FT,
percent_snow_g::Ref{FT}, depth_water::Ref{FT}, depth_snow::Ref{FT}, mass_water_g::Ref{FT}, mass_snow_g::Ref{FT}, # Ref{FT}
percent_snow_g::Ref{FT}, depth_water::Ref{FT}, depth_snow::Ref{FT}, mass_water_g::Ref{FT}, mass_snow_g::Ref{FT},
density_snow::FT, swc_g::FT, porosity_g::FT) where {FT<:Real}
# evapo_soil::Ref{FT}, evapo_water_g::Ref{FT}, evapo_snow_g::Ref{FT}

met = meteo_pack_jl(Tg, RH)
ρ_a = met.rho_a
cp = met.cp
Expand Down
11 changes: 11 additions & 0 deletions src/BEPS/lai2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ function lai2(clumping::Float64, CosZs::Float64,
LAI.u_sunlit = CosZs > 0 ? 2 * CosZs * (1 - exp(-0.5 * clumping * (lai_o + lai_u) / CosZs)) - LAI.o_sunlit : 0
LAI.u_shaded = max(0, lai_u - LAI.u_sunlit) # edited by J. Leng
end

function lai2(clumping::Float64, CosZs::Float64,
stem_o::Float64, stem_u::Float64,
lai_o::Float64, lai_u::Float64)

LAI = Leaf()
PAI = Leaf()

lai2(clumping, CosZs, stem_o, stem_u, lai_o, lai_u, LAI, PAI)
LAI, PAI
end
3 changes: 3 additions & 0 deletions src/BEPS/netRadiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ function netRadiation_jl(Rs_global::FT, CosZs::FT,
# 参考Chen 2012年的聚集指数论文
Rn_o, Rn_u, Rn_g
end


# TODO: 切分成两个函数,长波与短波
84 changes: 42 additions & 42 deletions src/DataType/Soil.jl
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
T = Vector{Float64}

@with_kw mutable struct Soil
flag::Cint = Cint(0)
n_layer::Cint = Cint(5)
step_period::Cint = Cint(1)
flag ::Cint = Cint(0)
n_layer ::Cint = Cint(5)
step_period ::Cint = Cint(1)

Zp::Cdouble = Cdouble(0)
Zsp::Cdouble = Cdouble(0)
r_rain_g::Cdouble = Cdouble(0)
soil_r::Cdouble = Cdouble(0)
r_drainage::Cdouble = Cdouble(0)
Zp ::Cdouble = Cdouble(0)
Zsp ::Cdouble = Cdouble(0)
r_rain_g ::Cdouble = Cdouble(0)
soil_r ::Cdouble = Cdouble(0)
r_drainage ::Cdouble = Cdouble(0)
r_root_decay::Cdouble = Cdouble(0)
psi_min::Cdouble = Cdouble(0)
alpha::Cdouble = Cdouble(0)
f_soilwater::Cdouble = Cdouble(0)
d_soil::T = zeros(10)
f_root::T = zeros(10)
dt::T = zeros(10)
psi_min ::Cdouble = Cdouble(0)
alpha ::Cdouble = Cdouble(0)
f_soilwater ::Cdouble = Cdouble(0)

d_soil ::T = zeros(10)
f_root ::T = zeros(10)
dt ::T = zeros(10)
thermal_cond::T = zeros(10)
theta_vfc::T = zeros(10)
theta_vwp::T = zeros(10)
fei::T = zeros(10)
Ksat::T = zeros(10)
psi_sat::T = zeros(10)
b::T = zeros(10)
theta_vfc ::T = zeros(10)
theta_vwp ::T = zeros(10)
fei ::T = zeros(10)
Ksat ::T = zeros(10)
psi_sat ::T = zeros(10)
b ::T = zeros(10)
density_soil::T = zeros(10)
f_org::T = zeros(10)
ice_ratio::T = zeros(10)
thetam::T = zeros(10)
thetam_prev::T = zeros(10)
temp_soil_p::T = zeros(10)
temp_soil_c::T = zeros(10)
f_ice::T = zeros(10)
psim::T = zeros(10)
thetab::T = zeros(10)
psib::T = zeros(10)
r_waterflow::T = zeros(10)
km::T = zeros(10)
Kb::T = zeros(10)
KK::T = zeros(10)
Cs::T = zeros(10)
lambda::T = zeros(10)
Ett::T = zeros(10)
G::T = zeros(10)
f_org ::T = zeros(10) # organic matter
ice_ratio ::T = zeros(10) # ice ratio
thetam ::T = zeros(10) # soil moisture
thetam_prev ::T = zeros(10) # soil moisture in previous time
temp_soil_p ::T = zeros(10) # soil temperature in previous time
temp_soil_c ::T = zeros(10) # soil temperature in current time
f_ice ::T = zeros(10)
psim ::T = zeros(10)
thetab ::T = zeros(10)
psib ::T = zeros(10)
r_waterflow ::T = zeros(10)
km ::T = zeros(10) # hydraulic conductivity
Kb ::T = zeros(10)
KK ::T = zeros(10) # average conductivity of two soil layers
Cs ::T = zeros(10)
lambda ::T = zeros(10)
Ett ::T = zeros(10)
G ::T = zeros(10)

# temporary variables in soil_water_factor_v2
ft::T = zeros(10)
dtt::T = zeros(10)
fpsisr::T = zeros(10)
ft ::T = zeros(10)
dtt ::T = zeros(10)
fpsisr ::T = zeros(10)
end

# ft = zeros(Float64, p.n_layer)
Expand Down
63 changes: 1 addition & 62 deletions src/Ipaper.jl
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
# using BEPS
## MutableNamedTuples
# using MutableNamedTuples
# using Ipaper
import MutableNamedTuples: MutableNamedTuple

const MNT = MutableNamedTuple

# mnt(keys::Vector{Symbol}, values) = (; zip(keys, values)...)
"""
mnt(keys::Vector{Symbol}, values)
mnt(keys::Vector{<:AbstractString}, values)
# Examples
```julia
mnt([:dw, :betaw, :swmax, :a, :c, :kh, :uh]
```
"""
mnt(; kw...) = MNT(; kw...)


mnt(keys::Vector{Symbol}, values) = MNT(; zip(keys, values)...)

mnt(keys::Vector{<:AbstractString}, values) = mnt(Symbol.(keys), values)

mnt(keys::Vector{Symbol}) = mnt(Symbol.(keys), zeros(length(keys)))

mnt(keys::Tuple, values) = MNT(; zip(keys, values)...)
mnt(keys::Tuple) = mnt(keys, zeros(length(keys)))

mnt(keys::Vector{<:AbstractString}) = mnt(Symbol.(keys))

to_list = mnt;

Base.names(x::MNT) = keys(x) |> collect

# function Base.values(x::MNT)
# @show "hello"
# getindex.(values(getfield(x, :nt))) |> collect
# # values(x) |> collect
# end


function add(x::MutableNamedTuple, y::MutableNamedTuple)
mnt([keys(x)..., keys(y)...],
[values(x)..., values(y)...],)
end

function Base.:(==)(x::MNT, y::MNT)
if length(x) != length(y)
return false
end
keys(x) == keys(y) && values(x) == values(y)
end

export mnt, add, MNT

# a = MNT{(:o_sunlit, :o_shaded, :u_sunlit, :u_shaded), NTuple{4, Base.RefValue{Int64}}}

export LVector, list

## second version
import LabelledArrays
Expand Down Expand Up @@ -99,6 +41,3 @@ Base.:+(x::T1, y::AbstractVector{T2}) where {T1<:Real,T2<:Real} = x .+ y
Base.:-(x::T1, y::AbstractVector{T2}) where {T1<:Real,T2<:Real} = x .- y
Base.:*(x::T1, y::AbstractVector{T2}) where {T1<:Real,T2<:Real} = x .* y
Base.:/(x::T1, y::AbstractVector{T2}) where {T1<:Real,T2<:Real} = x ./ y


export LVector, list
14 changes: 5 additions & 9 deletions src/beps_inter_prg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function inter_prg_jl(
Ks = meteo.Srad
rh_air = meteo.rh
wind_sp = meteo.wind
precip = meteo.rain / step # precipitation in meters
prcp = meteo.rain / step # precipitation in meters
Ta = meteo.temp

VPS_air = cal_es(Ta) # to estimate saturated water vapor pressure in kpa
Expand Down Expand Up @@ -194,7 +194,7 @@ function inter_prg_jl(
# for(kkk = 1;kkk <= kloop;kkk++)
@inbounds for kkk = 2:kloop+1
# /***** Snow pack stage 1 by X. Luo *****/
var.Xcs_o[kkk], var.Xcs_u[kkk], var.Xg_snow[kkk] = snowpack_stage1_jl(Ta, precip,
var.Xcs_o[kkk], var.Xcs_u[kkk], var.Xg_snow[kkk] = snowpack_stage1_jl(Ta, prcp,
# var.Wcs_o[kkk-1], var.Wcs_u[kkk-1], var.Wg_snow[kkk-1],
Ref(var.Wcs_o, kkk), Ref(var.Wcs_u, kkk), Ref(var.Wg_snow, kkk),
lai_o, lai_u, clumping,
Expand All @@ -204,7 +204,7 @@ function inter_prg_jl(

# /***** Rain fall stage 1 by X. Luo *****/
var.Wcl_o[kkk], var.Wcl_u[kkk], var.Xcl_o[kkk], var.Xcl_u[kkk], var.r_rain_g[kkk] =
rainfall_stage1_jl(Ta, precip, var.Wcl_o[kkk-1], var.Wcl_u[kkk-1], lai_o, lai_u, clumping)
rainfall_stage1_jl(Ta, prcp, var.Wcl_o[kkk-1], var.Wcl_u[kkk-1], lai_o, lai_u, clumping)

# Old version
# if(thetam[0][kkk-1]<soilp.theta_vwp[1]*0.5) var.alpha_g = alpha_dry;
Expand All @@ -220,12 +220,8 @@ function inter_prg_jl(

# /***** Soil water factor module by L. He *****/
soil_water_factor_v2(soilp)
f_soilwater = soilp.f_soilwater

if (f_soilwater > 1.0)
f_soilwater = 1.0
end # to be used for module photosynthesis

f_soilwater = min(soilp.f_soilwater, 1.0) # used in `photosynthesis`

GH_o = var.Qhc_o[kkk-1]# to be used as the init. for module aerodynamic_conductance

init_leaf_dbl(Ci_old, 0.7 * CO2_air)
Expand Down

0 comments on commit e78b555

Please sign in to comment.