LeMonADE-project / LeMonADE

Library for Monte Carlo Simulation applying the Bond Fluctuation Model
Other
3 stars 11 forks source link

Molecules operator= bugged #77

Closed mxmlnkn closed 7 years ago

mxmlnkn commented 7 years ago

When trying to repeat simulations e.g. for a naive ensemble average, then the first result is always higher. My first try looked a bit like this:

auto & molecules = simulation.modifyMolecules();
auto const molecules0 = molecules;
for ( auto iRun = 0u; iRun < nRepetitions; ++iRun )
{
    taskManager.initialize();
    taskManager.run( nTotalTimesteps / nTimeStepsPerCycle );
    /* get and print radius of gyration */
    taskManager.cleanup();
    molecules = molecules0;
}

Attached is my test program: testSimulationRepetition.cpp. The results are:

=== rg-means.log ===
<Rg> = 6.06089 +- 0.371778
<Rg> = 4.98674 +- 0.609736
<Rg> = 5.21327 +- 0.335749
<Rg> = 5.93059 +- 0.328959
=== testFullCleanRepetition.log ===
5.97932 15.7525 12.7321 7.26763
5.91749 14.6561 12.8429 7.51774
6.05552 17.0971 8.19222 11.38
6.12224 11.2011 15.9985 10.2822
6.31416 14.8004 18.241 6.82732
5.9307 17.8436 6.49889 10.8307
6.91591 27.9014 6.92954 12.9988
5.58759 14.1259 6.88959 10.2057
5.64761 12.5291 10.0551 9.31118
6.13832 16.1411 10.605 10.9329
=== testSaveConstructorsRepetition.log ===
6.47989 26.3087 8.27318 7.40712
5.38021 10.2215 9.86793 8.85721
5.00549 12.7064 7.53382 4.81466
4.86796 10.7826 6.6144 6.29996
4.99283 10.7786 8.32759 5.82218
4.81039 8.61821 6.90675 7.61492
4.26821 7.21779 5.09191 5.90789
4.42889 8.06931 6.16718 5.37861
4.69265 10.4474 4.26873 7.30481
4.94088 10.8748 6.53204 7.00547
=== testSaveConstructorsRepetitionRespawnMolecules.log ===
6.30503 23.4519 7.12468 9.17675
5.94103 14.5468 12.4792 8.26979
5.35956 9.53151 11.3178 7.87557
6.06499 16.3702 11.3801 9.03384
5.81442 15.794 6.98324 11.0303
6.46024 22.3255 9.92891 9.48029
5.81216 13.3543 11.6108 8.81615
5.87273 16.0284 11.3479 7.11273
6.12152 17.1389 7.866 12.4681
5.55425 14.8885 7.82639 8.13484
=== testSaveConstructorsRepetitionWithTaskManager.log ===
5.65273 12.9796 9.89698 9.07677
4.92699 8.33113 6.34801 9.59611
4.94741 10.848 6.43847 7.19038
5.2126 10.7393 8.62337 7.80857
4.92652 10.8736 6.09205 7.30496
4.82811 11.2332 6.94839 5.12898
5.29403 13.054 6.30282 8.67
5.77559 17.0541 8.87555 7.42769
5.05481 7.81535 8.13093 9.60486
5.5139 14.06 8.6149 7.72825

testFullCleanRepetition completely reconstructs the simulation object, resets the box, allowed movements and molecules. testSaveConstructorsRepetition this was my first try as can be seen above testSaveConstructorsRepetitionWithTaskManager This is the same as above, but in each run the task manager and all analyzers, updaters are deconstructed and newly constructed. testSaveConstructorsRepetitionRespawnMolecules in this test the line molecules = molecules0 is replaced by molecules.resize(0); spawnMolecules(molecules);

As can be seen testSaveConstructorsRepetitionRespawnMolecules and testFullCleanRepetition do work as expected, but the others don't, therefore I assume the copy-method in Molecules.h is bugged.

mxmlnkn commented 7 years ago

Turns out I was just missing a call to synchronize after copying molecules from the backup in molecules0. After adding simulation.synchronize( simulation ); all versions do work. Btw, why is the argument necessary? synchronize is already a member function of simulation, so using the this-pointer should be just fine.