src/util/mom/mom.C

Go to the documentation of this file.
00001 #include<config.h>
00002 CPS_START_NAMESPACE
00008 // mom.C
00009 //
00010 // Mom calculates the phase factor for each
00011 // lattice site given a number of momenta and the source parameters
00012 //
00013 //------------------------------------------------------------------
00014 
00015 CPS_END_NAMESPACE
00016 #include <stdlib.h>     // exit()
00017 #include <util/qcdio.h>
00018 #include <util/mom.h>
00019 CPS_START_NAMESPACE
00020 
00021 CPS_END_NAMESPACE
00022 #include <util/gjp.h>
00023 #include <util/smalloc.h>
00024 #include <util/verbose.h> 
00025 #include <util/error.h>
00026 CPS_START_NAMESPACE
00027 
00028 Mom MOM;
00029 
00030 //------------------------------------------------------------------
00031 // Constructor 
00032 //------------------------------------------------------------------
00033 Mom::Mom()
00034 {
00035   cname = "Mom";
00036   char *fname = "Mom(MomArg*)";
00037   VRB.Func(cname,fname);
00038 }
00039 //------------------------------------------------------------------
00040 // Destructor
00041 //------------------------------------------------------------------
00042 Mom::~Mom() {
00043   char *fname = "~Mom()";
00044   VRB.Func(cname,fname);
00045 
00046   // de-allocate space for momentum factor
00047   VRB.Sfree(cname,fname, "mom_fact", mom_fact);
00048   sfree(mom_fact);
00049 }
00050 
00051 
00052 
00053 //------------------------------------------------------------------
00054 //Initialisation
00059 //------------------------------------------------------------------
00060 void Mom::Init(MomArg *arg)
00061 {
00062   char *fname = "Init()";
00063   VRB.Func(cname,fname);
00064 
00065   PI = 3.14159265358979323846; 
00066 
00067   // Initialize the argument pointer
00068   //----------------------------------------------------------------
00069   if(arg == 0)
00070     ERR.Pointer(cname,fname, "arg");
00071   mom_arg = arg;
00072 
00073   no_of_mom = mom_arg->no_of_momenta;
00074   deg       = mom_arg->deg;
00075   max_p1    = mom_arg->max_p1;
00076   max_p2    = mom_arg->max_p2;
00077   max_p3    = mom_arg->max_p3;
00078   // allocate space for momentum factor table
00079   int mom_fact_size = no_of_mom*GJP.VolNodeSites();
00080 
00081   mom_fact = (Complex *) smalloc(mom_fact_size * sizeof(Complex));
00082   if(mom_fact == 0)
00083     ERR.Pointer(cname,fname, "mom_fact");
00084   VRB.Smalloc(cname,fname, "mom_fact", mom_fact, mom_fact_size * sizeof(Complex));
00085   
00086   // local lattice extent
00087   nx[0] = GJP.XnodeSites();
00088   nx[1] = GJP.YnodeSites();
00089   nx[2] = GJP.ZnodeSites();
00090   nx[3] = GJP.TnodeSites();
00091 
00092   // global lattice extent
00093   glb_L[0] = GJP.XnodeSites()*GJP.Xnodes();
00094   glb_L[1] = GJP.YnodeSites()*GJP.Ynodes();
00095   glb_L[2] = GJP.ZnodeSites()*GJP.Znodes();
00096   glb_L[3] = GJP.TnodeSites()*GJP.Tnodes();
00097 
00098   // global source location
00099   glb_sour_center[0] = (mom_arg->src_end[0] + mom_arg->src_begin[0])/2;
00100   glb_sour_center[1] = (mom_arg->src_end[1] + mom_arg->src_begin[1])/2;
00101   glb_sour_center[2] = (mom_arg->src_end[2] + mom_arg->src_begin[2])/2;
00102   glb_sour_center[3] = (mom_arg->src_end[3] + mom_arg->src_begin[3])/2;
00103 
00104   // propagation direction
00105   dir = mom_arg->dir;
00106   // other directions: i,j,k
00107   i = (mom_arg->dir + 1)%4;
00108   j = (mom_arg->dir + 2)%4;
00109   k = (mom_arg->dir + 3)%4;
00110 
00111 }
00112 
00113 
00114 
00115 //------------------------------------------------------------------
00123 //------------------------------------------------------------------
00124 void Mom::run() 
00125 {
00126   char *fname = "run()";
00127   VRB.Func(cname,fname);
00128 
00129   int s[4];          // local  coordinates
00130   int glb[4];        // global coordinates
00131   int n[4];          // momentum in lattice units e.g. n=(1,0,0,0)
00132   n[dir]=0;          // momentum in propagation direction always zero 
00133   Float mom[4];      // momentum in physical units: p_mu = 2*PI*n_mu / L_mu  
00134 
00135   if (deg && (  (max_p1 < max_p2) || (max_p2 < max_p3) ) ) {
00136     ERR.General(cname, fname, "mom_deg requires ordered momenta %d %d %d \n", max_p1,max_p2,max_p3) ;
00137   }
00138 
00139   /*
00140   FILE *fp;
00141   if( (fp = Fopen("mom_table.log", "a")) == NULL ) {
00142     ERR.FileA(cname, fname, "mom_table.log");
00143   }
00144   Fprintf(fp,"# phase factors for dir = %d deg-flag = %d \n",dir,deg);
00145   Fprintf(fp,"# index   n[%d]  n[%d]  n[%d] \n",i,j,k);
00146   */
00147 
00148   int imom=0;
00149   for (int p1=0; p1<= max_p1; p1++){
00150     for (int p2=0; p2<= max_p2; p2++){
00151       if (p2>p1 && deg) continue;
00152       for (int p3=0; p3<= max_p3; p3++){
00153         if (p3>p2 && deg) continue;
00154 
00155         n[i]=p1; n[j]=p2; n[k]=p3;  // momentum in natural units
00156         
00157         // convert lattice momenta --> physical: p[mu] = 2 Pi n[mu] / L[mu] 
00158         for (int mu=0; mu<4; mu++) mom[mu] = 2.*PI*n[mu]/glb_L[mu];
00159         // printf("mom = %e %e %e %e \n",mom[0],mom[1],mom[2],mom[3]);
00160 
00161         // start loop over the local lattice volume
00162         for (s[dir] = 0; s[dir] < nx[dir]; s[dir]++) {
00163           for (s[i] = 0; s[i] < nx[i]; s[i]++) {
00164             for (s[j] = 0; s[j] < nx[j]; s[j]++) {
00165               for (s[k] = 0; s[k] < nx[k]; s[k]++) {
00166           
00167 
00168                 glb[0] = s[0] + GJP.XnodeSites()*GJP.XnodeCoor();
00169                 glb[1] = s[1] + GJP.YnodeSites()*GJP.YnodeCoor();
00170                 glb[2] = s[2] + GJP.ZnodeSites()*GJP.ZnodeCoor();
00171                 glb[3] = s[3] + GJP.TnodeSites()*GJP.TnodeCoor();
00172 
00173                 int x[4];
00174                 // global shifts from origin
00175                 for (int mu=0; mu<4; mu++) x[mu] = glb[mu]-glb_sour_center[mu];
00176   
00177                 // offset for mom_fact(imom,s)
00178                 int offset = imom + s[0]*no_of_mom + s[1]*no_of_mom*nx[0] + s[2]*no_of_mom*nx[0]*nx[1] + s[3]*no_of_mom*nx[0]*nx[1]*nx[2];
00179 
00180                 // mom-factor exp [ -i*alpha ] = cos(alpha) - i sin(alpha)
00181                 Float alpha[3]; 
00182                 alpha[0] = x[i]*mom[i] + x[j]*mom[j] + x[k]*mom[k];
00183 
00184 
00185                 // printf("s = %d %d %d %d offset = %d alpha = %e \n",s[0],s[1],s[2],s[3],offset,alpha[0]);
00186                 if (deg) {      
00187                   // to be used with SYMMETRIC LATTICES ONLY
00188                   // i.e. calculate also the equivalent 
00189                   // alpha[1] = x*py + y*pz + z*px
00190                   // alpha[2] = x*pz + y*px + z*py
00191 
00192                   alpha[1] = x[i]*mom[j] + x[j]*mom[k] + x[k]*mom[i];
00193                   alpha[2] = x[i]*mom[k] + x[j]*mom[i] + x[k]*mom[j];
00194 
00195                   // sum and normalise with respect to degenrate number of momenta
00196                   mom_fact[offset].real( ( cos(alpha[0])+cos(alpha[1])+cos(alpha[2]))/3.0 );
00197                   mom_fact[offset].imag( (-sin(alpha[0])-sin(alpha[1])-sin(alpha[2]))/3.0 );
00198 
00199                 } else {
00200                   // take only the first momentum choice
00201       
00202                   mom_fact[offset].real(  cos(alpha[0]) );
00203                   mom_fact[offset].imag( -sin(alpha[0]) );
00204                 } // end if (deg) { } else { }
00205 
00206               } // s[i]
00207             } // s[j]
00208           } // s[k]
00209         } // s[dir]
00210         // Fprintf(fp,"%d         %d      %d      %d \n",imom, p1,p2,p3);
00211         imom++; // calculate next momentum
00212 
00213       } // p3
00214     } // p2
00215   } // p1
00216 
00217   if (no_of_mom != imom)
00218     ERR.General(cname, fname, "conflict between imom=%d and no_of_mom = %d",imom,no_of_mom);
00219   
00220   /*
00221     Fprintf(fp,"total number of momenta = %d \n",no_of_mom);
00222     Fprintf(fp,"=================================== \n");
00223     Fclose(fp);
00224   */
00225   // finished determination of mom_fact[offset] ========
00226 }
00227 
00228 
00229 //------------------------------------------------------------------
00230 // fact(int imom, int *s)
00231 // returns the complex phase factor for momentum "imom" at site "s"
00240 //------------------------------------------------------------------
00241 Complex Mom::fact(int imom, int *s) 
00242 {
00243   char *fname = "fact()";
00244   VRB.Func(cname,fname);
00245 
00246   int offset = imom + s[0]*no_of_mom + s[1]*no_of_mom*nx[0] + s[2]*no_of_mom*nx[0]*nx[1] + s[3]*no_of_mom*nx[0]*nx[1]*nx[2];
00247 
00248   return mom_fact[offset];
00249 
00250 
00251 }
00252 
00253 CPS_END_NAMESPACE

Generated on Tue Mar 6 10:57:40 2007 for Columbia Physics System by  doxygen 1.4.6