Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

trouble with medium and connections

trouble with medium and connections

Hi,

im new with Modelica and some things i cant get to run and i Dont know why.

I want to simulate an Air Conditioning therefore i want to use the medium MoistAir but i dont know where exaktly i need to declare the medium. I found, that the ambient (source block) in Thermal has the parameter Medium but as far as i can see, its not working correctly. Is MoistAir broken like the library medium.air and if so how to work around this?
And if im not mistaken its nesseary to have a Ambient block at beginning of the Medium and at the end. Where do i define the Medium? just Input or both?

Another Question i have is: how can i get variables valued from connectors all the courses dont use connection with medium and the thermal examples dont comment well on that matter.

hope you can help me with my Questions

Re: trouble with medium and connections

is my question too difficult, is it the wrong place in the forum or is this forum just dead?

i solved my connection problem myself but my question regarding medium.air.moistair is still unsolved ... can anybody explain if the medium.air is usable or bugged.

Re: trouble with medium and connections

You mentioned Medium in the title, so I won't even bother reading the body text

Re: trouble with medium and connections

WOW,

didnt expect that answer. Whats the deal? does nobody use Medium?

Re: trouble with medium and connections

People do. I just don't understand it.

Re: trouble with medium and connections

The issue seems to be that there are different definitions of what a medium is. The Modelica.Media package in the MSL uses packages extended from Modelica.Media.InterfacesPartialMedium as medium, while Thermal instead uses records extended from Modelica.Thermal.FluidHeatFlow.Media.Medium. Same name, but very different things.

MoistAir is one of the medium packages in Media, so it's not meant to be used with Thermal. There are a couple of predefined mediums defined in Modelica.Thermal.FluidHeatFlow.Media that you can use:

Code:


Modelica.Thermal.FluidHeatFlow.Sources.Ambient amb(medium = Modelica.Thermal.FluidHeatFlow.Media.Air_30degC());

If you want to define your own medium you pretty much just extend from Medium and supply your own values:

Code:


record MyMedium
  extends Modelica.Thermal.FluidHeatFlow.Media.Medium(
    rho = 234,
    cp = 100,
    cv = 54,
    lambda = 0.54,
    nue = 94);
end MyMedium;

Modelica.Thermal.FluidHeatFlow.Sources.Ambient amb(medium = MyMedium());

or

MyMedium medium;
Modelica.Thermal.FluidHeatFlow.Sources.Ambient amb(medium = medium);

if you want to be able to use the same medium for multiple components

Re: trouble with medium and connections

okay thanks for the clarification so i should use fluid if i want to use the predefinded moistair?

since nobody answered i started to change the Connectors and Ambient in the Thermal category like follows in the spoiler:

 Spoiler Show Spoiler Hide Spoiler
 

Code:


connector MoistAir_FlowPort

  Modelica.Media.Air.MoistAir medium ;
  Modelica.SIunits.Pressure p;
  flow Modelica.SIunits.MassFlowRate m_flow;
  Modelica.SIunits.SpecificEnthalpy h;
  flow Modelica.SIunits.EnthalpyFlowRate H_flow;
   
