From 7c7179605e7fa4327027976005a8937155c3f651 Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Sun, 26 Oct 2025 11:51:30 +0000 Subject: [PATCH 1/4] update README code --- README.md | 65 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 6b78f2105a..344cef8308 100644 --- a/README.md +++ b/README.md @@ -36,30 +36,35 @@ lower it to a first order system, symbolically generate the Jacobian function for the numerical integrator, and solve it. ```julia -using OrdinaryDiffEqDefault, ModelingToolkit +using ModelingToolkit using ModelingToolkit: t_nounits as t, D_nounits as D +# Defines a ModelingToolkit `System` model. @parameters σ ρ β @variables x(t) y(t) z(t) - -eqs = [D(D(x)) ~ σ * (y - x), +eqs = [ + D(D(x)) ~ σ * (y - x), D(y) ~ x * (ρ - z) - y, - D(z) ~ x * y - β * z] - + D(z) ~ x * y - β * z +] @mtkcompile sys = System(eqs, t) -u0 = [D(x) => 2.0, +# Simulate the model for a specific condition (initial condition and parameter values). +using OrdinaryDiffEqDefault +sim_cond = [ + D(x) => 2.0, x => 1.0, y => 0.0, - z => 0.0] - -p = [σ => 28.0, + z => 0.0, + σ => 28.0, ρ => 10.0, - β => 8 / 3] - -tspan = (0.0, 100.0) -prob = ODEProblem(sys, u0, tspan, p, jac = true) + β => 8 / 3 +] +tend = 100.0 +prob = ODEProblem(sys, sim_cond, tend; jac = true) sol = solve(prob) + +# Plot the solution in phase-space. using Plots plot(sol, idxs = (x, y)) ``` @@ -73,44 +78,46 @@ interacting Lorenz equations and simulate the resulting Differential-Algebraic Equation (DAE): ```julia -using DifferentialEquations, ModelingToolkit +using ModelingToolkit using ModelingToolkit: t_nounits as t, D_nounits as D -@parameters σ ρ β -@variables x(t) y(t) z(t) - -eqs = [D(x) ~ σ * (y - x), +# Defines two lorenz system model.s +eqs = [ + D(x) ~ σ * (y - x), D(y) ~ x * (ρ - z) - y, - D(z) ~ x * y - β * z] - + D(z) ~ x * y - β * z +] @named lorenz1 = System(eqs, t) @named lorenz2 = System(eqs, t) +# Connect the two models, creating a single model. @variables a(t) @parameters γ connections = [0 ~ lorenz1.x + lorenz2.y + a * γ] @mtkcompile connected = System(connections, t, systems = [lorenz1, lorenz2]) -u0 = [lorenz1.x => 1.0, +# Simulate the model for a specific condition (initial condition and parameter values). +using OrdinaryDiffEqDefault +sim_cond = [ + lorenz1.x => 1.0, lorenz1.y => 0.0, lorenz1.z => 0.0, lorenz2.x => 0.0, - lorenz2.y => 1.0, lorenz2.z => 0.0, - a => 2.0] - -p = [lorenz1.σ => 10.0, + a => 2.0, + lorenz1.σ => 10.0, lorenz1.ρ => 28.0, lorenz1.β => 8 / 3, lorenz2.σ => 10.0, lorenz2.ρ => 28.0, lorenz2.β => 8 / 3, - γ => 2.0] - -tspan = (0.0, 100.0) -prob = ODEProblem(connected, u0, tspan, p) + γ => 2.0 +] +tend = 100.0 +prob = ODEProblem(connected, sim_cond, tend) sol = solve(prob) +# Plot the solution in phase-space. using Plots plot(sol, idxs = (a, lorenz1.x, lorenz2.z)) ``` From b9f1e38e1e7a7f08e7427ff830a4f22b7599882e Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Sun, 26 Oct 2025 11:56:19 +0000 Subject: [PATCH 2/4] re-commit unsaved changes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 344cef8308..5f55dcc287 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ eqs = [ @variables a(t) @parameters γ connections = [0 ~ lorenz1.x + lorenz2.y + a * γ] -@mtkcompile connected = System(connections, t, systems = [lorenz1, lorenz2]) +@mtkcompile connected_lorenz = System(connections, t; systems = [lorenz1, lorenz2]) # Simulate the model for a specific condition (initial condition and parameter values). using OrdinaryDiffEqDefault @@ -114,7 +114,7 @@ sim_cond = [ γ => 2.0 ] tend = 100.0 -prob = ODEProblem(connected, sim_cond, tend) +prob = ODEProblem(connected_lorenz, sim_cond, tend) sol = solve(prob) # Plot the solution in phase-space. From 266e7479bc29a33f105b3b68e0752a143769e896 Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Sun, 26 Oct 2025 12:09:10 +0000 Subject: [PATCH 3/4] minor format fixes --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5f55dcc287..f8939a7501 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle) ModelingToolkit.jl is a modeling framework for high-performance symbolic-numeric computation -in scientific computing and scientific machine learning. +in scientific computing and scientific machine learning. It allows for users to give a high-level description of a model for symbolic preprocessing to analyze and enhance the model. ModelingToolkit can automatically generate fast functions for model components like Jacobians @@ -71,7 +71,7 @@ plot(sol, idxs = (x, y)) ![Lorenz2](https://user-images.githubusercontent.com/1814174/79118645-744eb580-7d5c-11ea-9c37-13c4efd585ca.png) -This automatically will have generated fast Jacobian functions, making +This will have automatically generated fast Jacobian functions, making it more optimized than directly building a function. In addition, we can then use ModelingToolkit to compose multiple ODE subsystems. Now, let's define two interacting Lorenz equations and simulate the resulting Differential-Algebraic @@ -81,7 +81,7 @@ Equation (DAE): using ModelingToolkit using ModelingToolkit: t_nounits as t, D_nounits as D -# Defines two lorenz system model.s +# Defines two lorenz system models. eqs = [ D(x) ~ σ * (y - x), D(y) ~ x * (ρ - z) - y, @@ -124,7 +124,7 @@ plot(sol, idxs = (a, lorenz1.x, lorenz2.z)) ![](https://user-images.githubusercontent.com/17304743/187790221-528046c3-dbdb-4853-b977-799596c147f3.png) -# Citation +## Citation If you use ModelingToolkit.jl in your research, please cite [this paper](https://arxiv.org/abs/2103.05244): From a761db9434815c664985ae3a83626e6f314fed8d Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Sun, 26 Oct 2025 12:14:53 +0000 Subject: [PATCH 4/4] Update to use new som plots --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f8939a7501..5583e3e682 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ using Plots plot(sol, idxs = (x, y)) ``` -![Lorenz2](https://user-images.githubusercontent.com/1814174/79118645-744eb580-7d5c-11ea-9c37-13c4efd585ca.png) +![Lorenz2](https://github.com/user-attachments/assets/e82fb2ce-97b7-4f56-b272-85653c88bdb3) This will have automatically generated fast Jacobian functions, making it more optimized than directly building a function. In addition, we can then @@ -122,7 +122,7 @@ using Plots plot(sol, idxs = (a, lorenz1.x, lorenz2.z)) ``` -![](https://user-images.githubusercontent.com/17304743/187790221-528046c3-dbdb-4853-b977-799596c147f3.png) +![LorenzConnected](https://github.com/user-attachments/assets/ef65d812-c10e-42c6-945d-e61515e3b6a1) ## Citation