Skip to content

Commit 64d9d43

Browse files
committed
Merge branch 'master' into myb/state_machine
2 parents af7c670 + 4b2ef38 commit 64d9d43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1099
-466
lines changed

NEWS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
+ `t_nounits` and `D_nounits` are unitless.
2121
- `ODAEProblem` is deprecated in favor of `ODEProblem`.
2222
- Specifying the independent variable for an `ODESystem` is now mandatory. The `ODESystem(eqs)`
23-
constructor is removed.
23+
constructor is removed. Use `ODESystem(eqs,t)` instead.
2424
- Systems must be marked as `complete` before creating `*Function`/`*FunctionExpr`/`*Problem`/
2525
`*ProblemExpr`. Typically this involved using `@mtkbuild` to create the system or calling
2626
`structural_simplify` on an existing system.
@@ -45,3 +45,7 @@
4545
equations. For example, `[p[1] => 1.0, p[2] => 2.0]` is no longer allowed in default equations, use
4646
`[p => [1.0, 2.0]]` instead. Also, array equations like for `@variables u[1:2]` have `D(u) ~ A*u` as an
4747
array equation. If the scalarized version is desired, use `scalarize(u)`.
48+
- Parameter dependencies are now supported. They can be specified using the syntax
49+
`(single_parameter => expression_involving_other_parameters)` and a `Vector` of these can be passed to
50+
the `parameter_dependencies` keyword argument of `ODESystem`, `SDESystem` and `JumpSystem`. The dependent
51+
parameters are updated whenever other parameters are modified, e.g. in callbacks.

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Yingbo Ma <[email protected]>", "Chris Rackauckas <[email protected]> and contributors"]
4-
version = "8.76.0"
4+
version = "9.0.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -69,7 +69,7 @@ Compat = "3.42, 4"
6969
ConstructionBase = "1"
7070
DataStructures = "0.17, 0.18"
7171
DiffEqBase = "6.103.0"
72-
DiffEqCallbacks = "2.16"
72+
DiffEqCallbacks = "2.16, 3"
7373
DiffRules = "0.1, 1.0"
7474
Distributed = "1"
7575
Distributions = "0.23, 0.24, 0.25"
@@ -97,16 +97,16 @@ RecursiveArrayTools = "2.3, 3"
9797
Reexport = "0.2, 1"
9898
RuntimeGeneratedFunctions = "0.5.9"
9999
SciMLBase = "2.0.1"
100+
SciMLStructures = "1.0"
100101
Serialization = "1"
101102
Setfield = "0.7, 0.8, 1"
102103
SimpleNonlinearSolve = "0.1.0, 1"
103-
SciMLStructures = "1.0"
104104
SparseArrays = "1"
105105
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
106106
StaticArrays = "0.10, 0.11, 0.12, 1.0"
107107
SymbolicIndexingInterface = "0.3.1"
108108
SymbolicUtils = "1.0"
109-
Symbolics = "5.7"
109+
Symbolics = "5.20.1"
110110
URIs = "1"
111111
UnPack = "0.1, 1.0"
112112
Unitful = "1.1"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ BifurcationKit = "0.3"
2525
DifferentialEquations = "7.6"
2626
Distributions = "0.25"
2727
Documenter = "1"
28-
ModelingToolkit = "8.33"
28+
ModelingToolkit = "8.33, 9"
2929
ModelingToolkitDesigner = "1"
3030
NonlinearSolve = "0.3, 1, 2, 3"
3131
Optim = "1.7"

docs/src/basics/Composition.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ of `decay2` is the value of the unknown variable `x`.
1616

1717
```@example composition
1818
using ModelingToolkit
19+
using ModelingToolkit: t_nounits as t, D_nounits as D
1920
2021
function decay(; name)
21-
@parameters t a
22+
@parameters a
2223
@variables x(t) f(t)
23-
D = Differential(t)
2424
ODESystem([
2525
D(x) ~ -a * x + f
26-
];
26+
], t;
2727
name = name)
2828
end
2929
3030
@named decay1 = decay()
3131
@named decay2 = decay()
3232
33-
@parameters t
34-
D = Differential(t)
3533
connected = compose(
3634
ODESystem([decay2.f ~ decay1.x
3735
D(decay1.f) ~ 0], t; name = :connected), decay1, decay2)
@@ -137,7 +135,7 @@ sys.y = u * 1.1
137135
In a hierarchical system, variables of the subsystem get namespaced by the name of the system they are in. This prevents naming clashes, but also enforces that every unknown and parameter is local to the subsystem it is used in. In some cases it might be desirable to have variables and parameters that are shared between subsystems, or even global. This can be accomplished as follows.
138136

139137
```julia
140-
@parameters t a b c d e f
138+
@parameters a b c d e f
141139

