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 60fdb2d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 115 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
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 60fdb2d

Please sign in to comment.