Buildings.Utilities.Math

Library with functions such as for smoothing

Package Content

NameDescription
Buildings.Utilities.Math.BaseClasses BaseClasses Library with base classes for mathematical functions
Buildings.Utilities.Math.Examples Examples Collection of models that illustrate model use and test models
Buildings.Utilities.Math.regNonZeroPower regNonZeroPower Power function, regularized near zero, but nonzero value for x=0
Buildings.Utilities.Math.smoothExponential smoothExponential Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta
Buildings.Utilities.Math.SmoothMax SmoothMax Assert when condition is violated
Buildings.Utilities.Math.SmoothMin SmoothMin Assert when condition is violated
Buildings.Utilities.Math.spliceFunction spliceFunction  


Buildings.Utilities.Math.regNonZeroPower

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

Information


Function that approximates y=|x|^n where n>0 so that

This function replaces y=|x|^n in the interval -delta...+delta by a 4-th order polynomial that has the same function value, first and second derivative at x=+/-delta.

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 -delta...+delta may be interpreted as the region where heat conduction dominates convection in the boundary layer.

See the package Examples for the graph.


Inputs

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

Outputs

TypeNameDescription
RealyFunction value

Modelica definition

function regNonZeroPower 
  "Power function, regularized near zero, but nonzero value for x=0" 
  annotation(derivative=BaseClasses.der_regNonZeroPower);  
  
 input Real x "Abscissa value";
 input Real n "Exponent";
 input Real delta = 0.01 "Abscissa value where transition occurs";
 output Real y "Function value";
protected 
  Real a1;
  Real a3;
  Real a5;
  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
   y := abs(x)^n;
  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;
   a5 := (y_d - delta2 * (a3 + delta2 * a1));
   y := a5 + x2 * (a3 + x2 * a1);
   assert(a5>0, "delta is too small for this exponent n");
  end if;
end regNonZeroPower;

Buildings.Utilities.Math.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| < delta for some positive delta


Inputs

TypeNameDefaultDescription
Realx Input argument
Realdelta Transition point where approximation occurs

Outputs

TypeNameDescription
RealyOutput argument

Modelica definition

function smoothExponential 
  "Once continuously differentiable approximation to exp(-|x|) in interval |x| < delta" 
  
  
  input Real x "Input argument";
  input Real delta "Transition point where approximation occurs";
  output Real y "Output argument";
protected 
  Real absX "Absolute value of x";
  Real a2 "Coefficient for approximating function";
  Real a3 "Coefficient for approximating function";
  Real e;
  Real d2;
  Real x2;
algorithm 
  absX :=abs(x);
  if absX > delta then
    y :=  exp(-absX);
  else
    d2 := delta*delta;
    e  := exp(-delta);
    a2 := (delta*e-4*(1-e))/2/d2;
    a3 := (e-1-a2*d2)/d2/d2;
    x2 := x*x;
    y  := 1+x2*(a2+x2*a3);
  end if;
end smoothExponential;

Buildings.Utilities.Math.SmoothMax Buildings.Utilities.Math.SmoothMax

Assert when condition is violated

Buildings.Utilities.Math.SmoothMax

Information


Once continuously differentiable approximation to the max(.,.) function.


Parameters

TypeNameDefaultDescription
RealdeltaX Width of transition interval

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block SmoothMax "Assert when condition is violated" 
  extends Modelica.Blocks.Interfaces.SI2SO;
  Modelica.Blocks.Interfaces.RealOutput y "Connector of Real output signal";
 parameter Real deltaX "Width of transition interval";
equation 
  y = Buildings.Utilities.Math.spliceFunction(u1, u2, u1-u2, deltaX);
end SmoothMax;

Buildings.Utilities.Math.SmoothMin Buildings.Utilities.Math.SmoothMin

Assert when condition is violated

Buildings.Utilities.Math.SmoothMin

Information


Once continuously differentiable approximation to the max(.,.) function.


Parameters

TypeNameDefaultDescription
RealdeltaX Width of transition interval

Connectors

TypeNameDescription
input RealInputu1Connector of Real input signal 1
input RealInputu2Connector of Real input signal 2
output RealOutputyConnector of Real output signal

Modelica definition

block SmoothMin "Assert when condition is violated" 
  extends Modelica.Blocks.Interfaces.SI2SO;
  Modelica.Blocks.Interfaces.RealOutput y "Connector of Real output signal";
 parameter Real deltaX "Width of transition interval";
equation 
  y = Buildings.Utilities.Math.spliceFunction(u1, u2, u2-u1, deltaX);
end SmoothMin;

Buildings.Utilities.Math.spliceFunction

Information


Function to provide a once continuously differentialbe 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

TypeNameDefaultDescription
Realpos Argument of x > 0
Realneg Argument of x < 0
Realx Independent value
Realdeltax1Width of transition interval

Outputs

TypeNameDescription
RealoutSmoothed value

Modelica definition

function spliceFunction 
  annotation(derivative=BaseClasses.der_spliceFunction);  
    input Real pos "Argument of x > 0";
    input Real neg "Argument of x < 0";
    input Real x "Independent value";
    input Real deltax=1 "Width of transition interval";
    output Real out "Smoothed value";
protected 
    Real scaledX;
    Real scaledX1;
    Real y;
algorithm 
    scaledX1 := x/deltax;
    scaledX := scaledX1*Modelica.Math.asin(1);
    if scaledX1 <= -0.999999999 then
      y := 0;
    elseif scaledX1 >= 0.999999999 then
      y := 1;
    else
      y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX)) + 1)/2;
    end if;
    out := pos*y + (1 - y)*neg;
end spliceFunction;

HTML-documentation generated by Dymola Fri Oct 31 16:24:05 2008.