I am designing a set of custom components for fluid system modelling. As there will only be one medium throughout the model, I want to be able to define that medium in one place. The system
component we need for most Modelica.Fluid systems anyway seems like a good place.
I have tried the following MWE, but I'm running into problems with class lookup that I don't know how to avoid.
Using current OpenModelica, when checking the CommonMediaClosedVolume
, I'm getting an error
Class name 'system.CommonMedium' was found via a component (only component and function call names may be accessed in this way).
I noticed that there is a Fluid.System.Medium
defined which I thought could serve a similar purpose, but it's not visible for changing in the parameter dialog in OMEdit (Although it has a choicesAllMatching
annotation -- an OM bug?), and it does not seem to get used anywhere else. In any case, it shows the same lookup error message.
Question:
- How can I define a default class (derived from
PartialMedium
) inTweakedSystem
so that I can extend my models to pick that up by default, and so that I can select the desired medium in aTweakedSystem
instancesystem
?
package CommonMediaDefinition
model TweakedSystem "Extended system featuring a common media definition"
extends Modelica.Fluid.System(Medium = CommonMedium);
replaceable package CommonMedium = Modelica.Media.Air.DryAirNasa constrainedby Modelica.Media.Interfaces.PartialMedium annotation(
choicesAllMatching = true);
annotation(
defaultComponentName = "system",
defaultComponentPrefixes = "inner");
end TweakedSystem;
model CommonMediaClosedVolume "ClosedVolume with a default Medium defined in system"
extends Modelica.Fluid.Vessels.ClosedVolume;
// Want to define a Medium default choice that is defined in system (a TweakedSystem instance)
redeclare replaceable package Medium = system.CommonMedium;
// Errors with Class name 'system.CommonMedium' was found via a component (only component and function call names may be accessed in this way).
end CommonMediaClosedVolume;
model SimulationModel
inner TweakedSystem system
annotation(
Placement(visible = true, transformation(origin = {-60, -56}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
CommonMediaClosedVolume commonMediaClosedVolume(V = 1)
annotation(
Placement(visible = true, transformation(origin = {0, -20}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
end SimulationModel;
end CommonMediaDefinition;
Edit: It seems that this way I envisioned propagating a class is not allowed in Modelica: https://mcmap.net/q/1725329/-propagating-packages-using-inner-outer