Changeset 22729


Ignore:
Timestamp:
05/01/18 02:28:49 (7 years ago)
Author:
Mathieu Morlighem
Message:

CHG: convert index to int

Location:
issm/trunk-jpl/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.cpp

    r21828 r22729  
    66#include "../../shared/shared.h"
    77
    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){
     8void 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){
    99
    1010        /*Intermediary*/
    11         int    i,j;
    1211        int    i1,i2,j1,j2;
    1312        int    interpolation_type;
     
    2827        else _error_("length of vector data not supported yet. It should be of length (number of nodes) or (number of elements)!");
    2928
    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;
    3232
    33         /*Set debug to 1 if there are lots of elements*/
     33        /*Set debug to "true" if there are lots of elements*/
    3434        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;
    3835
    3936        /*figure out if x or y are flipped*/
    4037        bool xflip = false;
    4138        bool yflip = false;
    42         if (x_grid[1]-x_grid[0]<0) xflip=true;
    43         if (y_grid[1]-y_grid[0]<0) yflip=true;
     39        if(x_grid[1]-x_grid[0]<0) xflip=true;
     40        if(y_grid[1]-y_grid[0]<0) yflip=true;
    4441
    4542        /*Get min/max coordinates of the grid*/
     
    6764
    6865                /*display current iteration*/
    69                 if(debug && fmod((double)n,(double)100)==0)
     66                if(debug && fmod(double(n),1000)==0)
    7067                 _printf_("\r      interpolation progress: "<<setw(6)<<setprecision(2)<<double(n)/double(nels)*100<<"%   ");
    7168
    7269                /*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];
    8077                }
    8178
     
    8380                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;
    8481
    85                 /*Get indices i and j that form a square around the currant triangle*/
     82                /*Get indices i and j that form a square around the current triangle*/
    8683                if(yflip){
    8784                        i1=max(0,       (int)floor((y_tria_max-y_grid_max)/yposting)-1);
     
    103100                /*get area of the current element (Jacobian = 2 * area)*/
    104101                //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];
    108105
    109106                /*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++){
    111108
    112109                        //exit if y not between y_tria_min and y_tria_max
    113110                        if((y_grid[i]>y_tria_max) || (y_grid[i]<y_tria_min)) continue;
    114111
    115                         for(j=j1;j<=j2; j++){
     112                        for(int j=j1;j<=j2; j++){
    116113
    117114                                //exit if x not between x_tria_min and x_tria_max
     
    119116
    120117                                /*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;
    123120                                /*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;
    126123                                /*Get third area coordinate = 1-area1-area2*/
    127124                                area_3=1.-area_1-area_2;
    128125
    129126                                /*is the current point in the current element?*/
    130                                 if(area_1>-10e-12 && area_2>-10e-12 && area_3>-10e-12){
     127                                if(area_1>-1e-12 && area_2>-1e-12 && area_3>-1e-12){
    131128
    132129                                        /*Yes ! compute the value on the point*/
    133130                                        if(interpolation_type==1){
    134131                                                /*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];
    136133                                        }
    137134                                        else{
     
    147144                }
    148145        }
    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");
    150147
    151148        /*Assign output pointers:*/
  • TabularUnified issm/trunk-jpl/src/c/modules/InterpFromMeshToGridx/InterpFromMeshToGridx.h

    r21828 r22729  
    88#include "../../toolkits/toolkits.h"
    99
    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);
     10void 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);
    1111
    1212#endif /* _INTERPFROMMESHTOGRIDX_H */
  • TabularUnified issm/trunk-jpl/src/wrappers/InterpFromMeshToGrid/InterpFromMeshToGrid.cpp

    r21828 r22729  
    2323
    2424        /*inputs */
    25         double* index=NULL;
     25        int*    index=NULL;
    2626        double* x=NULL;
    2727        double* y=NULL;
     
    6363
    6464        /*Free ressources: */
    65         xDelete<double>(index);
     65        xDelete<int>(index);
    6666        xDelete<double>(x);
    6767        xDelete<double>(y);
Note: See TracChangeset for help on using the changeset viewer.