Skip to content

Commit

Permalink
Merge pull request #101 from UdK-VPT/smoothMin
Browse files Browse the repository at this point in the history
refactor softcut_upper
  • Loading branch information
nytschgeusen authored Mar 23, 2018
2 parents a2d1494 + 69e27d9 commit 7b2a76c
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions BuildingSystems/Utilities/SmoothFunctions/softcut_upper.mo
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 7b2a76c

Please sign in to comment.