ModelingToolkit.jl cryptic error

I was trying to model a thermo-fluid system with ModelingToolkit.jl, however I encountered this:

julia>     prob = ODAEProblem(sys, Pair[], (0.0, 10.0))
ERROR: AssertionError: !(isalgvar(s, var))

What does it mean?

The connection equations are based on: 15 Stream Connectors‣ Modelica® Language Specification version 3.6-dev

The equations before structural_simplify:

julia> model
Model model with 38 equations
States (42):
  r1₊a₊mdot(t) [defaults to 0.0]
  mixing_valve₊a₊mdot(t) [defaults to 0.0]
  r1₊a₊p(t) [defaults to 100000.0]
⋮
Parameters (7):
  r1₊p [defaults to 200000.0]
  r1₊T [defaults to 353.15]
  r2₊p [defaults to 200000.0]
⋮

julia> equations(model)
38-element Array{Equation,1}:
 mixing_valve₊a₊mdot(t) + r1₊a₊mdot(t) ~ 0.0      
 r1₊a₊p(t) ~ mixing_valve₊a₊p(t)
 r1₊a₊T_in_stream(t) ~ mixing_valve₊a₊T_outflow(t)
 mixing_valve₊a₊T_in_stream(t) ~ r1₊a₊T_outflow(t)
 mixing_valve₊b₊mdot(t) + r2₊a₊mdot(t) ~ 0.0      
 r2₊a₊p(t) ~ mixing_valve₊b₊p(t)
 r2₊a₊T_in_stream(t) ~ mixing_valve₊b₊T_outflow(t)
 mixing_valve₊b₊T_in_stream(t) ~ r2₊a₊T_outflow(t)
 mixing_valve₊c₊mdot(t) + r3₊a₊mdot(t) ~ 0.0      
 mixing_valve₊c₊p(t) ~ r3₊a₊p(t)
 mixing_valve₊c₊T_in_stream(t) ~ r3₊a₊T_outflow(t)
 r3₊a₊T_in_stream(t) ~ mixing_valve₊c₊T_outflow(t)
 r1₊a₊p(t) ~ r1₊p
 r1₊a₊T_outflow(t) ~ r1₊T
 r2₊a₊p(t) ~ r2₊p
 r2₊a₊T_outflow(t) ~ r2₊T
 mixing_valve₊valve_1₊A(t) ~ 7.0e-5mixing_valve₊y 
 mixing_valve₊valve_2₊A(t) ~ 7.0e-5(1 - mixing_valve₊y)
 mixing_valve₊valve_1₊a₊mdot(t) - mixing_valve₊a₊mdot(t) ~ 0.0
 mixing_valve₊a₊p(t) ~ mixing_valve₊valve_1₊a₊p(t)
 mixing_valve₊a₊T_outflow(t) ~ mixing_valve₊valve_1₊a₊T_outflow(t)
 mixing_valve₊valve_1₊a₊T_in_stream(t) ~ mixing_valve₊a₊T_in_stream(t)
 mixing_valve₊valve_2₊a₊mdot(t) - mixing_valve₊b₊mdot(t) ~ 0.0
 mixing_valve₊b₊p(t) ~ mixing_valve₊valve_2₊a₊p(t)
 mixing_valve₊b₊T_outflow(t) ~ mixing_valve₊valve_2₊a₊T_outflow(t)
 mixing_valve₊valve_2₊a₊T_in_stream(t) ~ mixing_valve₊b₊T_in_stream(t)
 mixing_valve₊valve_1₊b₊mdot(t) + mixing_valve₊valve_2₊b₊mdot(t) - mixing_valve₊c₊mdot(t) ~ 0.0
 mixing_valve₊valve_1₊b₊p(t) ~ mixing_valve₊valve_2₊b₊p(t)
 mixing_valve₊valve_1₊b₊p(t) ~ mixing_valve₊c₊p(t)
 mixing_valve₊valve_1₊b₊T_in_stream(t) ~ (mixing_valve₊c₊T_in_stream(t)*max(mixing_valve₊c₊mdot(t), 0) + mixing_valve₊valve_2₊b₊T_outflow(t)*max(-mixing_valve₊valve_2₊b₊mdot(t), 0))*((max(mixing_valve₊c₊mdot(t), 0) + max(-mixing_valve₊valve_2₊b₊mdot(t), 0))^-1)
 mixing_valve₊valve_2₊b₊T_in_stream(t) ~ (mixing_valve₊c₊T_in_stream(t)*max(mixing_valve₊c₊mdot(t), 0) + mixing_valve₊valve_1₊b₊T_outflow(t)*max(-mixing_valve₊valve_1₊b₊mdot(t), 0))*((max(mixing_valve₊c₊mdot(t), 0) + max(-mixing_valve₊valve_1₊b₊mdot(t), 0))^-1)
 mixing_valve₊c₊T_outflow(t) ~ (mixing_valve₊valve_1₊b₊T_outflow(t)*max(-mixing_valve₊valve_1₊b₊mdot(t), 0) + mixing_valve₊valve_2₊b₊T_outflow(t)*max(-mixing_valve₊valve_2₊b₊mdot(t), 0))*((max(-mixing_valve₊valve_1₊b₊mdot(t), 0) + max(-mixing_valve₊valve_2₊b₊mdot(t), 0))^-1)
 mixing_valve₊valve_1₊a₊mdot(t) + mixing_valve₊valve_1₊b₊mdot(t) ~ 0
 mixing_valve₊valve_1₊b₊mdot(t) ~ 44.67661580737735max(min(mixing_valve₊valve_1₊A(t), 7.0e-5), 1.0e-9)*regRoot(mixing_valve₊valve_1₊b₊p(t) - mixing_valve₊valve_1₊a₊p(t), 0.0005000000000000004(202650.0 + mixing_valve₊valve_1₊a₊p(t) + mixing_valve₊valve_1₊b₊p(t)))
 mixing_valve₊valve_2₊a₊mdot(t) + mixing_valve₊valve_2₊b₊mdot(t) ~ 0
 mixing_valve₊valve_2₊b₊mdot(t) ~ 44.67661580737735max(min(mixing_valve₊valve_2₊A(t), 7.0e-5), 1.0e-9)*regRoot(mixing_valve₊valve_2₊b₊p(t) - mixing_valve₊valve_2₊a₊p(t), 0.0005000000000000004(202650.0 + mixing_valve₊valve_2₊a₊p(t) + mixing_valve₊valve_2₊b₊p(t)))
 r3₊a₊p(t) ~ r3₊p
 r3₊a₊T_outflow(t) ~ r3₊T

