예제 #1
0
void splint2_a(double *ya, double *y,
                int n1, int n2, int ni1, int ni2)
{
    double      *x1a, *x2a, *xi1a, *xi2a;
    int         i;

    x1a = new double[n1];
    x2a = new double[n2];
    xi1a = new double[ni1];
    xi2a = new double[ni2];

    for(i=0; i<n1; i++)  x1a[i]  = i*1.0/(n1-1);
    for(i=0; i<n2; i++)  x2a[i]  = i*1.0/(n2-1);
    for(i=0; i<ni1; i++) xi1a[i] = i*1.0/(ni1-1);
    for(i=0; i<ni2; i++) xi2a[i] = i*1.0/(ni2-1);

    splint2(x1a, x2a, ya,
            xi1a, xi2a, y,
            n1, n2, ni1, ni2);

    delete [] x1a;
    delete [] x2a;
    delete [] xi1a;
    delete [] xi2a;
}
예제 #2
0
/******************************************************************************\
 * 3-D spline interpolation
 *
 * Parameters:
 *      x1a             [in] axis-1 coordinate (chage slowest)
 *      x2a             [in] axis-2 coordinate
 *      x3a             [in] axis-3 coordinate (change fast)
 *      ya              [in] values
 *      xi1a            [in] interpolate axis-1 coordinate
 *      xi2a            [in] interpolate axis-2 coordinate
 *      xi3a            [in] interpolate axis-3 coordinate
 *      y               [out] interpolated values
 *      n1              [in] data number in axis-1
 *      n2              [in] data number in axis-2
 *      n3              [in] data number in axis-3
 *      ni1             [in] data number in interpolated axis-1
 *      ni2             [in] data number in interpolated axis-2
 *      ni3             [in] data number in interpolated axis-3
\******************************************************************************/
void splint3(double *x1a, double *x2a, double *x3a, double *ya,
             double *xi1a, double *xi2a, double *xi3a, double *y,
             int n1, int n2, int n3, int ni1, int ni2, int ni3)
{
    int     i, j, k;
    double  *ytmp, *p1, *p2;
    double  *pp1, *pp2;
    int     omp_tn, omp_ti;

#ifdef HAVE_OPENMP
    omp_tn = omp_get_max_threads();
#else
    omp_tn = 1;
#endif

    // allocate buffer
    ytmp = new double[n1*ni2*ni3];
    p1   = new double[n1*omp_tn];
    p2   = new double[ni1*omp_tn];

    // interpolation in axis-2 and axis-3
#ifdef HAVE_OPENMP
    #pragma omp parallel for private(k)
#endif
    for (k=0; k<n1; k++) {
        splint2(x2a, x3a, ya+k*n2*n3,
                xi2a, xi3a, ytmp+k*ni2*ni3,
                n2, n3, ni2, ni3);
    }

    // interpolation in axis1
#ifdef HAVE_OPENMP
    #pragma omp parallel for private(i,j,k,pp1,pp2,omp_ti)
#endif
    for (i=0; i<ni3; i++) {
        for (j=0; j<ni2; j++) {
#ifdef HAVE_OPENMP
            omp_ti = omp_get_thread_num();
#else
            omp_ti = 0;
#endif
            pp1 = p1 + n1*omp_ti;
            pp2 = p2 + ni1*omp_ti;

            for (k=0; k<n1; k++)
                pp1[k] = ytmp[k*ni2*ni3 + j*ni3 + i];

            splint(x1a, pp1, xi1a, pp2, n1, ni1);

            for (k=0; k<ni1; k++)
                y[k*ni2*ni3 + j*ni3 + i] = pp2[k];
        }
    }

    // free temp buffer
    delete [] ytmp;
    delete [] p1;
    delete [] p2;
}
예제 #3
0
파일: gkernel.c 프로젝트: cran/Rwave
double gintegrand(double b,int x,int y,double *p2,double *nodes,
		   double *phi_nodes,int nb_nodes,double scale)

{
  double xpos,ypos,tmp,tmp2, phi_b,phip_b, u;
  double g_x,g_y,gprime_x,gprime_y;
  double integ=0;


  /* Spline interpolation of the ridge; computation of its derivative
     ---------------------------------------------------------------*/
  splint2(nodes,phi_nodes,p2,nb_nodes,b,&phi_b,&phip_b);


  /* Evaluation of the integrand
     --------------------------*/
  xpos = (x-b);
  g_x = gfunc(xpos,scale);
  gprime_x = gprime(xpos,scale);
  ypos = (y-b);
  g_y = gfunc(ypos,scale);
  gprime_y = gprime(ypos,scale);

  u = phi_b*(x-y);

  /* First part */

  tmp= (phip_b*phip_b*xpos*ypos - phi_b*phip_b*(xpos+ypos));
  tmp *= g_x*g_y;
  integ = tmp;

  tmp=gprime_x*gprime_y;
  integ += tmp;

  integ *= cos(u);

  /* Second part */

  tmp2 = phip_b*xpos -phi_b;
  tmp2 *= (gprime_y*g_x);

  tmp = phip_b*ypos -phi_b;
  tmp *= (gprime_x*g_y);
  tmp2 -= tmp;

  tmp2 *= sin(u);

  integ += tmp2;

  return integ;
}