Name | Description |
---|---|
extendedPolynomial | Polynomial that is linearly extended at user specified values |
massFlowRate_dp | Mass flow rate as a function of pressure drop |
polynomial | Polynomial, used because OpenModelica 1.4.3 does not expand the sum() into a scalar |
pressureLoss_m_flow | Pressure loss as a function of flow rate |
printer | Model that prints values to a file |
printRealArray | Print string to terminal or file |
y = c1 + c2 * x + ... + cN * x^(N-1)where N > 1 and x is between the bounds xMin < x < xMax. If x is outside this range, then the polynomial is replaced with a linear function in such a way that the first derivative is continuous everywhere.
Type | Name | Default | Description |
---|---|---|---|
Real | c[:] | Polynomial coefficients | |
Real | x | x value | |
Real | xMin | Minimum x value for polynomial | |
Real | xMax | Maximum x value for polynomial |
Type | Name | Description |
---|---|---|
Real | y | y value |
function extendedPolynomial "Polynomial that is linearly extended at user specified values" 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;
Type | Name | Default | Description |
---|---|---|---|
Pressure | dp | Pressure drop (dp = port_a.p - port_b.p) [Pa] | |
AbsolutePressure | dp_small | 1 | Turbulent flow if |dp| >= dp_small [Pa] |
Real | k | Flow coefficient, k=m_flow/sqrt(dp) [(kg*m)^(1/2)] |
Type | Name | Description |
---|---|---|
MassFlowRate | m_flow | Mass flow rate from port_a to port_b [kg/s] |
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;
Type | Name | Default | Description |
---|---|---|---|
Real | c[:] | Coefficients | |
Real | x | Independent variable |
Type | Name | Description |
---|---|---|
Real | y | Dependent variable |
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;
Type | Name | Default | Description |
---|---|---|---|
MassFlowRate | m_flow | Mass flow rate from port_a to port_b [kg/s] | |
MassFlowRate | m_small_flow | Mass flow rate where function is approximated [kg/s] | |
Real | k | Flow coefficient, k=dp/m_flow^2 [1/kg/m] |
Type | Name | Description |
---|---|---|
Pressure | dp | Pressure drop (dp = port_a.p - port_b.p) [Pa] |
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;
This model prints to a file at a fixed sample interval.
Type | Name | Default | Description |
---|---|---|---|
String | header | "" | Header to be printed |
String | fileName | "" | File where to print (empty string is the terminal) |
Integer | nin | 1 | Number of inputs |
Time | samplePeriod | 0.1 | Sample period of component [s] |
Time | startTime | 0 | First sample time instant [s] |
Type | Name | Description |
---|---|---|
input RealInput | x[nin] | Value to be printed |
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;
Function that prints a real array to an output file.
Type | Name | Default | Description |
---|---|---|---|
Real | x[:] | Input to be printed | |
String | fileName | "" | File where to print (empty string is the terminal) |
Type | Name | Description |
---|---|---|
String | outStr | String to be printed |
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;