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

Issue1840 interpolate not smooth #1841

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
within IBPSA.Airflow.Multizone.BaseClasses.Examples;
model Interpolate "Test model for the function flowElementData"
model Interpolate "Test model for the interpolation function"
extends Modelica.Icons.Example;

parameter Real table[:,:]=[-50,-0.08709; -25,-0.06158; -10,-0.03895; -5,-0.02754;
Expand Down
35 changes: 17 additions & 18 deletions IBPSA/Airflow/Multizone/BaseClasses/interpolate.mo
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,22 @@ algorithm
end if;
end for;

// Extrapolate or interpolate the data
if i == 1 then
z:=yd[1]+(u-xd[1])*(yd[2]-yd[1])/(xd[2]-xd[1]); //Interpolate linearly between first and second point
elseif i == (size(xd, 1) - 1) then
z:=yd[end-1]+(u-xd[end-1])*(yd[end]-yd[end-1])/(xd[end]-xd[end-1]); //Interpolate linearly between last and second-to-last point.
z :=IBPSA.Utilities.Math.Functions.cubicHermiteLinearExtrapolation(
x=u,
x1=xd[i],
x2=xd[i + 1],
y1=yd[i],
y2=yd[i + 1],
y1d=d[i],
y2d=d[i + 1]);

else
z :=IBPSA.Utilities.Math.Functions.cubicHermiteLinearExtrapolation(
x=u,
x1=xd[i],
x2=xd[i + 1],
y1=yd[i],
y2=yd[i + 1],
y1d=d[i],
y2d=d[i + 1]);
end if;

annotation (
annotation (smoothOrder = 1,
Documentation(info="<html>
<p>
This function returns the value on a cubic hermite spline through the given support points
and provided spline derivatives at these points with monotonically increasing values.
The last 2 points in the table are linearly interpolated.
Outside the provided support points, the function returns a linear extrapolation with
the same slope as the cubic spline has at the respective support point.
</p>
<p>
A similar model is also used in the CONTAM software (Dols and Walton, 2015).
Expand All @@ -67,6 +60,12 @@ National Institute of Standards and Technology, NIST TN 1887, Sep. 2015. doi:
</html>", revisions="<html>
<ul>
<li>
February 26, 2024, by Hongxiang Fu:<br/>
Correct implementation to make it smooth.<br/>
This is for
<a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1840\">IBPSA, #1840</a>.
</li>
<li>
February 2, 2022, by Michael Wetter:<br/>
Revised implementation.<br/>
This is for
Expand Down
Loading
Loading