Reputation: 1232
I am currently evaluating Dymola 2020 to build a solar power plant model, but I struggle with the number of equations in models which use a custom connector.
Here is the code:
connector Port
flow Real Q;
Real P;
Real T;
end Port;
model Inlet
parameter Real Q = 1;
parameter Real P = 2;
parameter Real T = 3;
Port a;
equation
a.Q = Q;
a.P = P;
a.T = T;
end Inlet;
I set 3 equations in the model, but there is an error showing there are 4 equations. How are the equations counted? Why are there 4 of them?
The problem is structurally singular.
It has 3 scalar unknowns and 4 scalar equations. The Real part has 3 unknowns and 4 equations. The Integer part has 0 unknowns and 0 equations. The Boolean part has 0 unknowns and 0 equations. The String part has 0 unknowns and 0 equations.
The number of scalar Real unknown elements are 3. The number of scalar Real equation elements are 4.
Part of the problem for Real elements is overdetermined. There are 1 scalar equations too many in the set: a.T = T; a.P = P; a.Q = Q;
Upvotes: 2
Views: 452
Reputation: 3403
As mentioned in the comments I think you should look into Modelica's stream connectors
which inherently support zero-flow and flow-reversal in thermofluid components.
They can be a bit tricky to understand so a while ago I put a small exemplary package on GitHub, demonstrating the very basics of stream connectors. If you're interested you can find it here: https://github.com/justnielsen/ModelicaTutorials. There is also a Wiki page explaining the Stream connector
syntax.
By the way, Claytex has an excellent blog, updated weekly. They have a post from 2017 on stream connectors: https://www.claytex.com/tech-blog/fluid-connectors-modelica-standard-library/
Best regards, Rene Just Nielsen
Upvotes: 2
Reputation: 7510
There are two separated problems with your example:
Connectors usually contain pairs of across/potential and flow/through variables Modelica Language Specification, Section 9.3.1. Following this convention, the models using these connectors usually define a relation between flow and across variables. For some general - and very readable - information on the definition of connectors see Modelica by Exmple. I think it is not mandatory to follow this convention, but it will make life a lot easier if you do so when modeling physical systems.
The Inlet
sets all interface variables. Physical source models set either the across or the flow variable. You have a source of pressure or a source of flow, it cannot set both. This comes down to a pipe computing either a pressure drop from a flow, or a flow from a pressure drop. Models generally assume that either the across variables or the flow variable is determined by the outside. From that the model computes the other one using the relations defined in its equation
section. For your example, all this comes down to: If you remove any equation, e.g. a.Q = Q;
from the Inlet
, the model checks. The explanation to this is how equations are generated from connectors and models. For more information on this see Modelica Language Specification, Section 9.2, bottom of page 110, saying "Each connection set is used to generate..."
Regarding both of the above points, I would recommend to take a look at the Modelica Standard Library's FluidHeatFlow library, especially the interface defined in Modelica.Thermal.FluidHeatFlow.Interfaces.FlowPort
. Judging from your interface variables this library serves a similar physical domain.
For a simpler start it would also make sense to take a close look at Modelica.Thermal.HeatTransfer
. This package only has a single pair of across/flow variables making it much easier to understand.
Upvotes: 7