From 69e27d93f290b677ca9b4b0b58f01cbc643d1c43 Mon Sep 17 00:00:00 2001 From: thorade Date: Fri, 10 Nov 2017 14:00:35 +0100 Subject: [PATCH] refactor this is for https://github.com/ibpsa/modelica-ibpsa/issues/169 also see https://github.com/xogeny/ModelicaBook/issues/338 --- .../SmoothFunctions/softcut_upper.mo | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/BuildingSystems/Utilities/SmoothFunctions/softcut_upper.mo b/BuildingSystems/Utilities/SmoothFunctions/softcut_upper.mo index 624ce2f6..90c8a504 100644 --- a/BuildingSystems/Utilities/SmoothFunctions/softcut_upper.mo +++ b/BuildingSystems/Utilities/SmoothFunctions/softcut_upper.mo @@ -4,20 +4,11 @@ function softcut_upper "Softly cuts to upper limit" input Real x_ulimit; input Real r; output Real y; -protected - Real x_start; - Real x_end; - Real help; - Real SQRT_TWO = 1.4142135624; + algorithm - x_start := x_ulimit - r * (1.0-1.0/SQRT_TWO); - x_end := x_start + r/SQRT_TWO; - if x <= x_start then - y := x; - elseif x >= x_end then - y := x_ulimit; - else - help := x_ulimit - x - r * (1.0 - SQRT_TWO); - y := x_ulimit - r + sqrt(r*r - help*help); - end if; + y := if x <= x_ulimit - r + r/sqrt(2) then x + elseif x >= x_ulimit - r + r*sqrt(2) then x_ulimit + else x_ulimit - r + sqrt(r^2 - (x_ulimit - x - r + r*sqrt(2))^2); + + annotation (Inline=true, smoothOrder=1); end softcut_upper;