annotation (Documentation(info = "<html>
Basic definition of the connector.<br>
<strong>Variables:</strong>
<ul>
<li>Pressure p</li>
<li>flow MassFlowRate m_flow</li>
<li>Specific Enthalpy h</li>
<li>flow EnthaplyFlowRate H_flow</li>
</ul>
If ports with different media are connected, the simulation is asserted due to the check of parameter.
</html>"),
    Icon(graphics = {Ellipse(fillColor = {85, 170, 127}, fillPattern = FillPattern.Solid,extent = {{-100, 100}, {100, -100}}, endAngle = 360)}));
end MoistAir_FlowPort;

model MoistAir_Ambient "Ambient with constant properties"

  Modelica.Thermal.FluidHeatFlow.Media.Medium medium=Modelica.Thermal.FluidHeatFlow.Media.Medium() "Medium"
    annotation(choicesAllMatching=true);
  parameter Modelica.SIunits.Temperature T0(start=293.15, displayUnit="degC")
    "Initial temperature of medium";
  parameter Boolean T0fixed=false
    "Initial temperature guess value or fixed"
  annotation(choices(checkBox=true));
  output Modelica.SIunits.Temperature T_port "Temperature at flowPort_a";
  output Modelica.SIunits.Temperature T(start=T0, fixed=T0fixed) "Outlet temperature of medium";
  Interfaces.FlowPort_a flowPort(final medium=medium)
    annotation (Placement(transformation(extent={{-110,-10},{-90,10}})));
protected
  constant Boolean Exchange=true "Exchange of medium via flowport"
    annotation(HideResult=true);
  Modelica.SIunits.SpecificEnthalpy h "Specific enthalpy in the volume";
equation
  T_port=flowPort.h/medium.cp;
  T=h/medium.cp;
  // mass flow -> ambient: mixing rule
  // mass flow <- ambient: energy flow defined by ambient's temperature
  if Exchange then
    flowPort.H_flow = semiLinear(flowPort.m_flow,flowPort.h,h);
  else
    h=flowPort.h;
  end if;
annotation (Documentation(info="<html>
<p>
Partial model of single port at the left, defining the medium and the temperature at the port.
</p>
</html>"), Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},
            {100,100}}), graphics={       Text(
          extent={{-150,140},{150,100}},
          lineColor={0,0,255},
          textString="%name")}));

 
 

  parameter Boolean usePressureInput = false "Enable / disable pressure input" annotation(
    Evaluate = true,
    choices(checkBox = true));
 
  parameter Modelica.SIunits.Pressure constantAmbientPressure(start = 0) "Ambient pressure" annotation(
    Dialog(enable = not usePressureInput));
 
  parameter Boolean useTemperatureInput = false "Enable / disable temperature input" annotation(
    Evaluate = true,
    choices(checkBox = true));

  parameter Boolean useHumidityInput = false "Enable / disable humidity input" annotation(
    Evaluate = true,
    choices(checkBox = true));
 
  parameter Modelica.SIunits.Temperature constantAmbientTemperature(start = 293.15, displayUnit = "degC") "Ambient temperature" annotation(
    Dialog(enable = not useTemperatureInput));
  Modelica.Blocks.Interfaces.RealInput ambientPressure = pAmbient if usePressureInput annotation(
    Placement(transformation(extent = {{-20, -20}, {20, 20}}, rotation = 180, origin = {100, 60}), iconTransformation(extent = {{-20, -20}, {20, 20}}, rotation = 180, origin = {100, 60})));
  Modelica.Blocks.Interfaces.RealInput ambientTemperature = TAmbient if useTemperatureInput annotation(
    Placement(transformation(extent = {{-20, -20}, {20, 20}}, rotation = 180, origin = {100, -60}), iconTransformation(extent = {{-20, -20}, {20, 20}}, rotation = 180, origin = {100, -60})));
  Modelica.Blocks.Interfaces.RealInput ambientHumidity annotation(
    Placement(visible = true, transformation(origin = {100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 180), iconTransformation(origin = {110, 70}, extent = {{-20, -20}, {20, 20}}, rotation = 180)));
protected
  Modelica.SIunits.Pressure pAmbient;
  Modelica.SIunits.Temperature TAmbient;
equation
  if not usePressureInput then
    pAmbient = constantAmbientPressure;
  end if;
  if not useTemperatureInput then
    TAmbient = constantAmbientTemperature;
  end if;
  MoistAir_FlowPort.p = pAmbient;
  T = TAmbient;
  annotation(
    Documentation(info = "<html>
<p>(Infinite) ambient with constant pressure and temperature.</p>
<p>Thermodynamic equations are defined by Partials.Ambient.</p>
</html>"),
    Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Ellipse(lineColor = {255, 0, 0}, fillColor = {0, 0, 255}, fillPattern = FillPattern.Solid, extent = {{-90, 90}, {90, -90}}, endAngle = 360), Text(extent = {{20, 80}, {80, 20}}, textString = "p"), Text(extent = {{20, -20}, {80, -80}}, textString = "T")}));
