Skip to content

Commit

Permalink
docs and indent cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amartyads committed Sep 6, 2023
1 parent eddfd07 commit e085bd0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
39 changes: 9 additions & 30 deletions src/plugins/MamicoCoupling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
41 changes: 38 additions & 3 deletions src/plugins/MamicoCoupling.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,41 @@ 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(
ParticleContainer* particleContainer, DomainDecompBase* domainDecomp,
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
Expand All @@ -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
Expand All @@ -66,15 +86,30 @@ class MamicoCoupling: public PluginBase {
_macroscopicCellService = static_cast<coupling::services::MacroscopicCellServiceImpl<ls1::LS1RegionWrapper,3>*>
(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<ls1::LS1RegionWrapper,3>* _macroscopicCellService;
bool _couplingEnabled = false;
#endif
bool _couplingEnabled = false;
};

0 comments on commit e085bd0

Please sign in to comment.