Skip to content

Commit 2f02a6e

Browse files
author
Est
committed
itermediate state
1 parent 3bc5b81 commit 2f02a6e

File tree

5 files changed

+76
-71
lines changed

5 files changed

+76
-71
lines changed

docs/examples/getting_started_with_network_dynamics.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ by the authors of `DifferentialEquations.jl` for most non-stiff problems.
175175
=#
176176
ode_prob = ODEProblem(nd, x0, (0.0, 2.0))
177177

178-
# We test all ex styles #src (@Hans: can you write here what this means?)
179-
Main.test_execution_styles(ode_prob)
178+
# We test all ex styles #src
179+
Main.test_execution_styles(ode_prob) #src
180+
180181

181182
# Solve the simulation commend
182183
sol = solve(ode_prob, Tsit5());
@@ -216,7 +217,7 @@ nd_2 = Network(g, nd_diffusion_vertex_2, nd_diffusion_edge_2)
216217
# x ~ N(0,1)^2; ϕ ~ N(0,1)
217218
x0_2 = vec(transpose([randn(rng, N) .^ 2 randn(rng, N)]))
218219
ode_prob_2 = ODEProblem(nd_2, x0_2, (0.0, 3.0))
219-
Main.test_execution_styles(ode_prob_2)
220+
Main.test_execution_styles(ode_prob_2) #src
220221
sol_2 = solve(ode_prob_2, Tsit5());
221222

222223

@@ -253,7 +254,6 @@ To study the asymptotic behaviour of the system it suffices to analyze the eigen
253254

254255
#=
255256
# Putting it all together
256-
We begin by loading the necessary packages.
257257
=#
258258

