Skip to content

Commit f137b1a

Browse files
chore: add string manipulation hack
1 parent 8c4f770 commit f137b1a

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/utils.jl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,31 @@ function underscore_to_D(v::AbstractVector, sys)
10931093
for (k, v) in maps
10941094
push!(get!(() -> valtype(inv_maps)[], inv_maps, v), k)
10951095
end
1096-
map(Base.Fix2(underscore_to_D, inv_maps), v)
1096+
iv = get_iv(sys)
1097+
map(x -> underscore_to_D(x, iv, inv_maps), v)
10971098
end
10981099

1099-
function underscore_to_D(v, inv_map)
1100-
only(get(inv_map, v, [v]))
1100+
function underscore_to_D(v, iv, inv_map)
1101+
if haskey(inv_map, v)
1102+
only(get(inv_map, v, [v]))
1103+
else
1104+
v = ModelingToolkit.detime_dvs(v)
1105+
s = split(string(getname(v)), 'ˍ')
1106+
if length(s) > 1
1107+
n, suffix = s
1108+
else
1109+
n, suffix = first(s), ""
1110+
end
1111+
repeats = length(suffix) ÷ length(string(iv))
1112+
D = Differential(iv)
1113+
wrap_with_D(Symbol(n), D, repeats)
1114+
end
11011115
end
1116+
1117+
function wrap_with_D(n, D, repeats)
1118+
if repeats <= 0
1119+
return n
1120+
else
1121+
wrap_with_D(D(n), D, repeats - 1)
1122+
end
1123+
end

0 commit comments

Comments
 (0)