Skip to content
Snippets Groups Projects
Commit 792a6132 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Changed regtest to use move semantics

parent a4f3d8c1
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
using namespace PLMD; using namespace PLMD;
void go(Plumed* p,int natoms,unsigned iw,unsigned is){ void go(Plumed& p,int natoms,unsigned iw,unsigned is){
std::vector<double> positions(3*natoms,0.0); std::vector<double> positions(3*natoms,0.0);
for(unsigned i=0;i<natoms;i++) positions[i]=i+iw+is; for(unsigned i=0;i<natoms;i++) positions[i]=i+iw+is;
std::vector<double> masses(natoms,1.0); std::vector<double> masses(natoms,1.0);
...@@ -12,38 +12,41 @@ void go(Plumed* p,int natoms,unsigned iw,unsigned is){ ...@@ -12,38 +12,41 @@ void go(Plumed* p,int natoms,unsigned iw,unsigned is){
std::vector<double> box(9,0.0); std::vector<double> box(9,0.0);
std::vector<double> virial(9,0.0); std::vector<double> virial(9,0.0);
p->cmd("setStep",&is); p.cmd("setStep",&is);
p->cmd("setPositions",&positions[0]); p.cmd("setPositions",&positions[0]);
p->cmd("setBox",&box[0]); p.cmd("setBox",&box[0]);
p->cmd("setForces",&forces[0]); p.cmd("setForces",&forces[0]);
p->cmd("setVirial",&virial[0]); p.cmd("setVirial",&virial[0]);
p->cmd("setMasses",&masses[0]); p.cmd("setMasses",&masses[0]);
p->cmd("calc"); p.cmd("calc");
} }
int main(){ int main(){
std::vector<Plumed*> p; /*
This regtest uses a STL containing Plumed objects.
This is only possible with a c++11 compiler that implements move semantics.
*/
std::vector<Plumed> p;
unsigned nwalkers=3; unsigned nwalkers=3;
unsigned nsteps=10; unsigned nsteps=10;
p.resize(nwalkers); p.resize(nwalkers);
for(unsigned iw=0;iw<nwalkers;iw++) p[iw]=new Plumed;
int natoms=10; int natoms=10;
for(unsigned iw=0;iw<nwalkers;iw++){ for(unsigned iw=0;iw<nwalkers;iw++){
p[iw]->cmd("setNatoms",&natoms); p[iw].cmd("setNatoms",&natoms);
std::ostringstream iwss; std::ostringstream iwss;
iwss<<iw; iwss<<iw;
std::string file; std::string file;
file="test." + iwss.str() + ".log"; file="test." + iwss.str() + ".log";
p[iw]->cmd("setLogFile",file.c_str()); p[iw].cmd("setLogFile",file.c_str());
file="plumed." + iwss.str() + ".dat"; file="plumed." + iwss.str() + ".dat";
p[iw]->cmd("setPlumedDat",file.c_str()); p[iw].cmd("setPlumedDat",file.c_str());
p[iw]->cmd("init"); p[iw].cmd("init");
} }
// half steps for each walker // half steps for each walker
...@@ -52,7 +55,5 @@ int main(){ ...@@ -52,7 +55,5 @@ int main(){
// other half steps for each walker // other half steps for each walker
for(unsigned iw=0;iw<nwalkers;iw++) for(unsigned is=nsteps/2;is<nsteps;is++) go(p[iw],natoms,iw,is); for(unsigned iw=0;iw<nwalkers;iw++) for(unsigned is=nsteps/2;is<nsteps;is++) go(p[iw],natoms,iw,is);
for(unsigned iw=0;iw<nwalkers;iw++) delete p[iw];
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment