You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/structural_transformation/symbolics_tearing.jl
+85-29Lines changed: 85 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -341,14 +341,18 @@ in order to properly generate the difference equations.
341
341
342
342
In the system x(k) ~ x(k-1) + x(k-2), becomes Shift(t, 1)(x(t)) ~ x(t) + Shift(t, -1)(x(t))
343
343
344
-
The lowest-order term is Shift(t, k)(x(t)), instead of x(t).
345
-
As such we actually want dummy variables for the k-1 lowest order terms instead of the k-1 highest order terms.
344
+
The lowest-order term is Shift(t, k)(x(t)), instead of x(t). As such we actually want
345
+
dummy variables for the k-1 lowest order terms instead of the k-1 highest order terms.
346
346
347
347
Shift(t, -1)(x(t)) -> x\_{t-1}(t)
348
348
349
-
Since Shift(t, -1)(x) is not a derivative, it is directly substituted in `fullvars`. No equation or variable is added for it.
349
+
Since Shift(t, -1)(x) is not a derivative, it is directly substituted in `fullvars`.
350
+
No equation or variable is added for it.
350
351
351
-
For ODESystems D(D(D(x))) in equations is recursively substituted as D(x) ~ x_t, D(x_t) ~ x_tt, etc. The analogue for discrete systems, Shift(t, 1)(Shift(t,1)(Shift(t,1)(Shift(t, -3)(x(t))))) does not actually appear. So `total_sub` in generate_system_equations` is directly initialized with all of the lowered variables `Shift(t, -3)(x) -> x_t-3(t)`, etc.
352
+
For ODESystems D(D(D(x))) in equations is recursively substituted as D(x) ~ x_t, D(x_t) ~ x_tt, etc.
353
+
The analogue for discrete systems, Shift(t, 1)(Shift(t,1)(Shift(t,1)(Shift(t, -3)(x(t)))))
354
+
does not actually appear. So `total_sub` in generate_system_equations` is directly
355
+
initialized with all of the lowered variables `Shift(t, -3)(x) -> x_t-3(t)`, etc.
352
356
=#
353
357
"""
354
358
Generate new derivative variables for the system.
@@ -358,7 +362,7 @@ Effects on the system structure:
358
362
- neweqs: add the identity equations for the new variables, D(x) ~ x_t
359
363
- graph: update graph with the new equations and variables, and their connections
360
364
- solvable_graph:
361
-
- var_eq_matching: match D(x) to the added identity equation
365
+
- var_eq_matching: match D(x) to the added identity equation D(x) ~ x_t
362
366
"""
363
367
functiongenerate_derivative_variables!(ts::TearingState, neweqs, var_eq_matching; mm =nothing, iv =nothing, D =nothing)
364
368
@unpack fullvars, sys, structure = ts
@@ -406,7 +410,7 @@ function generate_derivative_variables!(ts::TearingState, neweqs, var_eq_matchin
Occurs when a variable D(x) occurs in a non-differential system.
592
+
"""
553
593
struct UnexpectedDifferentialError
554
594
eq::Equation
555
595
end
@@ -558,12 +598,20 @@ function Base.showerror(io::IO, err::UnexpectedDifferentialError)
558
598
error("Differential found in a non-differential system. Likely this is a bug in the construction of an initialization system. Please report this issue with a reproducible example. Offending equation: $(err.eq)")
559
599
end
560
600
601
+
"""
602
+
Generate a first-order differential equation whose LHS is `dx`.
603
+
604
+
`var` and `dx` represent the same variable, but `var` may be a higher-order differential and `dx` is always first-order. For example, if `var` is D(D(x)), then `dx` would be `D(x_t)`. Solve `eq` for `var`, substitute previously solved variables, and return the differential equation.
Copy file name to clipboardExpand all lines: src/systems/discrete_system/discrete_system.jl
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -270,15 +270,19 @@ function shift_u0map_forward(sys::DiscreteSystem, u0map, defs)
270
270
v = u0map[k]
271
271
if!((op =operation(k)) isa Shift)
272
272
error("Initial conditions must be for the past state of the unknowns. Instead of providing the condition for $k, provide the condition for $(Shift(iv, -1)(k)).")
273
+
elseif op.steps >0
274
+
error("Initial conditions must be for the past state of the unknowns. Instead of providing the condition for $k, provide the condition for $(Shift(iv, -1)(only(arguments(k)))).")
273
275
end
276
+
274
277
updated[Shift(iv, op.steps +1)(arguments(k)[1])] = v
275
278
end
276
279
for var inunknowns(sys)
277
280
op =operation(var)
278
-
haskey(updated, var) &&continue
279
281
root =getunshifted(var)
282
+
shift =getshift(var)
280
283
isnothing(root) &&continue
281
-
haskey(defs, root) ||error("Initial condition for $root not provided.")
Fetch the unit associated with variable `x`. This function is a metadata getter for an individual variable, while `get_unit` is used for unit inference on more complicated sdymbolic expressions.
0 commit comments