Skip to content

Commit e4b9235

Browse files
committed
Merge branch 'master' into myb/new_domain
2 parents 5de3206 + a1369f3 commit e4b9235

Some content is hidden

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

42 files changed

+1065
-517
lines changed

.github/workflows/Documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- uses: julia-actions/setup-julia@latest
1616
with:
1717
version: '1'

.github/workflows/Downstream.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ jobs:
3131
- {user: SciML, repo: MethodOfLines.jl, group: DAE}
3232
- {user: ai4energy, repo: Ai4EComponentLib.jl, group: Downstream}
3333
steps:
34-
- uses: actions/checkout@v3
34+
- uses: actions/checkout@v4
3535
- uses: julia-actions/setup-julia@v1
3636
with:
3737
version: ${{ matrix.julia-version }}
3838
arch: x64
3939
- uses: julia-actions/julia-buildpkg@latest
4040
- name: Clone Downstream
41-
uses: actions/checkout@v3
41+
uses: actions/checkout@v4
4242
with:
4343
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
4444
path: downstream

.github/workflows/FormatCheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
version: ${{ matrix.julia-version }}
2323

24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
- name: Install JuliaFormatter and format
2626
# This will use the latest version by default but you can set the version like so:
2727
#

.github/workflows/Invalidations.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
- uses: julia-actions/setup-julia@v1
2020
with:
2121
version: '1'
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v4
2323
- uses: julia-actions/julia-buildpkg@v1
2424
- uses: julia-actions/julia-invalidations@v1
2525
id: invs_pr
2626

