]> git.treefish.org Git - phys/latlib.git/blobdiff - o815/sim.cpp
...
[phys/latlib.git] / o815 / sim.cpp
index 1b81dda4401b4bd042750763445c5dac4cd5adad..b37549aa9994977f7000c34517dbcd1a3292114f 100644 (file)
@@ -7,51 +7,78 @@ o815::sim::sim(o815 *_O815, const int& _confmemSize) {
   O815 = _O815;
   log = O815->out->log;
   hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, _confmemSize, O815->comargs.confcache.second, log);
   O815 = _O815;
   log = O815->out->log;
   hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, _confmemSize, O815->comargs.confcache.second, log);
-  toEquilibrate = true;
   nequi = O815->comargs.nequi;
   nskip = O815->comargs.nskip;
   confmemSize = confmemSize;
 }
 
 void o815::sim::nextConfig() {
   nequi = O815->comargs.nequi;
   nskip = O815->comargs.nskip;
   confmemSize = confmemSize;
 }
 
 void o815::sim::nextConfig() {
-  int nequileft = hypercache::readC();
+  bool readnewconfig;
+  int nequileftReadConfig;
+  bool skippedInEqui = false;
+  bool readNoSingleConfig = true;
+  bool createdNoNewConfigs = true;
 
 
-  if ( nequileft != -1 ) {
-    /* try to use excluded config-file for equilibration */
-    if (toEquilibrate && hypercache::CFilesLeft() > 0) {
-      int exnequileft;
-      char *tmpconfig = (char*) malloc(confmemSize);
+  hypercache::readC(readnewconfig, nequileftReadConfig);
 
 
+  if (readnewconfig) {
+    nequileft = nequileftReadConfig;
+    readNoSingleConfig = false;
+  }
+
+  /* try to find more equilibrated config-file for equilibration including excluded files */
+  if ( nequileft > 0 && hypercache::CFilesLeft() > 0 ) {
+    char *tmpconfig = (char*) malloc(confmemSize);
+
+    while (true) {
       memcpy (tmpconfig, confMem, confmemSize);
       memcpy (tmpconfig, confMem, confmemSize);
-      exnequileft = hypercache::read1CForEqui();
+      hypercache::readC(readnewconfig, nequileftReadConfig);
 
 
-      if (exnequileft < nequileft) {
-       *log << "SIM: Found suitable excluded config-file configuration for equilibration." << endl << flush;
-       nequileft = exnequileft;
+      if (! readnewconfig) {
+       *log << "SIM: No more excluded config-files for possible equilibration available." << endl << flush;
+       break;
       }
       }
-      else {
-       *log << "SIM: Could not find suitable excluded config-file configuration for equilibration." << endl << flush;
+      
+      if (nequileftReadConfig <= nequileft) {
+       *log << "SIM: Found more equilibrated or same equilibrated excluded config-file configuration for equilibration." << endl << flush;
+       nequileft = nequileftReadConfig;
+       readNoSingleConfig = false;
+      }
+      else if (nequileftReadConfig > nequileft) {
+       *log << "SIM: Excluded config-file configuration for equilibration is less equilibrated than actual config." << endl << flush;
        memcpy (confMem, tmpconfig, confmemSize);
       }
        memcpy (confMem, tmpconfig, confmemSize);
       }
+    }
+    free(tmpconfig);
+  }
 
 
-      free(tmpconfig);
+  /* equilibrate if necessary */
+  if (nequileft > 0) {
+    *log << "SIM: Starting equilibration." << endl << flush;
+    if (nequileft != nequi)
+      *log << "SIM: " << nequileft << " of " << nequi << " equilibration steps left after virtual equilibration." << endl << flush;
+    progress equiProg(nequileft);
+    for ( int iequi=0; iequi<nequileft; iequi++ ) {
+      _makeSweep();
+      while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
     }
     }
+    nequileft = 0;
+    skippedInEqui = true;
+    createdNoNewConfigs = false;
+  }
 
 
-    if(toEquilibrate && nequileft > 0) {
-      _reset();
-      *log << "SIM: Starting equilibration." << endl << flush;
-      if (nequileft != nequi)
-       *log << "SIM: " << nequileft << " of " << nequi << " equilibration steps left after virtual equilibration." << endl << flush;
-      progress equiProg(nequileft);
-      for( int iequi=0; iequi<nequileft; iequi++ ) {
-       _makeSweep(1);
-       while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
-      }
+  /* make skip if no config could be read */
+  if ( ! skippedInEqui && readNoSingleConfig ) {
+    cout << "here" << endl;
+    for (int iskip=0; iskip<nskip; iskip++) {
+      _makeSweep();
+      nequileft--;
     }
     }
-       
-    _makeSweep(nskip);
-    hypercache::writeC();
+    createdNoNewConfigs = false;
   }
   }
-  
-  toEquilibrate = false;
+  if (! createdNoNewConfigs)
+    hypercache::writeC(nequi-nequileft);
+
+  cout << nequileft << endl;
 }
 }