and after

julia>     sys = structural_simplify(model)
Model model with 1 equations
States (3):
  mixing_valve₊valve_1₊b₊T_outflow(t) [defaults to 293.15]
  mixing_valve₊valve_2₊b₊T_outflow(t) [defaults to 293.15]
  mixing_valve₊valve_2₊b₊T_in_stream(t) [defaults to 293.15]
Parameters (7):
  r1₊p [defaults to 200000.0]
  r1₊T [defaults to 353.15]
  r2₊p [defaults to 200000.0]
⋮
Incidence matrix:
  [1, 1]  =  ×
  [1, 3]  =  ×

julia> equations(sys)
1-element Array{Equation,1}:
 0 ~ (r3₊T*max(44.67661580737735regRoot(r3₊p - r1₊p, 0.0005000000000000004(202650.0 + r1₊p + r3₊p))*max(min(7.0e-5mixing_valve₊y, 7.0e-5), 1.0e-9) + 44.67661580737735regRoot(r3₊p - r2₊p, 0.0005000000000000004(202650.0 + r2₊p + r3₊p))*max(min(7.0e-5(1 - mixing_valve₊y), 7.0e-5), 1.0e-9), 0) + mixing_valve₊valve_1₊b₊T_outflow(t)*max(-44.67661580737735regRoot(r3₊p - r1₊p, 0.0005000000000000004(202650.0 + r1₊p + r3₊p))*max(min(7.0e-5mixing_valve₊y, 7.0e-5), 1.0e-9), 0))*((max(44.67661580737735regRoot(r3₊p - r1₊p, 0.0005000000000000004(202650.0 + r1₊p + r3₊p))*max(min(7.0e-5mixing_valve₊y, 7.0e-5), 1.0e-9) + 44.67661580737735regRoot(r3₊p - r2₊p, 0.0005000000000000004(202650.0 + r2₊p + r3₊p))*max(min(7.0e-5(1 - mixing_valve₊y), 7.0e-5), 1.0e-9), 0) + max(-44.67661580737735regRoot(r3₊p - r1₊p, 0.0005000000000000004(202650.0 + r1₊p + r3₊p))*max(min(7.0e-5mixing_valve₊y, 7.0e-5), 
1.0e-9), 0))^-1) - mixing_valve₊valve_2₊b₊T_in_stream(t)

Open an issue for this. Could be a bug. Please share how to recreate it.

It is not, the model was missing four equations.
Is there a way to check the consistency of the model?
First thing might be if the number of equations and number of states are the same. But is this true in general.

We’re adding a check_consistency fairly soon. See the issue on it.

2 Likes