Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4312 #4522

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions Modelica/Fluid/Utilities.mo
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ for a smooth transition from y1 to y2.
c := 0.1*Delta0;
end if;
theta0 := (y0d*mu + y1d*eta)/h0;
if abs(theta0 - c) < 1e-6 then
if abs(theta0 - c) < 1e-6*abs(c) then
// Slightly reduce c in order to avoid ill-posed problem
c := (1 - 1e-6)*theta0;
end if;
Expand All @@ -700,22 +700,18 @@ for a smooth transition from y1 to y2.
eta_tilde := rho*eta;
xi1 := x0 + mu_tilde;
xi2 := x1 - eta_tilde;
if xi1 < x0 or xi2>x1 then
// The limits don't make sense, just use linear interpolation
y := (y1-y0)*(x-x0)/(x1-x0) + y0;

a1 := (y0d - c)/max(mu_tilde^2, 100*Modelica.Constants.eps);
a2 := (y1d - c)/max(eta_tilde^2, 100*Modelica.Constants.eps);
const12 := y0 - a1/3*(x0 - xi1)^3 - c*x0;
const3 := y1 - a2/3*(x1 - xi2)^3 - c*x1;
// Do actual interpolation
if (x < xi1) then
y := a1/3*(x - xi1)^3 + c*x + const12;
elseif (x < xi2) then
y := c*x + const12;
else
a1 := (y0d - c)/max(mu_tilde^2, 100*Modelica.Constants.eps);
a2 := (y1d - c)/max(eta_tilde^2, 100*Modelica.Constants.eps);
const12 := y0 - a1/3*(x0 - xi1)^3 - c*x0;
const3 := y1 - a2/3*(x1 - xi2)^3 - c*x1;
// Do actual interpolation
if (x < xi1) then
y := a1/3*(x - xi1)^3 + c*x + const12;
elseif (x < xi2) then
y := c*x + const12;
else
y := a2/3*(x - xi2)^3 + c*x + const3;
end if;
y := a2/3*(x - xi2)^3 + c*x + const3;
end if;
else
// Cubic S0 is monotonic, use it as is
Expand Down
Loading