Skip to content

Commit 96935e0

Browse files
committed
Merge remote-tracking branch 'origin/master' into event_discpars_autoinfer
2 parents aa40b5c + 5572a5c commit 96935e0

40 files changed

+1554
-155
lines changed

Project.toml

Lines changed: 5 additions & 1 deletion
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 = "10.26.1"
4+
version = "10.28.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -26,6 +26,7 @@ DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
2626
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
2727
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
2828
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
29+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
2930
FindFirstFunctions = "64ca27bc-2ba2-4a57-88aa-44e436879224"
3031
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
3132
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
@@ -44,6 +45,7 @@ NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
4445
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
4546
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
4647
OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
48+
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
4749
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
4850
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
4951
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
@@ -114,6 +116,7 @@ DynamicQuantities = "^0.11.2, 0.12, 0.13, 1"
114116
EnumX = "1.0.4"
115117
ExprTools = "0.1.10"
116118
FMI = "0.14"
119+
FillArrays = "1.13.0"
117120
FindFirstFunctions = "1"
118121
ForwardDiff = "0.10.3, 1"
119122
FunctionWrappers = "1.1"
@@ -141,6 +144,7 @@ OrdinaryDiffEq = "6.82.0"
141144
OrdinaryDiffEqCore = "1.34.0"
142145
OrdinaryDiffEqDefault = "1.2"
143146
OrdinaryDiffEqNonlinearSolve = "1.5.0"
147+
PreallocationTools = "0.4.27"
144148
PrecompileTools = "1"
145149
Pyomo = "0.1.0"
146150
REPL = "1"

README.md

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
1212

1313
ModelingToolkit.jl is a modeling framework for high-performance symbolic-numeric computation
14-
in scientific computing and scientific machine learning.
14+
in scientific computing and scientific machine learning.
1515
It allows for users to give a high-level description of a model for
1616
symbolic preprocessing to analyze and enhance the model. ModelingToolkit can
1717
automatically generate fast functions for model components like Jacobians
@@ -36,88 +36,95 @@ lower it to a first order system, symbolically generate the Jacobian function
3636
for the numerical integrator, and solve it.
3737

3838
```julia
39-
using OrdinaryDiffEqDefault, ModelingToolkit
39+
using ModelingToolkit
4040
using ModelingToolkit: t_nounits as t, D_nounits as D
4141

42+
# Defines a ModelingToolkit `System` model.
4243
@parameters σ ρ β
4344
@variables x(t) y(t) z(t)
44-
45-
eqs = [D(D(x)) ~ σ * (y - x),
45+
eqs = [
46+
D(D(x)) ~ σ * (y - x),
4647
D(y) ~ x *- z) - y,
47-
D(z) ~ x * y - β * z]
48-
48+
D(z) ~ x * y - β * z
49+
]
4950
@mtkcompile sys = System(eqs, t)
5051

51-
u0 = [D(x) => 2.0,
52+
# Simulate the model for a specific condition (initial condition and parameter values).
53+
using OrdinaryDiffEqDefault
54+
sim_cond = [
55+
D(x) => 2.0,
5256
x => 1.0,
5357
y => 0.0,
54-
z => 0.0]
55-
56-
p ==> 28.0,
58+
z => 0.0,
59+
σ => 28.0,
5760
ρ => 10.0,
58-
β => 8 / 3]
59-
60-
tspan = (0.0, 100.0)
61-
prob = ODEProblem(sys, u0, tspan, p, jac = true)
61+
β => 8 / 3
62+
]
63+
tend = 100.0
64+
prob = ODEProblem(sys, sim_cond, tend; jac = true)
6265
sol = solve(prob)
66+
67+
# Plot the solution in phase-space.
6368
using Plots
6469
plot(sol, idxs = (x, y))
6570
```
6671

