Changeset 2549
- Timestamp:
- 10/27/09 15:28:33 (15 years ago)
- Location:
- issm/trunk/src/c
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/InterpFromGridToMeshx/InterpFromGridToMeshx.cpp
r2286 r2549 2 2 * \brief "c" core code for interpolating values from a structured grid. 3 3 */ 4 5 #ifdef HAVE_CONFIG_H 6 #include "config.h" 7 #else 8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 9 #endif 10 4 11 5 12 #include "./InterpFromGridToMeshx.h" … … 9 16 #define __FUNCT__ "InterpFromGridToMeshx" 10 17 11 int findindices(int* pm,int* pn,double* x,int x_rows, double* y,int y_rows, double xgrid,double ygrid);12 18 13 19 int InterpFromGridToMeshx( Vec* pdata_mesh,double* x_in, int x_rows, double* y_in, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods,double default_value) { … … 20 26 double* x=NULL; 21 27 double* y=NULL; 22 int i,m,n; 23 double x_grid,y_grid; 24 double xi,eta; 25 double G1,G2,G3,G4,data_value; 26 double area_1,area_2,area_3; 27 double area; 28 double x_grid,y_grid; 29 int i; 30 31 /*threading: */ 32 InterpFromGridToMeshxThreadStruct gate; 33 int num=1; 34 35 #ifdef _MULTITHREADING_ 36 num=_NUMTHREADS_; 37 #endif 28 38 29 39 /*Some checks on arguments: */ … … 58 68 } 59 69 60 /*Linear (triangle) interpolation: */ 61 for ( i=MPI_Lowerrow(nods); i<MPI_Upperrow(nods); i++) { 70 /*initialize thread parameters: */ 71 gate.x_mesh=x_mesh; 72 gate.y_mesh=y_mesh; 73 gate.x_rows=x_rows; 74 gate.y_rows=y_rows; 75 gate.x=x; 76 gate.y=y; 77 gate.nods=nods; 78 gate.data_mesh=data_mesh; 79 gate.data=data; 80 gate.M=M; 81 gate.N=N; 62 82 63 x_grid=*(x_mesh+i); 64 y_grid=*(y_mesh+i); 65 66 /*Find indices m and n into y and x, for which y(m)<=y_grids<=y(m+1) and x(n)<=x_grid<=x(n+1)*/ 67 if(findindices(&n,&m,x,x_rows, y,y_rows, x_grid,y_grid)){ 68 69 /*Get area*/ 70 area=(x[n+1]-x[n])*(y[m+1]-y[m]); 71 72 /*is it the upper right triangle?*/ 73 /*2' 3' 74 *+-----+ 75 *1\ | 76 *| \ | 77 *| \ | 78 *| \ | 79 *| \| 80 *2----3+1' */ 81 if ((x_grid-x[n])/(x[n+1]-x[n])<(y_grid-y[m])/(y[m+1]-y[m])){ 82 83 /*Then find values of data at each summit*/ 84 G1=*(data+m*N+n); 85 G2=*(data+(m+1)*N+n+1); 86 G3=*(data+(m+1)*N+n); 87 88 /*Get first area coordinate*/ 89 area_1=((y[m+1]-y_grid)*(x[n+1]-x[n]))/area; 90 /*Get second area coordinate*/ 91 area_2=((x_grid-x[n])*(y[m+1]-y[m]))/area; 92 /*Get third area coordinate = 1-area1-area2*/ 93 area_3=1-area_1-area_2; 94 95 /*interpolate*/ 96 data_value=area_1*G1+area_2*G2+area_3*G3; 97 } 98 else { 99 100 /*Then find values of data at each summit*/ 101 G1=*(data+(m+1)*N+n+1); 102 G2=*(data+m*N+n); 103 G3=*(data+m*N+n+1); 104 105 /*Get first area coordinate*/ 106 area_1=((y_grid-y[m])*(x[n+1]-x[n]))/area; 107 /*Get second area coordinate*/ 108 area_2=((x[n+1]-x_grid)*(y[m+1]-y[m]))/area; 109 /*Get third area coordinate = 1-area1-area2*/ 110 area_3=1-area_1-area_2; 111 112 /*interpolate*/ 113 data_value=area_1*G1+area_2*G2+area_3*G3; 114 } 115 116 /*Treat NANs*/ 117 if (isnan(data_value)){ 118 data_value=default_value; 119 } 120 } 121 else{ 122 data_value=default_value; 123 } 124 VecSetValue(data_mesh,i,data_value,INSERT_VALUES); 125 } 83 /*launch the thread manager with InterpFromGridToMeshxt as a core: */ 84 LaunchThread(InterpFromGridToMeshxt,(void*)&gate,num); 126 85 127 86 /*Assign output pointers:*/ 128 87 *pdata_mesh=data_mesh; 129 88 } 130 131 int findindices(int* pm,int* pn,double* x,int x_rows, double* y,int y_rows, double xgrid,double ygrid){132 133 int foundx=0;134 int foundy=0;135 int i;136 int m=-1;137 int n=-1;138 139 for (i=0;i<x_rows-1;i++){140 if ( (*(x+i)<=xgrid) && (xgrid<*(x+i+1)) ){141 m=i;142 foundx= 1;143 break;144 }145 }146 if(*(x+x_rows-1)==xgrid){147 m=x_rows-2;148 foundx=1;149 }150 151 for (i=0;i<y_rows-1;i++){152 if ( (*(y+i)<=ygrid) && (ygrid<*(y+i+1)) ){153 n=i;154 foundy= 1;155 break;156 }157 }158 if(*(y+y_rows-1)==ygrid){159 m=y_rows-2;160 foundy=1;161 }162 163 /*Assign output pointers:*/164 *pm=m;165 *pn=n;166 return foundx*foundy;167 } -
issm/trunk/src/c/InterpFromGridToMeshx/InterpFromGridToMeshx.h
r2286 r2549 8 8 #include "../toolkits/toolkits.h" 9 9 10 11 12 /*threading: */ 13 typedef struct{ 14 15 double* x_mesh; 16 double* y_mesh; 17 int x_rows; 18 int y_rows; 19 double* x; 20 double* y; 21 int nods; 22 double default_value; 23 Vec data_mesh; 24 double* data; 25 int M; 26 int N; 27 28 } InterpFromGridToMeshxThreadStruct; 29 30 int findindices(int* pm,int* pn,double* x,int x_rows, double* y,int y_rows, double xgrid,double ygrid); 31 10 32 int InterpFromGridToMeshx( Vec* pdata_mesh,double* x, int x_rows, double* y, int y_rows, double* data, int M, int N, double* x_mesh, double* y_mesh, int nods, double default_value); 33 34 void* InterpFromGridToMeshxt(void* vInterpFromGridToMeshxThreadStruct); 35 11 36 12 37 #endif /* _INTERPFROMGRIDTOMESHX_H */ -
issm/trunk/src/c/InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp
r2417 r2549 45 45 double area_1,area_2,area_3; 46 46 double data_value; 47 int step;48 47 49 48 /*recover handle and gate: */ … … 72 71 73 72 /*distribute elements across threads :*/ 74 step=(int)floor((double)nels_data/(double)num_threads); 75 for(i=0;i<(my_thread+1);i++){ 76 i0=i*step; 77 if(i==(num_threads-1))i1=nels_data; 78 else i1=i0+step; 79 } 73 PartitionRange(&i0,&i1,nels_data,num_threads,my_thread); 80 74 81 75 for (i=i0;i<i1;i++){ -
issm/trunk/src/c/Makefile.am
r2417 r2549 89 89 ./shared/Threads/issm_threads.h\ 90 90 ./shared/Threads/LaunchThread.cpp\ 91 ./shared/Threads/PartitionRange.cpp\ 91 92 ./shared/Matlab/matlabshared.h\ 92 93 ./shared/Matlab/PrintfFunction.cpp\ … … 249 250 ./InterpFromGridToMeshx/InterpFromGridToMeshx.cpp\ 250 251 ./InterpFromGridToMeshx/InterpFromGridToMeshx.h\ 252 ./InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp\ 251 253 ./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\ 252 254 ./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp\ … … 386 388 ./shared/Threads/issm_threads.h\ 387 389 ./shared/Threads/LaunchThread.cpp\ 390 ./shared/Threads/PartitionRange.cpp\ 388 391 ./shared/Alloc/alloc.h\ 389 392 ./shared/Alloc/alloc.cpp\ … … 545 548 ./InterpFromGridToMeshx/InterpFromGridToMeshx.cpp\ 546 549 ./InterpFromGridToMeshx/InterpFromGridToMeshx.h\ 550 ./InterpFromGridToMeshx/InterpFromGridToMeshxt.cpp\ 547 551 ./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dx.cpp\ 548 552 ./InterpFromMeshToMesh2dx/InterpFromMeshToMesh2dxt.cpp\ -
issm/trunk/src/c/shared/Threads/issm_threads.h
r2417 r2549 18 18 * or just serially if not requested: */ 19 19 void LaunchThread(void* function(void*), void* gate,int num_threads); 20 void PartitionRange(int* pi0,int* pi1, int num_el,int num_threads,int my_thread); 20 21 21 22 #endif //ifndef _ISSM_THREADS_H_
Note:
See TracChangeset
for help on using the changeset viewer.