LeMonADE-project / LeMonADE

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

Analyzer run before updater (example 5 broken) #75

Open mxmlnkn opened 7 years ago

mxmlnkn commented 7 years ago

Example 5, which demonstrates how it is possible to add particles using an updater called only once, fails to output meaningful results:

make && ./bin/Example5 && tail Rg2.dat
echo "===ex5output.dat==="; cat ex5output.dat

Output:

9.91e+06    0   0   0   0   
9.92e+06    0   0   0   0   
9.93e+06    0   0   0   0   
9.94e+06    0   0   0   0   
9.95e+06    0   0   0   0   
9.96e+06    0   0   0   0   
9.97e+06    0   0   0   0   
9.98e+06    0   0   0   0   
9.99e+06    0   0   0   0   
1e+07   0   0   0   0   

===ex5output.dat===
0   0   0

That output looked wrong, so I looked in the code and found that the custom analyzer in ex5analyzer.h saves the number of particles in its initialize-method. But that method is called before ex5updater.h's execute method which spawns the particles. That's why the analyzer sees zero particles. One workaround might be to not save the number of particles in the initialize method. That shouldn't result in a measurable performance hit. Getting the number of elements in an std::vector should be O(1). I did this tentatively here. After that change the custom analyzer worked.

But as the default radius of gyration analyzer has the same problem it might be better to put the particle creation code into the initialize method of ex5updater.h instead of putting it in execute. But then again src/utility/TaskManager.cpp:TaskManager::initialize contains the comment @todo initialize updaters necessary?, so I guess the initialize method wasn't intended to be used like this. Therefore this might be a bigger design problem needing discussion.