Skip to content

Commit 6587325

Browse files
committed
Mark explicit io when introducing a new variable
1 parent 0a36928 commit 6587325

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/structural_transformation/StructuralTransformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using ModelingToolkit: ODESystem, AbstractSystem, var_from_nested_derivative, Di
2222
get_postprocess_fbody, vars!,
2323
IncrementalCycleTracker, add_edge_checked!, topological_sort,
2424
invalidate_cache!, Substitutions, get_or_construct_tearing_state,
25-
AliasGraph, filter_kwargs
25+
AliasGraph, filter_kwargs, lower_varname, setio
2626

2727
using ModelingToolkit.BipartiteGraphs
2828
import .BipartiteGraphs: invview

src/structural_transformation/symbolics_tearing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify = fal
269269
if var_eq_matching[var] !== SelectedState()
270270
dd = fullvars[dv]
271271
if (i_v_t = get(possible_x_t, dd, nothing)) === nothing
272-
v_t = diff2term(unwrap(dd))
272+
v_t = setio(diff2term(unwrap(dd)), false, false)
273273
else
274274
idx, v_t = i_v_t
275275
push!(removed_obs, idx)
@@ -423,7 +423,7 @@ function tearing_reassemble(state::TearingState, var_eq_matching; simplify = fal
423423
if (i_x_t = get(possible_x_t, dx, nothing)) === nothing &&
424424
(ogidx !== nothing &&
425425
(i_x_t = get(possible_x_t, fullvars[ogidx], nothing)) === nothing)
426-
x_t = ModelingToolkit.lower_varname(ogx, iv, o)
426+
x_t = setio(lower_varname(ogx, iv, o), false, false)
427427
else
428428
idx, x_t = i_x_t
429429
push!(removed_obs, idx)

src/systems/abstractsystem.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,18 +1109,15 @@ function markio!(state, inputs, outputs; check = true)
11091109
outputset = Dict(outputs .=> false)
11101110
for (i, v) in enumerate(fullvars)
11111111
if v in keys(inputset)
1112-
v = setmetadata(v, ModelingToolkit.VariableInput, true)
1113-
v = setmetadata(v, ModelingToolkit.VariableOutput, false)
1112+
v = setio(v, true, false)
11141113
inputset[v] = true
11151114
fullvars[i] = v
11161115
elseif v in keys(outputset)
1117-
v = setmetadata(v, ModelingToolkit.VariableInput, false)
1118-
v = setmetadata(v, ModelingToolkit.VariableOutput, true)
1116+
v = setio(v, false, true)
11191117
outputset[v] = true
11201118
fullvars[i] = v
11211119
else
1122-
v = setmetadata(v, ModelingToolkit.VariableInput, false)
1123-
v = setmetadata(v, ModelingToolkit.VariableOutput, false)
1120+
v = setio(v, false, false)
11241121
fullvars[i] = v
11251122
end
11261123
end

src/variables.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function isvarkind(m, x)
2525
getmetadata(x, m, false)
2626
end
2727

28+
setinput(x, v) = setmetadata(x, VariableInput, v)
29+
setoutput(x, v) = setmetadata(x, VariableOutput, v)
30+
setio(x, i, o) = setoutput(setinput(x, i), o)
2831
isinput(x) = isvarkind(VariableInput, x)
2932
isoutput(x) = isvarkind(VariableOutput, x)
3033
isirreducible(x) = isvarkind(VariableIrreducible, x) || isinput(x)

0 commit comments

Comments
 (0)