Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to mamico plugin after mamico refactor #293

Open
wants to merge 107 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
766e562
small ancient bug fix
amartyads Mar 15, 2023
a64a78e
initial utils added
amartyads Mar 24, 2023
ecb6245
added const, finished methods
amartyads Mar 24, 2023
e772fc4
rename
amartyads Mar 24, 2023
4bd1be4
moved functions to utils
amartyads Mar 27, 2023
34250ae
more utils
amartyads Mar 28, 2023
02b49d6
files moved
amartyads Apr 2, 2023
59efed3
additional util
amartyads Apr 2, 2023
319be03
files moved back
amartyads Apr 2, 2023
b58a033
xml reading done
amartyads Apr 2, 2023
4d1a3d2
boundary condition initial skeleton
amartyads Apr 3, 2023
9266f87
reflecting boundary done, untested
amartyads Apr 4, 2023
837250f
outflow done, not tested
amartyads Apr 4, 2023
61d6e91
working wall detection, wrong paths (halos)
amartyads Apr 4, 2023
383495f
removed debug, tested for 8x8
amartyads Apr 5, 2023
a78a2f4
halo removal PoC
amartyads Apr 15, 2023
c765df4
cleanup. modern arrays
amartyads Apr 17, 2023
2ae6831
bugfix
amartyads May 15, 2023
1e251a7
better names, changed responsibilities of classes
amartyads May 25, 2023
d972360
added timer
amartyads May 25, 2023
16b7d75
more outputs
amartyads May 26, 2023
8c55679
bugfix, code working here
amartyads May 26, 2023
f7b958d
renames and moves
amartyads Jun 1, 2023
53b23f6
halo conversion
amartyads Jun 2, 2023
8d24d76
Normal domain decomp tested, bugfixed
amartyads Jul 19, 2023
bcfa6a9
Merge branch 'master' into reflective-boundaries
amartyads Jul 19, 2023
35695bd
comments, update to all-options
amartyads Jul 19, 2023
2efb5b4
option from previous PR
amartyads Jul 19, 2023
fbecbde
some renames
amartyads Jul 19, 2023
2c94932
added verlet skin to halo check region
amartyads Aug 16, 2023
eb964bd
cleanup
amartyads Aug 16, 2023
75dcb81
Merge branch 'master' into reflective-boundaries
amartyads Sep 8, 2023
03256bc
Merge branch 'master' into reflective-boundaries
amartyads Sep 27, 2023
31e1e48
do not enter loops if no non-periodic boundary
amartyads Sep 27, 2023
233c02d
boundary files should compile in serial
amartyads Feb 19, 2024
8523df8
added to comment
amartyads Feb 20, 2024
0b89f6e
change to how fpic is enabled
amartyads Feb 21, 2024
663745b
bugfix
amartyads Feb 21, 2024
eae1b8b
merge with master
amartyads Feb 23, 2024
6032ae4
log namespacing
amartyads Feb 23, 2024
9235c87
changes to names to make plugin work, documentation, clangformat
amartyads Feb 26, 2024
a396b71
full plugin now optionally compiled
amartyads Feb 26, 2024
4256464
Apply Fabio's suggestions from code review
amartyads Feb 26, 2024
5bf619a
move halo removal location
amartyads Mar 19, 2024
1b8adfb
bugfix, clearer function name
amartyads Mar 20, 2024
f4592dc
add check for overlappingp2p
amartyads Mar 20, 2024
15e3b7d
Merge branch 'master' into reflective-boundaries
amartyads May 29, 2024
b2815fe
Merge branch 'master' into mamico-postrefactor-fix
amartyads Aug 9, 2024
e098a25
comments by Christoph, static codecheck pass
amartyads Aug 9, 2024
70a8495
Merge branch 'mamico-postrefactor-fix' into reflective-boundaries
amartyads Aug 9, 2024
53a9b47
removed simulation::exit
amartyads Aug 9, 2024
39a3a83
clangformat
amartyads Aug 9, 2024
7d25c51
clangformat
amartyads Aug 9, 2024
5bc422d
move enums, remove files, clangformat
amartyads Sep 2, 2024
eac7657
some documentation in boundaryutils
amartyads Sep 2, 2024
b1b0c0b
no use of globsim object in boundary, fix for lost particles
amartyads Sep 4, 2024
6359485
renames, documentation
amartyads Sep 4, 2024
6f7632a
clangformat
amartyads Sep 4, 2024
0b732bd
Merge branch 'master' into mamico-postrefactor-fix
amartyads Sep 10, 2024
552d79f
Merge branch 'master' into reflective-boundaries
amartyads Sep 10, 2024
c79562d
newlines for static code checker
amartyads Sep 10, 2024
57fc6fd
removed unused code that dealt with halo cells
amartyads Sep 11, 2024
3caeec9
pass molecule by reference
amartyads Sep 11, 2024
e292e8f
Apply suggestions from code review
amartyads Sep 11, 2024
c20a668
replace PERIODIC in more places, documentation
amartyads Sep 11, 2024
b133acb
better variable names
amartyads Sep 11, 2024
fe0dca7
removed skin from halo buffer
amartyads Sep 11, 2024
2b1d448
more documentation
amartyads Sep 11, 2024
147d826
added equality check for floats
amartyads Sep 11, 2024
407998a
compile errors fixed
amartyads Sep 11, 2024
463799c
Apply suggestions from code review
amartyads Sep 12, 2024
6b7edb0
typo
amartyads Sep 13, 2024
9a6084f
chnage function name to be more clear
amartyads Sep 13, 2024
3c165c5
re-update variable name
amartyads Sep 13, 2024
fba5ec3
Apply suggestions from code review
amartyads Sep 13, 2024
87894c4
reverting formatting, some screwup
amartyads Sep 13, 2024
c3b3d48
fix for map iteration
amartyads Sep 13, 2024
b36c902
Apply suggestions from code review
amartyads Sep 13, 2024
0b430a9
Apply suggestions from code review
amartyads Sep 13, 2024
fcfc0bc
adjustments to simulation.cpp (xml reading, errors, logging)
amartyads Sep 13, 2024
f35c631
Merge branch 'reflective-boundaries' of https://github.com/ls1mardyn/…
amartyads Sep 13, 2024
158b0ab
removed permissibleDimensionsString, formatting break, compiling
amartyads Sep 13, 2024
59f3463
style copied from suggestions
amartyads Sep 13, 2024
c06cde2
remove std::tie, add comment on outflow
amartyads Sep 16, 2024
e849d34
Apply suggestions from code review
amartyads Sep 16, 2024
fc81653
moved boundary init, lambda, remove std::array setRegions
amartyads Sep 17, 2024
4593083
consts, removed molecule deref
amartyads Sep 17, 2024
541a9f2
moved math to math.h, fixed array conversions
amartyads Sep 17, 2024
dfd5c57
rename get_halo_L, buffers now c++ arrays
amartyads Sep 17, 2024
9cad8d9
renames ls1dim to ls1dimindex
amartyads Sep 17, 2024
a8ee7a1
renamed "buffer", moved more math
amartyads Sep 18, 2024
1ab950b
split utils file (separation of concerns)
amartyads Sep 18, 2024
10de6cb
new clangformat
amartyads Sep 19, 2024
f0a1c32
documentation, clangformat (new)
amartyads Sep 19, 2024
b311f23
better error messages, format and docstring plugin
amartyads Sep 19, 2024
e625661
removed unised vars, clangformat
amartyads Sep 19, 2024
c958368
Merge branch 'mamico-postrefactor-fix' into reflective-boundaries
amartyads Sep 19, 2024
76d5191
Add const to getters and add some doc
HomesGH Sep 20, 2024
e38f4c7
Apply suggestions from review to ResultWriter.cpp
HomesGH Sep 20, 2024
741885f
Minor fixes regarding const in Domain
HomesGH Sep 20, 2024
570edce
align switch cases
amartyads Sep 20, 2024
8b6a5f6
bugfix
amartyads Sep 23, 2024
2db952e
some more documentation
amartyads Sep 23, 2024
c0c5581
bugfix, particles actually being reflected now
amartyads Oct 22, 2024
125c3b6
Merge pull request #339 from ls1mardyn/reflective-boundaries
amartyads Oct 29, 2024
ce1066d
Merge branch 'master' into mamico-postrefactor-fix
amartyads Oct 29, 2024
ed42fac
static codechecker, MARDYN_EXIT
amartyads Oct 29, 2024
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
85 changes: 35 additions & 50 deletions src/plugins/MamicoCoupling.cpp
Original file line number Diff line number Diff line change
@@ -1,64 +1,49 @@
#ifdef MAMICO_COUPLING

