Buildings.Utilities.Math.Functions.BaseClasses

Package with base classes for Buildings.Utilities.Math.Functions

Information

This package contains base classes that are used to construct the models in Buildings.Utilities.Math.Functions.

Extends from Modelica.Icons.BasesPackage (Icon for packages containing base classes).

Package Content

Name Description
Buildings.Utilities.Math.Functions.BaseClasses.der_2_regNonZeroPower der_2_regNonZeroPower Power function, regularized near zero, but nonzero value for x=0
Buildings.Utilities.Math.Functions.BaseClasses.der_2_smoothTransition der_2_smoothTransition Second order derivative of smoothTransition with respect to x
Buildings.Utilities.Math.Functions.BaseClasses.der_inverseXRegularized der_inverseXRegularized Derivative of inverseXRegularised function
Buildings.Utilities.Math.Functions.BaseClasses.der_regNonZeroPower der_regNonZeroPower Power function, regularized near zero, but nonzero value for x=0
Buildings.Utilities.Math.Functions.BaseClasses.der_smoothTransition der_smoothTransition First order derivative of smoothTransition with respect to x
Buildings.Utilities.Math.Functions.BaseClasses.der_spliceFunction der_spliceFunction Derivative of splice function
Buildings.Utilities.Math.Functions.BaseClasses.smoothTransition smoothTransition Twice continuously differentiable transition between the regions

Buildings.Utilities.Math.Functions.BaseClasses.der_2_regNonZeroPower Buildings.Utilities.Math.Functions.BaseClasses.der_2_regNonZeroPower

Power function, regularized near zero, but nonzero value for x=0

Information

Implementation of the second derivative of the function Buildings.Utilities.Math.Functions.regNonZeroPower.

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

Inputs

TypeNameDefaultDescription
Realx Abscissa value
Realn Exponent
Realdelta0.01Abscissa value where transition occurs
Realder_x  
Realder_2_x  

Outputs

TypeNameDescription
Realder_2_yFunction value

Modelica definition

function der_2_regNonZeroPower "Power function, regularized near zero, but nonzero value for x=0" extends Modelica.Icons.Function; input Real x "Abscissa value"; input Real n "Exponent"; input Real delta = 0.01 "Abscissa value where transition occurs"; input Real der_x; input Real der_2_x; output Real der_2_y "Function value"; protected Real a1; Real a3; Real delta2; Real x2; Real y_d "=y(delta)"; Real yP_d "=dy(delta)/dx"; Real yPP_d "=d^2y(delta)/dx^2"; algorithm if abs(x) > delta then der_2_y := n*(abs(x)^(n-1)*sign(x)*der_2_x + (n-1)*abs(x)^(n-2)*der_x^2); else delta2 :=delta*delta; x2 :=x*x; y_d :=delta^n; yP_d :=n*delta^(n - 1); yPP_d :=n*(n - 1)*delta^(n - 2); a1 := -(yP_d/delta - yPP_d)/delta2/8; a3 := (yPP_d - 12 * a1 * delta2)/2; der_2_y := (12*a1*x2+2*a3)*der_x^2 +x * ( 4 * a1 * x2 + 2 * a3)*der_2_x; end if; end der_2_regNonZeroPower;

Buildings.Utilities.Math.Functions.BaseClasses.der_2_smoothTransition Buildings.Utilities.Math.Functions.BaseClasses.der_2_smoothTransition

Second order derivative of smoothTransition with respect to x

Information

This function is the 2nd order derivative of Buildings.Utilities.Math.Functions.BaseClasses.smoothTransition.

Implementation

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.

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

Inputs

