@@ -193,14 +193,14 @@ end
193
193
=#
194
194
195
195
"""
196
- Replace derivatives of non-selected unknown variables by dummy derivatives.
196
+ Replace derivatives of non-selected unknown variables by dummy derivatives.
197
197
198
198
State selection may determine that some differential variables are
199
199
algebraic variables in disguise. The derivative of such variables are
200
200
called dummy derivatives.
201
201
202
- `SelectedState` information is no longer needed after this function is called.
203
- State selection is done. All non-differentiated variables are algebraic
202
+ `SelectedState` information is no longer needed after this function is called.
203
+ State selection is done. All non-differentiated variables are algebraic
204
204
variables, and all variables that appear differentiated are differential variables.
205
205
"""
206
206
function substitute_derivatives_algevars! (
@@ -241,7 +241,7 @@ function substitute_derivatives_algevars!(
241
241
end
242
242
end
243
243
244
- #=
244
+ #=
245
245
There are three cases where we want to generate new variables to convert
246
246
the system into first order (semi-implicit) ODEs.
247
247
@@ -288,32 +288,32 @@ where `:=` denotes assignment.
288
288
As a final note, in all the above cases where we need to introduce new
289
289
variables and equations, don't add them when they already exist.
290
290
291
- ###### DISCRETE SYSTEMS #######
291
+ ###### DISCRETE SYSTEMS #######
292
292
293
293
Documenting the differences to structural simplification for discrete systems:
294
294
295
295
In discrete systems everything gets shifted forward a timestep by `shift_discrete_system`
296
- in order to properly generate the difference equations.
296
+ in order to properly generate the difference equations.
297
297
298
298
In the system x(k) ~ x(k-1) + x(k-2), becomes Shift(t, 1)(x(t)) ~ x(t) + Shift(t, -1)(x(t))
299
299
300
- The lowest-order term is Shift(t, k)(x(t)), instead of x(t). As such we actually want
300
+ The lowest-order term is Shift(t, k)(x(t)), instead of x(t). As such we actually want
301
301
dummy variables for the k-1 lowest order terms instead of the k-1 highest order terms.
302
302
303
303
Shift(t, -1)(x(t)) -> x\_{t-1}(t)
304
304
305
- Since Shift(t, -1)(x) is not a derivative, it is directly substituted in `fullvars`.
306
- No equation or variable is added for it.
305
+ Since Shift(t, -1)(x) is not a derivative, it is directly substituted in `fullvars`.
306
+ No equation or variable is added for it.
307
307
308
- For ODESystems D(D(D(x))) in equations is recursively substituted as D(x) ~ x_t, D(x_t) ~ x_tt, etc.
309
- The analogue for discrete systems, Shift(t, 1)(Shift(t,1)(Shift(t,1)(Shift(t, -3)(x(t)))))
310
- does not actually appear. So `total_sub` in generate_system_equations` is directly
311
- initialized with all of the lowered variables `Shift(t, -3)(x) -> x_t-3(t)`, etc.
308
+ For ODESystems D(D(D(x))) in equations is recursively substituted as D(x) ~ x_t, D(x_t) ~ x_tt, etc.
309
+ The analogue for discrete systems, Shift(t, 1)(Shift(t,1)(Shift(t,1)(Shift(t, -3)(x(t)))))
310
+ does not actually appear. So `total_sub` in generate_system_equations` is directly
311
+ initialized with all of the lowered variables `Shift(t, -3)(x) -> x_t-3(t)`, etc.
312
312
=#
313
313
"""
314
314
Generate new derivative variables for the system.
315
315
316
- Effects on the system structure:
316
+ Effects on the system structure:
317
317
- fullvars: add the new derivative variables x_t
318
318
- neweqs: add the identity equations for the new variables, D(x) ~ x_t
319
319
- graph: update graph with the new equations and variables, and their connections
@@ -484,7 +484,7 @@ function find_duplicate_dd(dv, solvable_graph, diff_to_var, linear_eqs, mm)
484
484
end
485
485
486
486
"""
487
- Add a dummy derivative variable x_t corresponding to symbolic variable D(x)
487
+ Add a dummy derivative variable x_t corresponding to symbolic variable D(x)
488
488
which has index dv in `fullvars`. Return the new index of x_t.
489
489
"""
490
490
function add_dd_variable! (s:: SystemStructure , fullvars, x_t, dv)
@@ -516,22 +516,22 @@ function add_dd_equation!(s::SystemStructure, neweqs, eq, dv, v_t)
516
516
end
517
517
518
518
"""
519
- Solve the equations in `neweqs` to obtain the final equations of the
519
+ Solve the equations in `neweqs` to obtain the final equations of the
520
520
system.
521
521
522
- For each equation of `neweqs`, do one of the following:
522
+ For each equation of `neweqs`, do one of the following:
523
523
1. If the equation is solvable for a differentiated variable D(x),
524
524
then solve for D(x), and add D(x) ~ sol as a differential equation
525
525
of the system.
526
- 2. If the equation is solvable for an un-differentiated variable x,
526
+ 2. If the equation is solvable for an un-differentiated variable x,
527
527
solve for x and then add x ~ sol as a solved equation. These will
528
528
become observables.
529
529
3. If the equation is not solvable, add it as an algebraic equation.
530
530
531
531
Solved equations are added to `total_sub`. Occurrences of differential
532
532
or solved variables on the RHS of the final equations will get substituted.
533
533
The topological sort of the equations ensures that variables are solved for
534
- before they appear in equations.
534
+ before they appear in equations.
535
535
536
536
Reorder the equations and unknowns to be in the BLT sorted form.
537
537
@@ -610,7 +610,7 @@ function generate_system_equations!(state::TearingState, neweqs, var_eq_matching
610
610
@unpack neweqs′, eq_ordering, var_ordering, solved_eqs, solved_vars = eq_generator
611
611
612
612
is_diff_eq = .! iszero .(var_ordering)
613
- # Generate new equations and orderings
613
+ # Generate new equations and orderings
614
614
diff_vars = var_ordering[is_diff_eq]
615
615
diff_vars_set = BitSet (diff_vars)
616
616
if length (diff_vars_set) != length (diff_vars)
@@ -695,7 +695,7 @@ struct EquationGenerator{S, D, I}
695
695
neweqs′:: Vector{Equation}
696
696
"""
697
697
`eq_ordering[i]` is the index `neweqs′[i]` was originally at in the untorn equations of
698
- the system. This is used to permute the state of the system into BLT sorted form.
698
+ the system. This is used to permute the state of the system into BLT sorted form.
699
699
"""
700
700
eq_ordering:: Vector{Int}
701
701
"""
@@ -866,7 +866,7 @@ function make_solved_equation(var, eq, total_sub; simplify = false)
866
866
end
867
867
868
868
"""
869
- Given the ordering returned by `generate_system_equations!`, update the
869
+ Given the ordering returned by `generate_system_equations!`, update the
870
870
tearing state to account for the new order. Permute the variables and equations.
871
871
Eliminate the solved variables and equations from the graph and permute the
872
872
graph's vertices to account for the new variable/equation ordering.
@@ -916,7 +916,7 @@ function reorder_vars!(state::TearingState, var_eq_matching, var_sccs, eq_orderi
916
916
# Remove empty SCCs
917
917
filter! (! isempty, var_sccs)
918
918
919
- # Update system structure
919
+ # Update system structure
920
920
@set! state. structure. graph = complete (new_graph)
921
921
@set! state. structure. var_to_diff = new_var_to_diff
922
922
@set! state. structure. eq_to_diff = new_eq_to_diff
@@ -933,7 +933,7 @@ function update_simplified_system!(
933
933
@unpack fullvars, structure = state
934
934
@unpack solvable_graph, var_to_diff, eq_to_diff, graph = structure
935
935
diff_to_var = invview (var_to_diff)
936
- # Since we solved the highest order derivative varible in discrete systems,
936
+ # Since we solved the highest order derivative variable in discrete systems,
937
937
# we make a list of the solved variables and avoid including them in the
938
938
# unknowns.
939
939
solved_vars = Set ()
@@ -1058,7 +1058,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching::Matching,
1058
1058
state, neweqs, var_eq_matching, full_var_eq_matching, var_sccs; iv, D)
1059
1059
end
1060
1060
1061
- # Structural simplification
1061
+ # Structural simplification
1062
1062
substitute_derivatives_algevars! (state, neweqs, var_eq_matching, dummy_sub; iv, D)
1063
1063
1064
1064
var_sccs = generate_derivative_variables! (
0 commit comments