Package Modelica.​Fluid.​Utilities
Utility models to construct fluid components (should not be used directly)

Information

Extends from Modelica.​Icons.​UtilitiesPackage (Icon for utility packages).

Package Contents

NameDescription
checkBoundaryCheck whether boundary definition is correct
cubicHermiteEvaluate a cubic Hermite spline
cubicHermite_withDerivativeEvaluate a cubic Hermite spline, return value and derivative
evaluatePoly3_derivativeAtZeroEvaluate polynomial of order 3 that passes the origin with a predefined derivative
regFun3Co-monotonic and C1 smooth regularization function
regPowAnti-symmetric power approximation with non-zero derivative in the origin
regRootAnti-symmetric square root approximation with finite derivative in the origin
regRoot2Anti-symmetric approximation of square root with discontinuous factor so that the first derivative is finite and continuous
regRoot_derDerivative of regRoot
regSquareAnti-symmetric square approximation with non-zero derivative in the origin
regSquare2Anti-symmetric approximation of square with discontinuous factor so that the first derivative is non-zero and is continuous
regStepApproximation of a general step, such that the characteristic is continuous and differentiable

Function Modelica.​Fluid.​Utilities.​checkBoundary
Check whether boundary definition is correct

Information

This icon indicates Modelica functions.

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
StringmediumName 
StringsubstanceNames[:]Names of substances
BooleansingleState 
Booleandefine_p 
RealX_boundary[:] 
StringmodelName 

Function Modelica.​Fluid.​Utilities.​regRoot
Anti-symmetric square root approximation with finite derivative in the origin

Information

This function approximates sqrt(abs(x))*sgn(x), such that the derivative is finite and smooth in x=0.

FunctionApproximationRange
y = regRoot(x)y ~= sqrt(abs(x))*sgn(x)abs(x) >>delta
y = regRoot(x)y ~= x/sqrt(delta)abs(x) << delta

With the default value of delta=0.01, the difference between sqrt(x) and regRoot(x) is 16% around x=0.01, 0.25% around x=0.1 and 0.0025% around x=1.

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
Realx 
RealdeltaRange of significant deviation from sqrt(abs(x))*sgn(x)

Outputs

TypeNameDescription
Realy 

Function Modelica.​Fluid.​Utilities.​regRoot_der
Derivative of regRoot

Information

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
Realx 
RealdeltaRange of significant deviation from sqrt(x)
RealdxDerivative of x

Outputs

TypeNameDescription
Realdy 

Function Modelica.​Fluid.​Utilities.​regSquare
Anti-symmetric square approximation with non-zero derivative in the origin

Information

This function approximates x^2*sgn(x), such that the derivative is non-zero in x=0.

FunctionApproximationRange
y = regSquare(x)y ~= x^2*sgn(x)abs(x) >>delta
y = regSquare(x)y ~= x*deltaabs(x) << delta

With the default value of delta=0.01, the difference between x^2 and regSquare(x) is 41% around x=0.01, 0.4% around x=0.1 and 0.005% around x=1.

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
Realx 
RealdeltaRange of significant deviation from x^2*sgn(x)

Outputs

TypeNameDescription
Realy 

Function Modelica.​Fluid.​Utilities.​regPow
Anti-symmetric power approximation with non-zero derivative in the origin

Information

This function approximates abs(x)^a*sign(x), such that the derivative is positive, finite and smooth in x=0.

FunctionApproximationRange
y = regPow(x)y ~= abs(x)^a*sgn(x)abs(x) >>delta
y = regPow(x)y ~= x*delta^(a-1)abs(x) << delta

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
Realx 
Reala 
RealdeltaRange of significant deviation from x^a*sgn(x)

Outputs

TypeNameDescription
Realy 

Function Modelica.​Fluid.​Utilities.​regRoot2
Anti-symmetric approximation of square root with discontinuous factor so that the first derivative is finite and continuous

Information

Approximates the function

   y = if x ≥ 0 then sqrt(k1*x) else -sqrt(k2*abs(x)), with k1, k2 ≥ 0

in such a way that within the region -x_small ≤ x ≤ x_small, the function is described by two polynomials of third order (one in the region -x_small .. 0 and one within the region 0 .. x_small) such that

Typical screenshots for two different configurations are shown below. The first one with k1=k2=1:

regRoot2_a.png

and the second one with k1=1 and k2=3:

regRoot2_b.png

The (smooth) derivative of the function with k1=1, k2=3 is shown in the next figure:

regRoot2_c.png

Literature

Fritsch F.N. and Carlson R.E. (1980):
Monotone piecewise cubic interpolation. SIAM J. Numerc. Anal., Vol. 17, No. 2, April 1980, pp. 238-246

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
RealxAbscissa value
Realx_smallApproximation of function for |x| <= x_small
Realk1y = if x>=0 then sqrt(k1*x) else -sqrt(k2*|x|)
Realk2y = if x>=0 then sqrt(k1*x) else -sqrt(k2*|x|)
Booleanuse_yd0= true, if yd0 shall be used
Realyd0Desired derivative at x=0: dy/dx = yd0

Outputs

TypeNameDescription
RealyOrdinate value

Function Modelica.​Fluid.​Utilities.​regSquare2
Anti-symmetric approximation of square with discontinuous factor so that the first derivative is non-zero and is continuous

Information

Approximates the function

   y = if x ≥ 0 then k1*x*x else -k2*x*x, with k1, k2 > 0

in such a way that within the region -x_small ≤ x ≤ x_small, the function is described by two polynomials of third order (one in the region -x_small .. 0 and one within the region 0 .. x_small) such that

A typical screenshot for k1=1, k2=3 is shown in the next figure:

regSquare2_b.png

The (smooth, non-zero) derivative of the function with k1=1, k2=3 is shown in the next figure:

regSquare2_b.png

Literature

Fritsch F.N. and Carlson R.E. (1980):
Monotone piecewise cubic interpolation. SIAM J. Numerc. Anal., Vol. 17, No. 2, April 1980, pp. 238-246

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
Realxabscissa value
Realx_smallapproximation of function for |x| <= x_small
Realk1y = (if x>=0 then k1 else k2)*x*|x|
Realk2y = (if x>=0 then k1 else k2)*x*|x|
Booleanuse_yd0= true, if yd0 shall be used
Realyd0Desired derivative at x=0: dy/dx = yd0

Outputs

TypeNameDescription
Realyordinate value

Function Modelica.​Fluid.​Utilities.​regStep
Approximation of a general step, such that the characteristic is continuous and differentiable

Information

This function is used to approximate the equation

    y = if x > 0 then y1 else y2;

by a smooth characteristic, so that the expression is continuous and differentiable:

   y = smooth(1, if x >  x_small then y1 else
                 if x < -x_small then y2 else f(y1, y2));

In the region -x_small < x < x_small a 2nd order polynomial is used for a smooth transition from y1 to y2.

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
RealxAbscissa value
Realy1Ordinate value for x > 0
Realy2Ordinate value for x < 0
Realx_smallApproximation of step for -x_small <= x <= x_small; x_small >= 0 required

Outputs

TypeNameDescription
RealyOrdinate value to approximate y = if x > 0 then y1 else y2

Function Modelica.​Fluid.​Utilities.​evaluatePoly3_derivativeAtZero
Evaluate polynomial of order 3 that passes the origin with a predefined derivative

Information

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
RealxValue for which polynomial shall be evaluated
Realx1Abscissa value
Realy1y1=f(x1)
Realy1dFirst derivative at y1
Realy0dFirst derivative at f(x=0)

Outputs

TypeNameDescription
Realy 

Function Modelica.​Fluid.​Utilities.​regFun3
Co-monotonic and C1 smooth regularization function

Information

Approximates a function in a region between x0 and x1 such that

In this region, a continuation is constructed from the given points (x0, y0), (x1, y1) and the respective derivatives. For this purpose, a single polynomial of third order or two cubic polynomials with a linear section in between are used [Gasparo and Morandi, 1991]. This algorithm was extended with two additional conditions to avoid saddle points with zero/infinite derivative that lead to integrator step size reduction to zero.

This function was developed for pressure loss correlations properly addressing the static head on top of the established requirements for monotonicity and smoothness. In this case, the present function allows to implement the exact solution in the limit of x1-x0 -> 0 or y1-y0 -> 0.

Typical screenshots for two different configurations are shown below. The first one illustrates five different settings of xi and yid:

regFun3_a.png

The second graph shows the continuous derivative of this regularization function:

regFun3_a.png

Literature

Gasparo M. G. and Morandi R. (1991):
Piecewise cubic monotone interpolation with assigned slopes. Computing, Vol. 46, Issue 4, December 1991, pp. 355 - 365.

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
RealxAbscissa value
Realx0Lower abscissa value
Realx1Upper abscissa value
Realy0Ordinate value at lower abscissa value
Realy1Ordinate value at upper abscissa value
Realy0dDerivative at lower abscissa value
Realy1dDerivative at upper abscissa value

Outputs

TypeNameDescription
RealyOrdinate value
RealcSlope of linear section between two cubic polynomials or dummy linear section slope if single cubic is used

Function Modelica.​Fluid.​Utilities.​cubicHermite
Evaluate a cubic Hermite spline

Information

This icon indicates Modelica functions.

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
RealxAbscissa value
Realx1Lower abscissa value
Realx2Upper abscissa value
Realy1Lower ordinate value
Realy2Upper ordinate value
Realy1dLower gradient
Realy2dUpper gradient

Outputs

TypeNameDescription
RealyInterpolated ordinate value

Function Modelica.​Fluid.​Utilities.​cubicHermite_withDerivative
Evaluate a cubic Hermite spline, return value and derivative

Information

This icon indicates Modelica functions.

Extends from Modelica.​Icons.​Function (Icon for functions).

Inputs

TypeNameDescription
RealxAbscissa value
Realx1Lower abscissa value
Realx2Upper abscissa value
Realy1Lower ordinate value
Realy2Upper ordinate value
Realy1dLower gradient
Realy2dUpper gradient

Outputs

TypeNameDescription
RealyInterpolated ordinate value
Realdy_dxDerivative dy/dx at abscissa value x