#include "MamicoCoupling.h"
#include "Domain.h"

void MamicoCoupling::readXML(XMLfileUnits& xmlconfig)
{
return;
}

void MamicoCoupling::init(ParticleContainer* particleContainer,
DomainDecompBase* domainDecomp, Domain* domain)
{
#ifdef MAMICO_COUPLING
//code to print to log that plugin is initialised
Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl;
#endif
}

void MamicoCoupling::beforeEventNewTimestep(ParticleContainer* particleContainer,
DomainDecompBase* domainDecomp, unsigned long simstep)
{
void MamicoCoupling::readXML(XMLfileUnits &xmlconfig) {}

void MamicoCoupling::init(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp, Domain *domain) {
Log::global_log->info() << "MaMiCo coupling plugin initialized" << std::endl;
}

void MamicoCoupling::beforeForces(ParticleContainer* particleContainer,
DomainDecompBase* domainDecomp, unsigned long simstep)
{
#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
_macroscopicCellService->processInnerMacroscopicCellAfterMDTimestep();
_macroscopicCellService->distributeMass(simstep);
_macroscopicCellService->applyTemperatureToMolecules(simstep);
void MamicoCoupling::beforeEventNewTimestep(
ParticleContainer *particleContainer, DomainDecompBase *domainDecomp,
unsigned long simstep) {}

void MamicoCoupling::beforeForces(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp,
unsigned long simstep) {
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
_couplingCellService->processInnerCouplingCellAfterMDTimestep();
_couplingCellService->distributeMass(simstep);
_couplingCellService->applyTemperatureToMolecules(simstep);
#ifndef MARDYN_AUTOPAS
particleContainer->deleteOuterParticles();
#endif
}
particleContainer->deleteOuterParticles();
#endif
}
}