142140
# a is a local variable
143141
b = ParentScope(b) # b is a variable that belongs to one level up in the hierarchy
@@ -197,19 +195,16 @@ higher level system:
197195

198196
```@example compose
199197
using ModelingToolkit, OrdinaryDiffEq, Plots
198+
using ModelingToolkit: t_nounits as t, D_nounits as D
200199
201200
## Library code
202-
203-
@parameters t
204-
D = Differential(t)
205-
206201
@variables S(t), I(t), R(t)
207202
N = S + I + R
208203
@parameters β, γ
209204
210-
@named seqn = ODESystem([D(S) ~ -β * S * I / N])
211-
@named ieqn = ODESystem([D(I) ~ β * S * I / N - γ * I])
212-
@named reqn = ODESystem([D(R) ~ γ * I])
205+
@named seqn = ODESystem([D(S) ~ -β * S * I / N], t)
206+
@named ieqn = ODESystem([D(I) ~ β * S * I / N - γ * I], t)
207+
@named reqn = ODESystem([D(R) ~ γ * I], t)
213208
214209
sir = compose(
215210
ODESystem(

docs/src/basics/Events.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ friction
6565

6666
```@example events
6767
using ModelingToolkit, OrdinaryDiffEq, Plots
68+
using ModelingToolkit: t_nounits as t, D_nounits as D
69+
6870
function UnitMassWithFriction(k; name)
69-
@variables t x(t)=0 v(t)=0
70-
D = Differential(t)
71+
@variables x(t)=0 v(t)=0
7172
eqs = [D(x) ~ v
7273
D(v) ~ sin(t) - k * sign(v)]
7374
ODESystem(eqs, t; continuous_events = [v ~ 0], name) # when v = 0 there is a discontinuity
@@ -87,8 +88,7 @@ an `affect!` on the state. We can model the same system using ModelingToolkit
8788
like this
8889

8990
```@example events
90-
@variables t x(t)=1 v(t)=0
91-
D = Differential(t)
91+
@variables x(t)=1 v(t)=0
9292
9393
root_eqs = [x ~ 0] # the event happens at the ground x(t) = 0
9494
affect = [v ~ -v] # the effect is that the velocity changes sign
@@ -108,8 +108,7 @@ plot(sol)
108108
Multiple events? No problem! This example models a bouncing ball in 2D that is enclosed by two walls at $y = \pm 1.5$.
109109

110110
```@example events
111-
@variables t x(t)=1 y(t)=0 vx(t)=0 vy(t)=2
112-
D = Differential(t)
111+
@variables x(t)=1 y(t)=0 vx(t)=0 vy(t)=2
113112
114113
continuous_events = [[x ~ 0] => [vx ~ -vx]
115114
[y ~ -1.5, y ~ 1.5] => [vy ~ -vy]]
@@ -229,7 +228,7 @@ Suppose we have a population of `N(t)` cells that can grow and die, and at time
229228

