Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor types and model initialization #517

Merged
merged 22 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2703a3e
Simplify model type dispatch
SouthEndMusic Dec 9, 2024
8f814b1
Make Network data structure explicit in structs
SouthEndMusic Dec 9, 2024
4660004
Introduce Lateral struct
SouthEndMusic Dec 9, 2024
0d7dd56
Refactor `initialize_sbm_model`
SouthEndMusic Dec 10, 2024
0395614
Refactor `initialize_svm_gwf_model`
SouthEndMusic Dec 10, 2024
871a084
Refactor `initialize_sediment_model`
SouthEndMusic Dec 10, 2024
bd7de38
Make Model type parameters more informative
SouthEndMusic Dec 10, 2024
3d14d21
Remove ct
SouthEndMusic Dec 10, 2024
c8805f1
Update model struct in docs
SouthEndMusic Dec 10, 2024
9d0c217
Rename `vertical` to `land`
vers-w Dec 19, 2024
7a03e5e
Merge branch 'master' into refactorings
vers-w Dec 19, 2024
6f9baa3
Rename `vertical` to `land` in client.jl
vers-w Dec 19, 2024
9a118ae
Rename `lateral` to `routing`
vers-w Dec 20, 2024
2fe8b3f
Oh well, let's also include this file...
vers-w Dec 20, 2024
97defb9
Store network info reservoir and lake in `NetworkWaterBody`
vers-w Jan 6, 2025
aeeb911
Add inline documentation to network.jl
vers-w Jan 6, 2025
5ffa714
Refactor `network` of `sediment` model type
vers-w Jan 6, 2025
62f7c27
Remove `frac_to_river` computation from `sediment` model type
vers-w Jan 6, 2025
31508bc
Add abstract types to `Routing`
vers-w Jan 7, 2025
23cb579
Update `Model` struct in docs
vers-w Jan 7, 2025
a231381
Rename struct `Indices` to `EdgeConnectivity`
vers-w Jan 8, 2025
a338d3c
Rename `vertical_process.jl` to `land_process.jl`
vers-w Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@

julia_version = "1.10.7"
manifest_format = "2.0"
project_hash = "986b47155507036c06218d23750fe8de28eb001a"
project_hash = "7340a1e1d084fa2d694e3291e3df55fd710ca408"

[[deps.AbstractTrees]]
git-tree-sha1 = "2d9c9a55f9c93e8887ad391fbae72f8ef55e1177"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.4.5"

[[deps.Accessors]]
deps = ["CompositionsBase", "ConstructionBase", "InverseFunctions", "LinearAlgebra", "MacroTools", "Markdown"]
git-tree-sha1 = "b392ede862e506d451fc1616e79aa6f4c673dab8"
uuid = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
version = "0.1.38"

[deps.Accessors.extensions]
AccessorsAxisKeysExt = "AxisKeys"
AccessorsDatesExt = "Dates"
AccessorsIntervalSetsExt = "IntervalSets"
AccessorsStaticArraysExt = "StaticArrays"
AccessorsStructArraysExt = "StructArrays"
AccessorsTestExt = "Test"
AccessorsUnitfulExt = "Unitful"

[deps.Accessors.weakdeps]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "50c3c56a52972d78e8be9fd135bfb91c9574c140"
Expand Down Expand Up @@ -134,6 +159,30 @@ deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.1.1+0"

[[deps.CompositionsBase]]
git-tree-sha1 = "802bb88cd69dfd1509f6670416bd4434015693ad"
uuid = "a33af91c-f02d-484b-be07-31d278c5ca2b"
version = "0.1.2"
weakdeps = ["InverseFunctions"]

[deps.CompositionsBase.extensions]
CompositionsBaseInverseFunctionsExt = "InverseFunctions"

[[deps.ConstructionBase]]
git-tree-sha1 = "76219f1ed5771adbb096743bff43fb5fdd4c1157"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.5.8"

[deps.ConstructionBase.extensions]
ConstructionBaseIntervalSetsExt = "IntervalSets"
ConstructionBaseLinearAlgebraExt = "LinearAlgebra"
ConstructionBaseStaticArraysExt = "StaticArrays"

[deps.ConstructionBase.weakdeps]
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[[deps.CpuId]]
deps = ["Markdown"]
git-tree-sha1 = "fcbb72b032692610bfbdb15018ac16a36cf2e406"
Expand Down Expand Up @@ -228,6 +277,19 @@ version = "0.1.5"
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[deps.InverseFunctions]]
git-tree-sha1 = "a779299d77cd080bf77b97535acecd73e1c5e5cb"
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
version = "0.1.17"

[deps.InverseFunctions.extensions]
InverseFunctionsDatesExt = "Dates"
InverseFunctionsTestExt = "Test"

