Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/io/MultiObjectGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <mpi.h>
#endif

#include "IOHelpers.h"
#include "Domain.h"
#include "Simulation.h"
#include "ensemble/EnsembleBase.h"
#include "io/ObjectGenerator.h"
#include "molecules/MoleculeIdPool.h"
Expand Down Expand Up @@ -41,6 +43,7 @@ void MultiObjectGenerator::readXML(XMLfileUnits& xmlconfig) {
_generators.push_back(generator);
}
xmlconfig.changecurrentnode(oldpath);
xmlconfig.getNodeValue("removeDrift", _removeDrift);
}


Expand All @@ -55,6 +58,8 @@ unsigned long MultiObjectGenerator::readPhaseSpace(ParticleContainer* particleCo
numMolecules += generator->readPhaseSpace(particleContainer, domain, domainDecomp);
}
particleContainer->updateMoleculeCaches();
if(_removeDrift)
IOHelpers::removeMomentum(particleContainer, *(global_simulation->getEnsemble()->getComponents()), domainDecomp);
Log::global_log->info() << "Number of locally inserted molecules: " << numMolecules << std::endl;
_globalNumMolecules = numMolecules;
#ifdef ENABLE_MPI
Expand Down
6 changes: 6 additions & 0 deletions src/io/MultiObjectGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ class MultiObjectGenerator : public InputBase {

/** @brief Read in XML configuration for Generator and all its included objects.
*
* The removeDrift parameter uses the function IOHelpers::removeMomentum() to remove overall drift from the
* phasespace after initialisation, similar to what is done in CubicGridGenerator. This is off by default, as
* some experiments may want to load checkpoints with initial drift.
*
* The following xml object structure is handled by this method:
* @note This structure is not fixed yet and may see changes
* \code{.xml}
<generator name="MultiObjectGenerator">
<objectgenerator> <!-- ... --> </objectgenerator>
...
<velocityAssigner> <!-- ... --> </velocityAssigner>
<removeDrift>BOOL</removeDrift>
</generator >
\endcode
*/
Expand All @@ -38,6 +43,7 @@ class MultiObjectGenerator : public InputBase {

std::list<ObjectGenerator*> _generators;
unsigned long _globalNumMolecules;
bool _removeDrift = false;
};

#endif // SRC_IO_MULTIOBJECTGENERATOR_H_
11 changes: 10 additions & 1 deletion src/io/ObjectGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ void ObjectGenerator::readXML(XMLfileUnits& xmlconfig) {
const long seed = [&]() -> long {
bool enableRandomSeed = false;
xmlconfig.getNodeValue("@enableRandomSeed", enableRandomSeed);
long fixedSeed = 0;
xmlconfig.getNodeValue("@seed", fixedSeed);
if (fixedSeed != 0 && enableRandomSeed) {
std::ostringstream error_message;
error_message << "Cannot simultaneously have a simulation seed and a random seed!" << std::endl;
MARDYN_EXIT(error_message.str());
}
if(enableRandomSeed) {
/** A random seed for the velocity generator is created.
* The current rank is added to make sure that, if multiple simulations are instantiated across
Expand All @@ -74,7 +81,9 @@ void ObjectGenerator::readXML(XMLfileUnits& xmlconfig) {
*/
return std::chrono::system_clock::now().time_since_epoch().count() + _simulation.domainDecomposition().getRank();

} else {
} else if(fixedSeed != 0) {
return fixedSeed + _simulation.domainDecomposition().getRank();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to multiply fixedSeed by 1k to keep the ranks “visible” in the decimal representation for debugging purposes?

} else { // if the seed is zero, maintain old behaviour
return 0;
}
}();
Expand Down
7 changes: 6 additions & 1 deletion src/io/ObjectGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ class ObjectGenerator : public InputBase {
ObjectGenerator() : _filler(nullptr), _object(nullptr), _velocityAssigner(nullptr), _moleculeIdPool(nullptr) {};

/** @brief Read in XML configuration for ObjectGenerator and all its included objects.
*
* The velocityAssigner can take two additional parameters. enableRandomSeed adds the option of having random
* intial molecule velocities at the beginning of the simulation. If a seed is specified, that value is used
* instead. Leaving both blank gives the default behaviour (seed = 0). Both cannot be nonzero simultaneously.
*
* The following XML object structure is handled by this method:
* @note This structure is not fixed yet and may see changes
* \code{.xml}
<objectgenerator>
<filler type="STRING"> <!-- see Filler documentation --> </filler>
<object type="STRING"> <!-- see Object documentation --> </object>
<velocityAssigner type="STRING"> <!-- see VelocityAssignerBase documentation --> </velocityAssigner>
<velocityAssigner type="STRING" enableRandomSeed="BOOL" seed="LONG">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps one could also add a comment here to indicate that enableRandomSeed and seed are mutually exclusive.

<!-- see VelocityAssignerBase documentation --> </velocityAssigner>
</objectgenerator>
\endcode
*/
Expand Down
Loading