diff --git a/src/io/MultiObjectGenerator.cpp b/src/io/MultiObjectGenerator.cpp index 70fb9c4b44..22ec227918 100644 --- a/src/io/MultiObjectGenerator.cpp +++ b/src/io/MultiObjectGenerator.cpp @@ -9,7 +9,9 @@ #include #endif +#include "IOHelpers.h" #include "Domain.h" +#include "Simulation.h" #include "ensemble/EnsembleBase.h" #include "io/ObjectGenerator.h" #include "molecules/MoleculeIdPool.h" @@ -41,6 +43,7 @@ void MultiObjectGenerator::readXML(XMLfileUnits& xmlconfig) { _generators.push_back(generator); } xmlconfig.changecurrentnode(oldpath); + xmlconfig.getNodeValue("removeDrift", _removeDrift); } @@ -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 diff --git a/src/io/MultiObjectGenerator.h b/src/io/MultiObjectGenerator.h index d9e787b95b..ee86fbaeef 100644 --- a/src/io/MultiObjectGenerator.h +++ b/src/io/MultiObjectGenerator.h @@ -18,6 +18,10 @@ 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} @@ -25,6 +29,7 @@ class MultiObjectGenerator : public InputBase { ... + BOOL \endcode */ @@ -38,6 +43,7 @@ class MultiObjectGenerator : public InputBase { std::list _generators; unsigned long _globalNumMolecules; + bool _removeDrift = false; }; #endif // SRC_IO_MULTIOBJECTGENERATOR_H_ diff --git a/src/io/ObjectGenerator.cpp b/src/io/ObjectGenerator.cpp index 312b5ed830..6a95dfdcee 100644 --- a/src/io/ObjectGenerator.cpp +++ b/src/io/ObjectGenerator.cpp @@ -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 @@ -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(); + } else { // if the seed is zero, maintain old behaviour return 0; } }(); diff --git a/src/io/ObjectGenerator.h b/src/io/ObjectGenerator.h index b33158d45e..c983b01c26 100644 --- a/src/io/ObjectGenerator.h +++ b/src/io/ObjectGenerator.h @@ -24,6 +24,10 @@ 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 @@ -31,7 +35,8 @@ class ObjectGenerator : public InputBase { - + + \endcode */