Skip to content

Commit 26f8d5c

Browse files
Merge pull request #2019 from ArnoStrouwen/LT
[skip ci] LanguageTool
2 parents 71e8f34 + 2ac0307 commit 26f8d5c

16 files changed

+122
-125
lines changed

docs/src/basics/FAQ.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ such as `@register_symbolic`, are described in detail
4646

4747
## Using ModelingToolkit with Optimization / Automatic Differentiation
4848

49-
If you are using ModelingToolkit inside of a loss function and are having issues with
49+
If you are using ModelingToolkit inside a loss function and are having issues with
5050
mixing MTK with automatic differentiation, getting performance, etc... don't! Instead, use
51-
MTK outside of the loss function to generate the code, and then use the generated code
52-
inside of the loss function.
51+
MTK outside the loss function to generate the code, and then use the generated code
52+
inside the loss function.
5353

5454
For example, let's say you were building ODEProblems in the loss function like:
5555

@@ -62,9 +62,9 @@ end
6262
```
6363

6464
Since `ODEProblem` on a MTK `sys` will have to generate code, this will be slower than
65-
caching the generated code, and will required automatic differentiation to go through the
65+
caching the generated code, and will require automatic differentiation to go through the
6666
code generation process itself. All of this is unnecessary. Instead, generate the problem
67-
once outside of the loss function, and remake the prob inside of the loss function:
67+
once outside the loss function, and remake the prob inside of the loss function:
6868

6969
```julia
7070
prob = ODEProblem(sys, [], [p1 => p[1], p2 => p[2]])

docs/src/comparison.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
[Dymola](https://www.3ds.com/products-services/catia/products/dymola/) and
88
[OpenModelica](https://openmodelica.org/), which have differing levels of
99
performance and can give different results on the same model. Many of the
10-
commonly used Modelica compilers are not open source. ModelingToolkit.jl
11-
is a language with a single canonical open source implementation.
10+
commonly used Modelica compilers are not open-source. ModelingToolkit.jl
11+
is a language with a single canonical open-source implementation.
1212
- All current Modelica compiler implementations are fixed and not extendable
1313
by the users from the Modelica language itself. For example, the Dymola
14-
compiler [shares its symbolic processing pipeline](https://www.claytex.com/tech-blog/model-translation-and-symbolic-manipulation/)
14+
compiler [shares its symbolic processing pipeline](https://www.claytex.com/tech-blog/model-translation-and-symbolic-manipulation/),
1515
which is roughly equivalent to the `dae_index_lowering` and `structural_simplify`
1616
of ModelingToolkit.jl. ModelingToolkit.jl is an open and hackable transformation
1717
system which allows users to add new non-standard transformations and control
@@ -34,23 +34,23 @@
3434
academic reviews such as [this one](https://arxiv.org/abs/1909.00484). In this
3535
sense, ModelingToolkit.jl is more similar to the Simscape sub-environment.
3636
- Simulink is used from MATLAB while ModelingToolkit.jl is used from Julia.
37-
Thus any user defined functions have the performance of their host language.
37+
Thus any user-defined functions have the performance of their host language.
3838
For information on the performance differences between Julia and MATLAB,
39-
consult [open benchmarks](https://julialang.org/benchmarks/) which demonstrate
39+
consult [open benchmarks](https://julialang.org/benchmarks/), which demonstrate
4040
Julia as an order of magnitude or more faster in many cases due to its JIT
4141
compilation.
42-
- Simulink uses the MATLAB differential equation solvers while ModelingToolkit.jl
42+
- Simulink uses the MATLAB differential equation solvers, while ModelingToolkit.jl
4343
uses [DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/). For a systematic
4444
comparison between the solvers, consult
45-
[open benchmarks](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/)
45+
[open benchmarks](https://docs.sciml.ai/SciMLBenchmarksOutput/stable/),
4646
which demonstrate two orders of magnitude performance advantage for the native
4747
Julia solvers across many benchmark problems.
4848
- Simulink comes with a Graphical User Interface (GUI), ModelingToolkit.jl
4949
does not.
5050
- Simulink is a proprietary software, meaning users cannot actively modify or
5151
extend the software. ModelingToolkit.jl is built in Julia and used in Julia,
5252
where users can actively extend and modify the software interactively in the
53-
REPL and contribute to its open source repositories.
53+
REPL and contribute to its open-source repositories.
5454
- Simulink covers ODE and DAE systems. ModelingToolkit.jl has a much more
5555
expansive set of system types, including SDEs, PDEs, optimization problems,
5656
and more.
@@ -72,9 +72,9 @@
7272
In addition, the DifferentialEquations.jl interface is confederated, meaning
7373
that any user can dynamically extend the system to add new solvers to the
7474
interface by defining new dispatches of solve.
75-
- CASADI's DAEBuilder does not implement efficiency transformations like tearing
75+
- CASADI's DAEBuilder does not implement efficiency transformations like tearing,
7676
which are standard in the ModelingToolkit.jl transformation pipeline.
77-
- CASADI supports special functionality for quadratic programming problems while
77+
- CASADI supports special functionality for quadratic programming problems, while
7878
ModelingToolkit only provides nonlinear programming via `OptimizationSystem`.
7979
- ModelingToolkit.jl integrates with its host language Julia, so Julia code
8080
can be automatically converted into ModelingToolkit expressions. Users of

docs/src/examples/higher_order.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ systems. These transformations allow for symbolically changing
55
the representation of the model to problems that are easier to
66
numerically solve. One simple to demonstrate transformation is the
77
`structural_simplify` with does a lot of tricks, one being the
8-
transformation that sends an Nth order ODE
8+
transformation that sends a Nth order ODE
99
to a 1st order ODE.
1010

1111
To see this, let's define a second order riff on the Lorenz equations.

docs/src/examples/modelingtoolkitize_index_reduction.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Automated Index Reduction of DAEs
22

33
In many cases one may accidentally write down a DAE that is not easily solvable
4-
by numerical methods. In this tutorial we will walk through an example of a
4+
by numerical methods. In this tutorial, we will walk through an example of a
55
pendulum which accidentally generates an index-3 DAE, and show how to use the
66
`modelingtoolkitize` to correct the model definition before solving.
77

@@ -39,7 +39,7 @@ plot(sol, idxs=states(traced_sys))
3939

4040
### Attempting to Solve the Equation
4141

42-
In this tutorial we will look at the pendulum system:
42+
In this tutorial, we will look at the pendulum system:
4343

4444
```math
4545
\begin{aligned}
@@ -88,21 +88,21 @@ Did you implement the DAE incorrectly? No. Is the solver broken? No.
8888
It turns out that this is a property of the DAE that we are attempting to solve.
8989
This kind of DAE is known as an index-3 DAE. For a complete discussion of DAE
9090
index, see [this article](http://www.scholarpedia.org/article/Differential-algebraic_equations).
91-
Essentially the issue here is that we have 4 differential variables (``x``, ``v_x``, ``y``, ``v_y``)
91+
Essentially, the issue here is that we have 4 differential variables (``x``, ``v_x``, ``y``, ``v_y``)
9292
and one algebraic variable ``T`` (which we can know because there is no `D(T)`
9393
term in the equations). An index-1 DAE always satisfies that the Jacobian of
9494
the algebraic equations is non-singular. Here, the first 4 equations are
9595
differential equations, with the last term the algebraic relationship. However,
9696
the partial derivative of `x^2 + y^2 - L^2` w.r.t. `T` is zero, and thus the
97-
Jacobian of the algebraic equations is the zero matrix and thus it's singular.
98-
This is a very quick way to see whether the DAE is index 1!
97+
Jacobian of the algebraic equations is the zero matrix, and thus it's singular.
98+
This is a rapid way to see whether the DAE is index 1!
9999

100100
The problem with higher order DAEs is that the matrices used in Newton solves
101101
are singular or close to singular when applied to such problems. Because of this
102102
fact, the nonlinear solvers (or Rosenbrock methods) break down, making them
103103
difficult to solve. The classic paper [DAEs are not ODEs](https://epubs.siam.org/doi/10.1137/0903023)
104104
goes into detail on this and shows that many methods are no longer convergent
105-
when index is higher than one. So it's not necessarily the fault of the solver
105+
when index is higher than one. So, it's not necessarily the fault of the solver
106106
or the implementation: this is known.
107107

108108
But that's not a satisfying answer, so what do you do about it?
@@ -125,7 +125,7 @@ v_y^\prime =& y T - g \\
125125

126126
Note that this is mathematically-equivalent to the equation that we had before,
127127
but the Jacobian w.r.t. `T` of the algebraic equation is no longer zero because
128-
of the substitution. This means that if you wrote down this version of the model
128+
of the substitution. This means that if you wrote down this version of the model,
129129
it will be index-1 and solve correctly! In fact, this is how DAE index is
130130
commonly defined: the number of differentiations it takes to transform the DAE
131131
into an ODE, where an ODE is an index-0 DAE by substituting out all of the
@@ -154,12 +154,12 @@ plot(sol, idxs=states(traced_sys))
154154
```
155155

156156
Note that plotting using `states(traced_sys)` is done so that any
157-
variables which are symbolically eliminated, or any variable reorderings
157+
variables which are symbolically eliminated, or any variable reordering
158158
done for enhanced parallelism/performance, still show up in the resulting
159159
plot and the plot is shown in the same order as the original numerical
160160
code.
161161

162-
Note that we can even go a little bit further. If we use the `ODAEProblem`
162+
Note that we can even go a bit further. If we use the `ODAEProblem`
163163
constructor, we can remove the algebraic equations from the states of the
164164
system and fully transform the index-3 DAE into an index-0 ODE which can
165165
be solved via an explicit Runge-Kutta method:

docs/src/examples/perturbation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ end
3636

3737
In the first two examples, we applied the perturbation method to algebraic problems. However, the main power of the perturbation method is to solve differential equations (usually ODEs, but also occasionally PDEs). Surprisingly, the main procedure developed to solve algebraic problems works well for differential equations. In fact, we will use the same two helper functions, `collect_powers` and `solve_coef`. The main difference is in the way we expand the dependent variables. For algebraic problems, the coefficients of $\epsilon$ are constants; whereas, for differential equations, they are functions of the dependent variable (usually time).
3838

39-
As the first ODE example, we have chosen a simple and well-behaved problem, which is a variation of a standard first-year physics problem: what is the trajectory of an object (say, a ball or a rocket) thrown vertically at velocity $v$ from the surface of a planet? Assuming a constant acceleration of gravity, $g$, every burgeoning physicist knows the answer: $x(t) = x(0) + vt - \frac{1}{2}gt^2$. However, what happens if $g$ is not constant? Specifically, $g$ is inversely proportional to the distant from the center of the planet. If $v$ is large and the projectile travels a large fraction of the radius of the planet, the assumption of constant gravity does not hold anymore. However, unless $v$ is large compared to the escape velocity, the correction is usually small. After simplifications and change of variables to dimensionless, the problem becomes
39+
As the first ODE example, we have chosen a simple and well-behaved problem, which is a variation of a standard first-year physics problem: what is the trajectory of an object (say, a ball, or a rocket) thrown vertically at velocity $v$ from the surface of a planet? Assuming a constant acceleration of gravity, $g$, every burgeoning physicist knows the answer: $x(t) = x(0) + vt - \frac{1}{2}gt^2$. However, what happens if $g$ is not constant? Specifically, $g$ is inversely proportional to the distant from the center of the planet. If $v$ is large and the projectile travels a large fraction of the radius of the planet, the assumption of constant gravity does not hold anymore. However, unless $v$ is large compared to the escape velocity, the correction is usually small. After simplifications and change of variables to dimensionless, the problem becomes
4040

4141
```math
4242
\ddot{x}(t) = -\frac{1}{(1 + \epsilon x(t))^2}
@@ -87,7 +87,7 @@ subs = Dict(∂∂y[i] => D(D(y[i])) for i in eachindex(y))
8787
eqs = [substitute(first(v), subs) ~ substitute(last(v), subs) for v in vals]
8888
```
8989

90-
We are nearly there! From this point on, the rest is standard ODE solving procedures. Potentially we can use a symbolic ODE solver to find a closed form solution to this problem. However, **Symbolics.jl** currently does not support this functionality. Instead, we solve the problem numerically. We form an `ODESystem`, lower the order (convert second derivatives to first), generate an `ODEProblem` (after passing the correct initial conditions), and, finally, solve it.
90+
We are nearly there! From this point on, the rest is standard ODE solving procedures. Potentially, we can use a symbolic ODE solver to find a closed form solution to this problem. However, **Symbolics.jl** currently does not support this functionality. Instead, we solve the problem numerically. We form an `ODESystem`, lower the order (convert second derivatives to first), generate an `ODEProblem` (after passing the correct initial conditions), and, finally, solve it.
9191

9292
```julia
9393
using ModelingToolkit, DifferentialEquations

docs/src/examples/sparse_jacobians.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Automated Sparse Analytical Jacobians
22

33
In many cases where you have large stiff differential equations, getting a
4-
sparse Jacobian can be essential for performance. In this tutorial we will show
4+
sparse Jacobian can be essential for performance. In this tutorial, we will show
55
how to use `modelingtoolkitize` to regenerate an `ODEProblem` code with
66
the analytical solution to the sparse Jacobian, along with the sparsity
77
pattern required by DifferentialEquations.jl's solvers to specialize the solving
88
process.
99

10-
First let's start out with an implementation of the 2-dimensional Brusselator
10+
First, let's start out with an implementation of the 2-dimensional Brusselator
1111
partial differential equation discretized using finite differences:
1212

1313
```@example sparsejac

docs/src/examples/spring_mass.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Component-Based Modeling a Spring-Mass System
1+
# Component-Based Modeling of a Spring-Mass System
22

3-
In this tutorial we will build a simple component-based model of a spring-mass system. A spring-mass system consists of one or more masses connected by springs. [Hooke's law](https://en.wikipedia.org/wiki/Hooke%27s_law) gives the force exerted by a spring when it is extended or compressed by a given distance. This specifies a differential-equation system where the acceleration of the masses is specified using the forces acting on them.
3+
In this tutorial, we will build a simple component-based model of a spring-mass system. A spring-mass system consists of one or more masses connected by springs. [Hooke's law](https://en.wikipedia.org/wiki/Hooke%27s_law) gives the force exerted by a spring when it is extended or compressed by a given distance. This specifies a differential-equation system where the acceleration of the masses is specified using the forces acting on them.
44

55
## Copy-Paste Example
66

@@ -58,7 +58,7 @@ plot(sol)
5858

5959
## Explanation
6060
### Building the components
61-
For each component we use a Julia function that returns an `ODESystem`. At the top, we define the fundamental properties of a `Mass`: it has a mass `m`, a position `pos` and a velocity `v`. We also define that the velocity is the rate of change of position with respect to time.
61+
For each component, we use a Julia function that returns an `ODESystem`. At the top, we define the fundamental properties of a `Mass`: it has a mass `m`, a position `pos` and a velocity `v`. We also define that the velocity is the rate of change of position with respect to time.
6262

6363
```@example component
6464
function Mass(; name, m = 1.0, xy = [0., 0.], u = [0., 0.])
@@ -69,7 +69,7 @@ function Mass(; name, m = 1.0, xy = [0., 0.], u = [0., 0.])
6969
end
7070
```
7171

72-
Note that this is an incompletely specified `ODESystem`. It cannot be simulated on its own since the equations for the velocity `v[1:2](t)` are unknown. Notice the addition of a `name` keyword. This allows us to generate different masses with different names. A `Mass` can now be constructed as:
72+
Note that this is an incompletely specified `ODESystem`. It cannot be simulated on its own, since the equations for the velocity `v[1:2](t)` are unknown. Notice the addition of a `name` keyword. This allows us to generate different masses with different names. A `Mass` can now be constructed as:
7373

7474
```@example component
7575
Mass(name = :mass1)
@@ -81,7 +81,7 @@ Or using the `@named` helper macro
8181
@named mass1 = Mass()
8282
```
8383

84-
Next we build the spring component. It is characterised by the spring constant `k` and the length `l` of the spring when no force is applied to it. The state of a spring is defined by its current length and direction.
84+
Next, we build the spring component. It is characterized by the spring constant `k` and the length `l` of the spring when no force is applied to it. The state of a spring is defined by its current length and direction.
8585

8686
```@example component
8787
function Spring(; name, k = 1e4, l = 1.)

docs/src/examples/tearing_parallelism.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exposing More Parallelism By Tearing Algebraic Equations in ODESystems
22

3-
Sometimes it can be very non-trivial to parallelize a system. In this tutorial
3+
Sometimes it can be very non-trivial to parallelize a system. In this tutorial,
44
we will demonstrate how to make use of `structural_simplify` to expose more
55
parallelism in the solution process and parallelize the resulting simulation.
66

@@ -150,8 +150,8 @@ If you look at the system we defined:
150150
length(equations(big_rc))
151151
```
152152

153-
You see it started as a massive 1051 set of equations. However, after eliminating
154-
redundancies we arrive at 151 equations:
153+
You see, it started as a massive 1051 set of equations. However, after eliminating
154+
redundancies, we arrive at 151 equations:
155155

156156
```@example tearing
157157
equations(sys)
@@ -178,7 +178,7 @@ equations, and so the full set of equations must be solved together. That expose
178178
no parallelism. However, the Block Lower Triangular (BLT) transformation exposes
179179
independent blocks. This is then further improved by the tearing process, which
180180
removes 90% of the equations and transforms the nonlinear equations into 50
181-
independent blocks *which can now all be solved in parallel*. The conclusion
181+
independent blocks, *which can now all be solved in parallel*. The conclusion
182182
is that, your attempts to parallelize are neigh: performing parallelism after
183183
structural simplification greatly improves the problem that can be parallelized,
184184
so this is better than trying to do it by hand.

0 commit comments

Comments
 (0)