end MoistAir_Ambient;

the Ambient is not yet finished, but can you please tell me, if the idea shoud work or if it is leading to failure? Im Far from a finished Model so i cant simulate yet.

Should i rather switch to a fluid model and where do i Define my medium there? in each component individually or once in the Package for all? In the Fluid Library it is nowere stated as an Parameter unlike in Thermal.
Edited by: Pyrukar - Feb-17-21 09:46:05

Re: trouble with medium and connections

I'm afraid I'm not much of a modeler, so I can't give you an answer on which parts of the MSL you should use for your application. But for Fluid you usually need to redeclare the medium in the components you use, for example:

Code:


Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium = Modelica.Media.Air.MoistAir);

or

package Medium = Modelica.Media.Air.MoistAir;
Modelica.Fluid.Pipes.StaticPipe pipe(redeclare package Medium = Medium);

Re: trouble with medium and connections

Thanks for your Reply,

maybe you can answer me this question:

What parts of the Ambient declaration (including expands) do you realy need to get a fluid source that gives all the Medium.Air.MoistAir variables? reading some tutorials i get the impression that in the Ambient Thermal declaration there is quite so unnessesary stuff i could just delet. I mean i Get it there is the possibility to use fixed values or imput values which expands the declaration, but whats all the stuff in the expanded class all about. lets say all i Care fore is Temperature and Humidity imputs at a fixed Pressure ... pushing with a imputed massflow through the system, wouldnt that be a rather short declaration or what do i need for shuch a rather limited flowsoruce?

Re: trouble with medium and connections

i tried to get some tests done but i dont get why folloing code compiles but the code below doesnt anymore. Why does setting variables doesnt Work with .BaseProperties

This compiles:

Code:


model TestModel

Modelica.SIunits.Temp_K t = 294;
Real p = 1.0e5;
Real AbsHumid= 0.01;

Modelica.Media.Air.MoistAir.BaseProperties Medium(
    T(start=294, fixed=false),
    X(start={0.95,0.05}),
    p(start=1.0e5, fixed=false));

equation

end TestModel;

this Doesnt anymore:

Code:


model TestModel


Modelica.SIunits.Temp_K t = 294;
Real p = 1.0e5;
Real AbsHumid= 0.01;

Modelica.Media.Air.MoistAir.BaseProperties Medium(
    T(start= t, fixed=false),
    X(start={0.95,0.05}),
    p(start=1.0e5, fixed=false));

equation

end TestModel;

Error Message:[Test: 21:9-21:17]: Component start of variability parameter has binding 't' of higher variability continuous

neither does this compile:

Code:


model TestModel


Modelica.SIunits.Temp_K t = 294;
Real p = 1.0e5;
Real AbsHumid= 0.01;

Modelica.Media.Air.MoistAir.BaseProperties Medium(
    T(start= 294, fixed=false),
    X(start={0.95,0.05}),
    p(start= p, fixed=false));

equation

end TestModel;

Same Error

Changing variables to Integer gives another error but at last still similar

Can somebody pleas explain, how to get variables into Baseproperties and how to change BaseProperties after setting them initially? If there is any tutorial on that please show me where current/smile

Edited by: Pyrukar - Feb-18-21 09:57:02

Re: trouble with medium and connections

The attributes in the builtin types are parameters, see the specification. So this works:

Code:


model M
  parameter Real s = 1.0;
  Real x(start = s);  // ok, s is a parameter expression
end M;

while this doesn't:

Code:


model M
  Real s = 1.0;
  Real x(start = s);  // s is continuous, not parameter
