Buildings.Utilities.Math.Functions
Package with mathematical functions
Information
This package contains functions for commonly used mathematical operations. The functions are used in the blocks Buildings.Utilities.Math.
Extends from Modelica.Icons.VariantsPackage (Icon for package containing variants).
Package Content
Name | Description |
---|---|
average | Average of a vector |
bicubic | Bicubic function |
biquadratic | Biquadratic function |
booleanReplicator | Replicates Boolean signals |
cubicHermiteLinearExtrapolation | Interpolate using a cubic Hermite spline with linear extrapolation |
integerReplicator | Replicates integer signals |
inverseXRegularized | Function that approximates 1/x by a twice continuously differentiable function |
isMonotonic | Returns true if the argument is a monotonic sequence |
polynomial | Polynomial function |
powerLinearized | Power function that is linearized below a user-defined threshold |
quadraticLinear | Function that is quadratic in first argument and linear in second argument |
regNonZeroPower | Power function, regularized near zero, but nonzero value for x=0 |
regStep | Approximation of a general step, such that the approximation is continuous and differentiable |
smoothExponential | Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta |
smoothHeaviside | Once continuously differentiable approximation to the Heaviside function |
smoothInterpolation | Interpolate using a cubic Hermite spline with linear extrapolation for a vector xSup[], ySup[] and independent variable x |
smoothLimit | Once continuously differentiable approximation to the limit function |
smoothMax | Once continuously differentiable approximation to the maximum function |
smoothMin | Once continuously differentiable approximation to the minimum function |
spliceFunction | |
splineDerivatives | Function to compute the derivatives for cubic hermite spline interpolation |
trapezoidalIntegration | Integration using the trapezoidal rule |
Examples | Collection of models that illustrate model use and test models |
BaseClasses | Package with base classes for Buildings.Utilities.Math.Functions |
Buildings.Utilities.Math.Functions.average
Average of a vector
Information
This function outputs the average of the vector.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Integer | nin | Number of inputs | |
Real | u[nin] | Input vector |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.bicubic
Bicubic function
Information
This function computesy = a1 + a2 x1 + a3 x12 + a4 x2 + a5 x22 + a6 x1 x2 + a7 x1^3 + a8 x2^3 + a9 x12 x2 + a10 x1 x22
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | a[10] | Coefficients | |
Real | x1 | Independent variable | |
Real | x2 | Independent variable |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.biquadratic
Biquadratic function
Information
This function computesy = a1 + a2 x1 + a3 x12 + a4 x2 + a5 x22 + a6 x1 x2
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | a[6] | Coefficients | |
Real | x1 | Independent variable | |
Real | x2 | Independent variable |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.booleanReplicator
Replicates Boolean signals
Information
This function replicates the boolean input signal to an array of nout
identical output signals.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Integer | nout | 1 | Number of outouts |
Boolean | u | Boolean input signal |
Outputs
Type | Name | Description |
---|---|---|
Boolean | y[nout] | Boolean output signals |
Modelica definition
Buildings.Utilities.Math.Functions.cubicHermiteLinearExtrapolation
Interpolate using a cubic Hermite spline with linear extrapolation
Information
For x1 < x < x2, this function interpolates using cubic hermite spline. For x outside this interval, the function linearly extrapolates.
For how to use this function, see Buildings.Utilities.Math.Functions.Examples.CubicHermite.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | x1 | Lower abscissa value | |
Real | x2 | Upper abscissa value | |
Real | y1 | Lower ordinate value | |
Real | y2 | Upper ordinate value | |
Real | y1d | Lower gradient | |
Real | y2d | Upper gradient |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Interpolated ordinate value |
Modelica definition
Buildings.Utilities.Math.Functions.integerReplicator
Replicates integer signals
Information
This function replicates the integer input signal to an array of
nout
identical output signals.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Integer | nout | Number of outputs | |
Integer | u | Integer input signal |
Outputs
Type | Name | Description |
---|---|---|
Integer | y[nout] | Integer output signals |
Modelica definition
Buildings.Utilities.Math.Functions.inverseXRegularized
Function that approximates 1/x by a twice continuously differentiable function
Information
Function that approximates y=1 ⁄ x inside the interval -δ ≤ x ≤ δ. The approximation is twice continuously differentiable with a bounded derivative on the whole real line.
See the plot of Buildings.Utilities.Math.Functions.Examples.InverseXRegularized for the graph.
For efficiency, the polynomial coefficients
a, b, c, d, e, f
and
the inverse of the smoothing parameter deltaInv
are exposed as arguments to this function.
Typically, these coefficients only depend on parameters and hence
can be computed once.
They must be equal to their default values, otherwise the function
is not twice continuously differentiable.
By exposing these coefficients as function arguments, models
that call this function can compute them as parameters, and
assign these parameter values in the function call.
This avoids that the coefficients are evaluated for each time step,
as they would otherwise be if they were to be computed inside the
body of the function. However, assigning the values is optional
as otherwise, at the expense of efficiency, the values will be
computed each time the function is invoked.
See
Buildings.Utilities.Math.Functions.Examples.InverseXRegularized
for how to efficiently call this function.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | delta | Abscissa value below which approximation occurs | |
Real | deltaInv | 1/delta | Inverse value of delta |
Real | a | -15*deltaInv | Polynomial coefficient |
Real | b | 119*deltaInv^2 | Polynomial coefficient |
Real | c | -361*deltaInv^3 | Polynomial coefficient |
Real | d | 534*deltaInv^4 | Polynomial coefficient |
Real | e | -380*deltaInv^5 | Polynomial coefficient |
Real | f | 104*deltaInv^6 | Polynomial coefficient |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Function value |
Modelica definition
Buildings.Utilities.Math.Functions.isMonotonic
Returns true if the argument is a monotonic sequence
Information
This function returns true
if its argument is
monotonic increasing or decreasing, and false
otherwise.
If strict=true
, then strict monotonicity is tested,
otherwise weak monotonicity is tested.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x[:] | Sequence to be tested | |
Boolean | strict | false | Set to true to test for strict monotonicity |
Outputs
Type | Name | Description |
---|---|---|
Boolean | monotonic | True if x is monotonic increasing or decreasing |
Modelica definition
Buildings.Utilities.Math.Functions.polynomial
Polynomial function
Information
This function computes a polynomial of arbitrary order. The polynomial has the formy = a1 + a2 x + a3 x2 + ...
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Independent variable | |
Real | a[:] | Coefficients |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.powerLinearized
Power function that is linearized below a user-defined threshold
Information
Function that approximates y=xn where 0 < n so that- the function is defined and monotone increasing for all x.
- dy/dx is bounded and continuous everywhere (for n < 1).
For x < x0, this function replaces y=xn by a linear function that is continuously differentiable everywhere.
A typical use of this function is to replace T = T4(1/4) in a radiation balance to ensure that the function is defined everywhere. This can help solving the initialization problem when a solver may be far from a solution and hence T4 < 0.
See the package Examples
for the graph.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | n | Exponent | |
Real | x0 | Abscissa value below which linearization occurs |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Function value |
Modelica definition
Buildings.Utilities.Math.Functions.quadraticLinear
Function that is quadratic in first argument and linear in second argument
Information
This function computesy = a1 + a2 x1 + a3 x12 + (a4 + a5 x1 + a6 x12) x2
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | a[6] | Coefficients | |
Real | x1 | Independent variable for quadratic part | |
Real | x2 | Independent variable for linear part |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.regNonZeroPower
Power function, regularized near zero, but nonzero value for x=0
Information
Function that approximates y=|x|n where n > 0 so that- y(0) is not equal to zero.
- dy/dx is bounded and continuous everywhere.
This function replaces y=|x|n in the interval -δ...+δ by a 4-th order polynomial that has the same function value and the first and second derivative at x=± δ.
A typical use of this function is to replace the function for the convective heat transfer coefficient for forced or free convection that is of the form h=c |dT|n for some constant c and exponent 0 ≤ n ≤ 1. By using this function, the original function that has an infinite derivative near zero and that takes on zero at the origin is replaced by a function with a bounded derivative and a non-zero value at the origin. Physically, the region -δ...+δ may be interpreted as the region where heat conduction dominates convection in the boundary layer.
See the packageExamples
for the graph.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | n | Exponent | |
Real | delta | 0.01 | Abscissa value where transition occurs |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Function value |
Modelica definition
Buildings.Utilities.Math.Functions.regStep
Approximation of a general step, such that the approximation 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
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | y1 | Ordinate value for x > 0 | |
Real | y2 | Ordinate value for x < 0 | |
Real | x_small | 1e-5 | Approximation of step for -x_small <= x <= x_small; x_small >= 0 required |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Ordinate value to approximate y = if x > 0 then y1 else y2 |
Modelica definition
Buildings.Utilities.Math.Functions.smoothExponential
Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta
Information
Function to provide a once continuously differentiable approximation to exp(- |x| ) in the interval |x| < δ for some positive δ
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Input argument | |
Real | delta | Transition point where approximation occurs |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Output argument |
Modelica definition
Buildings.Utilities.Math.Functions.smoothHeaviside
Once continuously differentiable approximation to the Heaviside function
Information
Once Lipschitz continuously differentiable approximation to the
Heaviside(.,.)
function.
See Example
Buildings.Utilities.Math.Examples.SmoothHeaviside.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Argument | |
Real | delta | Parameter used for scaling |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.smoothInterpolation
Interpolate using a cubic Hermite spline with linear extrapolation for a vector xSup[], ySup[] and independent variable x
Information
For xSup1 ≤ x ≤ xSupn, where n is the size of the support points xSup, which must be strictly monotonically increasing, this function interpolates using cubic hermite spline. For x outside this interval, the function linearly extrapolates.
If n=2, linear interpolation is used an if n=1, the function value y1 is returned.
Note that if xSup
and ySup
only depend on parameters
or constants, then
Buildings.Utilities.Math.Functions.cubicHermiteLinearExtrapolation
will be more efficient.
In contrast to the function
Modelica.Math.Vectors.interpolate
which provides linear interpolation, this function does
not trigger events.
For how to use this function, see Buildings.Utilities.Math.Functions.Examples.SmoothInterpolation.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Abscissa value | |
Real | xSup[:] | Support points (strictly increasing) | |
Real | ySup[size(xSup, 1)] | Function values at xSup | |
Boolean | ensureMonotonicity | isMonotonic(ySup, strict=fal... | Set to true to ensure monotonicity of the cubic hermite |
Outputs
Type | Name | Description |
---|---|---|
Real | yInt | Interpolated ordinate value |
Modelica definition
Buildings.Utilities.Math.Functions.smoothLimit
Once continuously differentiable approximation to the limit function
Information
Once continuously differentiable approximation to the limit(.,.)
function.
The output is bounded to be in [l, u].
Note that the limit need not be respected, such as illustrated in Buildings.Utilities.Math.Examples.SmoothMin.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x | Variable | |
Real | l | Low limit | |
Real | u | Upper limit | |
Real | deltaX | Width of transition interval |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.smoothMax
Once continuously differentiable approximation to the maximum function
Information
Once continuously differentiable approximation to the max(.,.)
function.
Note that the maximum need not be respected, such as illustrated in Buildings.Utilities.Math.Examples.SmoothMin.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x1 | First argument | |
Real | x2 | Second argument | |
Real | deltaX | Width of transition interval |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.smoothMin
Once continuously differentiable approximation to the minimum function
Information
Once continuously differentiable approximation to the min(.,.)
function.
Note that the minimum need not be respected, such as illustrated in Buildings.Utilities.Math.Examples.SmoothMin.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x1 | First argument | |
Real | x2 | Second argument | |
Real | deltaX | Width of transition interval |
Outputs
Type | Name | Description |
---|---|---|
Real | y | Result |
Modelica definition
Buildings.Utilities.Math.Functions.spliceFunction
Information
Function to provide a once continuously differentiable transition between to arguments.
The function is adapted from Modelica.Media.Air.MoistAir.Utilities.spliceFunction and provided here for easier accessability to model developers.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | pos | Argument of x > 0 | |
Real | neg | Argument of x < 0 | |
Real | x | Independent value | |
Real | deltax | Half width of transition interval |
Outputs
Type | Name | Description |
---|---|---|
Real | out | Smoothed value |
Modelica definition
Buildings.Utilities.Math.Functions.splineDerivatives
Function to compute the derivatives for cubic hermite spline interpolation
Information
This function computes the derivatives at the support points xi that can be used as input for evaluating a cubic hermite spline.
If ensureMonotonicity=true
, then the support points yi
need to be monotone increasing (or increasing), and the computed derivatives
di are such that the cubic hermite is monotone increasing (or decreasing).
The algorithm to ensure monotonicity is based on the method described in Fritsch and Carlson (1980) for
ρ = ρ2.
This function is typically used with Buildings.Utilities.Math.Functions.cubicHermiteLinearExtrapolation which is used to evaluate the cubic spline. Because in many applications, the shape of the spline depends on parameters, this function has been implemented in such a way that all derivatives can be computed at once and then stored for use during the time stepping, in which the above function may be called.
References
F.N. Fritsch and R.E. Carlson, Monotone piecewise cubic interpolation. SIAM J. Numer. Anal., 17 (1980), pp. 238-246.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Real | x[:] | Support point, strict monotone increasing | |
Real | y[size(x, 1)] | Function values at x | |
Boolean | ensureMonotonicity | isMonotonic(y, strict=false) | Set to true to ensure monotonicity of the cubic hermite |
Outputs
Type | Name | Description |
---|---|---|
Real | d[size(x, 1)] | Derivative at the support points |
Modelica definition
Buildings.Utilities.Math.Functions.trapezoidalIntegration
Integration using the trapezoidal rule
Information
This function computes a definite integral using the trapezoidal rule.
Inputs
Type | Name | Default | Description |
---|---|---|---|
Integer | N | Number of integrand points | |
Real | f[:] | Integrands | |
Real | deltaX | Width of interval for Trapezoidal integration |
Outputs
Type | Name | Description |
---|---|---|
Real | result | Result |