Skip to content

Strange behaviour for SDEs with continuous callbacks #2723

@TorkelE

Description

@TorkelE

Here I create a continuous callback that should add 20 units of X whenever X hits the threshold at 50.0. Practically, the about of X added seems a bit random, and typically less that 20.0.

using ModelingToolkit
@variables t X(t)
@parameters p d
D = Differential(t)

eqs = [D(X) ~ p - d*X]
noiseeqs = [0.1*X]
continuous_events =[[X ~ 50.0] => [X ~ X + 20.0]]
@named ssys = SDESystem(eqs, noiseeqs, t, [X], [p, d]; continuous_events)
ssys = complete(ssys) # because @mtkbuild/structural_simplify are broken for SDE systems.

u0 = [X => 55.0]
tspan = (0.0, 100.0)
ps = [p => 10.0, d => 0.2]

oprob = SDEProblem(ssys, u0, tspan, ps)
sol = solve(oprob, ImplicitEM())
plot(sol)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions