Skip to content

Commit

Permalink
Merge branch 'master' into code-refactor-mamico
Browse files Browse the repository at this point in the history
  • Loading branch information
amartyads committed Sep 5, 2023
2 parents f4d309f + af5365a commit 40a87f3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 68 deletions.
6 changes: 6 additions & 0 deletions examples/all-options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

<!-- simulation options -->
<simulation type="MD" >
<!-- block for misc options -->
<options>
<!-- immediately after filling the simulation with particles, reset all id's to start at zero and are consecutive -->
<option name="refreshIDs">true</option>
</options>

<run>
<currenttime>0</currenttime>
<production>
Expand Down
128 changes: 68 additions & 60 deletions src/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,38 +678,6 @@ void Simulation::readXML(XMLfileUnits& xmlconfig) {
}

xmlconfig.changecurrentnode(oldpath);

/** Prepare start options, affecting behavior of method prepare_start() */
_prepare_start_opt.refreshIDs = false;

oldpath = xmlconfig.getcurrentnodepath();
if(xmlconfig.changecurrentnode("options")) {
unsigned long numOptions = 0;
XMLfile::Query query = xmlconfig.query("option");
numOptions = query.card();
global_log->info() << "Number of prepare start options: " << numOptions << endl;

XMLfile::Query::const_iterator optionIter;
for( optionIter = query.begin(); optionIter; optionIter++ ) {
xmlconfig.changecurrentnode(optionIter);
std::string strOptionName;
xmlconfig.getNodeValue("@name", strOptionName);
if(strOptionName == "refreshIDs") {
bool bVal = false;
xmlconfig.getNodeValue(".", bVal);
_prepare_start_opt.refreshIDs = bVal;
if(_prepare_start_opt.refreshIDs)
global_log->info() << "Particle IDs will be refreshed before simulation start." << endl;
else
global_log->info() << "Particle IDs will NOT be refreshed before simulation start." << endl;
}
else
{
global_log->warning() << "Unknown option '" << strOptionName << "'" << endl;
}
}
}
xmlconfig.changecurrentnode(oldpath);
}


Expand Down Expand Up @@ -753,6 +721,14 @@ void Simulation::initConfigXML(const string& inputfilename) {
global_log->error() << "Simulation section missing" << endl;
Simulation::exit(1);
}

parseMiscOptions(inp);
if(_miscOptions["refreshIDs"]) {
global_log->info() << "Particle IDs will be refreshed before simulation start." << endl;
} else {
global_log->info() << "Particle IDs will NOT be refreshed before simulation start." << endl;
}

} catch (const std::exception& e) {
global_log->error() << "Error in XML config. Please check your input file!" << std::endl;
global_log->error() << "Exception: " << e.what() << std::endl;
Expand All @@ -778,6 +754,11 @@ void Simulation::initConfigXML(const string& inputfilename) {
_moleculeContainer->update();
_moleculeContainer->deleteOuterParticles();

/** reset particle IDs */
if(_miscOptions["refreshIDs"]) {
this->refreshParticleIDs();
}

unsigned long globalNumMolecules = _domain->getglobalNumMolecules(true, _moleculeContainer, _domainDecomposition);
double rho_global = globalNumMolecules / _ensemble->V();
global_log->info() << "Setting domain class parameters: N_global: " << globalNumMolecules
Expand Down Expand Up @@ -925,7 +906,9 @@ void Simulation::prepare_start() {
for (auto plugin : _plugins) {
global_log->debug() << "[AFTER FORCES] Plugin: "
<< plugin->getPluginName() << endl;
global_simulation->timers()->start(plugin->getPluginName());
plugin->afterForces(_moleculeContainer, _domainDecomposition, _simstep);
global_simulation->timers()->stop(plugin->getPluginName());
}

#ifndef MARDYN_AUTOPAS
Expand Down Expand Up @@ -954,9 +937,6 @@ void Simulation::prepare_start() {
global_log->info() << "Set initial time step to start from to " << _initSimulation << endl;
global_log->info() << "System initialised with " << _domain->getglobalNumMolecules(true, _moleculeContainer, _domainDecomposition) << " molecules." << endl;

/** refresh particle IDs */
if(_prepare_start_opt.refreshIDs)
this->refreshParticleIDs();
}

void Simulation::simulate() {
Expand Down Expand Up @@ -1059,23 +1039,27 @@ void Simulation::simulateOneTimestep()

computationTimer->start();

// beforeEventNewTimestep Plugin Call
global_log -> debug() << "[BEFORE EVENT NEW TIMESTEP] Performing beforeEventNewTimestep plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[BEFORE EVENT NEW TIMESTEP] Plugin: " << plugin->getPluginName() << endl;
plugin->beforeEventNewTimestep(_moleculeContainer, _domainDecomposition, _simstep);
}
// beforeEventNewTimestep Plugin Call
global_log -> debug() << "[BEFORE EVENT NEW TIMESTEP] Performing beforeEventNewTimestep plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[BEFORE EVENT NEW TIMESTEP] Plugin: " << plugin->getPluginName() << endl;
global_simulation->timers()->start(plugin->getPluginName());
plugin->beforeEventNewTimestep(_moleculeContainer, _domainDecomposition, _simstep);
global_simulation->timers()->stop(plugin->getPluginName());
}

_ensemble->beforeEventNewTimestep(_moleculeContainer, _domainDecomposition, _simstep);

_integrator->eventNewTimestep(_moleculeContainer, _domain);

// beforeForces Plugin Call
global_log -> debug() << "[BEFORE FORCES] Performing BeforeForces plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[BEFORE FORCES] Plugin: " << plugin->getPluginName() << endl;
plugin->beforeForces(_moleculeContainer, _domainDecomposition, _simstep);
}
// beforeForces Plugin Call
global_log -> debug() << "[BEFORE FORCES] Performing BeforeForces plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[BEFORE FORCES] Plugin: " << plugin->getPluginName() << endl;
global_simulation->timers()->start(plugin->getPluginName());
plugin->beforeForces(_moleculeContainer, _domainDecomposition, _simstep);
global_simulation->timers()->stop(plugin->getPluginName());
}

