X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/ad54f29de351976a096b4991fe426ffc30332df2..c819c7a5996c18a6b1c5501c1984245840ddc8ca:/o815/sim.cpp?ds=sidebyside diff --git a/o815/sim.cpp b/o815/sim.cpp index 1b81dda..ec47339 100644 --- a/o815/sim.cpp +++ b/o815/sim.cpp @@ -3,55 +3,73 @@ #include "latlib/hypercache.h" #include "latlib/progress.h" +#include "latlib/datread.h" + 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); - toEquilibrate = true; nequi = O815->comargs.nequi; nskip = O815->comargs.nskip; - confmemSize = confmemSize; + confmemSize = _confmemSize; + + startConfiguration = NULL; + + if ( O815->comargs.startconfig != "" ) { + *log << "SIM: Fetching startconfig from " << O815->comargs.startconfig << endl; + + datread dataReader(confmemSize); + dataReader.openFile(O815->comargs.startconfig); + + if ( dataReader.fisopen() ) { + startConfiguration = (char*)malloc(confmemSize); + + if ( dataReader.readFullBlock(startConfiguration) < 0 ) { + *log << "SIM: Error while reading config from " << O815->comargs.startconfig << endl; + delete[] startConfiguration; + startConfiguration = NULL; + } + } + else { + *log << "SIM: Could not open startconfigfile " << O815->comargs.startconfig << endl; + } + } + +} + +o815::sim::~sim () +{ + if (startConfiguration != NULL) + delete[] startConfiguration; } void o815::sim::nextConfig() { - int nequileft = hypercache::readC(); - - if ( nequileft != -1 ) { - /* try to use excluded config-file for equilibration */ - if (toEquilibrate && hypercache::CFilesLeft() > 0) { - int exnequileft; - char *tmpconfig = (char*) malloc(confmemSize); - - memcpy (tmpconfig, confMem, confmemSize); - exnequileft = hypercache::read1CForEqui(); - - if (exnequileft < nequileft) { - *log << "SIM: Found suitable excluded config-file configuration for equilibration." << endl << flush; - nequileft = exnequileft; - } - else { - *log << "SIM: Could not find suitable excluded config-file configuration for equilibration." << endl << flush; - memcpy (confMem, tmpconfig, confmemSize); - } - - free(tmpconfig); + bool readAtLeastOneConfig = hypercache::readC(); + + /* equilibrate if necessary */ + if (hypercache::getNEquiLeft() > 0) { + *log << "SIM: Starting equilibration." << endl << flush; + if (hypercache::getNEquiLeft() != nequi) + *log << "SIM: " << hypercache::getNEquiLeft() << " of " << nequi << " equilibration steps left after virtual equilibration." << endl << flush; + progress equiProg(hypercache::getNEquiLeft()); + for ( int iequi = 0; iequi < hypercache::getNEquiLeft(); iequi++ ) { + _makeSweep(); + while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush; } + } - 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= 0) ) { + for (int iskip=0; iskip