void MamicoCoupling::afterForces(ParticleContainer* particleContainer,
DomainDecompBase* domainDecomp, unsigned long simstep)
{
#ifdef MAMICO_COUPLING
if(_couplingEnabled)
{
_macroscopicCellService->distributeMomentum(simstep);
_macroscopicCellService->applyBoundaryForce(simstep);
}
#endif
void MamicoCoupling::afterForces(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp,
unsigned long simstep) {
if (_couplingEnabled) {
_couplingCellService->distributeMomentum(simstep);
_couplingCellService->applyBoundaryForce(simstep);
}
}

void MamicoCoupling::endStep(ParticleContainer* particleContainer,
DomainDecompBase* domainDecomp, Domain* domain, unsigned long simstep)
{
void MamicoCoupling::endStep(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp, Domain *domain,
unsigned long simstep) {}

}

void MamicoCoupling::finish(ParticleContainer* particleContainer,
DomainDecompBase* domainDecomp, Domain* domain)
{
void MamicoCoupling::finish(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp, Domain *domain) {}

}
#endif
229 changes: 124 additions & 105 deletions src/plugins/MamicoCoupling.h
Original file line number Diff line number Diff line change
@@ -1,115 +1,134 @@
#ifdef MAMICO_COUPLING

#pragma once

#include "PluginBase.h"
#ifdef MAMICO_COUPLING
#include <coupling/services/MacroscopicCellService.h>
#include <coupling/interface/impl/ls1/LS1RegionWrapper.h>
#endif

/** @brief Allows execution of MaMiCo code to enable coupling with MaMiCo.
*
* When MaMiCo is coupled with any simulation software, it needs to control the simulation from both the outside and inside.
* From the outside, MaMiCo needs to be able to start and stop the simulation, and keep unique simulations distinct.
* From the inside, MaMiCo code needs to be executed at specific points within the same simulation step. This plugin enables the "inside" behaviour.
*
* MaMiCo coupling requires the MAMICO_COUPLING flag to be set, and the MAMICO_SRD_DIR flag to point to MaMiCo source files. With these enabled, ls1 compiles as a library.
* To make sure the program compiles and works with tests, the relevant MaMiCo portions for the code are put in #ifdef regions.
*
* */

class MamicoCoupling: public PluginBase {
#include <coupling/services/CouplingCellService.h>

/**
* Allows execution of MaMiCo code to enable coupling with MaMiCo.
*
* When MaMiCo is coupled with any simulation software, it needs to control the
* simulation from both the outside and inside. From the outside, MaMiCo needs
* to be able to start and stop the simulation, and keep unique simulations
* distinct. From the inside, MaMiCo code needs to be executed at specific
* points within the same simulation step. This plugin enables the "inside"
* behaviour.
*
* MaMiCo coupling requires the MAMICO_COUPLING flag to be set, and the
* MAMICO_SRD_DIR flag to point to MaMiCo source files. With these enabled, ls1
* compiles as a library. To make sure the program compiles and works with
* tests, the relevant MaMiCo portions for the code are put in #ifdef regions.
*/
class MamicoCoupling : public PluginBase {

public:
MamicoCoupling() {}
virtual ~MamicoCoupling() {}

/** @brief Prints to log that mamico coupling is initialized
*
* */
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
) override;

void endStep(
ParticleContainer* particleContainer, DomainDecompBase* domainDecomp,
Domain* domain, unsigned long simstep) override;

void finish(ParticleContainer* particleContainer,
DomainDecompBase* domainDecomp, Domain* domain) override;

std::string getPluginName() override {
return std::string("MamicoCoupling");
}

static PluginBase* createInstance() { return new MamicoCoupling(); }

#ifdef MAMICO_COUPLING
/** @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
* */
void setMamicoMacroscopicCellService(coupling::services::MacroscopicCellService<3>* macroscopicCellService){
_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; }
MamicoCoupling() = default;
~MamicoCoupling() override = default;

void init(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp, Domain *domain) override;

/*
* No XML tags defined for this plugin, so does nothing
*/
void readXML(XMLfileUnits &xmlconfig) override;
amartyads marked this conversation as resolved.
Show resolved Hide resolved

void beforeEventNewTimestep(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp,
unsigned long simstep) override;

/**
* 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;

/**
* 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) override;

void endStep(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp, Domain *domain,
unsigned long simstep) override;

void finish(ParticleContainer *particleContainer,
DomainDecompBase *domainDecomp, Domain *domain) override;

std::string getPluginName() override { return "MamicoCoupling"; }

static PluginBase *createInstance() { return new MamicoCoupling(); }

/**
* 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/CouplingCellService.cpph
*/
void setMamicoCouplingCellService(
coupling::services::CouplingCellService<3> *couplingCellService) {
_couplingCellService =
static_cast<coupling::services::CouplingCellServiceImpl<
ls1::LS1RegionWrapper, 3> *>(couplingCellService);
}

/**
* 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; }

/**
* 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; }

/**
* Getter method for the coupling state.
*
* Not used currently, but may be used in future
*/
bool getCouplingState() const { return _couplingEnabled; }

/** @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;}
private:
coupling::services::CouplingCellServiceImpl<ls1::LS1RegionWrapper, 3>
*_couplingCellService = nullptr;

bool _couplingEnabled = false;
};

private:
#ifdef MAMICO_COUPLING
coupling::services::MacroscopicCellServiceImpl<ls1::LS1RegionWrapper,3>* _macroscopicCellService;
#endif
bool _couplingEnabled = false;
};
Loading