diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 625583c01d..d0a7189966 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -326,8 +326,9 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) { else if(parallelisationtype == "DomainDecomposition") { delete _domainDecomposition; _domainDecomposition = new DomainDecomposition( -#ifdef MAMICO_COUPLING coupling::interface::LS1StaticCommData::getInstance().getLocalCommunicator(), - coupling::interface::LS1StaticCommData::getInstance().getDomainGridDecomp() +#ifdef MAMICO_COUPLING + coupling::interface::LS1StaticCommData::getInstance().getLocalCommunicator(), + coupling::interface::LS1StaticCommData::getInstance().getDomainGridDecomp() #endif ); } diff --git a/src/plugins/MamicoCoupling.cpp b/src/plugins/MamicoCoupling.cpp index 37721c768e..d0c29b9fe9 100644 --- a/src/plugins/MamicoCoupling.cpp +++ b/src/plugins/MamicoCoupling.cpp @@ -2,22 +2,17 @@ #include "Domain.h" void MamicoCoupling::readXML(XMLfileUnits& xmlconfig) -{ +{ return; } -/** @brief Ensures _macroscopicCellService is initialized, and switches the ls1 thermostat off. - * - * MaMiCo uses its own thermostat, which will conflict with the ls1 thermostat. */ void MamicoCoupling::init(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, Domain* domain) { - #ifdef MAMICO_COUPLING - //since using mamico thermostat, switch off ls1 thermostat - domain->thermostatOff(); +#ifdef MAMICO_COUPLING //code to print to log that plugin is initialised global_log->info() << "MaMiCo coupling plugin initialized" << std::endl; - #endif +#endif } void MamicoCoupling::beforeEventNewTimestep(ParticleContainer* particleContainer, @@ -26,21 +21,11 @@ void MamicoCoupling::beforeEventNewTimestep(ParticleContainer* particleContainer } -/** @brief Takes coupling steps such as particle insertion, to make sure they are accounted for before forces are calculated. - * - * Following steps are taken, if coupling is switched on: - * - Iterate over cells to average values like momentum and mass, to pass to macroscopic solvers - * - Distribute incoming mass from macroscopic solver by inserting perticles (if enabled) - * - Run the MaMiCo thermostat cell by cell - * - * The distributeMass method calls the updateParticleContainerAndDecomposition() function at the end, so we end up with a container with halo particles present. - * Hence a manual halo clearance is done to restore the state of the container. - * */ void MamicoCoupling::beforeForces(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, unsigned long simstep) { - #ifdef MAMICO_COUPLING - if(_couplingEnabled) //only perform coupling steps if coupling is enabled +#ifdef MAMICO_COUPLING + if(_couplingEnabled) { // This object should be set by MaMiCo after the plugins are created in the simulation readxml file // Even though this method is called before the object is set, at this point the coupling switch is always off @@ -50,26 +35,20 @@ void MamicoCoupling::beforeForces(ParticleContainer* particleContainer, #ifndef MARDYN_AUTOPAS particleContainer->deleteOuterParticles(); #endif - } - #endif + } +#endif } -/** @brief Performs adjustments after force calculation - * - * Following steps are taken, if coupling is switched on: - * - Distribute incoming momentum among affected cells - * - Apply boundary force to molecules near microscopic domain boundary - * */ void MamicoCoupling::afterForces(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, unsigned long simstep) { - #ifdef MAMICO_COUPLING +#ifdef MAMICO_COUPLING if(_couplingEnabled) { _macroscopicCellService->distributeMomentum(simstep); _macroscopicCellService->applyBoundaryForce(simstep); } - #endif +#endif } void MamicoCoupling::endStep(ParticleContainer* particleContainer, diff --git a/src/plugins/MamicoCoupling.h b/src/plugins/MamicoCoupling.h index 0b4a558ee7..3184b23b40 100644 --- a/src/plugins/MamicoCoupling.h +++ b/src/plugins/MamicoCoupling.h @@ -23,9 +23,13 @@ class MamicoCoupling: public PluginBase { MamicoCoupling() {} virtual ~MamicoCoupling() {} + /** @brief Prints to log that mamico coupling is inited + * + * */ void init(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, Domain* domain) override; + void readXML(XMLfileUnits& xmlconfig) override; void beforeEventNewTimestep( @@ -33,11 +37,27 @@ class MamicoCoupling: public PluginBase { unsigned long simstep ) override; + /** @brief Takes coupling steps such as particle insertion, to make sure they are accounted for before forces are calculated. + * + * Following steps are taken, if coupling is switched on: + * - Iterate over cells to average values like momentum and mass, to pass to macroscopic solvers + * - Distribute incoming mass from macroscopic solver by inserting perticles (if enabled) + * - Run the MaMiCo thermostat cell by cell + * + * The distributeMass method calls the updateParticleContainerAndDecomposition() function at the end, so we end up with a container with halo particles present. + * Hence a manual halo clearance is done to restore the state of the container. + * */ void beforeForces( ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, unsigned long simstep ) override; + /** @brief Performs adjustments after force calculation + * + * Following steps are taken, if coupling is switched on: + * - Distribute incoming momentum among affected cells + * - Apply boundary force to molecules near microscopic domain boundary + * */ void afterForces( ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, unsigned long simstep @@ -57,7 +77,7 @@ class MamicoCoupling: public PluginBase { static PluginBase* createInstance() { return new MamicoCoupling(); } #ifdef MAMICO_COUPLING -/** @brief sets the macroscopicCellService object that controls the inner coupling logic. +/** @brief Sets the macroscopicCellService object that controls the inner coupling logic. * * MaMiCo extracts the MamicoCoupling plugin object from the simulation object after initialization and uses this function to set the macroscopicCellCervice. * The code for this object can be found in https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/services/MacroscopicCellService.cpph @@ -66,15 +86,30 @@ class MamicoCoupling: public PluginBase { _macroscopicCellService = static_cast*> (macroscopicCellService); } +#endif +/** @brief Enables coupling logic, allowing coupling steps to run while simulation is running. + * + * Set from within MaMiCo, check https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, class LS1MDSimulation + * */ void switchOnCoupling(){ _couplingEnabled = true; } + +/** @brief Disables coupling logic, not allowing coupling steps to run. Typically done when equilibrating the simulation initially. + * + * Set from within MaMiCo, check https://github.com/HSU-HPC/MaMiCo/blob/master/coupling/interface/MDSimulationFactory.h, class LS1MDSimulation + * */ void switchOffCoupling(){ _couplingEnabled = false; } + +/** @brief Getter method for the coupling state. + * + * Not used currently, but may be used in future + * */ bool getCouplingState() { return _couplingEnabled;} -#endif + private: #ifdef MAMICO_COUPLING coupling::services::MacroscopicCellServiceImpl* _macroscopicCellService; - bool _couplingEnabled = false; #endif + bool _couplingEnabled = false; };