Skip to content

Code generation contains Differential when equations contain variable time parameter #3480

Open
@bradcarman

Description

@bradcarman

Take the following

@component function FilteredInput(; name, x0=0, T=0.1)
    params = @parameters begin
      k(t) = x0
      T = T
    end
    vars = @variables begin
      x(t) = k
      dx(t) = 0
      ddx(t)
    end
    systems = []
    eqs = [
      D(x) ~ dx
      D(dx) ~ ddx
      dx ~ (k - x)/T
    ]
    return ODESystem(eqs, t, vars, params; systems, name)
end

@mtkbuild sys = FilteredInput()
ModelingToolkit.observed(sys)

gives...

julia> ModelingToolkit.observed(sys)
3-element Vector{Equation}:
 dx(t) ~ (k(t) - x(t)) / T
 dxˍt(t) ~ (-dx(t) + Differential(t)(k(t))) / T
 ddx(t) ~ dxˍt(t)

Note the Differential(t)(k(t))) which cannot be computed.

Manifest:

[961ee093] ModelingToolkit v9.66.0

Metadata

Metadata

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