Buildings.Fluids.Utilities

Package with utility functions

Package Content

NameDescription
Buildings.Fluids.Utilities.BaseClasses BaseClasses Library with base classes for utility functions
Buildings.Fluids.Utilities.Examples Examples Collection of models that illustrate model use and test models
Buildings.Fluids.Utilities.extendedPolynomial extendedPolynomial Polynomial that is linearly extended at user specified values
Buildings.Fluids.Utilities.massFlowRate_dp massFlowRate_dp Mass flow rate as a function of pressure drop
Buildings.Fluids.Utilities.polynomial polynomial Polynomial, used because OpenModelica 1.4.3 does not expand the sum() into a scalar
Buildings.Fluids.Utilities.pressureLoss_m_flow pressureLoss_m_flow Pressure loss as a function of flow rate
Buildings.Fluids.Utilities.printer printer Model that prints values to a file
Buildings.Fluids.Utilities.printRealArray printRealArray Print string to terminal or file


Buildings.Fluids.Utilities.extendedPolynomial Buildings.Fluids.Utilities.extendedPolynomial

Polynomial that is linearly extended at user specified values

Information


For x between the bounds xMin < x < xMax,
this function defines a polynomial 
   y = c1 + c2 * x + ... + cN * x^(N-1)
where N > 1 and xMin, xMax are parameters. For x < xMin and x > xMax, the polynomial is replaced with a linear function in such a way that the first derivative is continuous everywhere.

Inputs

TypeNameDefaultDescription
Realc[:] Polynomial coefficients
Realx x value
RealxMin Minimum x value for polynomial
RealxMax Maximum x value for polynomial

Outputs

TypeNameDescription
Realyy value

Modelica definition

function extendedPolynomial 
  "Polynomial that is linearly extended at user specified values" 
  annotation(derivative=BaseClasses.der_extendedPolynomial);  
  extends Modelica.Icons.Function;
  input Real[:] c "Polynomial coefficients";
  input Real x "x value";
  input Real xMin "Minimum x value for polynomial";
  input Real xMax "Maximum x value for polynomial";
  output Real y "y value";
protected 
 Integer N = size(c,1) "Number of coefficients";
algorithm 
if x < xMin then
   y := c[1];
   for i in 2:N loop
     y := y + xMin^(i - 1)*c[i] + (x - xMin)*(i - 1)*xMin^(i - 2)*c[i];
   end for;
  elseif x < xMax then
   y := c[1];
   for i in 2:N loop
     y := y + x^(i - 1)*c[i];
  end for;
  else
     y := c[1];
     for i in 2:N loop
       y := y + xMax^(i - 1)*c[i] + (x - xMax)*(i - 1)*xMax^(i - 2)*c[i];
    end for;
  end if;
end extendedPolynomial;

Buildings.Fluids.Utilities.massFlowRate_dp Buildings.Fluids.Utilities.massFlowRate_dp

Mass flow rate as a function of pressure drop

Inputs

TypeNameDefaultDescription
Pressuredp Pressure drop (dp = port_a.p - port_b.p) [Pa]
AbsolutePressuredp_small1Turbulent flow if |dp| >= dp_small [Pa]
Realk Flow coefficient, k=m_flow/sqrt(dp) [(kg*m)^(1/2)]

Outputs

TypeNameDescription
MassFlowRatem_flowMass flow rate from port_a to port_b [kg/s]

Modelica definition

function massFlowRate_dp 
  "Mass flow rate as a function of pressure drop" 
  extends Modelica.Icons.Function;
  import SI = Modelica.SIunits;
  input SI.Pressure dp "Pressure drop (dp = port_a.p - port_b.p)";
  input SI.AbsolutePressure dp_small = 1 "Turbulent flow if |dp| >= dp_small";
  input Real k(min=0, unit="(kg*m)^(1/2)") 
    "Flow coefficient, k=m_flow/sqrt(dp)";
  output SI.MassFlowRate m_flow "Mass flow rate from port_a to port_b";
protected 
   Real kk;
algorithm 
  kk:=k*k;
  m_flow:=Modelica_Fluid.Utilities.regRoot2(x=dp, x_small=dp_small, k1=kk, k2=kk);
end massFlowRate_dp;

Buildings.Fluids.Utilities.polynomial Buildings.Fluids.Utilities.polynomial

Polynomial, used because OpenModelica 1.4.3 does not expand the sum() into a scalar

Inputs

TypeNameDefaultDescription
Realc[:] Coefficients
Realx Independent variable

Outputs

TypeNameDescription
RealyDependent variable

Modelica definition

function polynomial 
  "Polynomial, used because OpenModelica 1.4.3 does not expand the sum() into a scalar" 
  extends Modelica.Icons.Function;
  input Real[:] c "Coefficients";
  input Real x "Independent variable";
  output Real y "Dependent variable";
algorithm 
 y := c[1];
 for i in 2 : size(c,1) loop
   y := y + x^(i-1) * c[i];
 end for;
end polynomial;

Buildings.Fluids.Utilities.pressureLoss_m_flow Buildings.Fluids.Utilities.pressureLoss_m_flow

Pressure loss as a function of flow rate

Inputs

TypeNameDefaultDescription
MassFlowRatem_flow Mass flow rate from port_a to port_b [kg/s]
MassFlowRatem_small_flow Mass flow rate where function is approximated [kg/s]
Realk Flow coefficient, k=dp/m_flow^2 [1/kg/m]

Outputs

TypeNameDescription
PressuredpPressure drop (dp = port_a.p - port_b.p) [Pa]

Modelica definition

function pressureLoss_m_flow 
  "Pressure loss as a function of flow rate" 
  extends Modelica.Icons.Function;
  import SI = Modelica.SIunits;
  input SI.MassFlowRate m_flow "Mass flow rate from port_a to port_b";
  input SI.MassFlowRate m_small_flow 
    "Mass flow rate where function is approximated";
  input Real k(min=0, unit="1/kg/m") "Flow coefficient, k=dp/m_flow^2";
  output SI.Pressure dp "Pressure drop (dp = port_a.p - port_b.p)";
algorithm 
  dp:=Modelica_Fluid.Utilities.regSquare2(
    x=m_flow,
    x_small=m_small_flow,
    k1=k,
    k2=k);
end pressureLoss_m_flow;

Buildings.Fluids.Utilities.printer Buildings.Fluids.Utilities.printer

Model that prints values to a file

Buildings.Fluids.Utilities.printer

Information


This model prints to a file at a fixed sample interval.


Parameters

TypeNameDefaultDescription
Stringheader""Header to be printed
StringfileName""File where to print (empty string is the terminal)
Integernin1Number of inputs
TimesamplePeriod0.1Sample period of component [s]
TimestartTime0First sample time instant [s]

Connectors

TypeNameDescription
input RealInputx[nin]Value to be printed

Modelica definition

model printer "Model that prints values to a file" 
  extends Buildings.BaseClasses.BaseIcon;
  parameter String header="" "Header to be printed";
  parameter String fileName="" 
    "File where to print (empty string is the terminal)";
  parameter Integer nin=1 "Number of inputs";
  Modelica.Blocks.Interfaces.RealInput x[nin] "Value to be printed";
  parameter Modelica.SIunits.Time samplePeriod(min=100*Modelica.Constants.eps) = 0.1 
    "Sample period of component";
  parameter Modelica.SIunits.Time startTime=0 "First sample time instant";
protected 
  output Boolean sampleTrigger "True, if sample time instant";
  output Boolean firstTrigger "Rising edge signals first sample instant";
initial algorithm 
  assert(fileName <> "", "Filename must not be empty string");
  Modelica.Utilities.Files.removeFile(fileName);
  Modelica.Utilities.Streams.print(fileName=fileName, string=header);
equation 
  sampleTrigger = sample(startTime, samplePeriod);
  when sampleTrigger then
    firstTrigger = time <= startTime + samplePeriod/2;
  end when;
algorithm 
  
  when {sampleTrigger, initial()} then
     printRealArray(x=x, fileName=fileName);
  end when;
end printer;

Buildings.Fluids.Utilities.printRealArray Buildings.Fluids.Utilities.printRealArray

Print string to terminal or file

Information


Function that prints a real array to an output file.


Inputs

TypeNameDefaultDescription
Realx[:] Input to be printed
StringfileName""File where to print (empty string is the terminal)

Outputs

TypeNameDescription
StringoutStrString to be printed

Modelica definition

function printRealArray "Print string to terminal or file" 
  extends Modelica.Icons.Function;
  input Real[:] x "Input to be printed";
  input String fileName="" "File where to print (empty string is the terminal)";
  output String outStr="" "String to be printed";
algorithm 
  for i in 1:size(x,1) loop
     outStr :=outStr + "  " + realString(number=  x[i], minimumWidth=  8, precision=  8);
  end for;
  Modelica.Utilities.Streams.print(string=outStr, fileName=fileName);
end printRealArray;

HTML-documentation generated by Dymola Tue Sep 30 14:24:36 2008.