- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Declaring Medium for Library Components
Declaring Medium for Library Components
Declaring Medium for Library Components
I have tried many different ways at declaring new mediums for components taken from the Modelica library and nothing seems to work. The "simple" line of code "replaceable package Medium = Modelica.Media.Water.StandardWater" never fixes the errors.
Since this was an issue on all aspects of the library I tried with just a single component; the pump. I want to keep it as simple as possible because I still cannot get the pump to simulate because of this media issue.
If someone can give me some advice on how to correctly declare the medium that would be a great help. Below is the line of code for the single pump machine.
Code:
model pump
Modelica.Fluid.Machines.Pump pump1 annotation(
Placement(visible = true, transformation(origin = {-22, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
annotation(
uses(Modelica(version = "3.2.2")));end pump;
I've always declared the media at the beginning of the model, look below.
Code:
model pump
replaceable package Medium = Modelica.Media.Water.StandardWater
Modelica.Fluid.Machines.Pump pump1 annotation(
Placement(visible = true, transformation(origin = {-22, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
annotation(
uses(Modelica(version = "3.2.2")));end pump;
However this always results in the error(s) like : [4] 09:25:35 Translation Error
[pump: 2:5-3:112]: component pump1 contains the definition of a partial class Medium.
Please redeclare it to any package compatible with Modelica.Media.Interfaces.PartialMedium.
Let me know what you think, thanks.
- KFung
- 27 Posts
Re: Declaring Medium for Library Components
For simple library models, like the pump or ClosedVolume models, errors will direct you to change the medium within the "interfaces" package.
Here, there can be thousands of lines of code where one might have to re-declare the medium? This I am not sure, for I cannot get the basic models from the library to instantiate.
However, using the keyboard " Ctrl + f " you are able to search through the thousands of lines of code to look for the lines
Code:
replaceable package Medium = Modelica.Media.Interfaces.PartialMedium
within the "interfaces" package of the library model to
Code:
replaceable package Medium = Modelica.Media.Water.StandardWater
in my case.
Unfortunately, this method of changing the old code to the desired one still causes errors on OpenModelica where it says "[2] 11:10:44 Translation Error
[Modelica.Fluid.Interfaces: 551:7-553:51]: Medium is partial, name lookup is not allowed in partial classes."
If anyone has any thoughts or recommendations that would be great!
I DO NOT believe it should be this complicated however I still cannot figure out the easy solution by myself.
- KFung
- 27 Posts
Re: Declaring Medium for Library Components
Adding
Code:
replaceable package Medium = Modelica.Media.Water.StandardWater;
to your model does nothing more than declare a new package called Medium, that's not used anywhere. What you want to do is redeclare the Medium inside the pump1 component via a modifier:
Code:
model pump
Modelica.Fluid.Machines.Pump pump1(redeclare package Medium = Modelica.Media.Water.StandardWater);
end pump;
For Fluid models you also need to declare an inner system component that defines the properties and default values used:
Code:
model pump
Modelica.Fluid.Machines.Pump pump1(redeclare package Medium = Modelica.Media.Water.StandardWater);
inner Modelica.Fluid.System system;
end pump;
This model will flatten without errors, but won't simulate though. I assume that's because it makes no sense to simulate a pump by itself, it needs to be connected to something such that you get a complete fluid system.
- perost
- 114 Posts
Re: Declaring Medium for Library Components
perost,
Hey thanks for the reply and what you wrote makes a lot of sense. But you are also correct about the simulation, I really just want to verify that the declaration worked correctly when instantiating the model, simulating is besides the point.
However, the pump model I have chosen to investigate already has an annotation modifier associated with it. So would the correct code syntax look like ...
Code:
model Pump
Modelica.Fluid.Machines.Pump pump1 annotation(
redeclare package Medium = Modelica.Media.Water.StandardWater,
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
annotation(
uses(Modelica(version = "3.2.2")));
end Pump;
OR
Code:
model Pump
Modelica.Fluid.Machines.Pump pump1(redeclare package Medium = Modelica.Media.Water.StandardWater);
Modelica.Fluid.Machines.Pump pump1 annotation(
redeclare package Medium = Modelica.Media.Water.StandardWater,
Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
annotation(
uses(Modelica(version = "3.2.2")));
end Pump;
I'm asking because neither of these methods has been able to flatten the pump.mo model.
Let me know what you think when you get the chance and thanks again for your input. It's really appreciated.
- KFung
- 27 Posts
Re: Declaring Medium for Library Components
The annotation is separate from the modifier, so it would look like this:
Code:
model Pump
Modelica.Fluid.Machines.Pump pump1(redeclare package Medium = Modelica.Media.Water.StandardWater)
annotation(Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
annotation(
uses(Modelica(version = "3.2.2")));
end Pump;
In other words, the syntax for a component is:
Code:
model M
SomeType componentName(modifier1 = value, modifier2 = value, ...) annotation(...);
end M;
- perost
- 114 Posts
Re: Declaring Medium for Library Components
perost,
Thank you so much for spelling it out for a new user like myself! I really appreciate it.
- KFung
- 27 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Declaring Medium for Library Components