]> git.treefish.org Git - phys/latlib.git/blob - o815/sim.cpp
Made c++11 standard dependency obsolete.
[phys/latlib.git] / o815 / sim.cpp
1 #include "o815.h"
2
3 #include "latlib/hypercache.h"
4 #include "latlib/progress.h"
5
6 #include "latlib/datread.h"
7
8 o815::sim::sim(o815 *_O815, const int& _confmemSize) {
9   O815 = _O815;
10   log = O815->out->log;
11   hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, _confmemSize, O815->comargs.confcache.second, log);
12   nequi = O815->comargs.nequi;
13   nskip = O815->comargs.nskip;
14   confmemSize = _confmemSize;
15
16   startConfiguration = NULL;
17   
18   if ( O815->comargs.startconfig != "" ) {
19     *log << "SIM: Fetching startconfig from " << O815->comargs.startconfig << endl;
20     
21     datread dataReader(confmemSize);
22     dataReader.openFile(O815->comargs.startconfig);
23     
24     if ( dataReader.fisopen() ) {
25       startConfiguration = (char*)malloc(confmemSize);
26       
27       if ( dataReader.readFullBlock(startConfiguration) < 0 ) {
28         *log << "SIM: Error while reading config from " << O815->comargs.startconfig << endl;
29         delete[] startConfiguration;
30         startConfiguration = NULL;
31       }     
32     }
33     else {
34       *log << "SIM: Could not open startconfigfile " << O815->comargs.startconfig << endl;
35     }
36   }
37   
38 }
39
40 o815::sim::~sim ()
41 {
42   if (startConfiguration != NULL)
43     delete[] startConfiguration;
44 }
45
46 void o815::sim::nextConfig() {
47   bool readAtLeastOneConfig = hypercache::readC();
48
49   /* equilibrate if necessary */
50   if (hypercache::getNEquiLeft() > 0) {
51     *log << "SIM: Starting equilibration." << endl << flush;
52     if (hypercache::getNEquiLeft() != nequi)
53       *log << "SIM: " << hypercache::getNEquiLeft() << " of " << nequi << " equilibration steps left after virtual equilibration." << endl << flush;
54     progress equiProg(hypercache::getNEquiLeft());
55     for ( int iequi = 0; iequi < hypercache::getNEquiLeft(); iequi++ ) {
56       _makeSweep();
57       while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
58     }
59   }
60
61   /* make skip if no config could be read or one skip is left after equilibration */
62   if ( (! readAtLeastOneConfig) || (hypercache::getNEquiLeft() >= 0) ) {
63     for (int iskip=0; iskip<nskip; iskip++) {
64       _makeSweep();
65     }
66     hypercache::writeC();
67   }
68 }
69
70 void o815::sim::resetConfig() {
71   if ( startConfiguration != NULL )
72     memcpy(confMem, startConfiguration, confmemSize);
73   else
74     _resetConfig();
75 }