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/tutorials/custom_component.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# Custom Component
2
-
In this tutorial the creation of a custom component is demonstrated via the [Chua's circuit](https://en.wikipedia.org/wiki/Chua%27s_circuit).
2
+
In this tutorial, the creation of a custom component is demonstrated via the [Chua's circuit](https://en.wikipedia.org/wiki/Chua%27s_circuit).
3
3
The circuit is a simple circuit that shows chaotic behaviour.
4
4
Except for a non-linear resistor every other component already is part of `ModelingToolkitStandardLibrary.Electrical`.
5
5
6
-
First we need to make some imports.
6
+
First, we need to make some imports.
7
7
```@example components
8
8
using ModelingToolkit
9
9
using ModelingToolkitStandardLibrary.Electrical
@@ -26,7 +26,7 @@ equation
26
26
i = if (v < -Ve) then Gb*(v + Ve) - Ga*Ve else if (v > Ve) then Gb*(v - Ve) + Ga*Ve else Ga*v;
27
27
end NonlinearResistor;
28
28
```
29
-
this can almost be directly translate it to the syntax of `ModelingToolkit`.
29
+
this can almost be directly translated to the syntax of `ModelingToolkit`.
30
30
```@example components
31
31
@parameters t
32
32
@@ -49,26 +49,26 @@ nothing # hide
49
49
```
50
50
51
51
### Explanation
52
-
All components in `ModelingToolkit` are created via a function that serves as the constructor and returns some form of system, in this case a`ODESystem`.
52
+
All components in `ModelingToolkit` are created via a function that serves as the constructor and returns some form of system, in this case, an`ODESystem`.
53
53
Since the non-linear resistor is essentially a standard electrical component with two ports, we can extend from the `OnePort` component of the library.
54
54
```julia
55
55
@named oneport =OnePort()
56
56
```
57
57
This creates a `OnePort` with the `name = :oneport`.
58
-
For easier notation we can unpack the states of the component
58
+
For easier notation, we can unpack the states of the component
59
59
```julia
60
60
@unpack v, i = oneport
61
61
```
62
62
It might be a good idea to create parameters for the constants of the `NonlinearResistor`.
63
63
```julia
64
64
pars =@parameters Ga=Ga Gb=Gb Ve=Ve
65
65
```
66
-
The syntax looks funny but it simply creates symbolic parameters with the name `Ga` where it's default value is set from the function's argument `Ga`.
67
-
While this is not strictly necessary it allows the user to `remake` the problem easily with different parameters or allow for auto-tuning or parameter optimization without having to do all costly steps that may be involved with building and simplifying a model.
66
+
The syntax looks funny but it simply creates symbolic parameters with the name `Ga` where its default value is set from the function's argument `Ga`.
67
+
While this is not strictly necessary it allows the user to `remake` the problem easily with different parameters or allow for auto-tuning or parameter optimization without having to do all the costly steps that may be involved with building and simplifying a model.
68
68
The non-linear (in this case piece-wise constant) equation for the current can be implemented using `IfElse.ifelse`.
69
69
Finally, the created `oneport` component is extended with the created equations and parameters.
70
-
In this case no extra state variables are added, hence an empty vector is supplied.
71
-
The independent variable `t` needs to be supplied as second argument.
70
+
In this case, no extra state variables are added, hence an empty vector is supplied.
71
+
The independent variable `t` needs to be supplied as the second argument.
0 commit comments