Modia.jl
Modia.jl copied to clipboard
Handling of assignment of submodel variables, infinite derivatives
The following nonsensical code seems to spawn an infinite derivative tower out of Pantelides for N>=2:
using Modia
# N = 5
Type5() = Var(T=Float64, size=(5,))
# doesn't seem to have the issue when I manually flatten this into InfLoop below
@model Submodel begin
a = Type5()
b = Type5()
@equations begin
a + b = 0
end
end
@model InfLoop begin
sub = Submodel()
c = Type5()
@equations begin
sub.a = c
sub.b = c
# N-1 of these
sub.AnyVariableNameAtAll1 = 0
sub.AnyVariableNameAtAll2 = 0
sub.AnyVariableNameAtAll3 = 0
sub.AnyVariableNameAtAll4 = 0
end
end
# simulation time doesn't matter
# logTranslation makes it easy to see what's going on, I also enabled:
# * log in BLTandPantelides.jl
# * log and logIndexReduction in BasicStructuralTransform.jl
# removeSingularities is required to reproduce
res = simulate(InfLoop, -1000; logTranslation=true, removeSingularities=false);
I'm using latest master with Julia 1.0.3, and I applied PR #92 to get logTranslation
passed thru.
I triggered this with a larger model that had a typo, and have simplified as much as I can. Perhaps assignment into the sub
model is not treated correctly, and also perhaps there are issues with non-scalar values? Ideally this code would trigger at least one of the following error messages:
-
AnyVariableNameAtAll1
/2
/3
/4
undefined - Dimension mismatch in the
Submodel
equation
I think this could be helped by a warning such as the following in BasicStructuralTransform.jl
in analyzeStructurally
around line 673, or perhaps by doing some sanity checking on submodule variables in Instantiation.jl
(which would catch the assignment to undefined names within the sub
module).
if isempty(vertices)
loglnModia("Warning: equation $(neq) ($(prettyPrint(eq))) is unconnected to other equations!")
end