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

binding of variabilities PARAM and VAR

binding of variabilities PARAM and VAR

Hello,

the simulation of the attached code with simulate(cap) stops with the error msg
"Error: Component hcap.C of variability PARAM has binding 3900000.0 * V of higher variability VAR."

While I thought to have understood the purpose of the restriction not to allow an assignment of a variable with a higher variability to a variable with a lower variability, I am puzzled about the particular case below: The model "Volume" has only parameter inputs which, when applied an algorithm to them, yield a defined, unique result. My feeling was that V should also have (implicitly) the variability PARAM. If I did the calculation myself on paper, I'd have much more work but the expected result and no error. Such a behaviour doesn't appear sound/consistent to me. Is there a particular reason for that or is the reason purely of a formal nature, i.e., the implementation of the language?

Code:

model Volume

  import Modelica.SIunits;
  parameter Modelica.SIunits.Length a=1;
  parameter Modelica.SIunits.Length b=1;
  parameter Modelica.SIunits.Length c=1;
  Modelica.SIunits.Length dh;
  Modelica.SIunits.Area A;
  Modelica.SIunits.Volume V;
algorithm
  //some sophisticated algorithm which can not be written in one line; only depending on the parameters a,b,c
  dh:=4*a*b/2./(a+b);
  A:=2.*(a+b)*c;
  V:=a*b*c;
end Volume;

model cap
  import Modelica.SIunits;
  extends Volume;
  constant Modelica.SIunits.SpecificHeatCapacity cp=500.;
  constant Modelica.SIunits.Density rho=7800.;
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor hcap(C=V*cp*rho,T(start=300.));
end cap;

How can I achieve a code where I can make some sophisticated calculation for the volume "V" and being able to initiate the HeatCapacitor with the result of that calculation?

Thank you for your help.

al

Edited by: alberich - May-11-13 00:14:46

Re: binding of variabilities PARAM and VAR

Hello,
when replacing the "model Volume" by a "function Volume" the initialisation works, if the first variable of the function is the required variable. In the example below, the program takes the hydraulic diameter instead of the volume (it does btw not issue a warning for the mismatch of the units). I'd have to change the order of the outputs, which would then render the function unusable for other initialisations than the volume. Is there a way to select a specific output variable when the function is part of a function?
al

Code:

function Volume

  import Modelica.SIunits;
  input  Modelica.SIunits.Length a=1;
  input  Modelica.SIunits.Length b=1;
  input  Modelica.SIunits.Length c=1;
  output Modelica.SIunits.Length dh;
  output Modelica.SIunits.Area A; 
  output Modelica.SIunits.Volume V;
algorithm
  //some sophisticated algorithm which can not be written in one line; only depending on the parameters a,b,c
  dh:=4*a*b/2./(a+b);
  A:=2.*(a+b)*c;
  V:=a*b*c;   
end Volume;


model cap
  import Modelica.SIunits;
  constant Modelica.SIunits.SpecificHeatCapacity cp=500.;
  constant Modelica.SIunits.Density rho=7800.;
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor hcap(C=Volume(a=2,b=2,c=2)*cp*rho,T(start=300.)); //wrong: it takes dh!
end cap;

Re: binding of variabilities PARAM and VAR

No need to call a function, just do the calculation in a model with final parameter
like:
parameter Modelica.SIunits.Length a=1;
parameter Modelica.SIunits.Length b=1;
parameter Modelica.SIunits.Length c=1;
final parameter Real V = a*b*c;
I'm doing calculations on compact HE, using the same equations as U did.

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