TypeNameDefaultDescription
Realx Abscissa value
Realdeltadelta(min=Modelica.Constants...Abscissa value below which approximation occurs
RealdeltaInv Inverse value of delta
Reala Polynomial coefficient
Realb Polynomial coefficient
Realc Polynomial coefficient
Reald Polynomial coefficient
Reale Polynomial coefficient
Realf Polynomial coefficient
Realx_der Derivative of x
Realx_der2 Second order derivative of x

Outputs

TypeNameDescription
Realy_der2Second order derivative of function value

Modelica definition

function der_2_smoothTransition "Second order derivative of smoothTransition with respect to x" extends Modelica.Icons.Function; input Real x "Abscissa value"; input Real delta(min=Modelica.Constants.eps) "Abscissa value below which approximation occurs"; input Real deltaInv "Inverse value of delta"; input Real a "Polynomial coefficient"; input Real b "Polynomial coefficient"; input Real c "Polynomial coefficient"; input Real d "Polynomial coefficient"; input Real e "Polynomial coefficient"; input Real f "Polynomial coefficient"; input Real x_der "Derivative of x"; input Real x_der2 "Second order derivative of x"; output Real y_der2 "Second order derivative of function value"; protected Real aX "Absolute value of x"; Real ex "Intermediate expression"; algorithm aX:= abs(x); ex := 2*c + aX*(6*d + aX*(12*e + aX*20*f)); y_der2 := (b + aX*(2*c + aX*(3*d + aX*(4*e + aX*5*f))))*x_der2 + x_der*x_der*( if x > 0 then ex else -ex); end der_2_smoothTransition;

Buildings.Utilities.Math.Functions.BaseClasses.der_inverseXRegularized Buildings.Utilities.Math.Functions.BaseClasses.der_inverseXRegularized

Derivative of inverseXRegularised function

Information

Implementation of the first derivative of the function Buildings.Utilities.Math.Functions.inverseXRegularized.

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

Inputs

TypeNameDefaultDescription
Realx Abscissa value
Realdeltadelta(min=Modelica.Constants...Abscissa value below which approximation occurs
RealdeltaInv1/deltaInverse value of delta
Reala-15*deltaInvPolynomial coefficient
Realb119*deltaInv^2Polynomial coefficient
Realc-361*deltaInv^3Polynomial coefficient
Reald534*deltaInv^4Polynomial coefficient
Reale-380*deltaInv^5Polynomial coefficient
Realf104*deltaInv^6Polynomial coefficient
Realx_der Abscissa value

Outputs

TypeNameDescription
Realy_derFunction value

Modelica definition

function der_inverseXRegularized "Derivative of inverseXRegularised function" extends Modelica.Icons.Function; input Real x "Abscissa value"; input Real delta(min=Modelica.Constants.eps) "Abscissa value below which approximation occurs"; input Real deltaInv = 1/delta "Inverse value of delta"; input Real a = -15*deltaInv "Polynomial coefficient"; input Real b = 119*deltaInv^2 "Polynomial coefficient"; input Real c = -361*deltaInv^3 "Polynomial coefficient"; input Real d = 534*deltaInv^4 "Polynomial coefficient"; input Real e = -380*deltaInv^5 "Polynomial coefficient"; input Real f = 104*deltaInv^6 "Polynomial coefficient"; input Real x_der "Abscissa value"; output Real y_der "Function value"; algorithm y_der :=if (x > delta or x < -delta) then -x_der/x/x elseif (x < delta/2 and x > -delta/2) then x_der/(delta*delta) else Buildings.Utilities.Math.Functions.BaseClasses.der_smoothTransition( x=x, x_der=x_der, delta=delta, deltaInv=deltaInv, a=a, b=b, c=c, d=d, e=e, f=f); end der_inverseXRegularized;

Buildings.Utilities.Math.Functions.BaseClasses.der_regNonZeroPower Buildings.Utilities.Math.Functions.BaseClasses.der_regNonZeroPower

Power function, regularized near zero, but nonzero value for x=0

Information

Implementation of the first derivative of the function Buildings.Utilities.Math.Functions.regNonZeroPower.

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

Inputs

TypeNameDefaultDescription
Realx Abscissa value
Realn Exponent
Realdelta0.01Abscissa value where transition occurs
Realder_x  

Outputs

TypeNameDescription
Realder_yFunction value

Modelica definition

function der_regNonZeroPower "Power function, regularized near zero, but nonzero value for x=0" annotation(derivative=der_2_regNonZeroPower); extends Modelica.Icons.Function; input Real x "Abscissa value"; input Real n "Exponent"; input Real delta = 0.01 "Abscissa value where transition occurs"; input Real der_x; output Real der_y "Function value"; protected Real a1; Real a3; Real delta2; Real x2; Real y_d "=y(delta)"; Real yP_d "=dy(delta)/dx"; Real yPP_d "=d^2y(delta)/dx^2"; algorithm if abs(x) > delta then der_y := sign(x)*n*abs(x)^(n-1)*der_x; else delta2 :=delta*delta; x2 :=x*x; y_d :=delta^n; yP_d :=n*delta^(n - 1); yPP_d :=n*(n - 1)*delta^(n - 2); a1 := -(yP_d/delta - yPP_d)/delta2/8; a3 := (yPP_d - 12 * a1 * delta2)/2; der_y := x * ( 4 * a1 * x * x + 2 * a3) * der_x; end if; end der_regNonZeroPower;

Buildings.Utilities.Math.Functions.BaseClasses.der_smoothTransition Buildings.Utilities.Math.Functions.BaseClasses.der_smoothTransition

First order derivative of smoothTransition with respect to x

Information

This function is the 1st order derivative of Buildings.Utilities.Math.Functions.BaseClasses.smoothTransition.

Implementation

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. Also, its derivative is provided in Buildings.Utilities.Math.Functions.BaseClasses.der_2__smoothTransition.

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

Inputs

TypeNameDefaultDescription
Realx Abscissa value
Realdeltadelta(min=Modelica.Constants...Abscissa value below which approximation occurs
RealdeltaInv Inverse value of delta
Reala Polynomial coefficient
Realb Polynomial coefficient
Realc Polynomial coefficient
Reald Polynomial coefficient
Reale Polynomial coefficient
Realf Polynomial coefficient
Realx_der Derivative of x

Outputs

TypeNameDescription
Realy_derDerivative of function value

Modelica definition

function der_smoothTransition "First order derivative of smoothTransition with respect to x" annotation(derivative=Buildings.Utilities.Math.Functions.BaseClasses.der_2_smoothTransition); extends Modelica.Icons.Function; input Real x "Abscissa value"; input Real delta(min=Modelica.Constants.eps) "Abscissa value below which approximation occurs"; input Real deltaInv "Inverse value of delta"; input Real a "Polynomial coefficient"; input Real b "Polynomial coefficient"; input Real c "Polynomial coefficient"; input Real d "Polynomial coefficient"; input Real e "Polynomial coefficient"; input Real f "Polynomial coefficient"; input Real x_der "Derivative of x"; output Real y_der "Derivative of function value"; protected Real aX "Absolute value of x"; algorithm aX:= abs(x); y_der := (b + aX*(2*c + aX*(3*d + aX*(4*e + aX*5*f))))*x_der; end der_smoothTransition;

Buildings.Utilities.Math.Functions.BaseClasses.der_spliceFunction Buildings.Utilities.Math.Functions.BaseClasses.der_spliceFunction

Derivative of splice function

Information

Implementation of the first derivative of the function Buildings.Utilities.Math.Functions.spliceFunction.

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

Inputs

TypeNameDefaultDescription
Realpos  
Realneg  
Realx  
Realdeltax1 
Realdpos  
Realdneg  
Realdx  
Realddeltax0 

Outputs

TypeNameDescription
Realout 

Modelica definition

function der_spliceFunction "Derivative of splice function" extends Modelica.Icons.Function; input Real pos; input Real neg; input Real x; input Real deltax=1; input Real dpos; input Real dneg; input Real dx; input Real ddeltax=0; output Real out; protected Real scaledX; Real scaledX1; Real dscaledX1; Real y; constant Real asin1 = Modelica.Math.asin(1); algorithm scaledX1 := x/deltax; if scaledX1 <= -0.99999999999 then out := dneg; elseif scaledX1 >= 0.9999999999 then out := dpos; else scaledX := scaledX1*asin1; dscaledX1 := (dx - scaledX1*ddeltax)/deltax; y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX)) + 1)/2; out := dpos*y + (1 - y)*dneg; out := out + (pos - neg)*dscaledX1*asin1/2/( Modelica.Math.cosh(Modelica.Math.tan(scaledX))*Modelica.Math.cos( scaledX))^2; end if; end der_spliceFunction;

