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
Copy file name to clipboardExpand all lines: docs/src/model_simulation/simulation_structure_interfacing.md
+10-4Lines changed: 10 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,9 @@ When simulating a model, one begins with creating a [problem](https://docs.sciml
3
3
4
4
Generally, when we have a structure `simulation_struct` and want to interface with the unknown (or parameter) `G`, we use `simulation_struct[:G]` to access the value, and `simulation_struct[:G] = 5.0` to set it to a new value. However, see the following examples for full details.
5
5
6
+
!!! note
7
+
The following tutorial will describe how to interface with problems, integrators, and solutions using `[]` notation. An alternative is to use the `ModelingToolkit.getu`, `ModelingToolkit.getp`, `ModelingToolkit.setu`, and `ModelingToolkit.setp` functions. These requires an additional step to use, however, they can also improve performance when a very large number interfaces are carried out.
8
+
6
9
## Interfacing problem objects
7
10
8
11
We begin by demonstrating how we can interface with problem objects. We will demonstrate using a `ODEProblem`, however, it works similarly for other problem types.
@@ -24,7 +27,7 @@ oprob[:X1]
24
27
```
25
28
with the notation being identical for parameters:
26
29
```@example ex1
27
-
oprob[:k1]
30
+
oprob.ps[:k1]
28
31
```
29
32
30
33
If we want to change an unknown's initial condition value, we use the following notation
@@ -33,6 +36,9 @@ oprob[:X1] = 10.0
33
36
```
34
37
with parameters using the same notation.
35
38
39
+
!!! note
40
+
When interfacing with a parameter, `.ps` must be appended to the structure uses (e.g. `oprob`). This is not done when species are interfaced with.
41
+
36
42
#### [Remaking problems using the `remake` function](@id simulation_structure_interfacing_remake)
37
43
Typically, when modifying problems, it is recommended to use the `remake` function. Unlike when we do `oprob[:X1] = 10.0` (which modifies the problem in question), `remake` creates a new problem object. The `remake` function takes a problem as input, and any fields you wish to modify (and their new values) as optional inputs. Thus, we can do:
38
44
```@example ex1
@@ -74,7 +80,7 @@ integrator[:X1]
74
80
```
75
81
or a parameter:
76
82
```@example ex1
77
-
integrator[:k1]
83
+
integrator.ps[:k1]
78
84
```
79
85
Similarly, we can update their values using:
80
86
```@example ex1
@@ -95,7 +101,7 @@ sol[:X1]
95
101
```
96
102
while when we access a parameter we only get a single value:
97
103
```@example ex1
98
-
sol[:k1]
104
+
sol.ps[:k1]
99
105
```
100
106
Finally, we note that we cannot change the values of solution unknowns or parameters (i.e. both `sol[:X1] = 0.0` and `sol[:k1] = 0.0` generate errors).
101
107
@@ -124,7 +130,7 @@ u0 = [X1 => 1.0, X2 => 5.0]
124
130
p = [:k1 => 5.0, :k2 => 2.0]
125
131
oprob = ODEProblem(rn, u0, (0.0,10.0), p)
126
132
127
-
oprob[k1]
133
+
oprob.ps[k1]
128
134
```
129
135
To interface with integrators and solutions we use a similar syntax.
0 commit comments