test_para_grp_parse.C

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * $Source: /cvsroot/leanCP/src_charm_driver/utility/LINE_EQUAL_DECOMP_V.2/test_para_grp_parse.C,v $
00003  * $Author: bhatele $
00004  * $Date: 2007/12/05 09:02:17 $
00005  * $Revision: 1.2 $
00006  *****************************************************************************/
00007 
00008 ///////////////////////////////////////////////////////////////////////////////=
00009 ///////////////////////////////////////////////////////////////////////////////c
00010 ///////////////////////////////////////////////////////////////////////////////=
00011 /** \file test_para_grp_parse.C
00012  *
00013  */
00014 ///////////////////////////////////////////////////////////////////////////////=
00015 
00016 
00017 
00018 #include <string.h>
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include <math.h>
00022 
00023 #include "para_grp_parse.h"
00024 
00025 void create_kvec(int **,int **,int **, int ,int *);
00026 
00027 void get_glenn_prms(int ,int *,int *,int *,int *,int **,int **,
00028                     int **,int **,int **);
00029 
00030 void test_flip(int,int, int *,int *,int*);
00031 
00032 ///////////////////////////////////////////////////////////////////////////=
00033 ///////////////////////////////////////////////////////////////////////////c
00034 ///////////////////////////////////////////////////////////////////////////=
00035    int main(){
00036 ///////////////////////////////////////////////////////////////////////////=
00037 
00038    int nktot;
00039    int nplane;
00040    int *kx,*ky,*kz;
00041 
00042 ///////////////////////////////////////////////////////////////////////////=
00043 /// create the model data set
00044 
00045    PRINTF("\n");
00046    PRINTF("////////////////////////////////////////////////////\n");
00047    PRINTF("          Input data                                \n");
00048    PRINTF("----------------------------------------------------\n");
00049    PRINTF("Enter nplane : ");
00050    scanf("%d",&nplane);
00051 
00052    int ntemp;
00053    create_kvec(&kx,&ky,&kz,nplane,&ntemp);
00054    ParaGrpParse::flip_data_set(ntemp,&nktot,kx,ky,kz);
00055    test_flip(nktot,nplane,kx,ky,kz);
00056 
00057    PRINTF("      nktot  : %d\n",nktot);
00058 
00059    PRINTF("////////////////////////////////////////////////////\n");
00060 
00061 ///////////////////////////////////////////////////////////////////////////=
00062 /// Parse the data out by plane index
00063 
00064    PRINTF("\n");
00065    PRINTF("////////////////////////////////////////////////////\n");
00066    PRINTF("          Line decomposition                        \n");
00067    PRINTF("----------------------------------------------------\n");
00068 
00069    int nline;
00070    int *istrt;
00071    int *iend;
00072    int *npts;
00073    int *kx_line;
00074    int *ky_line;
00075 
00076    get_glenn_prms(nktot,kx,ky,&nplane,&nline,&istrt,&iend,&npts,&kx_line,&ky_line);
00077    PRINTF("nplane %d nline %d\n",nplane,nline);
00078 
00079    int *istrt_lgrp   = (int *)malloc(nplane*sizeof(int));
00080    int *iend_lgrp    = (int *)malloc(nplane*sizeof(int));
00081    int *npts_lgrp    = (int *)malloc(nplane*sizeof(int));
00082    int *nline_lgrp   = (int *)malloc(nplane*sizeof(int));
00083    int *kx_str_lgrp  = (int *)malloc(nplane*sizeof(int));
00084    int *kx_end_lgrp  = (int *)malloc(nplane*sizeof(int));
00085    int *ky_str_lgrp  = (int *)malloc(nplane*sizeof(int));
00086    int *ky_end_lgrp  = (int *)malloc(nplane*sizeof(int));
00087 
00088    ParaGrpParse::get_plane_line_prms(nktot,nplane,nline,npts,kx_line, ky_line,
00089                     istrt_lgrp,iend_lgrp,npts_lgrp,nline_lgrp,
00090                     kx_str_lgrp,kx_end_lgrp,ky_str_lgrp,ky_end_lgrp);
00091 
00092    for(int i=0;i<nplane;i++){
00093      PRINTF("i=%d : n=%d istrt=%d iend=%d nline=%d ",
00094              i,npts_lgrp[i],istrt_lgrp[i],iend_lgrp[i],nline_lgrp[i]);
00095      PRINTF("kx_str %d kx_end %d ky_str %d ky_end %d\n",
00096              kx_str_lgrp[i],kx_end_lgrp[i],ky_str_lgrp[i],ky_end_lgrp[i]);  
00097    }//endfor
00098 
00099    PRINTF("////////////////////////////////////////////////////\n");
00100 
00101    return 1;
00102 //-------------------------------------------------------------------------
00103    }//end routine 
00104 ///////////////////////////////////////////////////////////////////////////=
00105 
00106 
00107 ///////////////////////////////////////////////////////////////////////////=
00108 ///////////////////////////////////////////////////////////////////////////c
00109 ///////////////////////////////////////////////////////////////////////////=
00110 /// Create model data points in 3D with spherical truncation
00111 ///////////////////////////////////////////////////////////////////////////=
00112 
00113 void create_kvec(int **kx_out,int **ky_out,int **kz_out,
00114                  int nplane,int *nktot_out)
00115 
00116 ///////////////////////////////////////////////////////////////////////////=
00117       {//begin routine
00118 ///////////////////////////////////////////////////////////////////////////=
00119 
00120   int nktot = 0;
00121   double aplane1 = (double)(nplane-1);
00122   for(int ikx=0;ikx<=nplane;ikx++){
00123     int kymin = -nplane;
00124     if(ikx==0)kymin=0;
00125     for(int iky=kymin;iky<=nplane;iky++){
00126       int kzmin = -nplane;
00127       if(ikx==0 && iky==0)kzmin=1;
00128       for(int ikz=kzmin;ikz<=nplane;ikz++){
00129         double aka = (double)ikx;
00130         double akb = (double)iky;
00131         double akc = (double)ikz;
00132         double g   = sqrt(aka*aka + akb*akb + akc*akc);
00133         if(g<=aplane1){nktot++;}
00134       }//endfor
00135     }//endfor
00136   }//endfor
00137   nktot++;
00138 
00139   int *kx = (int *)malloc(2*nktot*sizeof(int));
00140   int *ky = (int *)malloc(2*nktot*sizeof(int));
00141   int *kz = (int *)malloc(2*nktot*sizeof(int));
00142 
00143   int ic = 0;
00144   for(int ikx=0;ikx<=nplane;ikx++){
00145     int kymin = -nplane;
00146     if(ikx==0)kymin=0;
00147     for(int iky=kymin;iky<=nplane;iky++){
00148       int kzmin = -nplane;
00149       if(ikx==0 && iky==0)kzmin=1;
00150       for(int ikz=kzmin;ikz<=nplane;ikz++){
00151         double aka = (double)ikx;
00152         double akb = (double)iky;
00153         double akc = (double)ikz;
00154         double g   = sqrt(aka*aka + akb*akb + akc*akc);
00155         if(g<=aplane1){kx[ic]=ikx; ky[ic]=iky; kz[ic]=ikz; ic++;}
00156       }//endfor
00157     }//endfor
00158   }//endfor
00159   kx[ic]=0;ky[ic]=0;kz[ic]=0;
00160   ic++;
00161 
00162   *nktot_out = nktot;
00163   *kx_out    = kx;
00164   *ky_out    = ky;
00165   *kz_out    = kz;
00166 
00167 //-------------------------------------------------------------------------
00168    }//end routine 
00169 ///////////////////////////////////////////////////////////////////////////=
00170 
00171 
00172 
00173 ///////////////////////////////////////////////////////////////////////////=
00174 ///////////////////////////////////////////////////////////////////////////c
00175 ///////////////////////////////////////////////////////////////////////////=
00176 /// Decompose the nktot data points into chunks based on plane index
00177 ///////////////////////////////////////////////////////////////////////////=
00178 
00179 void get_glenn_prms(int nktot,int *kx,int *ky,int *nplane_ret,
00180                     int *nline_ret,int **istrt_ret,int **iend_ret,
00181                     int **npts_ret,int **kx_line_ret,int **ky_line_ret)
00182 
00183 ///////////////////////////////////////////////////////////////////////////=
00184    { //begin routine
00185 ///////////////////////////////////////////////////////////////////////////=
00186 /// count the planes
00187   
00188    int nplane = 1;
00189    int nline  = 1;
00190    for(int i=1;i<nktot;i++){
00191      if(kx[i]!=kx[(i-1)]){nplane++;}
00192      if(ky[i]!=ky[(i-1)] || kx[i]!=kx[(i-1)]){nline++;}
00193    }
00194 
00195    int *iend    = (int *)malloc(nline*sizeof(int));
00196    int *istrt   = (int *)malloc(nline*sizeof(int));
00197    int *npts    = (int *)malloc(nline*sizeof(int));
00198    int *kx_line = (int *)malloc(nline*sizeof(int));
00199    int *ky_line = (int *)malloc(nline*sizeof(int));
00200 
00201    int ic     = 0;
00202    npts[0]    = 1;
00203    istrt[0]   = 0;
00204    iend[0]    = 1;
00205    kx_line[0] = kx[0];
00206    ky_line[0] = ky[0];
00207    for(int i=1;i<nktot;i++){
00208     if(kx[i]!=kx[(i-1)] || ky[i]!=ky[(i-1)]){
00209        iend[ic]  = i;
00210        ic       += 1;
00211        npts[ic]  = 0;
00212        istrt[ic] = i;
00213        kx_line[ic] = kx[i];
00214        ky_line[ic] = ky[i];
00215     }//endif
00216     npts[ic]++;
00217   }//endfor
00218   iend[(nline-1)]=nktot;
00219 
00220   *nplane_ret  = nplane;
00221   *nline_ret   = nline;
00222   *istrt_ret   = istrt;
00223   *iend_ret    = iend;
00224   *npts_ret    = npts;
00225   *kx_line_ret = kx_line;
00226   *ky_line_ret = ky_line;
00227 
00228 //-------------------------------------------------------------------------
00229    }//end routine 
00230 ///////////////////////////////////////////////////////////////////////////=
00231 
00232 
00233 
00234 ///////////////////////////////////////////////////////////////////////////=
00235 ///////////////////////////////////////////////////////////////////////////c
00236 ///////////////////////////////////////////////////////////////////////////=
00237 /// Create model data points in 3D with spherical truncation
00238 ///////////////////////////////////////////////////////////////////////////=
00239 
00240 void test_flip(int nktot, int nplane, int *kx,int *ky,int *kz)
00241 
00242 ///////////////////////////////////////////////////////////////////////////=
00243       {//begin routine
00244 ///////////////////////////////////////////////////////////////////////////=
00245 
00246   double aplane1 = (double)(nplane-1);
00247 
00248   int ic = 0;
00249   for(int ikx=0;ikx<=nplane;ikx++){
00250     int kymin = -nplane;
00251     for(int iky=kymin;iky<=nplane;iky++){
00252       int kzmin = -nplane;
00253       for(int ikz=kzmin;ikz<=nplane;ikz++){
00254         double aka = (double)ikx;
00255         double akb = (double)iky;
00256         double akc = (double)ikz;
00257         double g   = sqrt(aka*aka + akb*akb + akc*akc);
00258         if(g<=aplane1){
00259           if(ic>=nktot){
00260             printf("flip error 1\n");exit(1);
00261           }//endif
00262           if(kx[ic]!=ikx || ky[ic]!=iky || kz[ic]!=ikz){
00263             printf("flip error 2\n");exit(1);
00264           }//endif
00265           ic++;
00266         }//endif
00267       }//endfor
00268     }//endfor
00269   }//endfor
00270   if(ic!=nktot){printf("flip error 3\n");exit(1);}
00271 
00272 ///////////////////////////////////////////////////////////////////////////=
00273       }//end routine
00274 ///////////////////////////////////////////////////////////////////////////=
00275 

Generated on Thu Dec 6 18:25:32 2007 for leanCP by  doxygen 1.5.3