Skip to content

Conversation

@ChrisRackauckas
Copy link
Member

Fixes #860

Co-authored-by: Yingbo Ma <mayingbo5@gmail.com>
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) &&
Copy link
Member

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)
Copy link
Member

@YingboMa YingboMa Aug 4, 2021

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?

Copy link
Member Author

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.

Copy link
Member

@YingboMa YingboMa Aug 4, 2021

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.

@ChrisRackauckas
Copy link
Member Author

@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 y2(t) was changed from a parameter to a state in structural_simplify? That seems like it should never be able to happen?

@YingboMa
Copy link
Member

YingboMa commented Aug 4, 2021

Maybe rules drop the metadata.

@YingboMa
Copy link
Member

YingboMa commented Aug 4, 2021

What's the MWE?

@ChrisRackauckas
Copy link
Member Author

# 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically shuffle derivative terms to the left hand side of an ODESystem?

3 participants