-
Couldn't load subscription status.
- Fork 44
Closed
Description
using StructArrays
using BenchmarkTools
abstract type AbstractSoilParam{T} end
@kwdef mutable struct ParamCampbell{T} <: AbstractSoilParam{T}
θ_sat::T = 0.287 # [m3 m-3]
# θ_res::T = 0.075 # [m3 m-3]
ψ_sat::T = -10.0 # [cm]
Ksat::T = 34 / 3600 # [cm s-1]
b::T = 4.0 # [-]
end
mutable struct SoilParam{T}
par::StructVector{ParamCampbell{T}} # multiple layers
end
begin
N = 10
θ_sat = fill(0.287, N) # [m3 m-3]
ψ_sat = fill(-10.0, N) # [cm]
Ksat = fill(34 / 3600, N) # [cm s-1]
b = fill(4.0, N)
par = StructVector{ParamCampbell{Float64}}((θ_sat, ψ_sat, Ksat, b))
param = SoilParam{Float64}(par)
end
function test_param(param::SoilParam{Float64}, N::Int)
@inbounds for k in 1:100_00
for i in 1:N
_par = param.par[i]
end
end
endjulia> @btime test_param($param, N)
2.558 ms (100000 allocations: 4.58 MiB)Metadata
Metadata
Assignees
Labels
No labels