27-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2828
with:
2929
ref: ${{ github.event.repository.default_branch }}
3030
- uses: julia-actions/julia-buildpkg@v1

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- '1'
1818
- '1.6'
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- uses: julia-actions/setup-julia@v1
2222
with:
2323
version: ${{ matrix.version }}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
- This repository follows the [SciMLStyle](https://github.com/SciML/SciMLStyle) and the SciML [ColPrac](https://github.com/SciML/ColPrac).
2-
- Please run `using JuliaFormatter, ModelingToolkit; format(joinpath(dirname(pathof(ModelingToolkit)), ".."))` before commiting.
2+
- Please run `using JuliaFormatter, ModelingToolkit; format(joinpath(dirname(pathof(ModelingToolkit)), ".."))` before committing.
33
- Add tests for any new features.

Project.toml

Lines changed: 6 additions & 3 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.64.0"
4+
version = "8.69.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -31,6 +31,8 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3131
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
3232
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
3333
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
34+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
35+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
3436
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
3537
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
3638
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
@@ -78,6 +80,8 @@ Latexify = "0.11, 0.12, 0.13, 0.14, 0.15, 0.16"
7880
MLStyle = "0.4.17"
7981
MacroTools = "0.5"
8082
NaNMath = "0.3, 1"
83+
OrdinaryDiffEq = "6"
84+
PrecompileTools = "1"
8185
RecursiveArrayTools = "2.3"
8286
Reexport = "0.2, 1"
8387
RuntimeGeneratedFunctions = "0.5.9"
@@ -107,7 +111,6 @@ NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
107111
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
108112
OptimizationMOI = "fd9f6733-72f4-499f-8506-86b2bdd0dea1"
109113
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
110-
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
111114
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
112115
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
113116
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
@@ -120,4 +123,4 @@ Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
120123
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
121124

122125
[targets]
123-
test = ["AmplNLWriter", "BenchmarkTools", "ControlSystemsMTK", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "OrdinaryDiffEq", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq"]
126+
test = ["AmplNLWriter", "BenchmarkTools", "ControlSystemsMTK", "NonlinearSolve", "ForwardDiff", "Ipopt", "Ipopt_jll", "ModelingToolkitStandardLibrary", "Optimization", "OptimizationOptimJL", "OptimizationMOI", "Random", "ReferenceTests", "SafeTestsets", "StableRNGs", "Statistics", "SteadyStateDiffEq", "Test", "StochasticDiffEq", "Sundials", "StochasticDelayDiffEq"]

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
2121
BenchmarkTools = "1.3"
2222
DifferentialEquations = "7.6"
2323
Distributions = "0.25"
24-
Documenter = "0.27"
24+
Documenter = "0.27, 1"
2525
ModelingToolkit = "8.33"
2626
NonlinearSolve = "0.3, 1"
2727
Optim = "1.7"

docs/src/basics/FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ We can solve this problem by using the `missing_variable_defaults()` function
120120
prob = ODEProblem(sys, ModelingToolkit.missing_variable_defaults(sys), (0,1))
121121
```
122122

123-
This function provides 0 for the default values, which is a safe assumption for dummy derivatives of most models. However, the 2nd arument allows for a different default value or values to be used if needed.
123+
This function provides 0 for the default values, which is a safe assumption for dummy derivatives of most models. However, the 2nd argument allows for a different default value or values to be used if needed.
124124

125125
```
126126
julia> ModelingToolkit.missing_variable_defaults(sys, [1,2,3])

docs/src/basics/MTKModel_Connector.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
## Defining components with `@mtkmodel`
2+
3+
`@mtkmodel` is a convenience macro to define ModelingToolkit components. It returns `ModelingToolkit.Model`, which includes a constructor that returns an ODESystem, a `structure` dictionary with metadata and flag `isconnector` which is set to `false`.
4+
5+
### What can an MTK-Model definition have?
6+
7+
`@mtkmodel` definition contains begin blocks of
8+
9+
- `@components`: for listing sub-components of the system
10+
- `@equations`: for the list of equations
11+
- `@extend`: for extending a base system and unpacking its states
12+
- `@parameters`: for specifying the symbolic parameters
13+
- `@structural_parameters`: for specifying non-symbolic parameters
14+
- `@variables`: for specifing the states
15+
16+
Let's explore these in more detail with the following example:
17+
18+
```@example mtkmodel-example
19+
using ModelingToolkit
20+
21+
@mtkmodel ModelA begin
22+
@parameters begin
23+
k1
24+
k2
25+
end
26+
end
27+
28+
@mtkmodel ModelB begin
29+
@parameters begin
30+
p1 = 1.0, [description = "Parameter of ModelB"]
31+
p2 = 1.0, [description = "Parameter of ModelB"]
32+
end
33+
end
34+
35+
@mtkmodel ModelC begin
36+
@structural_parameters begin
37+
f = sin
38+
end
39+
begin
40+
v_var = 1.0
41+
end
42+
@variables begin
43+
v(t) = v_var
44+
end
45+
@extend p1, p2 = model_b = ModelB(; p1)
46+
@components begin
47+
model_a = ModelA(; k1)
48+
end
49+
@equations begin
50+
model_a.k1 ~ f(v)
51+
end
52+
end
53+
```
54+
55+
#### `@parameters` and `@variables` begin block
56+
57+
- Parameters and variables are declared with respective begin blocks.
58+
- Variables must be functions of an independent variable.
59+
- Optionally, default values and metadata can be specified for these parameters and variables. See `ModelB` in the above example.
60+
- Along with creating parameters and variables, keyword arguments of same name with default value `nothing` are created.
61+
- Whenever a parameter or variable has default value, for example `v(t) = 0.0`, a symbolic variable named `v` with default value 0.0 and a keyword argument `v`, with default value `nothing` are created. <br> This way, users can optionally pass new value of `v` while creating a component.
62+
63+
```julia
64+
julia > @named model_c = ModelC(; v = 2.0);
65+
66+
julia > ModelingToolkit.getdefault(model_c.v)
67+
2.0
68+
```
69+
70+
#### `@structural_parameters` begin block
71+
72+
- This block is for non symbolic input arguements. These are for inputs that usually are not meant to be part of components; but influence how they are defined. One can list inputs like boolean flags, functions etc... here.
73+
- Whenever default values are specified, unlike parameters/variables, they are reflected in the keyword argument list.
74+
75+
#### `@extend` block
76+
77+
To extend a partial system,
78+
79+
- List the variables to unpack. If there is a single variable, explicitly specify it as a tuple.
80+
- Give a name to the base system
81+
- List the kwargs of the base system that should be listed as kwargs of the main component.
82+
- Note that in above example, `p1` is promoted as an argument of `ModelC`. Users can set the value of `p1` as
83+
84+
```julia
85+
julia> @named model_c = ModelC(; p1 = 2.0)
86+
87+
```
88+
89+
However, as `p2` isn't listed in the model definition, its default can't be modified by users.
90+
91+
#### `@components` begin block
92+
93+
- Declare the subcomponents within `@components` begin block.
94+
- The arguments in these subcomponents are promoted as keyword arguments as `subcomponent_name__argname` with `nothing` as default value.
95+
- Whenever components are created with `@named` macro, these can be accessed with `.` operator as `subcomponent_name.argname`
96+
- In the above example, `k1` of `model_a` can be set in following ways:
97+
98+
```julia
99+
julia> @named model_c1 = ModelC(; model_a.k1 = 1);
100+
101+
```
102+
103+
And as `k2` isn't listed in the sub-component definition of `ModelC`, its default value can't be modified by users.
104+
105+
#### `@equations` begin block
106+
107+
- List all the equations here
108+
109+
#### A begin block
110+
111+
- Any other Julia operations can be included with dedicated begin blocks.
112+
113+
## Defining connectors with `@connector`
114+
115+
`@connector` returns `ModelingToolkit.Model`. It includes a constructor that returns a connector ODESystem, a `structure` dictionary with metadata and flag `isconnector` which is set to `true`.
116+
117+
A simple connector can be defined with syntax similar to following example:
118+
119+
```julia
120+
using ModelingToolkit
121+
122+
@connector Pin begin
123+
v(t) = 0.0, [description = "Voltage"]
124+
i(t), [connect = Flow]
125+
end
126+
```
127+
128+
- Variables (as function of independent variable) are listed out in the definition. These variables can optionally have default values and metadata like `descrption`, `connect` and so on.
129+
130+
`@connector`s accepts begin blocks of `@components`, `@equations`, `@extend`, `@parameters`, `@structural_parameters`, `@variables`. These keywords mean the same as described above for `@mtkmodel`.
131+
132+
!!! note
133+
134+
For more examples of usage, checkout [ModelingToolkitStandardLibrary.jl](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/)
135+
136+
* * *
137+
138+
### What's a `structure` dictionary?
139+
140+
For components defined with `@mtkmodel` or `@connector`, a dictionary with metadata is created. It lists `:components` (sub-component list), `:extend` (the extended states and base system), `:parameters`, `:variables`, ``:kwargs`` (list of keyword arguments), `:independent_variable`, `:equations`.
141+
142+
For example, the structure of `ModelC` is:
143+
144+
```julia
145+
julia> ModelC.structure
146+
Dict{Symbol, Any} with 6 entries:
147+
:components => [[:model_a, :ModelA]]
148+
:variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var))
149+
:kwargs => Dict{Symbol, Any}(:f=>:sin, :v=>:v_var, :p1=>nothing, :model_a__k1=>nothing)
150+
:independent_variable => t
151+
:extend => Any[[:p1, :p2], :model_b, :ModelB]
152+
:equations => ["model_a.k1 ~ f(v)"]
153+
```

0 commit comments

Comments
 (0)