I have the following simple hierarchical model comprising a reaction inside a chamber. The reaction model simply sets the mass rate to the mass, and it's connected to the chamber that encloses it.
connector Conn
Real mass;
flow Real massRate;
end Conn;
model Reaction
Conn conn;
equation
conn.massRate = conn.mass;
end Reaction;
model Chamber
Real mass(start = 1);
Reaction reaction;
Conn conn;
equation
conn.mass = mass;
der(mass) = conn.massRate;
connect(reaction.conn, conn);
end Chamber;
Now to my mind, there are in total five variables: mass
, reaction.conn.mass
, reaction.conn.massRate
, conn.mass
, and conn.massRate
. And there are five equations: two in the equation section, viz.
conn.mass = mass
der(mass) = conn.massRate
one from the reaction
reaction.conn.massRate = reaction.conn.mass
and two from the connect equation:
reaction.conn.mass = conn.mass
reaction.conn.massRate = conn.massRate
So we have five equations in five variables. The solver logic can simply combine these equations like so
der(mass) = conn.massRate = reaction.conn.massRate = reaction.conn.mass
= conn.mass = mass
and since the mass is given a start value, Bob's your uncle. The mass
should increase over time. But my simulation environment (Wolfram|One) says
Error: Simulation model is not globally balanced, having 1 variable and 2 equations.
Can someone please explain what is going on? Note that if I take the reactor outside the chamber (reversing the sign in the reaction to give conn.massRate = -conn.mass
), it works as intended.