Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Simplify external constructors.
  • Loading branch information
vers-w committed Oct 28, 2024
1 parent cc30210 commit 0e06992
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 92 deletions.
36 changes: 12 additions & 24 deletions src/snow/snow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@ abstract type AbstractSnowModel{T} end
end

"Initialize snow model variables"
function SnowVariables(
n;
snow_storage::Vector{T} = fill(0.0, n),
snow_water::Vector{T} = fill(0.0, n),
swe::Vector{T} = fill(mv, n),
snow_melt::Vector{T} = fill(mv, n),
runoff::Vector{T} = fill(mv, n),
) where {T}
function SnowVariables(T::Type{<:AbstractFloat}, n::Int)
return SnowVariables{T}(;
snow_storage = snow_storage,
snow_water = snow_water,
swe = swe,
runoff = runoff,
snow_melt = snow_melt,
snow_storage = fill(0.0, n),
snow_water = fill(0.0, n),
swe = fill(mv, n),
runoff = fill(mv, n),
snow_melt = fill(mv, n),
)
end

Expand All @@ -43,16 +36,11 @@ end
end

"Initialize snow model boundary conditions"
function SnowBC(
n;
effective_precip::Vector{T} = fill(mv, n),
snow_precip::Vector{T} = fill(mv, n),
liquid_precip::Vector{T} = fill(mv, n),
) where {T}
function SnowBC(T::Type{<:AbstractFloat}, n::Int)
return SnowBC{T}(;
effective_precip = effective_precip,
snow_precip = snow_precip,
liquid_precip = liquid_precip,
effective_precip = fill(mv, n),
snow_precip = fill(mv, n),
liquid_precip = fill(mv, n),
)
end

