Ignore:
Timestamp:
01/16/13 16:00:28 (11 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Rewrite implementations for locator and interpolator.
Documentation (doxygen format) is added to header files.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/CubicSplineInterpolator1D.cpp

    r2727 r2730  
    3232}
    3333
     34void CubicSplineInterpolator1D::setData(double *x, float *y, unsigned int n)
     35{
     36  Interpolator1D::setData(x, y, n);
     37  reusable_ = false;
     38}
     39
    3440void CubicSplineInterpolator1D::setY(float *y, unsigned int n)
    3541{
     
    5662  // determine second derivative of each point
    5763  if (!reusable_) {
    58     spline();
     64    evaly2();
    5965    reusable_ = true;
    6066  }
    6167
    6268  // cubic spline interpolation
    63   float y = splint(x, i);
     69  float y = dospline(x, i);
    6470  return y;
    6571}
    6672
    67 void CubicSplineInterpolator1D::spline()
     73void CubicSplineInterpolator1D::evaly2()
    6874{
    6975  if (n_ > ny2_) {
     
    7581
    7682  float *u = new float[ny2_-1];
     83
     84  // Natural cubic spline.
    7785  y2_[0] = 0.0;
     86  y2_[ny2_-1] = 0.0;
    7887  u[0] = 0.0;
    7988
     89  // Solve tridiagonal system.
     90  // Here, tridiagonal matrix is decomposed to triangular matrix
     91  // u stores upper triangular components while y2_ stores
     92  // right-hand side vector.
     93  double a1 = x_[1] - x_[0];
     94  double a2, bi;
    8095  for (unsigned int i = 1; i < ny2_ - 1; i++) {
    81     double sig = (x_[i] - x_[i-1]) / (x_[i+1] - x_[i-1]);
    82     double p = sig * y2_[i-1] + 2.0;
    83     y2_[i] = (sig - 1.0) / p;
    84     u[i] = (y_[i+1] - y_[i]) / (x_[i+1] - x_[i])
    85       - (y_[i] - y_[i-1]) / (x_[i] - x_[i-1]);
    86     u[i] = (6.0 * u[i] / (x_[i+1] - x_[i-1]) - sig * u[i-1]) / p;
     96    a2 = x_[i+1] - x_[i];
     97    bi = 1.0 / (x_[i+1] - x_[i-1]);
     98    y2_[i] = 3.0 * bi * ((y_[i+1] - y_[i]) / a2 - (y_[i] - y_[i-1]) / a1
     99                         - y2_[i-1] * 0.5 * a1);
     100    a1 = 1.0 / (1.0 - u[i-1] * 0.5 * a1 * bi);
     101    y2_[i] *= a1;
     102    u[i] = 0.5 * a2 * bi * a1;
     103    a1 = a2;
    87104  }
    88 
    89   y2_[ny2_-1] = 0.0;
    90 
     105 
     106  // Then, solve the system by backsubstitution and store solution
     107  // vector to y2_.
    91108  for (int k = ny2_ - 2; k >= 0; k--)
    92     y2_[k] = y2_[k] * y2_[k+1] + u[k];
     109    y2_[k] -= u[k] * y2_[k+1];
    93110
    94111  delete[] u;
    95112}
    96113
    97 float CubicSplineInterpolator1D::splint(double x, unsigned int i)
     114float CubicSplineInterpolator1D::dospline(double x, unsigned int i)
    98115{
    99116  unsigned int j = i - 1;
Note: See TracChangeset for help on using the changeset viewer.