259259
using Graphs
@@ -297,7 +297,7 @@ nd = Network(g, nd_diffusion_vertex, nd_diffusion_edge)
297297
rng = StableRNG(1)
298298
x0 = randn(rng, N)
299299
ode_prob = ODEProblem(nd, x0, (0.0, 2.0))
300-
Main.test_execution_styles(ode_prob)
300+
Main.test_execution_styles(ode_prob) #src
301301
sol = solve(ode_prob, Tsit5());
302302
nothing #hide #md
303303
plot(sol; idxs=vidxs(nd, :, :), fmt=:png)
@@ -309,7 +309,7 @@ nd_diffusion_edge_2 = EdgeModel(; g=AntiSymmetric(diffusionedge_g!), outsym=[:fl
309309
nd_2 = Network(g, nd_diffusion_vertex_2, nd_diffusion_edge_2)
310310
x0_2 = vec(transpose([randn(rng, N) .^ 2 randn(rng, N)]))
311311
ode_prob_2 = ODEProblem(nd_2, x0_2, (0.0, 3.0))
312-
Main.test_execution_styles(ode_prob_2)
312+
Main.test_execution_styles(ode_prob_2) #src
313313
sol_2 = solve(ode_prob_2, Tsit5());
314314
plot(sol_2; idxs=vidxs(nd_2, :, :x), fmt=:png)
315315
plot(sol_2; idxs=eidxs(nd_2, :, :flow_x), fmt=:png)

docs/examples/heterogeneous_system.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#=
22
# Modeling a heterogeneous system
33
4-
This example can be dowloaded as a normal Julia script [here](@__NAME__.jl). #md
4+
This example can be downloaded as a normal Julia script [here](@__NAME__.jl). #md
55
6-
One of the main purposes of NetworkDynamics.jl is to facilitate
7-
modeling coupled systems with heterogenities. This means that
8-
components can differ in their parameters as well as in their dynamics.
6+
One of the main purposes of NetworkDynamics.jl is to facilitate the
7+
modeling systems whose components can differ in their parameters as well as their dynamics.
8+
These are known as Coupled systems with heterogeneities.
99
10-
## Heterogenous parameters
10+
## Heterogeneous parameters
1111
1212
We start by setting up a simple system of Kuramoto oscillators.
1313
=#

docs/src/index.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# NetworkDynamics
22

3-
*NetworkDynamics.jl* is a package to simulate dynamical systems within complex networks. It provides an interface
3+
The *NetworkDynamics.jl* package simulates dynamical systems within complex networks. It provides an interface
44
between the [Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl) and the
55
[DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl) packages and facilitates the simulation of
6-
highly efficient dynamic networks by describing the local dynamics on the edges and vertices of the graph.
6+
highly efficient dynamic networks by describing the local dynamics on the edges and vertices of the network graph.
77

88
!!! note
9+
** Complex Networks in a glance **
910
Complex network systems are composed by the entities that comprise them (the nodes) and the relationships that connect
10-
each entity with one another (the edges). The graphical depictions of such networks are called graphs. The simplest
11-
The mathematical structure (used more or less interchangeably with Network) is also called [Graph](https://en.wikipedia.org/wiki/Graph_theory).
12-
The network (which can be seen in the figure below) is composed of two entities (so two nodes) who are only connected to each other.
13-
This connection between the two is the edge of the system. Complex networks are composed of multiple nodes and edges,
14-
with most nodes connected to multiple other nodes with multiple edges
11+
each entity with one another (the edges). The mathematical structure (used more or less interchangeably with
12+
Network) is called [Graph](https://en.wikipedia.org/wiki/Graph_theory). The graphical depictions of such
13+
networks are also called graphs. You will see both usages in this guide.
14+
A network (which can be seen in the figure below) is composed of nodes (v1 to v5) who are connected to each other.
15+
The lines connecting the nodes with each other ( e1: 1-->2, e2: 1-->3, e3: 2-->3, e4: 2-->4, e5: 3-->5) are called
16+
edges. Complex networks are composed of multiple nodes and edges, with most nodes connected to multiple other nodes
17+
with multiple edges
1518

1619
```@example
1720
using Graphs, GraphMakie, CairoMakie #hide
@@ -27,31 +30,22 @@ hidespines!(ax) #hide
2730
hidedecorations!(ax) #hide
2831
fig #hide
2932
```
30-
31-
The behavior of a node or an edge can be described through the use of (a) algebraic equations, (b) differential algebraic
32-
equation (DAEs) in mass matrix form or c) ordinary differential equations (ODE).
33-
34-
The core of the package is the function [`Network`](@ref). It accepts the functions describing the local dynamics on the
35-
edges and nodes of the graph `g` as inputs, and returns a composite function compatible with the
36-
DifferentialEquations.jl calling syntax.
37-
38-
```julia
39-
nd = Network(g, vertex_dynamics, edge_dynamics)
40-
nd(dx, x, p, t)
41-
```
33+
(@Hans after rereading the text I realised that the information about the core of the package and the behaviours of the
34+
nodes and edges does not belong in the introduction but rather in the mathematical model, so I moved it. If you are ok)
35+
with this just delete this comment)
4236

4337
Main features:
4438
- Clear separation of local dynamics and topology: you can easily change the topology of your system or switch out
45-
- dynamic components.
39+
dynamic components)
4640
- High performance when working with heterogeneous models: you can have different local dynamics in different parts of
47-
- your network.
41+
your network)
4842
- [Symbolic Indexing](@ref) into solutions and states: NetworkDynamics keeps track of the states of each individual
49-
- subsystem.
43+
subsystem.
5044
- Diverse execution schemes: NetworkDynamics exploits the known interdependencies between components to auto
51-
- parallelize execution, even on GPUs!
45+
parallelize execution, even on GPUs!
5246
- Equation based models: you can model local dynamics using
53-
- [ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/dev/) and them combine them into larger networks by using
54-
- `NetworkDynamics.jl`!
47+
[ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/dev/) and them combine them into larger networks using
48+
`NetworkDynamics.jl`!
5549

5650

5751
## Where to begin?

docs/src/mathematical_model.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,50 @@
11
# Mathematical Model
2-
The basic mathematical model of `NetworkDynamics.jl` splits the system in two parts: the vertex and
3-
the edge components.
42

