This package contains examples for the use of models that can be found in Buildings.Utilities.Math.Functions.
Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).
| Name | Description |
|---|---|
| Test problem for function that replaces 1/x around the origin by a twice continuously differentiable function | |
| Test problem for function that linearizes y=x^n below some threshold | |
Buildings.Utilities.Math.Functions.Examples.InverseXRegularized
| Type | Name | Default | Description |
|---|---|---|---|
| Real | delta | 0.5 | Small value for approximation |
model InverseXRegularized "Test problem for function that replaces 1/x around the origin by a twice continuously differentiable function" extends Modelica.Icons.Example; Real x "Indepedent variable"; parameter Real delta = 0.5 "Small value for approximation"; Real y "Function value"; Real xInv "Function value"; equation x=2*time-1; xInv = if ( abs(x) > 0.1) then 1 / x else 0; y = Buildings.Utilities.Math.Functions.inverseXRegularized(x=x, delta=delta);end InverseXRegularized;
Buildings.Utilities.Math.Functions.Examples.PolynomialDerivativeCheckThis example checks whether the function derivative is implemented correctly. If the derivative implementation is incorrect, the model will stop with an assert statement.
Extends from Modelica.Icons.Example (Icon for runnable examples).
model PolynomialDerivativeCheck
extends Modelica.Icons.Example;
Real x;
Real y;
initial equation
y=x;
equation
x=Buildings.Utilities.Math.Functions.polynomial(x=time-2, a={2, 4, -4, 5});
der(y)=der(x);
// Trigger an error if the derivative implementation is incorrect.
assert(abs(x-y) < 1E-2, "Model has an error.");
end PolynomialDerivativeCheck;
Buildings.Utilities.Math.Functions.Examples.PowerLinearized
model PowerLinearized "Test problem for function that linearizes y=x^n below some threshold" extends Modelica.Icons.Example; Real T4(start=300^4) "Temperature raised to 4-th power"; Real T "Temperature"; Real TExact "Temperature"; equation T = (1+500*time); T = Buildings.Utilities.Math.Functions.powerLinearized(x=T4, x0=243.15^4, n=0.25); TExact = abs(T4)^(1/4);end PowerLinearized;
Buildings.Utilities.Math.Functions.Examples.RegNonZeroPower
model RegNonZeroPower
extends Modelica.Icons.Example;
Real y "Function value";
equation
y=Buildings.Utilities.Math.Functions.regNonZeroPower(
time, 0.3, 0.5);
end RegNonZeroPower;
Buildings.Utilities.Math.Functions.Examples.RegNonZeroPowerDerivative_2_CheckThis example checks whether the function derivative is implemented correctly. If the derivative implementation is not correct, the model will stop with an assert statement.
Extends from Modelica.Icons.Example (Icon for runnable examples).
| Type | Name | Default | Description |
|---|---|---|---|
| Real | n | 0.33 | Exponent |
| Real | delta | 0.1 | Abscissa value where transition occurs |
model RegNonZeroPowerDerivative_2_Check
extends Modelica.Icons.Example;
parameter Real n=0.33 "Exponent";
parameter Real delta = 0.1 "Abscissa value where transition occurs";
Real x;
Real y;
initial equation
y=x;
equation
x=Buildings.Utilities.Math.Functions.BaseClasses.der_regNonZeroPower(
time,n, delta, time);
der(y)=der(x);
assert(abs(x-y) < 1E-2, "Model has an error");
end RegNonZeroPowerDerivative_2_Check;
Buildings.Utilities.Math.Functions.Examples.RegNonZeroPowerDerivativeCheckThis example checks whether the function derivative is implemented correctly. If the derivative implementation is not correct, the model will stop with an assert statement.
Extends from Modelica.Icons.Example (Icon for runnable examples).
| Type | Name | Default | Description |
|---|---|---|---|
| Real | n | 0.33 | Exponent |
| Real | delta | 0.1 | Abscissa value where transition occurs |
model RegNonZeroPowerDerivativeCheck
extends Modelica.Icons.Example;
parameter Real n=0.33 "Exponent";
parameter Real delta = 0.1 "Abscissa value where transition occurs";
Real x;
Real y;
initial equation
y=x;
equation
x=Buildings.Utilities.Math.Functions.regNonZeroPower(
time,n, delta);
der(y)=der(x);
assert(abs(x-y) < 1E-2, "Model has an error");
end RegNonZeroPowerDerivativeCheck;
Buildings.Utilities.Math.Functions.Examples.SmoothExponentialDerivativeCheckThis example checks whether the function derivative is implemented correctly. If the derivative implementation is not correct, the model will stop with an assert statement.
Extends from Modelica.Icons.Example (Icon for runnable examples).
model SmoothExponentialDerivativeCheck
extends Modelica.Icons.Example;
Real x;
Real y;
Real ex "exact function value";
initial equation
y=x;
equation
x=Buildings.Utilities.Math.Functions.smoothExponential(
x=time-2, delta=0.5);
der(y)=der(x);
assert(abs(x-y) < 1E-2, "Model has an error");
ex=exp(-abs(time-2));
end SmoothExponentialDerivativeCheck;
Buildings.Utilities.Math.Functions.Examples.SpliceFunction
model SpliceFunction
extends Modelica.Icons.Example;
Real y "Function value";
equation
y=Buildings.Utilities.Math.Functions.spliceFunction(
pos=10, neg=-10, x=time-0.4, deltax=0.2);
end SpliceFunction;
Buildings.Utilities.Math.Functions.Examples.SpliceFunctionDerivativeCheckThis example checks whether the function derivative is implemented correctly. If the derivative implementation is not correct, the model will stop with an assert statement.
Extends from Modelica.Icons.Example (Icon for runnable examples).
model SpliceFunctionDerivativeCheck
extends Modelica.Icons.Example;
Real x;
Real y;
initial equation
y=x;
equation
x=Buildings.Utilities.Math.Functions.spliceFunction(
10, -10, time+0.1, 0.2);
der(y)=der(x);
assert(abs(x-y) < 1E-2, "Model has an error");
end SpliceFunctionDerivativeCheck;