model M;

Re: trouble with medium and connections

Okay, that was Easy, Thanks for the explanation current/smile

is it possible that this variable is given to the model via a connector from an

means Connector has parameter Real s=1;

and Model2 has

connector.s y;

Real x(start=y);


or is it important that the parameter definition is within the model itself.
As far as i understand the definition this attribute can be passed through a connector, correct?

Re: trouble with medium and connections

The modifier expression just needs to be a parameter expression, where the parameter in question is declared doesn't matter as long as it's accessible in the scope where the modification occurs.

Re: trouble with medium and connections

Okay, Im at the next point where i dont understand, whats wrong with my code:

as in my former posting i declared the ... .BaseProperties medium (...)

then the code compiles and if i type medium. its recognised and i get things like  medium.x_sat as a posibility. But if i type  abc = medium.x_sat

i get the errror Code:Variable medium.x_sat not found in scope TestModel.

How can i work with the MoistAir i defined above?

Re: trouble with medium and connections

x_sat is a protected member of MoistAir.BaseProperties, so you're not supposed or allowed to modify it. If you want to change the definition of x_sat you'd have to either make your own BaseProperties model or make one that extends from one of the existing BaseProperties, but I don't really know how Media is supposed to be used.

Re: trouble with medium and connections

well than i have to test some more ... a other question that sometimes bothers me is: in many examples (even in the language declaraiton ModelicaSpec34.pdf ) things like follows seem to compile but not if i try current/sad

Code:


import SI= Modelica.SIunits;

SI.Mass x;

or

Code:

  package Medium = Air.MoistAir "Medium model";

with following package definition

Code:

package Medium = Air.MoistAir "Medium model";

As far i can say it at least the Import shoud work but it doesnt current/sad the question is why?

and shouldnt even:

Code:


import Medium = Modelica.Media.Air.MoistAir

Medium.BaseProperties

work?

Re: trouble with medium and connections

Something like this should work:

Code:


model M
  import Medium = Modelica.Media.Air.MoistAir;
  Medium.BaseProperties medium;
end M;

You can't import the name Air.MoistAir though, because import requires a fully qualified name. I.e. you must give the full path to the name, so Modelica.Media.Air.MoistAir instead of Air.MoistAir.

Re: trouble with medium and connections

Only the last one was made up by me, the others are straight out of examples or even the ModelicaSpec34.pdf ... why dont they work if i try to redo them in my models?

Re: trouble with medium and connections

okay my last question is still not answered but i think i finally understood how medium is meant to be used. Following code does Run but  "RelHumid=  Modelica.Media.Air.MoistAir.relativeHumidity (state1);"  is alsways =1 which it shouldnt be. I checked with hx-diagramm (by hand not modelica) that at 14°C and 1bar pressure the absolute humidity is about 10g (and Modelica gets this value right so it should be true and something is obviously working)
but if i define the mass of water to 1g the Relative humidity shoud be 10% but the equation always says 1 (100%) regardless of any parameters current/smile

Is my understanding of this function wrong or is there a bug with that one?

Code:


model TestModel1


parameter Modelica.SIunits.Temp_C t = 14; 
constant Real p = 1.0e5;
parameter Modelica.SIunits.Mass water=0.001;


Real AbsHumid[2];
Real AbsHumidMax;
Real RelHumid;

Modelica.Media.Air.MoistAir.ThermodynamicState state1;



equation

AbsHumid[1]= 1-water;
AbsHumid[2]=water;

state1.p = p;
state1.T = Modelica.SIunits.Conversions.from_degC(t);
state1.X = AbsHumid;

AbsHumidMax = Modelica.Media.Air.MoistAir.xsaturation(state1);

RelHumid=  Modelica.Media.Air.MoistAir.relativeHumidity (state1);

end TestModel1;

There are 0 guests and 0 other users also viewing this topic
You are here: