DSQSS  1.1
lattgene.cc
説明を見る。
00001 /*---------------------------------------------
00002 
00003    Generating lattice.xml for a square lattice.
00004 
00005 ----------------------------------------------*/
00006 
00007 #include<iostream>
00008 #include<fstream>
00009 #include<math.h>
00010 
00011 #include<cstdlib>
00012 
00013 using namespace std;
00014 
00015 //--------------------------------------------------------------
00016 void ShowUsage(int argc,char** argv){
00017   cout<<"usage: $ "<<argv[0]<<" [ D , L , B ]     \n";
00018   cout<<"    or $ "<<argv[0]<<" [ D , L0 , L1 , ... , B ] \n";
00019   cout<<"    D ... dimension.                     \n";
00020   cout<<"                                         \n";
00021   cout<<"    L ... the liner size of the lattice. \n";
00022   cout<<"          ( L, L0, L1, ..., must be even number. )\n";
00023   cout<<"    B ... the inverse tempereture.       \n";
00024   cout<<"                                         \n";
00025 }
00026 //-------------------------------------------------------------
00027 void WriteXML(int D, int L[], double B) {
00028 
00029   ofstream fout("lattice.xml");
00030   fout.precision(15);
00031   int N = 1; //number of sites.
00032   for(int i = 0 ; i<D ; i++) { N *= L[i] ; }
00033  
00034   int NumberOfCells = N;
00035   int NumberOfInteractions = N*D;
00036   int NumberOfSiteTypes = 1;
00037   int NumberOfInteractionTypes = 1;
00038 
00039   fout<<"<LATTICE>"<<endl<<endl;
00040   fout<<"<Comment>"<<endl;
00041   fout<<"  "<<D<<"-dimension square lattice"<<endl;
00042   fout<<"</Comment>"<<endl<<endl;
00043   
00044   fout<<"<Dimension> "              <<D<<" </Dimension>"<<endl;
00045   fout<<"<LinearSize> "             ;
00046   for(int i = 0 ; i<D ; i++){  fout<<L[i]<<" "; }
00047   fout<<"</LinearSize>"<<endl;
00048   fout<<"<Beta> "                   <<B<<" </Beta>"<<endl;
00049   fout<<"<NumberOfCells> "          <<NumberOfCells<<" </NumberOfCells>"<<endl;
00050   fout<<"<NumberOfSites> "           <<N<<" </NumberOfSites>"<<endl;
00051   fout<<"<NumberOfInteractions> "    <<NumberOfInteractions<<" </NumberOfInteractions>"<<endl;
00052   fout<<"<NumberOfSiteTypes> "       <<NumberOfSiteTypes<<" </NumberOfSiteTypes>"<<endl;
00053   fout<<"<NumberOfInteractionTypes> "<<NumberOfInteractionTypes<<" </NumberOfInteractionTypes>"<<endl;
00054   fout<<endl;
00055   
00056   fout<<"<!-- <S> [id] [stype] [mtype] </S> -->"<<endl<<endl;
00057  
00058   int stype = 0; 
00059   int mtype = 0;
00060   
00061   for ( int id = 0 ; id < N ; id++){
00062     int p  = id;
00063     int Nt = N;
00064     mtype = 0;
00065     for( int q = D -1 ; q >= 0 ; q-- ){
00066       Nt /= L[q] ;
00067       mtype += p / Nt ;
00068       p = p % Nt ;
00069     }
00070     
00071     mtype = mtype % 2;
00072     fout<<"<S> "<<id<<" "<<stype<<" "<<mtype<<" </S>"<<endl;
00073   }
00074 
00075   fout<<endl;
00076   fout<<"<!-- <I> [id] [itype] [nbody] [s0] [s1] ... </I> -->"<<endl<<endl;
00077   
00078   int  NB = D * N ;   // number of bonds
00079   int* x = new int[D];
00080   int  itype = 0;
00081   int  nbody = 2;
00082   NB = 0;
00083  
00084  
00085   for (int i=0; i<N; i++) {
00086     for (int p=0; p<D; p++) {
00087       int k = i;
00088       for (int q=0; q<D; q++) {
00089         x[q] = k % L[q];
00090         k /= L[q];
00091       }
00092       x[p] = (x[p] + 1) % L[p];
00093       int j = 0;
00094       for (int q=D-1; q>=0; q--) {
00095         j *= L[q];
00096         j += x[q];
00097       }
00098      
00099       fout<<"<I> "<<NB<<" "<<itype<<" "<<nbody<<" "<<i<<" "<<j<<" </I>"<<endl;
00100 
00101       NB++;
00102     }
00103   }
00104   
00105   fout<<endl;
00106   fout<<"</LATTICE>"<<endl;
00107   
00108   delete [] x;
00109   
00110 }
00111 //--------------------------------------------------------------
00112 
00113 int main(int argc,char** argv){
00114 
00115   int NARG = 3;
00116   if ( argc < NARG + 1 ) {
00117     ShowUsage(argc,argv);
00118     exit(0);
00119   }
00120   const int  D    = atoi(argv[1]);
00121 //  int        L[D] ;
00122   int* L = new int[D]; //edit sakakura
00123   double     B    = 0.0;
00124   
00125   if ( argc == NARG + 1 ){
00126     int    lx  = atoi(argv[2]);
00127     for( int i = 0 ; i < D ;i++){ L[i] = lx ; }
00128     B  = (double)atof(argv[3]);
00129   }else if( argc == D + NARG ){    
00130     for(int i = 0 ; i < D ; i++){ L[i] = atoi(argv[2+i]) ;}
00131     B = (double)atof(argv[D+NARG - 1 ]);
00132   } else{
00133     cout<<"error: D != number of L[]."<<endl;
00134     ShowUsage(argc,argv);
00135     exit(0);
00136   } 
00137   
00138   int EvenOrOdd = 0;
00139   cout.precision(15);
00140   cout<<"D     = "<<D<<endl;
00141   for(int i = 0 ; i < D ; i++){
00142     cout<<"L"<<i<<"    = "<<L[i]<<endl;
00143     EvenOrOdd += L[i]%2 ;
00144   }
00145   cout<<"B     = "<<B<<endl;
00146 
00147   if( EvenOrOdd ) { cout<<"Warnig: L should be an even number."<<endl;}
00148 
00149   WriteXML( D, L, B);
00150   cout<<"... done."<<endl;
00151   delete []L;
00152   return 0 ;
00153   
00154 }
 全て クラス ネームスペース ファイル 関数 変数 型定義 列挙型の値 フレンド マクロ定義