5-
The main goal of `NetworkDynamics.jl` is to express the overall network dynamics as a
6-
[Differential-Algebraic-Equation (DAE)](https://mathworld.wolfram.com/Differential-AlgebraicEquation.html)
3+
The core of the `NetworkDynamics.jl` package is the [`Network`](@ref) function. It accepts the functions describing the
4+
local dynamics on the edges and nodes of the graph `g` as inputs, and returns a composite function compatible with the
5+
DifferentialEquations.jl syntax.
76

7+
```julia
8+
nd = Network(g, vertex_dynamics, edge_dynamics)
9+
nd(dx, x, p, t)
10+
```
11+
12+
The local dynamics on the edges and nodes of the graph can be described through the use of (a) algebraic equations,
13+
(b) differential algebraic equation (DAEs) in mass matrix form or (c) ordinary differential equations (ODE). The
14+
`NetworkDynamics.jl` package uses [Differential-Algebraic-Equation (DAE)](https://mathworld.wolfram.com/Differential-AlgebraicEquation.html)
15+
to express the overall network dynamics:
816
```math
917
M\,\frac{\mathrm{d}}{\mathrm{d}t}u = f^{\mathrm{nw}}(u, p, t)
1018
```
1119
where $M$ is a (possibly singular) mass matrix, $u$ is the internal state vector of the system, $p$ are the parameters
12-
and $t$ is the time.
13-
To make this compatible with the solvers used in `OrdinaryDiffEq.jl`, the generated
14-
[`Network`](@ref) object is a callable object
20+
and $t$ is the time. To make this compatible with the solvers used in `OrdinaryDiffEq.jl`, the generated
21+
[`Network`](@ref) object is a callable object:
1522
```
1623
nw(du, u, p, t) # mutates du as an "output"
1724
```
18-
which represents the right-hand-side (RHS) of the equation above. The mass-matrix $m$ is stored in the `Network` object as well.
19-
20-
Instead of defining $f^{\mathrm{nw}}$ by hand, `ND.jl` helps you to build it automatically based on a list of
21-
decentralized nodal and edge dynamics, the so-called `VertexModel` and `EdgeModel` objects. Each component model
22-
$\mathrm c$ is modeled as a general input-output-system:
25+
which represents the right-hand-side (RHS) of the equation above. The mass-matrix $m$ is stored in the `Network` object
26+
as well.
2327

28+
Each component model $\mathrm c$ is modeled as a general input-output-system:
2429
```math
2530
\begin{aligned}
2631
M_{\mathrm c}\,\frac{\mathrm{d}}{\mathrm{d}t}x_{\mathrm c} &= f^{\mathrm c}(x^{\mathrm c}, i_{\mathrm c}, p_{\mathrm c}, t)\\
2732
y^{\mathrm c} &= g^{\mathrm c}(x^\mathrm{c}, i_{\mathrm c}, p_{\mathrm c}, t)
2833
\end{aligned}
2934
```
30-
3135
where $M_{\mathrm{c}}$ is the component mass matrix, $x^{\mathrm c}$ are the component states, $i^{\mathrm c}$ are the
32-
***inputs*** of the component and $y^{\mathrm c}$ is the ***output*** of the component.
33-
If $\mathrm{dim}(x^{\mathrm{c}}) = 0$, the number of internal states is 0.
36+
***inputs*** of the component and $y^{\mathrm c}$ is the ***output*** of the component. If
37+
$\mathrm{dim}(x^{\mathrm{c}}) = 0$, the number of internal states is 0.
38+
39+
The mathematical model of `NetworkDynamics.jl` splits the network system in two parts: the vertex and
40+
the edge components (the nodes and edges, respectively). Instead of defining the $f^{\mathrm{nw}}$ by hand, `ND.jl`
41+
builds it automatically based on a list of decentralized nodal and edge dynamics that you need to provide,
42+
the so-called `VertexModel` and `EdgeModel` objects.
3443

3544
In the context of the network, the **output of the edges are flow variables** and the **outputs of vertices are
36-
potential variables**.
37-
When the node and edge models are placed on a graph, the inputs and outputs ware connected: the nodes receive the output of the
38-
adjacent edges as inputs and the edges receive the output of the adjecent nodes as inputs.
45+
potential variables**. When the node and edge models are placed on a graph, the inputs and outputs ware connected:
46+
the nodes receive the output of the adjacent edges as inputs and the edges receive the output of the adjecent nodes as
47+
inputs.
3948

4049
Thus, the *flow* on the edges depends on the *potentials* at both ends as inputs. The *potentials* of the nodes depend on the
4150
incoming *flows* from all connected edges as an input. (Here, flow and potentials are meant in a conceptional and not
@@ -45,6 +54,8 @@ necessarily physical way.)
4554
<img src="../assets/mathmodel.svg" width="100%"/>
4655
```
4756

57+
58+
4859
## Vertex Models
4960
```@raw html
5061
<img src="../assets/nodemodel.svg" width="100%"/>

docs/src/symbolic_indexing.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
# Symbolic Indexing
22

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-
5-
!!! details "Setup code to make following examples work"
6-
```@example si
7-
using NetworkDynamics
8-
using Graphs
9-
using OrdinaryDiffEqTsit5
10-
using Plots
11-
```
3+
By using SciML's [`SymbolicIndexingInterface.jl`](https://github.com/SciML/SymbolicIndexingInterface.jl), `ND.jl`
4+
provides numerous methods to access and change variables and parameters.
125

136
## Provide Symbol Names
147
When constructing component models, you can pass symbolic names using the `sym` and `psym` keywords.
158
```@example si
9+
using NetworkDynamics
10+
using Graphs
11+
using OrdinaryDiffEqTsit5
12+
using Plots
1613
function _edgef!(e, v_s, v_d, (K,), t)
1714
e .= K * (v_s[1] .- v_d[1])
1815
end
1916
edgef = EdgeModel(;g=AntiSymmetric(_edgef!), outsym=[:flow], psym=[:K=>1])
2017
```
21-
Here we created a static diffusion edge with suitable variable and parameter names.
18+
Here we create a static diffusion edge with suitable variable and parameter names.
2219
Similarly, we define the diffusion vertex with symbolic names.
2320
```@example si
2421
function _vertexf!(dv, v, esum, p, t)
@@ -30,12 +27,11 @@ vertexf = VertexModel(f=_vertexf!, g=1, sym=[:storage])
3027

3128
## Fundamental Symbolic Indices
3229
The default types for this access are the types [`VIndex`](@ref), [`EIndex`](@ref), [`VPIndex`](@ref) and [`EPIndex`](@ref).
33-
Each of those symbolic indices consists of 2 elements: a reference to the network component and a reference to the symbol within that component.
30+
Each of those symbolic indices consists of 2 elements: a reference to the network component and a reference to the
31+
symbol within that component.
3432
As such:
3533
- `VIndex(2, :x)` refers to variable with symbolic name `:x` in vertex number 2.
3634
- `EPIndex(4, 2)` refers to the *second* parameter of the edge component for the 4th edge.
37-
- `VPIndex`() refers to (@Hans please fill in this with an example)
38-
- `EPIndex`() refers to (@Hans please fill in this with an example)
3935

4036
!!! details "Setup code to make following examples work"
4137
```@example si
@@ -55,7 +51,8 @@ plot(sol; idxs=[VIndex(1, :storage), VIndex(5,:storage)]) # plot storage of two
5551
```
5652

5753
## Generate Symbolic Indices
58-
Often, you need many individual symbolic indices. To achieve this you can use the helper methods [`vidxs`](@ref), [`eidxs`](@ref), [`vpidxs`](@ref) and [`epidxs`](@ref). With their help you can generate arrays of symbolic indices:
54+
Often, you need many individual symbolic indices. To achieve this you can use the helper methods [`vidxs`](@ref),
55+
[`eidxs`](@ref), [`vpidxs`](@ref) and [`epidxs`](@ref). With their help you can generate arrays of symbolic indices:
5956

6057
```@example si
6158
vidxs(nw, :, :storage) # get variable "storage" for all vertices
@@ -100,7 +97,8 @@ in these flat arrays corresponds exactly to the order returned by [`variable_sym
10097

10198
!!! note
10299
The `NWState` and `NWParameter` wrappers can be constructed from various objects.
103-
For example, within a callback you might construct `p = NWParameter(integrator)` to then change the parameters of the network within the callback.
100+
For example, within a callback you might construct `p = NWParameter(integrator)` to then change the parameters of
101+
the network within the callback.
104102

105103

106104
## Observables
@@ -113,7 +111,8 @@ It is also possible to define additional Observables manually by using the `obss
113111
on the `EdgeModel`/`VertexModel` constructors.
114112
When building models using ModelingToolkit, the reduced algebraic states will be preserved automatically as observables.
115113

116-
Observables can be accessed like any other state. For example, the flows in the network don't show up in the state array but can be accessed in all the ways discussed above.
114+
Observables can be accessed like any other state. For example, the flows in the network don't show up in the state array
115+
but can be accessed in all the ways discussed above.
117116
For example:
118117
```@example si
119118
plot(sol; idxs=eidxs(nw, :, :flow))
@@ -130,7 +129,8 @@ For example, we can directly plot the storage difference with respect to storage
130129
plot(sol; idxs=@obsex(vidxs(nw,:,:storage) .- VIndex(1,:storage)))
131130
```
132131

133-
Other examples include calculating the magnitude and argument of complex values that are modeled using real and imaginary parts.
132+
Other examples include calculating the magnitude and argument of complex values that are modeled using real and
133+
imaginary parts.
134134
```
135135
@obsex mag = sqrt(VIndex(1, :u_r)^2 + VIndex(2, :u_i)^2)
136136
```

0 commit comments

Comments
 (0)