Buildings.Utilities.Math.Functions.BaseClasses.smoothTransition Buildings.Utilities.Math.Functions.BaseClasses.smoothTransition

Twice continuously differentiable transition between the regions

Information

This function is used by Buildings.Utilities.Math.Functions.inverseXRegularized to provide a twice continuously differentiable transition between the different regions. The code has been implemented in a function as this allows to implement the function Buildings.Utilities.Math.Functions.inverseXRegularized in such a way that Dymola inlines it. However, this function will not be inlined as its body is too large.

Implementation

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. Also, derivatives are provided in Buildings.Utilities.Math.Functions.BaseClasses.der_smoothTransition and in Buildings.Utilities.Math.Functions.BaseClasses.der_2__smoothTransition.

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

Inputs

TypeNameDefaultDescription
Realx Abscissa value
Realdeltadelta(min=Modelica.Constants...Abscissa value below which approximation occurs
RealdeltaInv1/deltaInverse value of delta
Reala-15*deltaInvPolynomial coefficient
Realb119*deltaInv^2Polynomial coefficient
Realc-361*deltaInv^3Polynomial coefficient
Reald534*deltaInv^4Polynomial coefficient
Reale-380*deltaInv^5Polynomial coefficient
Realf104*deltaInv^6Polynomial coefficient

Outputs

TypeNameDescription
RealyFunction value

Modelica definition

function smoothTransition "Twice continuously differentiable transition between the regions" annotation(derivative=Buildings.Utilities.Math.Functions.BaseClasses.der_smoothTransition); extends Modelica.Icons.Function; // The function that transitions between the regions is implemented // using its own function. This allows Dymola 2016 to inline the function // inverseXRegularized. input Real x "Abscissa value"; input Real delta(min=Modelica.Constants.eps) "Abscissa value below which approximation occurs"; input Real deltaInv = 1/delta "Inverse value of delta"; input Real a = -15*deltaInv "Polynomial coefficient"; input Real b = 119*deltaInv^2 "Polynomial coefficient"; input Real c = -361*deltaInv^3 "Polynomial coefficient"; input Real d = 534*deltaInv^4 "Polynomial coefficient"; input Real e = -380*deltaInv^5 "Polynomial coefficient"; input Real f = 104*deltaInv^6 "Polynomial coefficient"; output Real y "Function value"; protected Real aX "Absolute value of x"; algorithm aX:= abs(x); y := (if x >= 0 then 1 else -1) * (a + aX*(b + aX*(c + aX*(d + aX*(e + aX*f))))); end smoothTransition;