Skip to content

Commit 66961d8

Browse files
adds doctests
1 parent 538fb2b commit 66961d8

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

docs/make.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ makedocs(
1414
authors="Julia Computing",
1515
clean=true,
1616
doctest=false,
17+
strict=[
18+
:doctest,
19+
:example_block,
20+
],
1721
modules=[ModelingToolkitStandardLibrary,
1822
ModelingToolkitStandardLibrary.Blocks,
1923
ModelingToolkitStandardLibrary.Mechanical,

docs/src/tutorials/custom_component.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The circuit is a simple circuit that shows chaotic behaviour.
44
Except for a non-linear resistor every other component already is part of `ModelingToolkitStandardLibrary.Electrical`.
55

66
First we need to make some imports.
7-
```julia
7+
```@example components
88
using ModelingToolkit
99
using ModelingToolkitStandardLibrary.Electrical
1010
using ModelingToolkitStandardLibrary.Electrical: OnePort
@@ -27,7 +27,7 @@ equation
2727
end NonlinearResistor;
2828
```
2929
this can almost be directly translate it to the syntax of `ModelingToolkit`.
30-
```julia
30+
```@example components
3131
@parameters t
3232
3333
function NonlinearResistor(;name, Ga, Gb, Ve)
@@ -45,6 +45,7 @@ function NonlinearResistor(;name, Ga, Gb, Ve)
4545
]
4646
extend(ODESystem(eqs, t, [], pars; name=name), oneport)
4747
end
48+
nothing # hide
4849
```
4950

5051
### Explanation
@@ -74,7 +75,7 @@ extend(ODESystem(eqs, t, [], pars; name=name), oneport)
7475

7576
## Building the Model
7677
The final model can now be created with the components from the library and the new custom component.
77-
```julia
78+
```@example components
7879
@named L = Inductor(L=18)
7980
@named Ro = Resistor(R=12.5e-3)
8081
@named G = Conductor(G=0.565)
@@ -99,24 +100,27 @@ connections = [
99100
]
100101
101102
@named model = ODESystem(connections, t, systems=[L, Ro, G, C1, C2, Nr])
103+
nothing # hide
102104
```
103105

104106
## Simulating the Model
105107
Now the model can be simulated.
106108
First `structural_simplify` is called on the model and a `ODEProblem` is build from the result.
107109
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.
108-
```julia
110+
```@example components
109111
sys = structural_simplify(model)
110112
prob = ODEProblem(sys, Pair[], (0, 5e4), saveat=0.01)
111113
sol = solve(prob, Rodas4())
112114
113115
Plots.plot(sol[C1.v], sol[C2.v], title="Chaotic Attractor", label="", ylabel="C1 Voltage in V", xlabel="C2 Voltage in V")
114116
Plots.savefig("chua_phase_plane.png")
117+
nothing # hide
115118
116119
Plots.plot(sol; vars=[C1.v, C2.v, L.i], labels=["C1 Voltage in V" "C1 Voltage in V" "Inductor Current in A"])
117120
Plots.savefig("chua.png")
121+
nothing # hide
118122
```
119123

120-
![Time series plot of C1.v, C2.v and L.i](https://user-images.githubusercontent.com/50108075/169712569-9ae5a074-ca1a-4801-b666-75a2f6e21bf5.png)
124+
![Time series plot of C1.v, C2.v and L.i](chua_phase_plane.png)
121125

122-
![Phase plane plot of C1.v and C2.v](https://user-images.githubusercontent.com/50108075/169712578-b3f314f6-3310-4471-a31e-af7fac3c0fbc.png)
126+
![Phase plane plot of C1.v and C2.v](chua.png)

docs/src/tutorials/rc_circuit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In that tutorial, the full RC circuit is built from scratch. Here, we will use t
66
components of the `Electrical` model in the ModelingToolkit Standard Library to simply
77
connect pre-made components and simulate the model.
88

9-
```julia
9+
```@example
1010
using ModelingToolkit, OrdinaryDiffEq, Plots
1111
using ModelingToolkitStandardLibrary.Electrical
1212
@@ -32,7 +32,7 @@ sol = solve(prob, Tsit5())
3232
plot(sol, vars = [capacitor.v,resistor.i],
3333
title = "RC Circuit Demonstration",
3434
labels = ["Capacitor Voltage" "Resistor Current"])
35-
savefig("plot.png")
35+
savefig("plot.png"); nothing # hide
3636
```
3737

38-
![](https://user-images.githubusercontent.com/1814174/164912983-c3f73628-0e19-4e42-b085-4f62ba6f23d1.png)
38+
![](plot.png)

0 commit comments

Comments
 (0)