Open TManikantan opened 1 year ago
Also read https://github.com/modelica/ModelicaStandardLibrary/issues/3758#issuecomment-1513765997 by @beutlich
Also read #3758 (comment) by @beutlich
I agree that there is something there, but I also realized a simple fix, that both seems to work and make sense. After computing xi2 add:
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;
else
...
end if;
Do we looker deeper into this issue for this milestone or different milestone ?as we have already found a working solution.
I guess this has lower priority now. I would fix other pending issues first.
This MWE replicates the problem with
regFun3()
at the point were the mass flow rate function jumps:Since
x
is very close tox1
, one would expecty
to be very close toy1 = 0.0015270174250288026
. Instead one getsy = 0.00137275
.What I understand is that the derivative
yd1
is very, very close to(y1-y0)/(x1-x0)
, while the derivativeyd0
is slightly larger. I can replicate the issue with round figures:Variable
y
should go fromy0
toy1
, and quite obviously it doesn't do that.Bottom line:
regFun3()
is numerically ill-conditioned when the two supplied derivatives are very close to the slope of the curve connecting the two points. I'm not sure whether this is inherent to the algorithm by Gasparo and Morandi or if it is just @sielemann's implementation that has some glitch in those conditions.At this point this is no longer a Fluid issue, but a plain old computer science problem, so I gladly hand it over to someone else who's more competent than I am. @sielemann, @gkurzbach, @beutlich any suggestion? @hubertus65 do you think Michael would be interested at plunging back into this problem?
Originally posted by @casella in https://github.com/modelica/ModelicaStandardLibrary/issues/3758#issuecomment-1513468578