Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modelica: Import Variable of other model

Tags:

modelica

I try to write a model (fix), where I want to use a variable of a different model(room): The variable is called: room.Temp. If I use in the model "fix" the variable: room.Temp --> i get an error message: Use of undeclared variable room.Temp.

Do I have to import the variables in my model "fix" ? Thanx for your help

like image 467
lars111 Avatar asked Nov 26 '25 21:11

lars111


2 Answers

In your case, the inner/outer keywords might be of use.

I don't know the exact details and purpose of your model but i assume that room.Temp represents a room temperature that should be known by other components in you overall model.

For instance, you could take a look at any of the examples in Modelica.Fluid.Examples. Here you will see that the system (lower case 's') model defined as an inner instance of the class Modelica.Fluid.System - a model that holds a number of general variables (ambient pressure and temperature etc.) that should be known by the other components in the examples.

Many of the components in Modelica.Fluid require an outer instance of the class System - and it should be named system. See for instance Modelica.Fluid.Interfaces.PartialTwoPort.

You apply the inner keyword when you instantiate your model (in Dymola, drag it to the canvas, right-click, select View Attributes and tick off Inner).

In your case, if your Fix class refers to an outer instance named 'room', you should be sure that you only have one instance of the Room class and that it is called room (not room1, room_1 or whatever). Annotations defaultComponentName, defaultComponentPrefixes and missingInnerMessage in the Room class can help you with that (see the annotations in Modelica.Fluid.System).

Best regards, Rene Just Nielsen

like image 187
Rene Just Nielsen Avatar answered Nov 30 '25 00:11

Rene Just Nielsen


I don't know how advanced solution you need, but the simplest one I can see is the following, where I assume your models look like this:

model Room
  Real temp;
end Room;
model Fix
  Real room_temp /* = ... Room.temp*/;
end Fix;

model Combined
  Room room;
  Fix fix;
end Combined;

Then add "input" in front of "room_temp" and change a line to:

Fix fix(room_temp=room.temp);

Changing room_temp to a connector make this more graphical.

like image 29
Hans Olsson Avatar answered Nov 30 '25 01:11

Hans Olsson