Reputation: 794
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?
Upvotes: 2
Views: 134
Reputation: 794
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.
Upvotes: 0
Reputation: 7525
I didn't fully understand the question so I'm doing some guessing here: My assumption is, that propagation went wrong somehow.
Would the following code result in what you need? Note that neither component nor Example will work:
package MultiFluid "Some psydo-code that could help"
connector Con
parameter Integer fluid=1 "1: 1st fluid / 2: 2nd fluid";
end Con;
model Component
parameter Integer fluid=1 "1: 1st fluid / 2: 2nd fluid";
Con C1(fluid=fluid) annotation (Placement(transformation(extent={{-110,-10},{-90,10}}), iconTransformation(extent={{-110,-10},{-90,10}})));
Con C2(fluid=fluid) annotation (Placement(transformation(extent={{90,-10},{110,10}}), iconTransformation(extent={{90,-10},{110,10}})));
end Component;
model Example
Component component(fluid=2) annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
end Example;
end MultiFluid;
gives the flat Modelica code for the Example:
model Example
parameter Integer component.fluid = 2 "1: 1st fluid / 2: 2nd fluid";
parameter Integer component.C1.fluid = component.fluid "1: 1st fluid / 2: 2nd fluid";
parameter Integer component.C2.fluid = component.fluid "1: 1st fluid / 2: 2nd fluid";
end Example;
If my assumption is correct, the essential part is the propagation of the Integer fluid
from the parameter
in Component
:
Con C1(fluid=fluid)
This line passes the actual value from Component
to the instances C1
of Con
.
Upvotes: 1