Skip to content

Commit c47e25f

Browse files
committed
Fix minor bugs
1 parent 153255d commit c47e25f

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/ModelingToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ include("systems/alias_elimination.jl")
136136
include("structural_transformation/StructuralTransformations.jl")
137137
@reexport using .StructuralTransformations
138138

139-
export ODESystem, ODEFunction, ODEFunctionExpr, ODEProblemExpr
139+
export ODESystem, ODEFunction, ODEFunctionExpr, ODEProblemExpr, toodesystem
140140
export DAEFunctionExpr, DAEProblemExpr
141141
export SDESystem, SDEFunction, SDEFunctionExpr, SDESystemExpr
142142
export SystemStructure

src/systems/abstractsystem.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,26 +745,31 @@ end
745745
# We have a stand-alone function to convert a `NonlinearSystem` or `ODESystem`
746746
# to an `ODESystem` to connect systems, and we later can reply on
747747
# `structural_simplify` to convert `ODESystem`s to `NonlinearSystem`s.
748-
function toodesystem(sys, t)
748+
function toodesystem(sys, t; name=nameof(sys))
749+
t = value(t)
749750
varmap = Dict()
750751
sts = states(sys)
752+
newsts = similar(sts, Any)
751753
for (i, s) in enumerate(sts)
752754
if istree(s)
753755
args = arguments(s)
754756
length(args) == 1 || throw(InvalidSystemException("Illegal state: $s. The state can have at most one argument like `x(t)`."))
755757
arg = args[1]
756-
isequal(arg, t) && continue
758+
if isequal(arg, t)
759+
newsts[i] = s
760+
continue
761+
end
757762
ns = operation(s)(t)
758-
sts[i] = ns
763+
newsts[i] = ns
759764
varmap[s] = ns
760765
else
761-
ns = indepvar2depvar(s)
762-
sts[i] = ns
766+
ns = indepvar2depvar(s, t)
767+
newsts[i] = ns
763768
varmap[s] = ns
764769
end
765770
end
766771
sub = Base.Fix2(substitute, varmap)
767772
neweqs = map(sub, equations(sys))
768773
defs = Dict(sub(k) => sub(v) for (k, v) in defaults(sys))
769-
return ODESystem(neweqs, t, sts, parameters(sys); defaults=defs)
774+
return ODESystem(neweqs, t, newsts, parameters(sys); defaults=defs, name=name)
770775
end

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ _merge(d1, d2) = merge(todict(d1), todict(d2))
8181

8282
function indepvar2depvar(s::Sym, args...)
8383
T = FnType{NTuple{length(args)}, symtype(s)}
84-
ns = Sym{T}(s)(args...)
84+
ns = Sym{T}(nameof(s))(args...)
8585
@set! ns.metadata = s.metadata
8686
end

0 commit comments

Comments
 (0)