[deps.InverseFunctions.weakdeps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.JLLWrappers]]
deps = ["Artifacts", "Preferences"]
git-tree-sha1 = "be3dc50a92e5a386872a493a10050136d4703f9b"
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Deltares and contributors"]
version = "0.8.1"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
BasicModelInterface = "59605e27-edc0-445a-b93d-c09a3a50b330"
CFTime = "179af706-886a-5703-950a-314cd64e0468"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -24,6 +25,7 @@ TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"

[compat]
Accessors = "0.1"
Aqua = "0.8"
BasicModelInterface = "0.1"
CFTime = "0.1"
Expand Down
19 changes: 10 additions & 9 deletions docs/developments/julia_structs.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ Below the composite type that represents all different aspects of a `Wflow.Model
network, parameters, clock, model type, configuration and input and output.

```julia
struct Model{N,L,V,R,W,T}
config::Config # all configuration options
network::N # connectivity information, directed graph
lateral::L # lateral model that holds lateral state, moves along network
vertical::V # vertical model that holds vertical state, independent of each other
clock::Clock # to keep track of simulation time
reader::R # provides the model with dynamic input
writer::W # writes model output
type::T # model type
struct Model{R <: Routing, L <: AbstractLandModel, T <: AbstractModelType} <:
AbstractModel{T}
config::Config # all configuration options
network::Network # connectivity information, directed graph
routing::R # routing model (horizontal fluxes), moves along network
land::L # land model simulating vertical fluxes, independent of each other
clock::Clock # to keep track of simulation time
reader::NCReader # provides the model with dynamic input
writer::Writer # writes model output
type::T # model type
end
```

Expand Down
67 changes: 32 additions & 35 deletions server/test/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ end
end

@testset "Reading and writing NaN values allowed" begin
msg =
(fn = "get_value", name = "vertical.soil.variables.vwc[1]", dest = fill(0.0, 50063))
msg = (fn = "get_value", name = "land.soil.variables.vwc[1]", dest = fill(0.0, 50063))
@test isnan(mean(request(msg)["value"]))
end

Expand All @@ -41,10 +40,10 @@ end
@test request((fn = "get_input_item_count",)) == Dict("input_item_count" => 202)
@test request((fn = "get_output_item_count",)) == Dict("output_item_count" => 202)
to_check = [
"vertical.soil.parameters.nlayers",
"vertical.soil.parameters.theta_r",
"lateral.river.variables.q",
"lateral.river.boundary_conditions.reservoir.variables.outflow",
"land.soil.parameters.nlayers",
"land.soil.parameters.theta_r",
"routing.river_flow.variables.q",
"routing.river_flow.boundary_conditions.reservoir.variables.outflow",
]
retrieved_vars = request((fn = "get_input_var_names",))["input_var_names"]
@test all(x -> x in retrieved_vars, to_check)
Expand All @@ -55,101 +54,99 @@ end
zi_size = 0
vwc_1_size = 0
@testset "variable information and get and set functions" begin
@test request((fn = "get_var_itemsize", name = "lateral.subsurface.variables.ssf")) ==
Dict("var_itemsize" => sizeof(Wflow.Float))
@test request((fn = "get_var_type", name = "vertical.n"))["status"] == "ERROR"
@test request((fn = "get_var_units", name = "vertical.soil.parameters.theta_s")) ==
@test request((
fn = "get_var_itemsize",
name = "routing.subsurface_flow.variables.ssf",
)) == Dict("var_itemsize" => sizeof(Wflow.Float))
@test request((fn = "get_var_type", name = "land.n"))["status"] == "ERROR"
@test request((fn = "get_var_units", name = "land.soil.parameters.theta_s")) ==
Dict("var_units" => "-")
@test request((fn = "get_var_location", name = "lateral.river.variables.q")) ==
@test request((fn = "get_var_location", name = "routing.river_flow.variables.q")) ==
Dict("var_location" => "node")
zi_nbytes =
request((fn = "get_var_nbytes", name = "vertical.soil.variables.zi"))["var_nbytes"]
request((fn = "get_var_nbytes", name = "land.soil.variables.zi"))["var_nbytes"]
@test zi_nbytes == 400504
zi_itemsize =
request((fn = "get_var_itemsize", name = "vertical.soil.variables.zi"))["var_itemsize"]
request((fn = "get_var_itemsize", name = "land.soil.variables.zi"))["var_itemsize"]
zi_size = Int(zi_nbytes / zi_itemsize)
vwc_1_nbytes =
request((fn = "get_var_nbytes", name = "vertical.soil.variables.vwc[1]"))["var_nbytes"]
request((fn = "get_var_nbytes", name = "land.soil.variables.vwc[1]"))["var_nbytes"]
@test vwc_1_nbytes == 400504
vwc_1_itemsize =
request((fn = "get_var_itemsize", name = "vertical.soil.variables.vwc[1]"))["var_itemsize"]
request((fn = "get_var_itemsize", name = "land.soil.variables.vwc[1]"))["var_itemsize"]
vwc_1_size = Int(vwc_1_nbytes / vwc_1_itemsize)
@test request((fn = "get_var_grid", name = "lateral.river.variables.h")) ==
@test request((fn = "get_var_grid", name = "routing.river_flow.variables.h")) ==
Dict("var_grid" => 3)
msg = (fn = "get_value", name = "vertical.soil.variables.zi", dest = fill(0.0, zi_size))
msg = (fn = "get_value", name = "land.soil.variables.zi", dest = fill(0.0, zi_size))
@test mean(request(msg)["value"]) ≈ 277.3620724821974
msg = (fn = "get_value_ptr", name = "vertical.soil.parameters.theta_s")
msg = (fn = "get_value_ptr", name = "land.soil.parameters.theta_s")
@test mean(request(msg)["value_ptr"]) ≈ 0.4409211971535584
msg = (
fn = "get_value_at_indices",
name = "lateral.river.variables.q",
name = "routing.river_flow.variables.q",
dest = [0.0, 0.0, 0.0],
inds = [1, 5, 10],
)
@test request(msg)["value_at_indices"] ≈
[2.1007361866518766, 2.5702292750107687, 3.2904803551115727]
msg =
(fn = "set_value", name = "vertical.soil.variables.zi", src = fill(300.0, zi_size))
msg = (fn = "set_value", name = "land.soil.variables.zi", src = fill(300.0, zi_size))
@test request(msg) == Dict("status" => "OK")
msg = (fn = "get_value", name = "vertical.soil.variables.zi", dest = fill(0.0, zi_size))
msg = (fn = "get_value", name = "land.soil.variables.zi", dest = fill(0.0, zi_size))
@test mean(request(msg)["value"]) == 300.0
msg = (
fn = "set_value_at_indices",
name = "vertical.soil.variables.zi",
name = "land.soil.variables.zi",
src = [250.0, 350.0],
inds = [1, 2],
)
@test request(msg) == Dict("status" => "OK")
msg = (
fn = "get_value_at_indices",
name = "vertical.soil.variables.zi",
name = "land.soil.variables.zi",
dest = [0.0, 0.0, 0.0],
inds = [1, 2, 3],
)
@test request(msg)["value_at_indices"] == [250.0, 350.0, 300.0]
msg = (
fn = "get_value",
name = "vertical.soil.variables.vwc[1]",
name = "land.soil.variables.vwc[1]",
dest = fill(0.0, vwc_1_size),
)
@test mean(request(msg)["value"]) ≈ 0.18600013563085036f0
msg = (
fn = "get_value_at_indices",
name = "vertical.soil.variables.vwc[1]",
name = "land.soil.variables.vwc[1]",
dest = [0.0, 0.0, 0.0],
inds = [1, 2, 3],
)
@test request(msg)["value_at_indices"] ≈
[0.12089607119560242f0, 0.11968416924304527f0, 0.14602328618707333f0]
msg = (
fn = "set_value",
name = "vertical.soil.variables.vwc[1]",
src = fill(0.3, vwc_1_size),
)
msg =
(fn = "set_value", name = "land.soil.variables.vwc[1]", src = fill(0.3, vwc_1_size))
@test request(msg) == Dict("status" => "OK")
msg = (
fn = "get_value",
name = "vertical.soil.variables.vwc[1]",
name = "land.soil.variables.vwc[1]",
dest = fill(0.0, vwc_1_size),
)
@test mean(request(msg)["value"]) ≈ 0.3f0
msg = (
fn = "get_value_at_indices",
name = "vertical.soil.variables.vwc[1]",
name = "land.soil.variables.vwc[1]",
dest = [0.0, 0.0, 0.0],
inds = [1, 2, 3],
)
@test request(msg)["value_at_indices"] == [0.3, 0.3, 0.3]
msg = (
fn = "set_value_at_indices",
name = "vertical.soil.variables.vwc[1]",
name = "land.soil.variables.vwc[1]",
src = [0.1, 0.25],
inds = [1, 2],
)
@test request(msg) == Dict("status" => "OK")
msg = (
fn = "get_value_at_indices",
name = "vertical.soil.variables.vwc[1]",
name = "land.soil.variables.vwc[1]",
dest = [0.0, 0.0],
inds = [1, 2],
)
Expand Down
Loading
Loading