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/basics/MTKModel_Connector.md
+38-31Lines changed: 38 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ equations.
19
19
`ModelingToolkit.Model`, which includes a constructor that returns the ODESystem, a
20
20
`structure` dictionary with metadata, and flag `isconnector` which is set to `false`.
21
21
22
-
## What can an MTK-Model definition have?
22
+
###What can an MTK-Model definition have?
23
23
24
24
`@mtkmodel` definition contains begin blocks of
25
25
@@ -37,8 +37,8 @@ using ModelingToolkit
37
37
38
38
@mtkmodel ModelA begin
39
39
@parameters begin
40
-
k1
41
-
k2
40
+
k
41
+
k_array[1:2]
42
42
end
43
43
end
44
44
@@ -59,17 +59,17 @@ end
59
59
@variables begin
60
60
v(t) = v_var
61
61
end
62
-
@extend p1, p2 = model_b = ModelB(; p1)
62
+
@extend ModelB(; p1)
63
63
@components begin
64
-
model_a = ModelA(; k1)
64
+
model_a = ModelA(; k_array)
65
65
end
66
66
@equations begin
67
-
model_a.k1 ~ f(v)
67
+
model_a.k ~ f(v)
68
68
end
69
69
end
70
70
```
71
71
72
-
### `@parameters` and `@variables` begin block
72
+
####`@parameters` and `@variables` begin block
73
73
74
74
- Parameters and variables are declared with respective begin blocks.
75
75
- Variables must be functions of an independent variable.
@@ -78,49 +78,54 @@ end
78
78
- Whenever a parameter or variable has initial value, for example `v(t) = 0.0`, a symbolic variable named `v` with initial 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.
79
79
80
80
```julia
81
-
julia>@named model_c=ModelC(; v =2.0);
81
+
julia>@mtkbuild model_c1=ModelC(; v =2.0);
82
82
83
-
julia> ModelingToolkit.getdefault(model_c.v)
83
+
julia> ModelingToolkit.getdefault(model_c.v)
84
84
2.0
85
85
```
86
86
87
-
### `@structural_parameters` begin block
87
+
####`@structural_parameters` begin block
88
88
89
89
- 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.
90
90
- Whenever default values are specified, unlike parameters/variables, they are reflected in the keyword argument list.
91
91
92
92
#### `@extend` begin block
93
93
94
-
To extend a partial system,
95
-
96
-
- List the variables to unpack. If there is a single variable, explicitly specify it as a tuple.
97
-
- Give a name to the base system
98
-
- List the kwargs of the base system that should be listed as kwargs of the main component.
99
-
- Note that in above example, `p1` is promoted as an argument of `ModelC`. Users can set the value of `p1` as
94
+
- Partial systems can be extended in a higher system as `@extend PartialSystem(; kwargs)`.
95
+
- Keyword arguments pf partial system in the `@extend` definition are added as the keyword arguments of the base system.
96
+
- Note that in above example, `p1` is promoted as an argument of `ModelC`. Users can set the value of `p1`. However, as `p2` isn't listed in the model definition, its initial guess can't be specified while creating an instance of `ModelC`.
100
97
101
98
```julia
102
-
julia>@named model_c=ModelC(; p1 =2.0)
99
+
julia>@mtkbuild model_c2=ModelC(; p1 =2.0)
103
100
104
101
```
105
102
106
-
However, as `p2` isn't listed in the model definition, its initial guess can't
107
-
specified while creating an instance of `ModelC`.
108
-
109
-
### `@components` begin block
103
+
#### `@components` begin block
110
104
111
105
- Declare the subcomponents within `@components` begin block.
112
106
- The arguments in these subcomponents are promoted as keyword arguments as `subcomponent_name__argname` with `nothing` as default value.
113
107
- Whenever components are created with `@named` macro, these can be accessed with `.` operator as `subcomponent_name.argname`
114
-
- In the above example, `k1` of `model_a` can be set in following ways:
108
+
- In the above example, as `k` of `model_a`isn't listed while defining the sub-component in `ModelC`, its default value can't be modified by users. While `k_array` can be set as:
Bifurcation diagrams describes how, for a dynamic system, the quantity and quality of its steady states changes with a parameter's value. These can be computed through the [BifurcationKit.jl](https://github.com/bifurcationkit/BifurcationKit.jl) package. ModelingToolkit provides a simple interface for creating BifurcationKit compatible `BifurcationProblem`s from `NonlinearSystem`s and `ODESystem`s. All teh features provided by BifurcationKit can then be applied to these systems. This tutorial provides a brief introduction for these features, with BifurcationKit.jl providing [a more extensive documentation](https://bifurcationkit.github.io/BifurcationKitDocs.jl/stable/).
we wish to compute a bifurcation diagram for this system as we vary the parameter `μ`. For this, we need to provide the following information:
15
-
1. The system for which we wish to compute the bifurcation diagram (`nsys`).
16
-
2. The parameter which we wish to vary (`μ`).
17
-
3. The parameter set for which we want to compute the bifurcation diagram.
18
-
4. An initial guess of the state of the system for which there is a steady state at our provided parameter value.
19
-
5. The variable which value we wish to plot in the bifurcation diagram (this argument is optional, if not provided, BifurcationKit default plot functions are used).
19
+
20
+
1. The system for which we wish to compute the bifurcation diagram (`nsys`).
21
+
2. The parameter which we wish to vary (`μ`).
22
+
3. The parameter set for which we want to compute the bifurcation diagram.
23
+
4. An initial guess of the state of the system for which there is a steady state at our provided parameter value.
24
+
5. The variable which value we wish to plot in the bifurcation diagram (this argument is optional, if not provided, BifurcationKit default plot functions are used).
20
25
21
26
We declare this additional information:
27
+
22
28
```@example Bif1
23
29
bif_par = μ
24
30
p_start = [μ => -1.0, α => 1.0]
25
31
u0_guess = [x => 1.0, y => 1.0]
26
32
plot_var = x;
27
33
```
34
+
28
35
For the initial state guess (`u0_guess`), typically any value can be provided, however, read BifurcatioKit's documentation for more details.
29
36
30
37
We can now create our `BifurcationProblem`, which can be provided as input to BifurcationKit's various functions.
Here, the `jac` argument (by default set to `true`) sets whenever to provide BifurcationKit with a Jacobian or not.
36
48
49
+
Here, the `jac` argument (by default set to `true`) sets whenever to provide BifurcationKit with a Jacobian or not.
37
50
38
51
### Computing a bifurcation diagram
39
52
40
-
Let us consider the `BifurcationProblem` from the last section. If we wish to compute the corresponding bifurcation diagram we must first declare various settings used by BifurcationKit to compute the diagram. These are stored in a `ContinuationPar` structure (which also contain a `NewtonPar` structure).
53
+
Let us consider the `BifurcationProblem` from the last section. If we wish to compute the corresponding bifurcation diagram we must first declare various settings used by BifurcationKit to compute the diagram. These are stored in a `ContinuationPar` structure (which also contain a `NewtonPar` structure).
Here, the value `2` sets how sub-branches of the diagram that BifurcationKit should compute. Generally, for bifurcation diagrams, it is recommended to use the `bothside=true` argument.
0 commit comments