Expand Down Expand Up @@ -131,8 +119,8 @@ end
function SnowHbvModel(nc, config, inds, dt)
n = length(inds)
params = SnowHbvParameters(nc, config, inds, dt)
vars = SnowVariables(n)
bc = SnowBC(n)
vars = SnowVariables(Float, n)
bc = SnowBC(Float, n)
model = SnowHbvModel(; boundary_conditions = bc, parameters = params, variables = vars)
return model
end
Expand Down
60 changes: 30 additions & 30 deletions src/soil/soil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ function SbmSoilVariables(n, parameters)
vars = SbmSoilVariables(;
ustorelayerdepth = zero(act_thickl),
ustorecapacity = soilwatercapacity .- satwaterdepth,
ustorelayerthickness = ustorelayerthickness,
satwaterdepth = satwaterdepth,
zi = zi,
n_unsatlayers = n_unsatlayers,
ustorelayerthickness,
satwaterdepth,
zi,
n_unsatlayers,
transpiration = fill(mv, n),
h3 = fill(mv, n),
ae_ustore = fill(mv, n),
Expand Down Expand Up @@ -604,36 +604,36 @@ function SbmSoilParameters(nc, config, vegetation_parameter_set, inds, dt)

n = length(inds)
sbm_params = SbmSoilParameters(;
maxlayers = maxlayers,
nlayers = nlayers,
soilwatercapacity = soilwatercapacity,
theta_s = theta_s,
theta_r = theta_r,
maxlayers,
nlayers,
soilwatercapacity,
theta_s,
theta_r,
kvfrac = svectorscopy(kvfrac, Val{maxlayers}()),
hb = hb,
h1 = h1,
h2 = h2,
h3_high = h3_high,
h3_low = h3_low,
h4 = h4,
alpha_h1 = alpha_h1,
soilthickness = soilthickness,
act_thickl = act_thickl,
sumlayers = sumlayers,
infiltcappath = infiltcappath,
infiltcapsoil = infiltcapsoil,
maxleakage = maxleakage,
pathfrac = pathfrac,
rootdistpar = rootdistpar,
hb,
h1,
h2,
h3_high,
h3_low,
h4,
alpha_h1,
soilthickness,
act_thickl,
sumlayers,
infiltcappath,
infiltcapsoil,
maxleakage,
pathfrac,
rootdistpar,
rootfraction = svectorscopy(rootfraction, Val{maxlayers}()),
cap_hmax = cap_hmax,
cap_n = cap_n,
cap_hmax,
cap_n,
c = svectorscopy(c, Val{maxlayers}()),
w_soil = w_soil,
cf_soil = cf_soil,
w_soil,
cf_soil,
soil_fraction = fill(mv, n),
kv_profile = kv_profile,
vegetation_parameter_set = vegetation_parameter_set,
kv_profile,
vegetation_parameter_set,
)
return sbm_params
end
Expand Down
36 changes: 12 additions & 24 deletions src/surfacewater/runoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@ abstract type AbstractRunoffModel{T} end
end

"Initialize open water runoff model variables"
function OpenWaterRunoffVariables(
n;
runoff_river::Vector{T} = fill(mv, n),
runoff_land::Vector{T} = fill(mv, n),
ae_openw_l::Vector{T} = fill(mv, n),
ae_openw_r::Vector{T} = fill(mv, n),
net_runoff_river::Vector{T} = fill(mv, n),
) where {T}
function OpenWaterRunoffVariables(T::Type{<:AbstractFloat}, n::Int)
return OpenWaterRunoffVariables{T}(;
runoff_river = runoff_river,
runoff_land = runoff_land,
ae_openw_l = ae_openw_l,
ae_openw_r = ae_openw_r,
net_runoff_river = net_runoff_river,
runoff_river = fill(mv, n),
runoff_land = fill(mv, n),
ae_openw_l = fill(mv, n),
ae_openw_r = fill(mv, n),
net_runoff_river = fill(mv, n),
)
end

Expand Down Expand Up @@ -64,16 +57,11 @@ end
end

"Initialize open water runoff boundary conditions"
function OpenWaterRunoffBC(
n;
water_flux_surface::Vector{T} = fill(mv, n),
waterlevel_land::Vector{T} = fill(mv, n),
waterlevel_river::Vector{T} = zeros(Float, n), # set to zero to account for cells outside river domain
) where {T}
function OpenWaterRunoffBC(T::Type{<:AbstractFloat}, n::Int)
return OpenWaterRunoffBC{T}(;
water_flux_surface = water_flux_surface,
waterlevel_land = waterlevel_land,
waterlevel_river = waterlevel_river,
water_flux_surface = fill(mv, n),
waterlevel_land = fill(mv, n),
waterlevel_river = zeros(T, n),
)
end

Expand All @@ -87,8 +75,8 @@ end
"Initialize open water runoff model"
function OpenWaterRunoff(nc, config, inds, riverfrac)
n = length(riverfrac)
vars = OpenWaterRunoffVariables(n)
bc = OpenWaterRunoffBC(n)
vars = OpenWaterRunoffVariables(Float, n)
bc = OpenWaterRunoffBC(Float, n)
params = OpenWaterRunoffParameters(nc, config, inds, riverfrac)
model =
OpenWaterRunoff(; boundary_conditions = bc, parameters = params, variables = vars)
Expand Down
21 changes: 7 additions & 14 deletions src/vegetation/canopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@ abstract type AbstractInterceptionModel{T} end
end

"Initialize interception model variables"
function InterceptionVariables(
n;
canopy_potevap::Vector{T} = fill(mv, n),
interception_rate::Vector{T} = fill(mv, n),
canopy_storage::Vector{T} = fill(0.0, n),
stemflow::Vector{T} = fill(mv, n),
throughfall::Vector{T} = fill(mv, n),
) where {T}
function InterceptionVariables(T::Type{<:AbstractFloat}, n::Int)
return InterceptionVariables(;
canopy_potevap = canopy_potevap,
interception_rate = interception_rate,
canopy_storage = canopy_storage,
stemflow = stemflow,
throughfall = throughfall,
canopy_potevap = fill(mv, n),
interception_rate = fill(mv, n),
canopy_storage = zeros(T, n),
stemflow = fill(mv, n),
throughfall = fill(mv, n),
)
end

Expand Down Expand Up @@ -58,7 +51,7 @@ function GashInterceptionModel(nc, config, inds, vegetation_parameter_set)
n = length(inds)
params =
GashParameters(; e_r = e_r, vegetation_parameter_set = vegetation_parameter_set)
vars = InterceptionVariables(n)
vars = InterceptionVariables(Float, n)
model = GashInterceptionModel(; parameters = params, variables = vars)
return model
end
Expand Down

0 comments on commit 0e06992

Please sign in to comment.