computationTimer->stop();

Expand Down Expand Up @@ -1114,12 +1098,14 @@ void Simulation::simulateOneTimestep()
// Force timer and computation timer are running at this point!
}

// siteWiseForces Plugin Call
global_log -> debug() << "[SITEWISE FORCES] Performing siteWiseForces plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[SITEWISE FORCES] Plugin: " << plugin->getPluginName() << endl;
plugin->siteWiseForces(_moleculeContainer, _domainDecomposition, _simstep);
}
// siteWiseForces Plugin Call
global_log -> debug() << "[SITEWISE FORCES] Performing siteWiseForces plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[SITEWISE FORCES] Plugin: " << plugin->getPluginName() << endl;
global_simulation->timers()->start(plugin->getPluginName());
plugin->siteWiseForces(_moleculeContainer, _domainDecomposition, _simstep);
global_simulation->timers()->stop(plugin->getPluginName());
}

// longRangeCorrection is a site-wise force plugin, so we have to call it before updateForces()
_longRangeCorrection->calculateLongRange();
Expand Down Expand Up @@ -1148,12 +1134,14 @@ void Simulation::simulateOneTimestep()
_FMM->computeElectrostatics(_moleculeContainer);
}

//afterForces Plugin Call
global_log -> debug() << "[AFTER FORCES] Performing AfterForces plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[AFTER FORCES] Plugin: " << plugin->getPluginName() << endl;
plugin->afterForces(_moleculeContainer, _domainDecomposition, _simstep);
}
//afterForces Plugin Call
global_log -> debug() << "[AFTER FORCES] Performing AfterForces plugin call" << endl;
for (auto plugin : _plugins) {
global_log -> debug() << "[AFTER FORCES] Plugin: " << plugin->getPluginName() << endl;
global_simulation->timers()->start(plugin->getPluginName());
plugin->afterForces(_moleculeContainer, _domainDecomposition, _simstep);
global_simulation->timers()->stop(plugin->getPluginName());
}

_ensemble->afterForces(_moleculeContainer, _domainDecomposition, _cellProcessor, _simstep);

Expand Down Expand Up @@ -1287,7 +1275,9 @@ void Simulation::postSimLoopSteps()

global_log->info() << "Finish plugins" << endl;
for (auto plugin : _plugins) {
global_simulation->timers()->start(plugin->getPluginName());
plugin->finish(_moleculeContainer, _domainDecomposition, _domain);
global_simulation->timers()->stop(plugin->getPluginName());
}
global_simulation->timers()->getTimer("SIMULATION_FINAL_IO")->stop();

Expand Down Expand Up @@ -1512,6 +1502,24 @@ void Simulation::refreshParticleIDs()

for (auto pit = _moleculeContainer->iterator(ParticleIterator::ONLY_INNER_AND_BOUNDARY); pit.isValid(); ++pit)
{
pit->setid(++start_ID);
pit->setid(start_ID++);
}
}

void Simulation::parseMiscOptions(XMLfileUnits& xmlconfig) {
const auto oldpath = xmlconfig.getcurrentnodepath();
const XMLfile::Query optionNodes = xmlconfig.query("/mardyn/simulation/options/option");
// parse everything in this path
for (auto optionIter = optionNodes.begin(); optionIter; optionIter++) {
xmlconfig.changecurrentnode(optionIter);
std::string strOptionName;
xmlconfig.getNodeValue("@name", strOptionName);
xmlconfig.getNodeValue(".", _miscOptions[strOptionName]);
}
// log what was parsed
global_log->info() << "Parsed " << optionNodes.card() << " misc options: \n" << std::boolalpha;
for (const auto& [name, value] : _miscOptions) {
global_log->info() << " " << name << ": " << value << std::endl;
}
xmlconfig.changecurrentnode(oldpath);
}
24 changes: 16 additions & 8 deletions src/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,21 @@ class Simulation {

CellProcessor *getCellProcessor() const;

/** @brief Refresh particle IDs to continuous numbering*/
/** @brief Refresh particle IDs to continuous numbering starting at zero*/
void refreshParticleIDs();

/** @brief Checks if Simsteps or MaxWallTime are reached */
bool keepRunning();

private:

/**
* Parse everything in the XML path </mardyn/simulation/options/option>
* and store it in _miscOptions.
* @param xmlconfig
*/
void parseMiscOptions(XMLfileUnits& xmlconfig);

/// the timer used for the load calculation.
Timer* _timerForLoad{nullptr};

Expand Down Expand Up @@ -514,15 +521,16 @@ class Simulation {
unsigned long _nWriteFreqGlobalEnergy;
std::string _globalEnergyLogFilename;

/** Prepare start options, affecting behavior of method prepare_start()
* Options
* -------
* refreshIDs: Refresh particle IDs to continuous numbering by method refreshParticleIDs()
/**
* Mechanism to easily add arbitrary options via the XML path <mardyn/simulation/options/option>
* Any option is identified via the label "name"
*
* @note Currently, only bool options are supported.
*
* Example:
* <option name="refreshIDs">true</option>
*/
struct PrepareStartOptions {
bool refreshIDs;
} _prepare_start_opt;
std::map<std::string, bool> _miscOptions;

FixedSizeQueue<double> _lastTraversalTimeHistory;

Expand Down

0 comments on commit 40a87f3

Please sign in to comment.