Changeset 22729
- Timestamp:
- 05/01/18 02:28:49 (7 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp ¶
r21828 r22729 6 6 #include "../../shared/shared.h" 7 7 8 void InterpFromMeshToGridx(double** pgriddata, double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh,int data_length,double* x_grid,double* y_grid,int nlines,int ncols,double default_value){8 void InterpFromMeshToGridx(double** pgriddata,int* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh,int data_length,double* x_grid,double* y_grid,int nlines,int ncols,double default_value){ 9 9 10 10 /*Intermediary*/ 11 int i,j;12 11 int i1,i2,j1,j2; 13 12 int interpolation_type; … … 28 27 else _error_("length of vector data not supported yet. It should be of length (number of nodes) or (number of elements)!"); 29 28 30 /*First, allocate pointers: */ 31 double* griddata=xNewZeroInit<double>(nlines*ncols); 29 /*First, prepare output*/ 30 double* griddata=xNew<double>(nlines*ncols); 31 for(int i=0;i<nlines;i++) for(int j=0;j<ncols; j++) griddata[i*ncols+j]=default_value; 32 32 33 /*Set debug to 1if there are lots of elements*/33 /*Set debug to "true" if there are lots of elements*/ 34 34 bool debug=(bool)((double)ncols*nlines*nels >= 5.e10); 35 36 /*Initialize coordintes and griddata*/37 for(i=0;i<nlines;i++) for(j=0;j<ncols; j++) griddata[i*ncols+j]=default_value;38 35 39 36 /*figure out if x or y are flipped*/ 40 37 bool xflip = false; 41 38 bool yflip = false; 42 if 43 if 39 if(x_grid[1]-x_grid[0]<0) xflip=true; 40 if(y_grid[1]-y_grid[0]<0) yflip=true; 44 41 45 42 /*Get min/max coordinates of the grid*/ … … 67 64 68 65 /*display current iteration*/ 69 if(debug && fmod( (double)n,(double)100)==0)66 if(debug && fmod(double(n),1000)==0) 70 67 _printf_("\r interpolation progress: "<<setw(6)<<setprecision(2)<<double(n)/double(nels)*100<<"% "); 71 68 72 69 /*Get extrema coordinates of current elements*/ 73 x_tria_min=x_mesh[ (int)index_mesh[3*n+0]-1]; x_tria_max=x_tria_min;74 y_tria_min=y_mesh[ (int)index_mesh[3*n+0]-1]; y_tria_max=y_tria_min;75 for(i =1;i<3;i++){76 if(x_mesh[ (int)index_mesh[3*n+i]-1]<x_tria_min) x_tria_min=x_mesh[(int)index_mesh[3*n+i]-1];77 if(x_mesh[ (int)index_mesh[3*n+i]-1]>x_tria_max) x_tria_max=x_mesh[(int)index_mesh[3*n+i]-1];78 if(y_mesh[ (int)index_mesh[3*n+i]-1]<y_tria_min) y_tria_min=y_mesh[(int)index_mesh[3*n+i]-1];79 if(y_mesh[ (int)index_mesh[3*n+i]-1]>y_tria_max) y_tria_max=y_mesh[(int)index_mesh[3*n+i]-1];70 x_tria_min=x_mesh[index_mesh[3*n+0]-1]; x_tria_max=x_tria_min; 71 y_tria_min=y_mesh[index_mesh[3*n+0]-1]; y_tria_max=y_tria_min; 72 for(int i=1;i<3;i++){ 73 if(x_mesh[index_mesh[3*n+i]-1]<x_tria_min) x_tria_min=x_mesh[index_mesh[3*n+i]-1]; 74 if(x_mesh[index_mesh[3*n+i]-1]>x_tria_max) x_tria_max=x_mesh[index_mesh[3*n+i]-1]; 75 if(y_mesh[index_mesh[3*n+i]-1]<y_tria_min) y_tria_min=y_mesh[index_mesh[3*n+i]-1]; 76 if(y_mesh[index_mesh[3*n+i]-1]>y_tria_max) y_tria_max=y_mesh[index_mesh[3*n+i]-1]; 80 77 } 81 78 … … 83 80 if( (x_tria_min>x_grid_max) || (x_tria_max<x_grid_min) || (y_tria_min>y_grid_max) || (y_tria_max<y_grid_min) ) continue; 84 81 85 /*Get indices i and j that form a square around the curr ant triangle*/82 /*Get indices i and j that form a square around the current triangle*/ 86 83 if(yflip){ 87 84 i1=max(0, (int)floor((y_tria_max-y_grid_max)/yposting)-1); … … 103 100 /*get area of the current element (Jacobian = 2 * area)*/ 104 101 //area =x2 * y3 - y2*x3 + x1 * y2 - y1 * x2 + x3 * y1 - y3 * x1; 105 area=x_mesh[ (int)index_mesh[3*n+1]-1]*y_mesh[(int)index_mesh[3*n+2]-1]-y_mesh[(int)index_mesh[3*n+1]-1]*x_mesh[(int)index_mesh[3*n+2]-1]106 + x_mesh[ (int)index_mesh[3*n+0]-1]*y_mesh[(int)index_mesh[3*n+1]-1]-y_mesh[(int)index_mesh[3*n+0]-1]*x_mesh[(int)index_mesh[3*n+1]-1]107 + x_mesh[ (int)index_mesh[3*n+2]-1]*y_mesh[(int)index_mesh[3*n+0]-1]-y_mesh[(int)index_mesh[3*n+2]-1]*x_mesh[(int)index_mesh[3*n+0]-1];102 area=x_mesh[index_mesh[3*n+1]-1]*y_mesh[index_mesh[3*n+2]-1]-y_mesh[index_mesh[3*n+1]-1]*x_mesh[index_mesh[3*n+2]-1] 103 + x_mesh[index_mesh[3*n+0]-1]*y_mesh[index_mesh[3*n+1]-1]-y_mesh[index_mesh[3*n+0]-1]*x_mesh[index_mesh[3*n+1]-1] 104 + x_mesh[index_mesh[3*n+2]-1]*y_mesh[index_mesh[3*n+0]-1]-y_mesh[index_mesh[3*n+2]-1]*x_mesh[index_mesh[3*n+0]-1]; 108 105 109 106 /*Go through x_grid and y_grid and interpolate if necessary*/ 110 for(i =i1;i<=i2;i++){107 for(int i=i1;i<=i2;i++){ 111 108 112 109 //exit if y not between y_tria_min and y_tria_max 113 110 if((y_grid[i]>y_tria_max) || (y_grid[i]<y_tria_min)) continue; 114 111 115 for( j=j1;j<=j2; j++){112 for(int j=j1;j<=j2; j++){ 116 113 117 114 //exit if x not between x_tria_min and x_tria_max … … 119 116 120 117 /*Get first area coordinate = det(x-x3 x2-x3 ; y-y3 y2-y3)/area*/ 121 area_1=((x_grid[j]-x_mesh[ (int)index_mesh[3*n+2]-1])*(y_mesh[(int)index_mesh[3*n+1]-1]-y_mesh[(int)index_mesh[3*n+2]-1])122 - (y_grid[i]-y_mesh[ (int)index_mesh[3*n+2]-1])*(x_mesh[(int)index_mesh[3*n+1]-1]-x_mesh[(int)index_mesh[3*n+2]-1]))/area;118 area_1=((x_grid[j]-x_mesh[index_mesh[3*n+2]-1])*(y_mesh[index_mesh[3*n+1]-1]-y_mesh[index_mesh[3*n+2]-1]) 119 - (y_grid[i]-y_mesh[index_mesh[3*n+2]-1])*(x_mesh[index_mesh[3*n+1]-1]-x_mesh[index_mesh[3*n+2]-1]))/area; 123 120 /*Get second area coordinate =det(x1-x3 x-x3 ; y1-y3 y-y3)/area*/ 124 area_2=((x_mesh[ (int)index_mesh[3*n+0]-1]-x_mesh[(int)index_mesh[3*n+2]-1])*(y_grid[i]-y_mesh[(int)index_mesh[3*n+2]-1])125 - (y_mesh[ (int)index_mesh[3*n+0]-1]-y_mesh[(int)index_mesh[3*n+2]-1])*(x_grid[j]-x_mesh[(int)index_mesh[3*n+2]-1]))/area;121 area_2=((x_mesh[index_mesh[3*n+0]-1]-x_mesh[index_mesh[3*n+2]-1])*(y_grid[i]-y_mesh[index_mesh[3*n+2]-1]) 122 - (y_mesh[index_mesh[3*n+0]-1]-y_mesh[index_mesh[3*n+2]-1])*(x_grid[j]-x_mesh[index_mesh[3*n+2]-1]))/area; 126 123 /*Get third area coordinate = 1-area1-area2*/ 127 124 area_3=1.-area_1-area_2; 128 125 129 126 /*is the current point in the current element?*/ 130 if(area_1>-1 0e-12 && area_2>-10e-12 && area_3>-10e-12){127 if(area_1>-1e-12 && area_2>-1e-12 && area_3>-1e-12){ 131 128 132 129 /*Yes ! compute the value on the point*/ 133 130 if(interpolation_type==1){ 134 131 /*nodal interpolation*/ 135 data_value=area_1*data_mesh[ (int)index_mesh[3*n+0]-1]+area_2*data_mesh[(int)index_mesh[3*n+1]-1]+area_3*data_mesh[(int)index_mesh[3*n+2]-1];132 data_value=area_1*data_mesh[index_mesh[3*n+0]-1]+area_2*data_mesh[index_mesh[3*n+1]-1]+area_3*data_mesh[index_mesh[3*n+2]-1]; 136 133 } 137 134 else{ … … 147 144 } 148 145 } 149 if(debug) _printf_("\r interpolation progress: "<< fixed<<setw(6)<<setprecision(2)<<100.<<"%\n");146 if(debug) _printf_("\r interpolation progress: "<<setw(6)<<setprecision(2)<<fixed<<100.<<"% \n"); 150 147 151 148 /*Assign output pointers:*/ -
TabularUnified issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h ¶
r21828 r22729 8 8 #include "../../toolkits/toolkits.h" 9 9 10 void InterpFromMeshToGridx(double** pgriddata, double* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh,int data_length,double* x_grid,double* y_grid,int nlines,int ncols,double default_value);10 void InterpFromMeshToGridx(double** pgriddata,int* index_mesh, double* x_mesh, double* y_mesh, int nods,int nels, double* data_mesh,int data_length,double* x_grid,double* y_grid,int nlines,int ncols,double default_value); 11 11 12 12 #endif /* _INTERPFROMMESHTOGRIDX_H */ -
TabularUnified issm/trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.cpp ¶
r21828 r22729 23 23 24 24 /*inputs */ 25 double*index=NULL;25 int* index=NULL; 26 26 double* x=NULL; 27 27 double* y=NULL; … … 63 63 64 64 /*Free ressources: */ 65 xDelete< double>(index);65 xDelete<int>(index); 66 66 xDelete<double>(x); 67 67 xDelete<double>(y);
Note:
See TracChangeset
for help on using the changeset viewer.