DSQSS
1.1
|
00001 00002 #ifndef LATTICE_H 00003 #define LATTICE_H 00004 00005 //###################################################################### 00006 00007 #include <stdio.h> 00008 #include "io.h" 00009 #include "objects.hpp" 00010 00011 //###################################################################### 00012 00013 class Lattice { 00014 00015 private: 00016 00017 Site* site; // the list of the poiters to sites 00018 Interaction* interaction; // the list of the pointers to interactions 00019 XML::Block X; 00020 Algorithm& ALG; 00021 00022 public: 00023 00024 int D; // dimension 00025 int* L; // linear size 00026 double BETA; // inverse temperature 00027 int NCELL; // total number of cells 00028 int NSITE; // total number of sites 00029 int NINT; // total number of interactions 00030 int NSTYPE; // number of site types 00031 int NITYPE; // number of interaction types 00032 00033 Lattice(const char* FNAME, Algorithm& A); 00034 00035 ~Lattice(); 00036 00037 void read(); 00038 00039 void initialize(); 00040 00041 Site& S(int i) { return site[i]; }; 00042 00043 Interaction& I(int i) { return interaction[i]; }; 00044 00045 int countVertices(); 00046 00047 void show_param(FILE* F) { 00048 fprintf(F,"P D = %12d\n",D); 00049 fprintf(F,"P L = "); 00050 for (int i=0; i<D; i++) { 00051 fprintf(F," %6d", L[i]); 00052 } 00053 fprintf(F,"\n"); 00054 fprintf(F,"P BETA = %24.16f\n", BETA); 00055 }; 00056 00057 void dump(); 00058 00059 }; 00060 00061 //###################################################################### 00062 00063 inline Lattice::Lattice(const char* FNAME, Algorithm& A) : ALG(A) { 00064 00065 if (DEBUG) printf("\nLattice::Lattice> Start.\n"); // koko 00066 00067 X.initialize( FNAME , "LATTICE" ); 00068 read(); 00069 initialize(); 00070 00071 if (DEBUG) printf("Lattice::Lattice> End.\n"); // koko 00072 00073 } 00074 00075 //====================================================================== 00076 00077 void Lattice::read() { 00078 00079 // if (DEBUG) printf("Lattice::read> Start.\n"); 00080 00081 D = X["Dimension"].getInteger(); 00082 L = new int [D]; 00083 for (int i=0; i<D; i++) { 00084 L[i] = X["LinearSize"].getInteger(i); 00085 } 00086 BETA = X["Beta"].getDouble(); 00087 00088 NCELL = X["NumberOfCells"].getInteger(); 00089 NSITE = X["NumberOfSites"].getInteger(); 00090 NINT = X["NumberOfInteractions"].getInteger(); 00091 NSTYPE = X["NumberOfSiteTypes"].getInteger(); 00092 NITYPE = X["NumberOfInteractionTypes"].getInteger(); 00093 site = new Site[NSITE]; 00094 interaction = new Interaction[NINT]; 00095 for (int i=0; i<X.NumberOfBlocks(); i++) { 00096 XML::Block& B = X[i]; 00097 00098 if ( B.getName() == "S" ) { 00099 int id = B.getInteger(0); 00100 int st = B.getInteger(1); 00101 int mt = B.getInteger(2); 00102 S(id).init( ALG.getSiteProperty(st) , mt ); 00103 00104 #ifdef NORM 00105 S(id).setBeta( 1.0 ); 00106 #else 00107 S(id).setBeta( BETA ); 00108 #endif 00109 } 00110 if ( B.getName() == "I" ) { 00111 int id = B.getInteger(0); 00112 int it = B.getInteger(1); 00113 int nb = B.getInteger(2); 00114 I(id).init(ALG.getInteractionProperty(it)); 00115 for (int ii=0; ii<nb; ii++) { 00116 int sid = B.getInteger(3+ii); 00117 I(id).setSite(ii,S(sid)); 00118 } 00119 } 00120 } 00121 } 00122 00123 //====================================================================== 00124 #include <set> 00125 void Lattice::initialize() { 00126 00127 if (DEBUG) printf("Lattice::initialize> Start.\n"); 00128 00129 //---// サイトに相互作用が働くサイトを登録する.// 00130 //set<Interaction*> InteractionOnEachSite[NSITE]; 00131 set<Interaction*>* InteractionOnEachSite; 00132 InteractionOnEachSite = new set<Interaction*> [NSITE]; 00133 00134 int NRVIMAX = 0; // maximum number of registered vertex informations 00135 00136 for(int iid=0; iid<NINT; iid++){ 00137 for (int i=0; i<I(iid).NBODY(); i++) { 00138 00139 InteractionOnEachSite[I(iid).site(i).id()-1].insert( &I(iid) ); 00140 } 00141 } 00142 00143 for(int sid=0; sid<NSITE; sid++){ 00144 S( sid ).setNCI( InteractionOnEachSite[sid].size() ); 00145 00146 int counter = 0 ; 00147 set<Interaction*>::iterator it = InteractionOnEachSite[sid].begin(); 00148 00149 while( it != InteractionOnEachSite[sid].end() ){ 00150 S( sid ).setCI( counter, (*it) ); 00151 ++it; 00152 ++counter; 00153 } 00154 00155 InteractionOnEachSite[sid].clear(); 00156 if(NRVIMAX < S(sid).getNCI()) NRVIMAX = S(sid).getNCI(); 00157 } 00158 00159 TheRVIPool.init(NRVIMAX*NRVIMAX); 00160 delete [] InteractionOnEachSite; 00161 if (DEBUG) printf("Lattice::initialize> End.\n"); 00162 } 00163 00164 //====================================================================== 00165 00166 inline Lattice::~Lattice() { 00167 // printf("*** Destroying Lattice\n"); 00168 if ( L != 0 ) { delete [] L; } 00169 if ( site != 0 ) { delete [] site; } 00170 if ( interaction != 0 ) { delete [] interaction; } 00171 } 00172 00173 //====================================================================== 00174 00175 inline int Lattice::countVertices() { 00176 int NV = 0; 00177 for (int b=0; b<NINT; b++) { 00178 NV += I(b).count(); 00179 } 00180 return NV; 00181 } 00182 00183 //====================================================================== 00184 00185 inline void Lattice::dump() { 00186 printf("\n"); 00187 printf("Lattice Information:\n"); 00188 printf(" D = %d\n",D); 00189 printf(" L ="); 00190 for (int i=0; i<D; i++) { 00191 printf(" %d", L[i]); 00192 } 00193 printf("\n"); 00194 printf(" BETA = %24.16f\n", BETA); 00195 printf(" NCELL = %d\n",NCELL); 00196 printf(" NSITE = %d\n",NSITE); 00197 printf(" NINT = %d\n",NINT); 00198 printf(" NSTYPE = %d\n",NSTYPE); 00199 printf(" NITYPE = %d\n",NITYPE); 00200 printf("\n"); 00201 for (int i=0; i<NSITE; i++) { S(i).dump(); } 00202 printf("\n"); 00203 for (int i=0; i<NINT; i++) { I(i).dump(); } 00204 } 00205 00206 #endif