From 9c1f0d413af7b79af84bd5f5bf6b72cde2ac7a3a Mon Sep 17 00:00:00 2001 From: thorade Date: Tue, 27 Sep 2022 08:46:52 +0200 Subject: [PATCH 1/3] der_spliceFunction check limits this is a follow-up for #1531 and #1532 there are two if-conditions that used a different value: 1 versus 0.9999999999 this PR makes sure the identical limit is used in spliceFunction and corresponding derivative --- .../Math/Functions/BaseClasses/der_spliceFunction.mo | 7 ++++--- IBPSA/Utilities/Math/Functions/spliceFunction.mo | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo b/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo index 663c337b6b..911fb99ac0 100644 --- a/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo +++ b/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo @@ -11,6 +11,7 @@ function der_spliceFunction "Derivative of splice function" input Real ddeltax=0; output Real out; protected + constant Real lim = 0.9999999999 "Limit in criterion for smoothing range"; Real scaledX1 "x scaled to -1 ... 1 interval"; Real scaledXp "x scaled to -pi/2 ... pi/2 interval"; Real scaledXt "x scaled to -inf ... inf interval"; @@ -18,9 +19,9 @@ protected Real y; algorithm scaledX1 := x/deltax; - if scaledX1 <= -0.9999999999 then + if scaledX1 <= -lim then y := 0.0; - elseif scaledX1 >= 0.9999999999 then + elseif scaledX1 >= lim then y := 1.0; else scaledXp := scaledX1*0.5*Modelica.Constants.pi; @@ -29,7 +30,7 @@ algorithm end if; out := dpos*y + (1 - y)*dneg; - if (abs(scaledX1) < 1) then + if (abs(scaledX1) < lim) then dscaledX1 := (dx - scaledX1*ddeltax)/deltax; out := out + (pos - neg)*dscaledX1*0.25*Modelica.Constants.pi*(1 - Modelica.Math.tanh(scaledXt)^2)*(scaledXt^2 + 1); end if; diff --git a/IBPSA/Utilities/Math/Functions/spliceFunction.mo b/IBPSA/Utilities/Math/Functions/spliceFunction.mo index 03f188a05f..8e039b15d3 100644 --- a/IBPSA/Utilities/Math/Functions/spliceFunction.mo +++ b/IBPSA/Utilities/Math/Functions/spliceFunction.mo @@ -7,14 +7,15 @@ function spliceFunction input Real deltax "Half width of transition interval"; output Real out "Smoothed value"; protected + constant Real lim = 0.9999999999; Real scaledX1; Real y; constant Real asin1 = Modelica.Math.asin(1); algorithm scaledX1 := x/deltax; - if scaledX1 <= -0.999999999 then + if scaledX1 <= -lim then out := neg; - elseif scaledX1 >= 0.999999999 then + elseif scaledX1 >= lim then out := pos; else y := (Modelica.Math.tanh(Modelica.Math.tan(scaledX1*asin1)) + 1)/2; From 2a26f28b231ddfa8cc04e5ead26b9fe5f40b8bce Mon Sep 17 00:00:00 2001 From: Michael Wetter Date: Tue, 27 Sep 2022 10:39:35 -0700 Subject: [PATCH 2/3] Updated revision notes. --- .../Math/Functions/BaseClasses/der_spliceFunction.mo | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo b/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo index 911fb99ac0..68cbd9cd33 100644 --- a/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo +++ b/IBPSA/Utilities/Math/Functions/BaseClasses/der_spliceFunction.mo @@ -48,6 +48,11 @@ IBPSA.Utilities.Math.Functions.spliceFunction. revisions="