Skip to content

Commit 610b936

Browse files
authored
Various doc and style improvements (#150)
* format markdown * strict links * LanguageTool
1 parent e24cf6a commit 610b936

Some content is hidden

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

43 files changed

+1213
-848
lines changed

.JuliaFormatter.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
style = "sciml"
1+
style = "sciml"
2+
format_markdown = true

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![codecov](https://codecov.io/gh/SciML/ModelingToolkitStandardLibrary.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/SciML/ModelingToolkitStandardLibrary.jl)
77
[![Build Status](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/workflows/CI/badge.svg)](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/actions?query=workflow%3ACI)
88

9-
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
9+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
1010
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
1111

1212
The ModelingToolkit Standard Library is a standard library of components to model the world and beyond.
@@ -19,7 +19,8 @@ Assuming that you already have Julia correctly installed, it suffices to import
1919
ModelingToolkitStandardLibrary.jl in the standard way:
2020

2121
```julia
22-
import Pkg; Pkg.add("ModelingToolkitStandardLibrary")
22+
import Pkg;
23+
Pkg.add("ModelingToolkitStandardLibrary");
2324
```
2425

2526
## Tutorials and Documentation
@@ -33,11 +34,11 @@ the documentation, which contains the unreleased features.
3334

3435
The following are the constituant libraries of the ModelingToolkit Standard Library.
3536

36-
- [Basic Blocks](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/blocks/)
37-
- [Mechanical Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/mechanical/)
38-
- [Electrical Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/electrical/)
39-
- [Magnetic Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/magnetic/)
40-
- [Thermal Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/thermal/)
37+
- [Basic Blocks](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/blocks/)
38+
- [Mechanical Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/mechanical/)
39+
- [Electrical Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/electrical/)
40+
- [Magnetic Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/magnetic/)
41+
- [Thermal Components](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/API/thermal/)
4142

4243
## Example
4344

@@ -52,20 +53,19 @@ R = 1.0
5253
C = 1.0
5354
V = 1.0
5455
@variables t
55-
@named resistor = Resistor(R=R)
56-
@named capacitor = Capacitor(C=C)
56+
@named resistor = Resistor(R = R)
57+
@named capacitor = Capacitor(C = C)
5758
@named source = Voltage()
58-
@named constant = Constant(k=V)
59+
@named constant = Constant(k = V)
5960
@named ground = Ground()
6061

61-
rc_eqs = [
62-
connect(constant.output, source.V)
63-
connect(source.p, resistor.p)
64-
connect(resistor.n, capacitor.p)
65-
connect(capacitor.n, source.n, ground.g)
66-
]
62+
rc_eqs = [connect(constant.output, source.V)
63+
connect(source.p, resistor.p)
64+
connect(resistor.n, capacitor.p)
65+
connect(capacitor.n, source.n, ground.g)]
6766

68-
@named rc_model = ODESystem(rc_eqs, t, systems=[resistor, capacitor, constant, source, ground])
67+
@named rc_model = ODESystem(rc_eqs, t,
68+
systems = [resistor, capacitor, constant, source, ground])
6969
sys = structural_simplify(rc_model)
7070
prob = ODEProblem(sys, Pair[], (0, 10.0))
7171
sol = solve(prob, Tsit5())

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ makedocs(sitename = "ModelingToolkitStandardLibrary.jl",
1818
authors = "Julia Computing",
1919
clean = true,
2020
doctest = false,
21+
linkcheck = true,
2122
strict = [
23+
:linkcheck,
2224
:doctest,
2325
:example_block,
2426
],

docs/src/API/blocks.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# ModelingToolkitStandardLibrary: Blocks
2+
23
```@meta
34
CurrentModule = ModelingToolkitStandardLibrary.Blocks
45
```
6+
57
```@contents
68
Pages = ["blocks.md"]
79
```
10+
811
## Index
12+
913
```@index
1014
Pages = ["blocks.md"]
1115
```
@@ -80,4 +84,4 @@ PI
8084
LimPI
8185
PID
8286
LimPID
83-
```
87+
```

docs/src/API/electrical.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# ModelingToolkitStandardLibrary: Electrical Components
2+
23
```@meta
34
CurrentModule = ModelingToolkitStandardLibrary.Electrical
45
```
56

6-
77
```@contents
88
Pages = ["electrical.md"]
99
```
10+
1011
## Index
12+
1113
```@index
1214
Pages = ["electrical.md"]
1315
```
@@ -63,6 +65,7 @@ ExpSineCurrent
6365
```
6466

6567
## Digital Gates
68+
6669
```@docs
6770
Not
6871
And
@@ -74,6 +77,7 @@ Xnor
7477
```
7578

7679
## Digital Components
80+
7781
```@docs
7882
HalfAdder
7983
FullAdder
@@ -84,6 +88,7 @@ Decoder
8488
```
8589

8690
## Digital Sources
91+
8792
```@docs
8893
PulseDiff
8994
Set

docs/src/API/linear_analysis.md

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
11
# Linear Analysis
22

33
!!! danger "Experimental"
4-
The interface described here is currently experimental and at any time subject to breaking changes not respecting semantic versioning.
4+
5+
The interface described here is currently experimental and at any time subject to breaking changes not respecting semantic versioning.
56

67
Linear analysis refers to the process of linearizing a nonlinear model and analysing the resulting linear dynamical system. To facilitate linear analysis, ModelingToolkitStandardLibrary provides the concept of an [`AnalysisPoint`](@ref), which can be inserted in-between two causal blocks (such as those from the `Blocks` sub module). Once a model containing analysis points is built, several operations are available:
78

8-
- [`get_sensitivity`](@ref) get the [sensitivity function (wiki)](https://en.wikipedia.org/wiki/Sensitivity_(control_systems)), $S(s)$, as defined in the field of control theory.
9-
- [`get_comp_sensitivity`](@ref) get the complementary sensitivity function $T(s) : S(s)+T(s)=1$.
10-
- [`get_looptransfer`](@ref) get the (open) loop-transfer function where the loop starts and ends in the analysis point. For a typical simple feedback connection with a plant $P(s)$ and a controller $C(s)$, the loop-transfer function at the plant output is $P(s)C(s)$.
11-
- [`linearize`](@ref) can be called with two analysis points denoting the input and output of the linearized system.
12-
- [`open_loop`](@ref) return a new (nonlinear) system where the loop has been broken in the analysis point, i.e., the connection the analysis point usually implies has been removed.
9+
- [`get_sensitivity`](@ref) get the [sensitivity function (wiki)](https://en.wikipedia.org/wiki/Sensitivity_(control_systems)), $S(s)$, as defined in the field of control theory.
10+
- [`get_comp_sensitivity`](@ref) get the complementary sensitivity function $T(s) : S(s)+T(s)=1$.
11+
- [`get_looptransfer`](@ref) get the (open) loop-transfer function where the loop starts and ends in the analysis point. For a typical simple feedback connection with a plant $P(s)$ and a controller $C(s)$, the loop-transfer function at the plant output is $P(s)C(s)$.
12+
- [`linearize`](@ref) can be called with two analysis points denoting the input and output of the linearized system.
13+
- [`open_loop`](@ref) return a new (nonlinear) system where the loop has been broken in the analysis point, i.e., the connection the analysis point usually implies has been removed.
1314

1415
An analysis point can be created explicitly using the constructor [`AnalysisPoint`](@ref), or automatically when connecting two causal components using `connect`:
16+
1517
```julia
1618
connect(comp1.output, :analysis_point_name, comp2.input)
1719
```
1820

1921
!!! warning "Causality"
20-
Analysis points are *causal*, i.e., they imply a directionality for the flow of information. The order of the connections in the connect statement is thus important, i.e., `connect(out, :name, in)` is different from `connect(in, :name, out)`.
2122

23+
Analysis points are *causal*, i.e., they imply a directionality for the flow of information. The order of the connections in the connect statement is thus important, i.e., `connect(out, :name, in)` is different from `connect(in, :name, out)`.
24+
2225
The directionality of an analysis point can be thought of as an arrow in a block diagram, where the name of the analysis point applies to the arrow itself.
26+
2327
```
2428
┌─────┐ ┌─────┐
2529
│ │ name │ │
2630
│ out├────────►│in │
2731
│ │ │ │
2832
└─────┘ └─────┘
2933
```
34+
3035
This is signified by the name being the middle argument to `connect`.
3136

3237
Of the above mentioned functions, all except for [`open_loop`](@ref) return the output of [`ModelingToolkit.linearize`](@ref), which is
38+
3339
```julia
3440
matrices, simplified_sys = linearize(...)
3541
# matrices = (; A, B, C, D)
3642
```
43+
3744
i.e., `matrices` is a named tuple containing the matrices of a linear state-space system on the form
45+
3846
```math
3947
\begin{aligned}
4048
\dot x &= Ax + Bu\\
@@ -43,29 +51,31 @@ y &= Cx + Du
4351
```
4452

4553
## Example
54+
4655
The following example builds a simple closed-loop system with a plant $P$ and a controller $C$. Two analysis points are inserted, one before and one after $P$. We then derive a number of sensitivity functions and show the corresponding code using the package ControlSystemBase.jl
4756

4857
```@example LINEAR_ANALYSIS
4958
using ModelingToolkitStandardLibrary.Blocks, ModelingToolkit
50-
@named P = FirstOrder(k=1, T=1) # A first-order system with pole in -1
59+
@named P = FirstOrder(k = 1, T = 1) # A first-order system with pole in -1
5160
@named C = Gain(-1) # A P controller
5261
t = ModelingToolkit.get_iv(P)
53-
eqs = [
54-
connect(P.output, :plant_output, C.input) # Connect with an automatically created analysis point called :plant_output
55-
connect(C.output, :plant_input, P.input) # Connect with an automatically created analysis point called :plant_input
56-
]
57-
sys = ODESystem(eqs, t, systems=[P,C], name=:feedback_system)
62+
eqs = [connect(P.output, :plant_output, C.input) # Connect with an automatically created analysis point called :plant_output
63+
connect(C.output, :plant_input, P.input)]
64+
sys = ODESystem(eqs, t, systems = [P, C], name = :feedback_system)
5865
5966
matrices_S = get_sensitivity(sys, :plant_input)[1] # Compute the matrices of a state-space representation of the (input)sensitivity function.
6067
matrices_T = get_comp_sensitivity(sys, :plant_input)[1]
6168
```
69+
6270
Continued linear analysis and design can be performed using ControlSystemsBase.jl.
6371
We create `ControlSystemsBase.StateSpace` objects using
72+
6473
```@example LINEAR_ANALYSIS
6574
using ControlSystemsBase, Plots
6675
S = ss(matrices_S...)
6776
T = ss(matrices_T...)
68-
bodeplot([S, T], lab=["S" "" "T" ""], plot_title="Bode plot of sensitivity functions", margin=5Plots.mm)
77+
bodeplot([S, T], lab = ["S" "" "T" ""], plot_title = "Bode plot of sensitivity functions",
78+
margin = 5Plots.mm)
6979
```
7080

7181
The sensitivity functions obtained this way should be equivalent to the ones obtained with the code below
@@ -84,38 +94,50 @@ We may also derive the loop-transfer function $L(s) = P(s)C(s)$ using
8494
matrices_L = get_looptransfer(sys, :plant_output)[1]
8595
L = ss(matrices_L...)
8696
```
97+
8798
which is equivalent to the following with ControlSystems
99+
88100
```@example LINEAR_ANALYSIS_CS
89-
L = P*(-C) # Add the minus sign to build the negative feedback into the controller
101+
L = P * (-C) # Add the minus sign to build the negative feedback into the controller
90102
```
91103

92-
93104
To obtain the transfer function between two analysis points, we call `linearize`
105+
94106
```@example LINEAR_ANALYSIS
95107
using ModelingToolkit # hide
96108
matrices_PS = linearize(sys, :plant_input, :plant_output)[1]
97109
```
110+
98111
this particular transfer function should be equivalent to the linear system `P(s)S(s)`, i.e., equivalent to
112+
99113
```@example LINEAR_ANALYSIS_CS
100114
feedback(P, C)
101115
```
102116

103117
### Obtaining transfer functions
118+
104119
A statespace system from [ControlSystemsBase](https://juliacontrol.github.io/ControlSystems.jl/stable/man/creating_systems/) can be converted to a transfer function using the function `tf`:
120+
105121
```@example LINEAR_ANALYSIS_CS
106122
tf(S)
107123
```
108124

109125
## Gain and phase margins
126+
110127
Further linear analysis can be performed using the [analysis methods from ControlSystemsBase](https://juliacontrol.github.io/ControlSystems.jl/stable/lib/analysis/). For example, calculating the gain and phase margins of a system can be done using
128+
111129
```@example LINEAR_ANALYSIS_CS
112130
margin(P)
113131
```
114-
(they are infinite for this system). A Nyquist plot can be produced using
132+
133+
(they are infinite for this system). A Nyquist plot can be produced using
134+
115135
```@example LINEAR_ANALYSIS_CS
116136
nyquistplot(P)
117137
```
138+
118139
## Index
140+
119141
```@index
120142
Pages = ["linear_analysis.md"]
121143
```

docs/src/API/magnetic.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# ModelingToolkitStandardLibrary: Magnetic Components
22

3-
43
```@contents
54
Pages = ["magnetic.md"]
65
```
6+
77
## Index
8+
89
```@index
910
Pages = ["magnetic.md"]
1011
```
12+
1113
## Flux Tubes
14+
1215
```@meta
1316
CurrentModule = ModelingToolkitStandardLibrary.Magnetic.FluxTubes
1417
```
@@ -39,4 +42,4 @@ ElectroMagneticConverter
3942
```@docs
4043
ConstantMagneticPotentialDifference
4144
ConstantMagneticFlux
42-
```
45+
```

docs/src/API/mechanical.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# ModelingToolkit Standard Library: Mechanical Components
22

3-
43
```@contents
54
Pages = ["mechanical.md"]
65
Depth = 3
76
```
7+
88
## Index
9+
910
```@index
1011
Pages = ["mechanical.md"]
1112
```
1213

1314
## Rotational Components
15+
1416
```@meta
1517
CurrentModule = ModelingToolkitStandardLibrary.Mechanical.Rotational
1618
```

docs/src/API/thermal.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# ModelingToolkitStandardLibrary: Thermal Components
2+
23
```@meta
34
CurrentModule = ModelingToolkitStandardLibrary.Thermal
45
```
56

6-
77
```@contents
88
Pages = ["thermal.md"]
99
```
10+
1011
## Index
12+
1113
```@index
1214
Pages = ["thermal.md"]
1315
```
@@ -46,4 +48,4 @@ FixedHeatFlow
4648
FixedTemperature
4749
PrescribedHeatFlow
4850
PrescribedTemperature
49-
```
51+
```

0 commit comments

Comments
 (0)