Skip to content

Commit

Permalink
Stylize
Browse files Browse the repository at this point in the history
  • Loading branch information
ptranq committed Apr 25, 2024
1 parent a12a645 commit 706876b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
8 changes: 4 additions & 4 deletions lib/algo/manifold_interp/SnapshotInterpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Vector;

/**
* Implements PCHIP algorithm. Based on "A METHOD FOR CONSTRUCTING LOCAL MONOTONE
* PIECEWISE CUBIC INTERPOLANTS", Fritchs and Butland (1984). as well as "MONOTONE
* PIECEWISE CUBIC INTERPOLANTS", Fritchs and Butland (1984). as well as "MONOTONE
* PIECEWISE CUBIC INTERPOLATION," Fritsch and Carlson (1980)
*
*/
Expand All @@ -22,18 +22,18 @@ class SnapshotInterpolator
SnapshotInterpolator();
~SnapshotInterpolator();

std::vector<Vector*> interpolate(std::vector<Vector*> snapshot_ts,
std::vector<Vector*> interpolate(std::vector<Vector*> snapshot_ts,
std::vector<Vector*> snapshots,
std::vector<Vector*> output_ts);

std::vector<Vector*> interpolate(std::vector<Vector*> snapshot_ts,
std::vector<Vector*> interpolate(std::vector<Vector*> snapshot_ts,
std::vector<Vector*> snapshots,
int n_out,
std::vector<Vector*>* output_ts);

std::vector<Vector*> interpolate();



private:

Expand Down
46 changes: 25 additions & 21 deletions unit_tests/snapshot_interpolator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ int main(int argc, char *argv[])
//input times
vector<double> t{ 0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15};
//Test function from original PCHIP paper
vector<double> y{10, 10, 10, 10, 10, 10, 10.5, 15, 50, 60, 85};
vector<double> y{10, 10, 10, 10, 10, 10, 10.5, 15, 50, 60, 85};
//sin(x)
vector<double> y2{0, 0.909297426825682, 0.141120008059867, -0.958924274663138, -0.279415498198926,
0.989358246623382, 0.412118485241757, -0.999990206550703, -0.536572918000435,
0.990607355694870, 0.650287840157117};

//query points
vector<double> tq{0, 0.6000, 1.2000, 1.8000, 2.4000, 3.0000, 3.6000, 4.2000, 4.8000, 5.4000, 6.0000, 6.6000,
7.2000, 7.8000, 8.4000, 9.0000, 9.6000, 10.2000, 10.8000, 11.4000, 12.0000, 12.6000,
7.2000, 7.8000, 8.4000, 9.0000, 9.6000, 10.2000, 10.8000, 11.4000, 12.0000, 12.6000,
13.2000, 13.8000, 14.4000, 15.000};
//pchip reference solution for original test function.
vector<double> yq1{10.000000000000000, 10.000000000000000, 10.000000000000002, 10.000000000000004,
10.000000000000000, 10.000000000000000, 10.000000000000002, 10.000000000000000,
vector<double> yq1{10.000000000000000, 10.000000000000000, 10.000000000000002, 10.000000000000004,
10.000000000000000, 10.000000000000000, 10.000000000000002, 10.000000000000000,
10.000000000000004, 10.000000000000000, 10.000000000000000, 10.000000000000002,
10.000000000000000, 10.000000000000004, 10.102641509433962, 10.500000000000000,
11.106230625292378, 12.213163262123807, 14.128630750038976, 27.078413223140512,
Expand Down Expand Up @@ -83,25 +83,27 @@ int main(int argc, char *argv[])
}

SnapshotInterpolator* interp = new SnapshotInterpolator();

std::cout << "Beginning base interpolation function" << std::endl;
out_snapshots = interp->interpolate(times,snapshots,out_times);
std::cout << "Finished interpolation " << std::endl;
/*
for(int i = 0; i < out_snapshots.size(); ++i)
{
std::cout << "Time " << i << " is " << out_times[i]->item(0) << std::endl;
std::cout << "Reference at " << i << " is (" << reference_snapshots[i]->item(0) <<
"," << reference_snapshots[i]->item(1) << ")" << std::endl;
std::cout << "Snapshot interpolation at " << i << " is (" << out_snapshots[i]->item(0) <<
"," << out_snapshots[i]->item(1) << ")" << std::endl;
}
*/
/*
for(int i = 0; i < out_snapshots.size(); ++i)
{
std::cout << "Time " << i << " is " << out_times[i]->item(0) << std::endl;
std::cout << "Reference at " << i << " is (" << reference_snapshots[i]->item(0) <<
"," << reference_snapshots[i]->item(1) << ")" << std::endl;
std::cout << "Snapshot interpolation at " << i << " is (" << out_snapshots[i]->item(0) <<
"," << out_snapshots[i]->item(1) << ")" << std::endl;
}
*/
for(int i = 0; i < out_snapshots.size(); ++i)
{
std::cout << "Error at time[" << i << "] = " << out_times[i]->item(0) << " is (" <<
reference_snapshots[i]->item(0) - out_snapshots[i]->item(0) << ","
<< reference_snapshots[i]->item(1) - out_snapshots[i]->item(1) << ") " << std::endl;
std::cout << "Error at time[" << i << "] = " << out_times[i]->item(
0) << " is (" <<
reference_snapshots[i]->item(0) - out_snapshots[i]->item(0) << ","
<< reference_snapshots[i]->item(1) - out_snapshots[i]->item(
1) << ") " << std::endl;
}


Expand All @@ -111,8 +113,10 @@ int main(int argc, char *argv[])

for(int i = 0; i < out_snapshots.size(); ++i)
{
std::cout << "Error at time[" << i << "] = " << out_times[i]->item(0) << " is (" <<
reference_snapshots[i]->item(0) - out_snapshots[i]->item(0) << ","
<< reference_snapshots[i]->item(1) - out_snapshots[i]->item(1) << ") " << std::endl;
std::cout << "Error at time[" << i << "] = " << out_times[i]->item(
0) << " is (" <<
reference_snapshots[i]->item(0) - out_snapshots[i]->item(0) << ","
<< reference_snapshots[i]->item(1) - out_snapshots[i]->item(
1) << ") " << std::endl;
}
}

0 comments on commit 706876b

Please sign in to comment.