I am currently working on a multi-fluid library in which I have coded physical components, connectors, boundary conditions, sensors, physical properties and so on... The fluid selection is currently based on an Integer fluid
selection.
So far, I have been able to conditionally assign the color of the components' style based on fluid
value.
Now, I want to go a step further and also conditionally assign the color of the connection. I know about Stack Overflow - Assign specific connection style to connector in Modelica as I have already put it to good use.
So I defined the parameter parameter Integer fluid=fluid
in the connector, so that it inherits the fluid
value from the component. Then I assigned a conditional style on a rectangle as stated in the link above.
However, I end up with the following error: mean circular equalities for conduite.C1.fluid
(where "conduite" is the component and "C1" one of its connector)
I am currently a bit clueless.
EDIT:
Initial approach:
In connector model:
parameter Integer fluid=fluid "1: 1st fluid / 2: 2nd fluid";
In component model:
parameter Integer fluid=1 "1: 1st fluid / 2: 2nd fluid";
for both instances of the connector: in the fluid
parameter cell, I leave the default fluid
value.
The obtained flat Modelica shed light on the circular equalities:
parameter Integer conduite.C1.fluid = conduite.C1.fluid;
parameter Integer conduite.C2.fluid = conduite.C2.fluid;
Other approach, that works but is not satisfying:
In connector model:
parameter Integer fluid=1 "1: 1st fluid / 2: 2nd fluid";
In component model:
parameter Integer fluid=1 "1: 1st fluid / 2: 2nd fluid";
for both instances of the connector:
in the fluid
cell: I type fluid
instead of the default 1
value.
The obtained flat Modelica is what I actually wanted:
parameter Integer conduite.C1.fluid = conduite.fluid;
parameter Integer conduite.C2.fluid = conduite.fluid;
Why does not the default value fluid
refer to the upper level parameter, whereas the locally overwritten value does?
I finally ended up with a satisfying solution using inner/outer
:
In connector model:
outer parameter Integer fluid;
In component model:
inner parameter Integer fluid=1 "1: 1st fluid / 2: 2nd fluid";
This way, each instance of a component (pipe, sensor, boundary condition, ...) has to be manually given a fluid
value, which is OK for now, whereas the fluid
value inside a component is automatically propagated to the connectors' instances.
BONUS: From here, it is easy-peasy to conditionally assign a connection style. Here is the Icon section of the annotation in the connector:
Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Rectangle(
extent={{82,-82},{90,-90}},
lineColor=colorVector[:,fluid],
lineThickness=1), Rectangle(
extent={{-100,100},{100,-100}},
lineColor={0,0,0},
fillPattern=FillPattern.Solid,
fillColor={0,128,255})})
where the colorVector
is defined as:
constant Integer colorVector[3,:] = [
fluid1Color,
fluid2Color];
constant Integer fluid1Color[3] = {0,140,72};
constant Integer fluid2Color[3] = {244,125,35};
This colorVector
is a bit of an overkill for now, but I will easily be able to add more fluids (and more fluid colors) in the future.
Note that the connection style depends on my fluid
parameter value when the connection is made. Modifying the parameter value afterwards won't affect the existing connections' style.