How to conditionally assign connection style in Dymola?

54 Views Asked by At

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?

1

There are 1 best solutions below

0
Markus A. On

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.