void ML_interp_check(ML *ml, int coarse_level, int fine_level) { int ii, jj, ncoarse, nfine; double *c_data, *f_data, coords[3], dtemp, d2, dlargest; ML_GridFunc *coarse_funs, *fine_funs; void *coarse_data, *fine_data; int nfine_eqn, ncoarse_eqn, stride = 1; /* check an interpolated linear function */ coarse_data = ml->SingleLevel[coarse_level].Grid->Grid; fine_data = ml->SingleLevel[ fine_level].Grid->Grid; coarse_funs = ml->SingleLevel[coarse_level].Grid->gridfcn; fine_funs = ml->SingleLevel[ fine_level].Grid->gridfcn; if ( (coarse_data==NULL)||(fine_data==NULL)) { printf("ML_interp_check: grid data not found?\n"); exit(1); } if ( (coarse_funs==NULL)||(fine_funs==NULL)) { printf("ML_interp_check: grid functions not found?\n"); exit(1); } if ( (coarse_funs->USR_grid_get_nvertices == 0) || ( fine_funs->USR_grid_get_nvertices == 0)) { printf("ML_interp_check: USR_grid_get_nvertices not found?\n"); exit(1); } ncoarse = coarse_funs->USR_grid_get_nvertices(coarse_data); nfine = fine_funs->USR_grid_get_nvertices( fine_data); nfine_eqn = ml->SingleLevel[coarse_level].Pmat->outvec_leng; ncoarse_eqn = ml->SingleLevel[coarse_level].Pmat->invec_leng; c_data = (double *) ML_allocate(ncoarse_eqn*sizeof(double)); f_data = (double *) ML_allocate(nfine_eqn*sizeof(double)); for (ii = 0; ii < ncoarse_eqn; ii++) c_data[ii] = 0.; for (ii = 0; ii < nfine_eqn; ii++) f_data[ii] = 0.; /* ASSUMING that for each grid point on this processor there are a */ /* set of equations and that all points at a grid point are numbered */ /* consecutively !!!!!!!!!!!!!! */ stride = nfine_eqn/nfine; for (ii = 0 ; ii < ncoarse ; ii++) { coarse_funs->USR_grid_get_vertex_coordinate(coarse_data,ii,coords); for (jj = 0; jj < stride; jj++) { c_data[ii*stride + jj] = coords[0] + 3.*coords[1] + .5; } } ML_Operator_Apply(ml->SingleLevel[coarse_level].Pmat,ncoarse_eqn,c_data, nfine_eqn,f_data); dlargest = 0.0; for (ii = 0 ; ii < nfine; ii++) { fine_funs->USR_grid_get_vertex_coordinate(fine_data , ii, coords); dtemp = coords[0] + 3.*coords[1] + .5; d2 = ML_dabs(dtemp - f_data[ii*stride])/(ML_dabs(dtemp)+1.e-9); /* Ray debugging if ( d2 > 1.e-8) printf("%d: f_data[%d] = %e %e | %e %e\n",ml->comm->ML_mypid, ii,f_data[ii*stride],dtemp,coords[0],coords[1]); */ if ( d2 > dlargest) { dlargest = d2; } } ML_free(f_data); ML_free(c_data); }
int ML_compute_basis_coefficients3D(void *grid, double *coord, int ncoord, double *coefs, int *coef_ptr) { int *vlist, the_pt, ncnt, i, j, ind, not_all_zero; int max_vert_per_ele; double xyz[3]; double x, y, z, xdist, ydist, zdist, xmax, ymax, zmax, xmin, ymin, zmin; double xwidth, ywidth, zwidth, coarse_x, coarse_y, coarse_z, local_coef[8]; /* checking the presence of the set of grid access functions */ if ( gridfcns_basis == NULL ) { printf("Error in compute_basis : no grid functions available. \n"); exit(0); } /* fetch the vertices (local vertex numbers) for the given coarse */ /* element (leng = the number of vertices for the element) */ max_vert_per_ele = gridfcns_basis->ML_MaxElmntVert; ML_memory_alloc( (void**) &vlist, max_vert_per_ele*sizeof(int), "BAS"); /* fetch the left-bottom-front and right-top-back vertices, which */ /* should give information about its bounds in each dimension */ xmax = ymax = zmax = -1.0E10; xmin = ymin = zmin = 1.0E10; for (i = 0; i < 8; i++) { if ( vlist[i] >= 0 ) { the_pt = vlist[i]; gridfcns_basis->USR_grid_get_vertex_coordinate(grid, the_pt, xyz); if (xyz[0] > xmax) xmax = xyz[0]; if (xyz[0] < xmin) xmin = xyz[0]; if (xyz[1] > ymax) ymax = xyz[1]; if (xyz[1] < ymin) ymin = xyz[1]; if (xyz[2] > zmax) zmax = xyz[2]; if (xyz[2] < zmin) zmin = xyz[2]; } } if (xmax == xmin || ymax == ymin || zmax == zmin) { printf("Error : get_basis - width = 0. \n"); exit(-1); } xwidth = (double) 1.0 / (xmax - xmin); ywidth = (double) 1.0 / (ymax - ymin); zwidth = (double) 1.0 / (zmax - zmin); /* Now examine each incoming vertex and determine its relationship */ /* with the coarse element vertices. */ ncnt = 0; for (i=0; i<ncoord; i++) { /* fetch the coordinate of the fine vertex */ x = (double) coord[3*i]; y = (double) coord[3*i+1]; z = (double) coord[3*i+2]; /* for each of the 8 coarse vertices */ not_all_zero = 0; for ( j = 0; j < 8; j++ ) { /* get the coarse vertex coordinate and find its */ /* distance from the fine vertex in question */ ind = vlist[j]; if ( ind >= 0 ) { gridfcns_basis->USR_grid_get_vertex_coordinate(grid, ind, xyz); coarse_x = (double) xyz[0]; coarse_y = (double) xyz[1]; coarse_z = (double) xyz[2]; xdist = 1.0 - ML_dabs((x - coarse_x)) * xwidth; ydist = 1.0 - ML_dabs((y - coarse_y)) * ywidth; zdist = 1.0 - ML_dabs((z - coarse_z)) * zwidth; if (xdist > 0.0 && ydist > 0.0 && zdist > 0.0) { local_coef[j] = xdist * ydist * zdist; if (local_coef[j] > 1.0E-6) not_all_zero++; else local_coef[j] = 0.0; } else local_coef[j] = 0.0; } else local_coef[j] = 0.0; } if (not_all_zero > 0) { for ( j = 0; j < 8; j++ ) coefs[ncnt++] = local_coef[j]; coef_ptr[i] = 8; } else { coefs[ncnt++] = -1.0; coef_ptr[i] = 1; } } ML_memory_free( (void **) &vlist ); return 0; }