y4cine
y4cine

Reputation: 394

How can I encapsulate models of the fluid library of openmodelica?

Problem and Motivation: the models of the fluid library in openmodelica are very elaborated, with a lot of parameters one has to set correctly to get the model running with acceptable results. I want to set up an environment for daily engineering calculations, for mechanical and process engineers - no simulation experts. So the components of my library must be pre-configured and the users shouldn't be forced to edit the code behind the graphical model (eg redeclaration of the Medium).

Idea: drop the fluid models in own models, configure them properly, redeclare the Medium and provide fluid connectors.

model flowEncapsulateFluid1
inner Modelica.Fluid.System system;
replaceable package Medium =  Modelica.Media.Water.ConstantPropertyLiquidWater                           constrainedby
Modelica.Media.Interfaces.PartialMedium "Medium in the component"
  annotation (choicesAllMatching = true);

model myStaticPipe
Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium = Medium, allowFlowReversal = true, height_ab = 2, length = 2, diameter = 0.1);
Modelica.Fluid.Interfaces.FluidPort_a port_a;
Modelica.Fluid.Interfaces.FluidPort_b port_b;
equation
connect(pipe.port_b, port_b);
connect(port_a, pipe.port_a);

model myTank1
Modelica.Fluid.Vessels.OpenTank tank1(crossArea = 1, 
redeclare package  Medium = Medium, use_portsData = true, height = 12,
level_start = 8, nPorts = 6, 
portsData = {Modelica.Fluid.Vessels.BaseClasses.VesselPortsData 
(diameter = 0.1)});
Modelica.Fluid.Interfaces.FluidPort_a port_a 
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a1 
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a2 
(redeclare package Medium = Medium);
Modelica.Fluid.Interfaces.FluidPort_a port_a3 
(redeclare package Medium = Medium) ;
Modelica.Fluid.Interfaces.FluidPort_a port_a4 
(redeclare package Medium = Medium) ;
Modelica.Fluid.Interfaces.FluidPort_b port_b 
(redeclare package Medium = Medium);

equation
connect(tank1.ports[6], port_b);
connect(port_a4, tank1.ports[5]);
connect(port_a3, tank1.ports[4]);
connect(port_a2, tank1.ports[3]);
connect(port_a1, tank1.ports[2]);
connect(port_a, tank1.ports[1]);
end myTank1;

package UnitTests

model Test1
flowEncapsulateFluid1.myTank1 myTank11;
myStaticPipe myStaticPipe1;
myTank1 myTank12;
equation
connect(myStaticPipe1.port_b, myTank12.ports_b);
  connect(myTank11.ports_b, myStaticPipe1.port_a);

end Test1;

end UnitTests;
annotation(
uses(Modelica(version = "3.2.2")));
end flowEncapsulateFluid1;

I get the message "No corresponding 'inner' declaration found for component .Modelica.Fluid.System tank1.system declared as 'outer '. The existing 'inner' components are: There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: Modelica.Fluid.Vessels.OpenTank$tank1. Check if you have not misspelled the 'outer' component name. Please declare an 'inner' component with the same name in the top scope. Continuing flattening by only considering the 'outer' component declaration."

I don't know how to interpret the message. Any help would be welcome.

Furthermore I would appreciate, if some one could provide me advices or links for this project.

Many thanks in advance.

Upvotes: 2

Views: 459

Answers (2)

Scott G
Scott G

Reputation: 2310

In regards to this portion of your question: "No corresponding 'inner' declaration found for component .Modelica.Fluid.System tank1.system declared as 'outer '.

outer and inner are special key words in modelica.

The fluid library defines an "outer" model called "system" located at Modelica.Fluid.System. If you drag that into a model that gives that warning the issue will go away as it will find this outer model. Typically this system model should be at a high level and not at individual components...

Upvotes: 0

Rene Just Nielsen
Rene Just Nielsen

Reputation: 3403

y4cine,

You could create a library of components that extend from the Modelica.Fluid components and finalize the parameters that you don't want your users to see. For example

model myPipe
  extends Modelica.Fluid.Pipes.DynamicPipe(
    redeclare package Medium = Modelica.Media.Water.StandardWater,
    final height_ab=0,
    final isCircular=true);
end myPipe;

When you instantiate the component (shown in Dymola) the parameters are not visible (see screenshot below).

parameters hidden

Best regards, Rene Just Nielsen

Upvotes: 4

Related Questions