67-
![Lorenz2](https://user-images.githubusercontent.com/1814174/79118645-744eb580-7d5c-11ea-9c37-13c4efd585ca.png)
72+
![Lorenz2](https://github.com/user-attachments/assets/e82fb2ce-97b7-4f56-b272-85653c88bdb3)
6873

69-
This automatically will have generated fast Jacobian functions, making
74+
This will have automatically generated fast Jacobian functions, making
7075
it more optimized than directly building a function. In addition, we can then
7176
use ModelingToolkit to compose multiple ODE subsystems. Now, let's define two
7277
interacting Lorenz equations and simulate the resulting Differential-Algebraic
7378
Equation (DAE):
7479

7580
```julia
76-
using DifferentialEquations, ModelingToolkit
81+
using ModelingToolkit
7782
using ModelingToolkit: t_nounits as t, D_nounits as D
7883

79-
@parameters σ ρ β
80-
@variables x(t) y(t) z(t)
81-
82-
eqs = [D(x) ~ σ * (y - x),
84+
# Defines two lorenz system models.
85+
eqs = [
86+
D(x) ~ σ * (y - x),
8387
D(y) ~ x *- z) - y,
84-
D(z) ~ x * y - β * z]
85-
88+
D(z) ~ x * y - β * z
89+
]
8690
@named lorenz1 = System(eqs, t)
8791
@named lorenz2 = System(eqs, t)
8892

93+
# Connect the two models, creating a single model.
8994
@variables a(t)
9095
@parameters γ
9196
connections = [0 ~ lorenz1.x + lorenz2.y + a * γ]
92-
@mtkcompile connected = System(connections, t, systems = [lorenz1, lorenz2])
97+
@mtkcompile connected_lorenz = System(connections, t; systems = [lorenz1, lorenz2])
9398

94-
u0 = [lorenz1.x => 1.0,
99+
# Simulate the model for a specific condition (initial condition and parameter values).
100+
using OrdinaryDiffEqDefault
101+
sim_cond = [
102+
lorenz1.x => 1.0,
95103
lorenz1.y => 0.0,
96104
lorenz1.z => 0.0,
97105
lorenz2.x => 0.0,
98-
lorenz2.y => 1.0,
99106
lorenz2.z => 0.0,
100-
a => 2.0]
101-
102-
p = [lorenz1.σ => 10.0,
107+
a => 2.0,
108+
lorenz1.σ => 10.0,
103109
lorenz1.ρ => 28.0,
104110
lorenz1.β => 8 / 3,
105111
lorenz2.σ => 10.0,
106112
lorenz2.ρ => 28.0,
107113
lorenz2.β => 8 / 3,
108-
γ => 2.0]
109-
110-
tspan = (0.0, 100.0)
111-
prob = ODEProblem(connected, u0, tspan, p)
114+
γ => 2.0
115+
]
116+
tend = 100.0
117+
prob = ODEProblem(connected_lorenz, sim_cond, tend)
112118
sol = solve(prob)
113119

120+
# Plot the solution in phase-space.
114121
using Plots
115122
plot(sol, idxs = (a, lorenz1.x, lorenz2.z))
116123
```
117124

118-
![](https://user-images.githubusercontent.com/17304743/187790221-528046c3-dbdb-4853-b977-799596c147f3.png)
125+
![LorenzConnected](https://github.com/user-attachments/assets/ef65d812-c10e-42c6-945d-e61515e3b6a1)
119126

120-
# Citation
127+
## Citation
121128

122129
If you use ModelingToolkit.jl in your research, please cite [this paper](https://arxiv.org/abs/2103.05244):
123130

docs/src/API/System.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ ModelingToolkit.eqtype_supports_collect_vars
214214
ModelingToolkit.modified_unknowns!
215215
```
216216

217-
## Namepsace manipulation
217+
## Namespace manipulation
218218

219219
ModelingToolkit namespaces variables from subsystems when using them in a parent system to
220220
disambiguate from identically named variables in other subsystems or the parent system. The

docs/src/API/codegen.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ ModelingToolkit.build_explicit_observed_function
2323
ModelingToolkit.generate_control_function
2424
ModelingToolkit.generate_update_A
2525
ModelingToolkit.generate_update_b
26+
ModelingToolkit.generate_semiquadratic_functions
27+
ModelingToolkit.generate_semiquadratic_jacobian
28+
ModelingToolkit.get_semiquadratic_W_sparsity
2629
```
2730

2831
For functions such as jacobian calculation which require symbolic computation, there

docs/src/API/problems.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ SciMLBase.ODEFunction
1717
SciMLBase.ODEProblem
1818
SciMLBase.DAEFunction
1919
SciMLBase.DAEProblem
20+
ModelingToolkit.SemilinearODEFunction
21+
ModelingToolkit.SemilinearODEProblem
2022
SciMLBase.SDEFunction
2123
SciMLBase.SDEProblem
2224
SciMLBase.DDEFunction

docs/src/basics/Composition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ p = [decay1.a => 0.1
5757
decay2.a => 0.2]
5858
5959
using OrdinaryDiffEq
60-
prob = ODEProblem(simplified_sys, x0, (0.0, 100.0), p)
60+
prob = ODEProblem(simplified_sys, [x0; p], (0.0, 100.0))
6161
sol = solve(prob, Tsit5())
6262
sol[decay2.f]
6363
```

docs/src/basics/Events.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ ev = ModelingToolkit.SymbolicDiscreteCallback(
418418
@mtkcompile sys = System(
419419
D(x) ~ c * cos(x), t, [x], [c]; discrete_events = [ev])
420420
421-
prob = ODEProblem(sys, [x => 0.0], (0.0, 2pi), [c => 1.0])
421+
prob = ODEProblem(sys, [x => 0.0, c => 1.0], (0.0, 2pi))
422422
sol = solve(prob, Tsit5())
423423
sol[c]
424424
```
@@ -439,7 +439,7 @@ will be saved. If we repeat the above example with `c` not a `discrete_parameter
439439
@mtkcompile sys = System(
440440
D(x) ~ c * cos(x), t, [x], [c]; discrete_events = [1.0 => [c ~ Pre(c) + 1]])
441441
442-
prob = ODEProblem(sys, [x => 0.0], (0.0, 2pi), [c => 1.0])
442+
prob = ODEProblem(sys, [x => 0.0, c => 1.0], (0.0, 2pi))
443443
sol = solve(prob, Tsit5())
444444
sol.ps[c] # sol[c] will error, since `c` is not a timeseries value
445445
```

docs/src/tutorials/ode_modeling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ end
3636
3737
using OrdinaryDiffEq
3838
@mtkcompile fol = FOL()
39-
prob = ODEProblem(fol, [], (0.0, 10.0), [])
39+
prob = ODEProblem(fol, [], (0.0, 10.0))
4040
sol = solve(prob)
4141
4242
using Plots

docs/src/tutorials/programmatically_generating.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ eqs = [D(x) ~ (h - x) / τ] # create an array of equations
4949
# Perform the standard transformations and mark the model complete
5050
# Note: Complete models cannot be subsystems of other models!
5151
fol = mtkcompile(model)
52-
prob = ODEProblem(fol, [], (0.0, 10.0), [])
52+
prob = ODEProblem(fol, [], (0.0, 10.0))
5353
using OrdinaryDiffEq
5454
sol = solve(prob)
5555

src/ModelingToolkit.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ const DQ = DynamicQuantities
104104
import DifferentiationInterface as DI
105105
using ADTypes: AutoForwardDiff
106106
import SciMLPublic: @public
107+
import PreallocationTools
108+
import PreallocationTools: DiffCache
109+
import FillArrays
107110

108111
export @derivatives
109112

@@ -262,6 +265,7 @@ export IntervalNonlinearProblem
262265
export OptimizationProblem, constraints
263266
export SteadyStateProblem
264267
export JumpProblem
268+
export SemilinearODEFunction, SemilinearODEProblem
265269
export alias_elimination, flatten
266270
export connect, domain_connect, @connector, Connection, AnalysisPoint, Flow, Stream,
267271
instream

0 commit comments

Comments
 (0)