Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions src/Backend/Causalize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1595,54 +1595,60 @@ function _resolveIntVarsInSystem!(syst::BDAE.EQSYSTEM)
local removedDefiners = OrderedSet{String}()
for (i, eq) in enumerate(syst.orderedEqs)
if eq isa BDAE.EQUATION
lhsIsInt = eq.lhs isa DAE.CREF && string(eq.lhs.componentRef) in intVarNames
rhsIsInt = eq.rhs isa DAE.CREF && string(eq.rhs.componentRef) in intVarNames
lhsName = eq.lhs isa DAE.CREF ? string(eq.lhs.componentRef) : nothing
rhsName = eq.rhs isa DAE.CREF ? string(eq.rhs.componentRef) : nothing
lhsIsInt = lhsName !== nothing && lhsName in intVarNames
rhsIsInt = rhsName !== nothing && rhsName in intVarNames
#= If this integer is actually when-driven discrete state, leave the
equation alone (it might be a continuous default / initial value
assignment). =#
isWhenDriven = (lhsIsInt && string(eq.lhs.componentRef) in intVarsWrittenInWhen) ||
(rhsIsInt && string(eq.rhs.componentRef) in intVarsWrittenInWhen)
isWhenDriven = (lhsIsInt && lhsName in intVarsWrittenInWhen) ||
(rhsIsInt && rhsName in intVarsWrittenInWhen)
if (lhsIsInt || rhsIsInt) && !isWhenDriven
#= Drop a `intvar = literal` binding outright; capture the value. =#
if lhsIsInt && _isLiteral(eq.rhs)
keepEq[i] = false
push!(removedDefiners, string(eq.lhs.componentRef))
valueMap[string(eq.lhs.componentRef)] = eq.rhs
push!(removedDefiners, lhsName)
valueMap[lhsName] = eq.rhs
elseif rhsIsInt && _isLiteral(eq.lhs)
keepEq[i] = false
push!(removedDefiners, string(eq.rhs.componentRef))
valueMap[string(eq.rhs.componentRef)] = eq.lhs
push!(removedDefiners, rhsName)
valueMap[rhsName] = eq.lhs
end
#= int-to-int aliases (e.g. `auxiliary_n = auxiliary[2]`) are
handled in the alias-chain follow-up pass below — we cannot
decide here because the RHS may not yet be in removedDefiners. =#
end
elseif eq isa BDAE.ARRAY_EQUATION
leftIsInt = eq.left isa DAE.CREF && string(eq.left.componentRef) in allIntNames
rightIsInt = eq.right isa DAE.CREF && string(eq.right.componentRef) in allIntNames
isWhenDriven = (leftIsInt && string(eq.left.componentRef) in intVarsWrittenInWhen) ||
(rightIsInt && string(eq.right.componentRef) in intVarsWrittenInWhen)
leftName = eq.left isa DAE.CREF ? string(eq.left.componentRef) : nothing
rightName = eq.right isa DAE.CREF ? string(eq.right.componentRef) : nothing
leftIsInt = leftName !== nothing && leftName in allIntNames
rightIsInt = rightName !== nothing && rightName in allIntNames
isWhenDriven = (leftIsInt && leftName in intVarsWrittenInWhen) ||
(rightIsInt && rightName in intVarsWrittenInWhen)
if (leftIsInt || rightIsInt) && !isWhenDriven
if leftIsInt && _isLiteral(eq.right)
keepEq[i] = false
push!(removedDefiners, string(eq.left.componentRef))
push!(removedDefiners, leftName)
elseif rightIsInt && _isLiteral(eq.left)
keepEq[i] = false
push!(removedDefiners, string(eq.right.componentRef))
push!(removedDefiners, rightName)
end
end
elseif eq isa BDAE.COMPLEX_EQUATION
leftIsInt = eq.left isa DAE.CREF && string(eq.left.componentRef) in allIntNames
rightIsInt = eq.right isa DAE.CREF && string(eq.right.componentRef) in allIntNames
isWhenDriven = (leftIsInt && string(eq.left.componentRef) in intVarsWrittenInWhen) ||
(rightIsInt && string(eq.right.componentRef) in intVarsWrittenInWhen)
leftName = eq.left isa DAE.CREF ? string(eq.left.componentRef) : nothing
rightName = eq.right isa DAE.CREF ? string(eq.right.componentRef) : nothing
leftIsInt = leftName !== nothing && leftName in allIntNames
rightIsInt = rightName !== nothing && rightName in allIntNames
isWhenDriven = (leftIsInt && leftName in intVarsWrittenInWhen) ||
(rightIsInt && rightName in intVarsWrittenInWhen)
if (leftIsInt || rightIsInt) && !isWhenDriven
if leftIsInt && _isLiteral(eq.right)
keepEq[i] = false
push!(removedDefiners, string(eq.left.componentRef))
push!(removedDefiners, leftName)
elseif rightIsInt && _isLiteral(eq.left)
keepEq[i] = false
push!(removedDefiners, string(eq.right.componentRef))
push!(removedDefiners, rightName)
end
end
end
Expand Down
8 changes: 0 additions & 8 deletions src/Runtime/Runtime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,6 @@ function solve(omProblem::OM_ProblemStructural, tspan, alg; kwargs...)
@BACKEND_LOGGING @info "u values at Δt $(integrator.dt) & t = $(integrator.t)" integrator.u
#= Check structural callbacks in order =#
@BACKEND_LOGGING @info "Stepping at:" i.t
#= AUDIT (ombackend-bug-audit-2026-06-05 #13): retCode is computed but never
branched on. Harmless here (inside `for i in integrator`, which
self-terminates on integrator failure); the concerning twin site is the
OM_ProblemRecompilation `while true` loop, which has no retcode /
dt-collapse break and relies solely on sol.retcode. VSS path; add a break
when the VSS-recompilation pipeline is hardened. =#
retCode = check_error(integrator)
for cb in structuralCallbacks
if cb.structureChanged && cb.name != activeModeName
@VSS_DEBUG @info "Structure changed at $(i.t) transition to $(cb.name) => $(cb.structureChanged)"
Expand Down Expand Up @@ -522,7 +515,6 @@ function solve(omProblem::OM_ProblemRecompilation, tspan::Tuple, alg; kwargs...)
local i = integrator
local old_t = i.t
#= Check structural callbacks in order =#
retCode = check_error(integrator)
for j in 1:length(structuralCallbacks)
local cb = structuralCallbacks[j]
@VSS_DEBUG @info "Structure Changed? $(cb.structureChanged)"
Expand Down
4 changes: 2 additions & 2 deletions src/SimulationCode/simCodeUtil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ function createEquationVariableBidirectionGraph(equations::AbstractVector,
allBackendVars::VARS,
stringToSimVarHT)::OrderedDict where{IF_EQS, WHEN_EQS, VARS}
local eqCounter::Int = 0
local variableEqMapping = OrderedDict()
local variableEqMapping = OrderedDict{String, Vector{Int}}()
local unknownVariables = filter((x) -> BDAEUtil.isVariable(x.varKind), allBackendVars)
#=TODO: The set of discrete variables are currently not in use. =#
local discreteVariables = filter((x) -> BDAEUtil.isDiscrete(x.varKind), allBackendVars)
Expand Down Expand Up @@ -696,7 +696,7 @@ function createEquationVariableBidirectionGraph(equations::RES_T,
allBackendVars::VECTOR_VAR,
stringToSimVarHT)::OrderedDict where{RES_T, VECTOR_VAR}
local eqCounter::Int = 0
local variableEqMapping = OrderedDict()
local variableEqMapping = OrderedDict{String, Vector{Int}}()
local unknownVariables = filter((x) -> BDAEUtil.isVariable(x.varKind), allBackendVars)
local discreteVariables = filter((x) -> BDAEUtil.isDiscrete(x.varKind), allBackendVars)
local stateVariables = filter((x) -> BDAEUtil.isState(x.varKind), allBackendVars)
Expand Down
Loading