Skip to content

Commit

Permalink
spelling and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinKaisermayer committed Jun 9, 2022
1 parent 48bc6e5 commit 1541500
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions docs/src/tutorials/custom_component.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Custom Component
In this tutorial the creation of a custom component is demonstrated via the [Chua's circuit](https://en.wikipedia.org/wiki/Chua%27s_circuit).
In this tutorial, the creation of a custom component is demonstrated via the [Chua's circuit](https://en.wikipedia.org/wiki/Chua%27s_circuit).
The circuit is a simple circuit that shows chaotic behaviour.
Except for a non-linear resistor every other component already is part of `ModelingToolkitStandardLibrary.Electrical`.

First we need to make some imports.
First, we need to make some imports.
```@example components
using ModelingToolkit
using ModelingToolkitStandardLibrary.Electrical
Expand All @@ -26,7 +26,7 @@ equation
i = if (v < -Ve) then Gb*(v + Ve) - Ga*Ve else if (v > Ve) then Gb*(v - Ve) + Ga*Ve else Ga*v;
end NonlinearResistor;
```
this can almost be directly translate it to the syntax of `ModelingToolkit`.
this can almost be directly translated to the syntax of `ModelingToolkit`.
```@example components
@parameters t
Expand All @@ -49,26 +49,26 @@ nothing # hide
```

### Explanation
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`.
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`.
Since the non-linear resistor is essentially a standard electrical component with two ports, we can extend from the `OnePort` component of the library.
```julia
@named oneport = OnePort()
```
This creates a `OnePort` with the `name = :oneport`.
For easier notation we can unpack the states of the component
For easier notation, we can unpack the states of the component
```julia
@unpack v, i = oneport
```
It might be a good idea to create parameters for the constants of the `NonlinearResistor`.
```julia
pars = @parameters Ga=Ga Gb=Gb Ve=Ve
```
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`.
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.
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`.
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.
The non-linear (in this case piece-wise constant) equation for the current can be implemented using `IfElse.ifelse`.
Finally, the created `oneport` component is extended with the created equations and parameters.
In this case no extra state variables are added, hence an empty vector is supplied.
The independent variable `t` needs to be supplied as second argument.
In this case, no extra state variables are added, hence an empty vector is supplied.
The independent variable `t` needs to be supplied as the second argument.
```julia
extend(ODESystem(eqs, t, [], pars; name=name), oneport)
```
Expand Down Expand Up @@ -105,7 +105,7 @@ nothing # hide

## Simulating the Model
Now the model can be simulated.
First `structural_simplify` is called on the model and a `ODEProblem` is build from the result.
First, `structural_simplify` is called on the model and an `ODEProblem` is built from the result.
Since the initial voltage of the first capacitor was already specified via `v_start`, no initial condition is given and an empty pair is supplied.
```@example components
sys = structural_simplify(model)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/rc_circuit.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RC Circuit Model

This tutorial is a simplified version of the [RC circuit tutorial in the
ModelingToolkit.jl documentation](https://mtk.sciml.ai/dev/tutorials/acausal_components/).
`ModelingToolkit.jl` documentation](https://mtk.sciml.ai/dev/tutorials/acausal_components/).
In that tutorial, the full RC circuit is built from scratch. Here, we will use the
components of the `Electrical` model in the ModelingToolkit Standard Library to simply
connect pre-made components and simulate the model.
Expand Down

0 comments on commit 1541500

Please sign in to comment.