You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A [`Network`](@ref) contains a list of vertex and edge models along with a graph.
4
+
However, in tight numerical loops, it will never access these lists of models directly.
5
+
Instead, the network maintains an internal representation that tracks all symbolic indices, defining the precise ordering of states and parameters in a flat array representation. To optimize performance, especially for heterogeneous networks, the network employs specialized data structures that batch identical models together.
6
+
7
+
This disconnect between the explicit lists and the internal data structures
8
+
can be confusing.
9
+
10
+
## Flat Parameter and State Arrays
11
+
12
+
The vertex and edge models may contain metadata, such as initial values for states and parameters.
13
+
Crucially, this metadata is **only** for building and initialization of the
14
+
simulation.
15
+
During actual simulation, the state and parameters are handled as **flat arrays**, i.e., plain `Vector{Float64}` objects.
16
+
17
+
[`NWState`](@ref) and [`NWParameter`](@ref) serve as wrappers around flat arrays and the [`Network`](@ref) objects, allowing you to inspect and modify those flat arrays by addressing vertices and edges directly.
18
+
19
+
A typical workflow is:
20
+
21
+
1. Set default values in the models using the metadata (see [Metadata](@ref)).
22
+
2. Create a network (see [Network Construction](@ref)).
23
+
3. Generate a state `s = NWState(nw)` which will be prefilled with the default values from the component metadata (see [SymbolicIndexing](@ref)).
24
+
4. Change the values of `s`, i.e., `s.v[1,:x] = 1.0`: This changes the **underlying flat array** but not the metadata of the models.
25
+
5. Build a problem with the updated flat arrays using `uflat(s)` and `pflat(s)`.
26
+
27
+
## Accessing Components
28
+
Per default, the models are not copied on Network construction:
nw[VIndex(1)] === nw[VIndex(3)] # neither of them === v1
66
+
```
67
+
68
+
## Extracting `Network`-object from Containers
69
+
`NetworkDynamics.jl` provides a [`extract_nw`](@ref) function, to get a reference to the wrapped `Network` object from different containers, such as solution objects or integrator objects.
Copy file name to clipboardExpand all lines: docs/src/mtk_integration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ as tearing of thousands of equations.
36
36
37
37
## RC-Circuit Example
38
38
In good [MTK tradition](https://docs.sciml.ai/ModelingToolkit/stable/tutorials/acausal_components/), this feature will be explained along a simple RC circuit example.
39
-
The [Dynamic Flow in Simple Gas Network](@ref)example is another showcase of the MTK constructors.
39
+
The [Gas Network Example](@ref gas-example) or [Initialization Tutorial](@ref init-tutorial) also showcase the MTK constructors.
40
40
41
41
The system to model is 2 node, 1 edge network. The node output states are the voltage (to ground), the edge output sates are the currents at both ends.
Copy file name to clipboardExpand all lines: docs/src/symbolic_indexing.md
+41-15Lines changed: 41 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Symbolic Indexing
2
2
3
-
Using SciML's [`SymblicIndexingInterface.jl`](https://github.com/SciML/SymbolicIndexingInterface.jl), `ND.jl` provides lots of methods to access and change variables and Parameters.
3
+
Using SciML's [`SymbolicIndexingInterface.jl`](https://github.com/SciML/SymbolicIndexingInterface.jl), `ND.jl` provides numerous methods to access and change variables and parameters.
4
4
5
5
!!! details "Setup code to make following examples work"
6
6
```@example si
@@ -11,7 +11,7 @@ Using SciML's [`SymblicIndexingInterface.jl`](https://github.com/SciML/SymbolicI
11
11
```
12
12
13
13
## Provide Symbol Names
14
-
When construction component models, you can pass symbolic names using the `sym` and `psym` keywords.
14
+
When constructing component models, you can pass symbolic names using the `sym` and `psym` keywords.
0 commit comments