MPC::~MPC() { if (VlongSpline) destroy_Bspline(VlongSpline); if (DensitySpline) destroy_Bspline(DensitySpline); }
void TestNUB_3d_d() { int Mx=20, My=27, Mz=23; NUgrid *x_grid = create_center_grid (-3.0, 4.0, 7.5, Mx); NUgrid *y_grid = create_center_grid (-1.0, 9.0, 3.5, My); NUgrid *z_grid = create_center_grid (-1.8, 2.0, 2.8, Mz); double data[Mx*My*Mz]; for (int ix=0; ix<Mx; ix++) for (int iy=0; iy<My; iy++) for (int iz=0; iz<Mz; iz++) data[(ix*My+iy)*Mz+iz] = -1.0+2.0*drand48(); BCtype_d xBC, yBC, zBC; // xBC.lCode = PERIODIC; // yBC.lCode = PERIODIC; xBC.lCode = PERIODIC; xBC.rCode = PERIODIC; yBC.lCode = PERIODIC; yBC.rCode = PERIODIC; zBC.lCode = PERIODIC; zBC.rCode = PERIODIC; NUBspline_3d_d *spline = create_NUBspline_3d_d (x_grid, y_grid, z_grid, xBC, yBC, zBC, data); int xFine = 200, yFine = 200, zFine=200; FILE *fout = fopen ("3d_d.dat", "w"); double xi = x_grid->start; double xf = x_grid->end; double yi = y_grid->start; double yf = y_grid->end; double zi = z_grid->start; double zf = z_grid->end; for (int ix=0; ix<xFine; ix++) { double x = xi+ (double)ix/(double)(xFine)*(xf-xi); for (int iy=0; iy<yFine; iy++) { double y = yi + (double)iy/(double)(yFine)*(yf-yi); for (int iz=0; iz<zFine; iz++) { double z = zi + (double)iz/(double)(zFine)*(zf-zi); double val, grad[3], hess[9]; eval_NUBspline_3d_d_vgh (spline, x, y, z, &val, grad, hess); fprintf (fout, "%1.16e ", val); } } fprintf (fout, "\n"); } fclose (fout); fprintf (stderr, "spline->sp_code = %d\n", spline->sp_code); destroy_Bspline (spline); }
int main (int argc, char* argv[]) { int nz, nx, ny, ic, nc; float dz, oz, dx, ox, dy, oy; size_t i, n, sz; float *buf = NULL, *buf2 = NULL; #ifdef HAVE_SSE unsigned char pad[64]; #endif sf_file velz, velx = NULL, theta = NULL, phi = NULL, eta = NULL, out; bool verb; Ugrid z_grid, x_grid, y_grid; BCtype_s zBC, xBC, yBC; multi_UBspline_3d_s *velspline = NULL; sf_init (argc, argv); velz = sf_input ("in"); /* Vertical velocity */ out = sf_output ("out"); /* Spline coefficients */ /* Spatial dimensions */ if (!sf_histint (velz, "n1", &nz)) sf_error ("No n1= in input"); if (!sf_histint (velz, "n2", &nx)) sf_error ("No n2= in input"); if (!sf_histint (velz, "n3", &ny)) sf_error ("No n3= in input"); if (!sf_histfloat (velz, "d1", &dz)) sf_error ("No d1= in input"); if (!sf_histfloat (velz, "o1", &oz)) oz = 0.0; if (!sf_histfloat (velz, "d2", &dx)) sf_error ("No d2= in input"); if (!sf_histfloat (velz, "o2", &ox)) ox = 0.0; if (!sf_histfloat (velz, "d3", &dy)) sf_error ("No d3= in input"); if (!sf_histfloat (velz, "o3", &oy)) oy = 0.0; if (!sf_getbool ("verb", &verb)) verb = false; /* verbosity flag */ n = (size_t)nz*(size_t)nx*(size_t)ny; buf = sf_floatalloc (n); nc = 1; if (sf_getstring ("vx")) { /* Horizontal velocity */ velx = sf_input ("vx"); nc++; } if (sf_getstring ("eta")) { /* Anellipticity */ if (NULL == velx) sf_error ("Need vx=, if eta= is given"); eta = sf_input ("eta"); nc++; } else if (velx) sf_error ("Need eta=, if vx= is given"); if (sf_getstring ("theta")) { /* Tilt angle elevation */ if (NULL == velx) sf_error ("Need vx=, if theta= is given"); theta = sf_input ("theta"); nc++; } if (sf_getstring ("phi")) { /* Tilt angle azimuth */ if (NULL == theta) sf_error ("Need theta=, if phi= is given"); phi = sf_input ("phi"); nc++; } z_grid.start = oz; z_grid.end = oz + (nz - 1)*dz; z_grid.num = nz; x_grid.start = ox; x_grid.end = ox + (nx - 1)*dx; x_grid.num = nx; y_grid.start = oy; y_grid.end = oy + (ny - 1)*dy; y_grid.num = ny; zBC.lCode = zBC.rCode = NATURAL; xBC.lCode = xBC.rCode = NATURAL; yBC.lCode = yBC.rCode = NATURAL; velspline = create_multi_UBspline_3d_s (y_grid, x_grid, z_grid, yBC, xBC, zBC, nc); /* Read data and compute spline coefficients */ if (verb) sf_warning ("Processing V_z"); sf_floatread (buf, n, velz); if (1 == nc) { /* Isotropic case - convert velocity to slowness */ if (verb) sf_warning ("Converting to slowness for isotropic case"); for (i = 0; i < n; i++) buf[i] = 1.0/buf[i]; } else { /* Convert to V_z^2 */ for (i = 0; i < n; i++) buf[i] *= buf[i]; } ic = 0; set_multi_UBspline_3d_s (velspline, ic, buf); ic++; if (velx) { if (verb) sf_warning ("Processing V_x"); buf2 = sf_floatalloc (n); sf_floatread (buf2, n, velx); sf_fileclose (velx); /* Convert to V_x^2 */ for (i = 0; i < n; i++) buf2[i] *= buf2[i]; set_multi_UBspline_3d_s (velspline, ic, buf2); ic++; /* Convert to (V_z*V_x)^2 */ for (i = 0; i < n; i++) buf[i] *= buf2[i]; } if (eta) { if (verb) sf_warning ("Processing Eta"); sf_floatread (buf2, n, eta); sf_fileclose (eta); /* Convert to -8*eta/(1 + 2*eta)*(V_z*V_x)^2 */ for (i = 0; i < n; i++) { buf2[i] = -8.0*buf2[i]/(1.0 + 2.0*buf2[i]); buf2[i] *= buf[i]; } set_multi_UBspline_3d_s (velspline, ic, buf2); ic++; } if (theta) { if (verb) sf_warning ("Processing Theta"); sf_floatread (buf, n, theta); sf_fileclose (theta); /* Convert to radians */ for (i = 0; i < n; i++) buf[i] = buf[i]*SF_PI/180.0; set_multi_UBspline_3d_s (velspline, ic, buf); ic++; } if (phi) { if (verb) sf_warning ("Processing Phi"); sf_floatread (buf, n, phi); sf_fileclose (phi); /* Convert to radians */ for (i = 0; i < n; i++) buf[i] = buf[i]*SF_PI/180.0; set_multi_UBspline_3d_s (velspline, ic, buf); ic++; } if (buf2) free (buf2); free (buf); sz = (size_t)sizeof(multi_UBspline_3d_s) + (size_t)velspline->nc; #ifdef HAVE_SSE if (sizeof(multi_UBspline_3d_s) % 64) sz += 64 - (sizeof(multi_UBspline_3d_s) % 64); #endif /* Make output a 1-D file of coefficients */ sf_unshiftdim2 (velz, out, 1); /* Set up output */ sf_settype (out, SF_UCHAR); sf_putlargeint (out, "n1", sz); sf_putfloat (out, "o1", 0.0); sf_putfloat (out, "d1", 1.0); sf_putstring (out, "label1", "Spline coefficients"); sf_putstring (out, "unit1", ""); sf_putstring (out, "label2", ""); sf_putstring (out, "unit2", ""); sf_putint (out, "Nz", nz); sf_putfloat (out, "Oz", oz); sf_putfloat (out, "Dz", dz); sf_putint (out, "Nx", nx); sf_putfloat (out, "Ox", ox); sf_putfloat (out, "Dx", dx); sf_putint (out, "Ny", ny); sf_putfloat (out, "Oy", oy); sf_putfloat (out, "Dy", dy); sf_putint (out, "Nc", nc); sf_putstring (out, "splines", "y"); if (verb) { sf_warning ("Number of spline coefficients: %lu", velspline->nc/(size_t)sizeof(float)); sf_warning ("Writing spline coefficients"); } sf_ucharwrite ((unsigned char*)velspline, (size_t)sizeof(multi_UBspline_3d_s), out); #ifdef HAVE_SSE if (sizeof(multi_UBspline_3d_s) % 64) sf_ucharwrite (pad, (size_t)(64 - (sizeof(multi_UBspline_3d_s) % 64)), out); #endif sf_ucharwrite ((unsigned char*)velspline->coefs, (size_t)velspline->nc, out); destroy_Bspline (velspline); return 0; }
static void destroy(interpT *spline){ destroy_Bspline(spline->spline); delete spline; spline=NULL; }
VHXC::~VHXC() { if (VSpline) destroy_Bspline(VSpline); }
KisBSpline2D::~KisBSpline2D() { if (m_d->spline) { destroy_Bspline(m_d->spline); } }