230229
```@example events
231230
@parameters M tinject α
232-
@variables t N(t)
231+
@variables N(t)
233232
Dₜ = Differential(t)
234233
eqs = [Dₜ(N) ~ α - N]
235234

docs/src/basics/FAQ.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ end
102102
This error can come up after running `structural_simplify` on a system that generates dummy derivatives (i.e. variables with `ˍt`). For example, here even though all the variables are defined with initial values, the `ODEProblem` generation will throw an error that defaults are missing from the variable map.
103103

104104
```
105-
@variables t
105+
using ModelingToolkit
106+
using ModelingToolkit: t_nounits as t, D_nounits as D
107+
106108
sts = @variables x1(t)=0.0 x2(t)=0.0 x3(t)=0.0 x4(t)=0.0
107-
D = Differential(t)
108109
eqs = [x1 + x2 + 1 ~ 0
109110
x1 + x2 + x3 + 2 ~ 0
110111
x1 + D(x3) + x4 + 3 ~ 0
@@ -137,9 +138,9 @@ container type. For example:
137138

138139
```
139140
using ModelingToolkit, StaticArrays
140-
@variables t
141+
using ModelingToolkit: t_nounits as t, D_nounits as D
142+
141143
sts = @variables x1(t)=0.0
142-
D = Differential(t)
143144
eqs = [D(x1) ~ 1.1 * x1]
144145
@mtkbuild sys = ODESystem(eqs, t)
145146
prob = ODEProblem{false}(sys, [], (0,1); u0_constructor = x->SVector(x...))

docs/src/basics/Linearization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ The `linearize` function expects the user to specify the inputs ``u`` and the ou
2121

2222
```@example LINEARIZE
2323
using ModelingToolkit
24-
@variables t x(t)=0 y(t)=0 u(t)=0 r(t)=0
24+
using ModelingToolkit: t_nounits as t, D_nounits as D
25+
@variables x(t)=0 y(t)=0 u(t)=0 r(t)=0
2526
@parameters kp = 1
26-
D = Differential(t)
2727
2828
eqs = [u ~ kp * (r - y) # P controller
2929
D(x) ~ -x + u # First-order plant

docs/src/basics/Validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ second argument.
8383
```@example validation2
8484
using ModelingToolkit, Unitful
8585
# Composite type parameter in registered function
86-
@parameters t
86+
@variables t
8787
D = Differential(t)
8888
struct NewType
8989
f::Any

docs/src/basics/Variable_metadata.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ Descriptive strings can be attached to variables using the `[description = "desc
1010

1111
```@example metadata
1212
using ModelingToolkit
13+
using ModelingToolkit: t_nounits as t, D_nounits as D
1314
@variables u [description = "This is my input"]
1415
getdescription(u)
1516
```
1617

1718
When variables with descriptions are present in systems, they will be printed when the system is shown in the terminal:
1819

1920
```@example metadata
20-
@parameters t
2121
@variables u(t) [description = "A short description of u"]
2222
@parameters p [description = "A description of p"]
2323
@named sys = ODESystem([u ~ p], t)
@@ -50,8 +50,9 @@ current in a resistor. These variables sum up to zero in connections.
5050

5151
```@example connect
5252
using ModelingToolkit
53+
using ModelingToolkit: t_nounits as t, D_nounits as D
5354
54-
@variables t, i(t) [connect = Flow]
55+
@variables i(t) [connect = Flow]
5556
@variables k(t) [connect = Stream]
5657
```
5758

@@ -61,6 +62,8 @@ Designate a variable as either an input or an output using the following
6162

6263
```@example metadata
6364
using ModelingToolkit
65+
using ModelingToolkit: t_nounits as t, D_nounits as D
66+
6467
@variables u [input = true]
6568
isinput(u)
6669
```
@@ -136,8 +139,6 @@ For systems that contain parameters with metadata like described above, have som
136139
In the example below, we define a system with tunable parameters and extract bounds vectors
137140

138141
```@example metadata
139-
@parameters t
140-
Dₜ = Differential(t)
141142
@variables x(t)=0 u(t)=0 [input = true] y(t)=0 [output = true]
142143
@parameters T [tunable = true, bounds = (0, Inf)]
143144
@parameters k [tunable = true, bounds = (0, Inf)]

docs/src/examples/higher_order.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ We utilize the derivative operator twice here to define the second order:
1313

1414
```@example orderlowering
1515
using ModelingToolkit, OrdinaryDiffEq
16+
using ModelingToolkit: t_nounits as t, D_nounits as D
1617
1718
@parameters σ ρ β
18-
@variables t x(t) y(t) z(t)
19-
D = Differential(t)
19+
@variables x(t) y(t) z(t)
2020
2121
eqs = [D(D(x)) ~ σ * (y - x),
2222
D(y) ~ x * (ρ - z) - y,
2323
D(z) ~ x * y - β * z]
2424
25-
@named sys = ODESystem(eqs)
25+
@named sys = ODESystem(eqs, t)
2626
```
2727

2828
Note that we could've used an alternative syntax for 2nd order, i.e.

0 commit comments

Comments
 (0)