-
-
Notifications
You must be signed in to change notification settings - Fork 236
Automatically move differentials to the left side #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Yingbo Ma <mayingbo5@gmail.com>
src/systems/diffeqs/odesystem.jl
Outdated
| function move_diffs(eq::Equation,r) | ||
| # Do not modify `D(x) ~ ...`, already correct | ||
| # Ignore `δ(x) ~ ...` for now | ||
| if !(eq.lhs isa Term && ModelingToolkit.operation(eq.lhs) isa Differential) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code already lives in MTK.
| 0 ~ y-x] | ||
| @test isequal(eqs2,eqs3) | ||
|
|
||
| eqs = [0 ~ x + y + D(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there's D(x)/x ~ x or D(x)*x ~ x?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D(x)/x ~ x will be untouched like before. D(x)*x ~ x will give you -D(x)*x ~ -x, which is a little odd but works fine for DAEProblem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test these cases as well? Also sin(D(x) * x) ~ x, sin(D(x) + x) ~ x, sin(D(x))*x ~ x, D(x)*D(y), etc.
|
@YingboMa one last test now throws the wrong error. It errored before, but it shouldn't throw this error. julia> equations(sys)
3-element Vector{Equation}:
0 ~ x(t) + sin(u1(t) + u2(t))
Differential(t)(x(t)) ~ x(t) + y1(t)
0 ~ sin(y2(t)) - cos(x(t))
fullvars = Any[Differential(t)(x(t)), x(t), u1(t), u2(t), y2(t)]How come |
|
Maybe rules drop the metadata. |
|
What's the MWE? |
# Example 5 from Pantelides' original paper
@parameters t
params = collect(@parameters y1(t) y2(t))
sts = collect(@variables x(t) u1(t) u2(t))
D = Differential(t)
eqs = [
0 ~ x + sin(u1 + u2)
D(x) ~ x + y1
cos(x) ~ sin(y2)
]
@named sys = ODESystem(eqs, t, sts, params)
@test_throws ModelingToolkit.InvalidSystemException structural_simplify(sys) |
Fixes #860