* allow the MdModuleNotifier to statically distinguish the callback
* function type from other 'int' function callbacks.
*
- * \param[in] pbc MdModuleNotification class that contains a variable
- * that enumerates the periodic boundary condition.
+ * \param[in] pbcType enumerates the periodic boundary condition.
*/
- void setPeriodicBoundaryConditionType(PeriodicBoundaryConditionType pbc)
+ void setPeriodicBoundaryConditionType(const PbcType& pbcType)
{
- pbcType_ = std::make_unique<PbcType>(pbc.pbcType);
+ pbcType_ = std::make_unique<PbcType>(pbcType);
}
//! Get the periodic boundary conditions
* \param[in] notifier allows the module to subscribe to notifications from MdModules.
*
* The density fitting code subscribes to these notifications:
- * - setting atom group indices in the densityFittingOptions_ by
- * taking a parmeter const IndexGroupsAndNames &
+ * - setting atom group indices in the densityFittingOptions_ from an
+ * index group string by taking a parmeter const IndexGroupsAndNames &
* - storing its internal parameters in a tpr file by writing to a
* key-value-tree during pre-processing by a function taking a
* KeyValueTreeObjectBuilder as parameter
// and subscribed, and will be dispatched correctly at run time
// based on the type of the parameter required by the lambda.
- // Setting atom group indices
+ // Setting the atom group indices from index group string
const auto setFitGroupIndicesFunction = [this](const IndexGroupsAndNames& indexGroupsAndNames) {
densityFittingOptions_.setFitGroupIndices(indexGroupsAndNames);
};
- notifier->notifier_.subscribe(setFitGroupIndicesFunction);
+ notifier->preProcessingNotifications_.subscribe(setFitGroupIndicesFunction);
// Writing internal parameters during pre-processing
const auto writeInternalParametersFunction = [this](KeyValueTreeObjectBuilder treeBuilder) {
densityFittingOptions_.writeInternalParametersToKvt(treeBuilder);
};
- notifier->notifier_.subscribe(writeInternalParametersFunction);
+ notifier->preProcessingNotifications_.subscribe(writeInternalParametersFunction);
// Reading internal parameters during simulation setup
const auto readInternalParametersFunction = [this](const KeyValueTreeObject& tree) {
densityFittingOptions_.readInternalParametersFromKvt(tree);
};
- notifier->notifier_.subscribe(readInternalParametersFunction);
+ notifier->simulationSetupNotifications_.subscribe(readInternalParametersFunction);
// Checking for consistency with all .mdp options
const auto checkEnergyCaluclationFrequencyFunction =
[this](EnergyCalculationFrequencyErrors* energyCalculationFrequencyErrors) {
densityFittingOptions_.checkEnergyCaluclationFrequency(energyCalculationFrequencyErrors);
};
- notifier->notifier_.subscribe(checkEnergyCaluclationFrequencyFunction);
+ notifier->preProcessingNotifications_.subscribe(checkEnergyCaluclationFrequencyFunction);
// constructing local atom sets during simulation setup
const auto setLocalAtomSetFunction = [this](LocalAtomSetManager* localAtomSetManager) {
this->constructLocalAtomSet(localAtomSetManager);
};
- notifier->notifier_.subscribe(setLocalAtomSetFunction);
+ notifier->simulationSetupNotifications_.subscribe(setLocalAtomSetFunction);
// constructing local atom sets during simulation setup
- const auto setPeriodicBoundaryContionsFunction = [this](PeriodicBoundaryConditionType pbc) {
+ const auto setPeriodicBoundaryContionsFunction = [this](const PbcType& pbc) {
this->densityFittingSimulationParameters_.setPeriodicBoundaryConditionType(pbc);
};
- notifier->notifier_.subscribe(setPeriodicBoundaryContionsFunction);
+ notifier->simulationSetupNotifications_.subscribe(setPeriodicBoundaryContionsFunction);
// setting the simulation time step
const auto setSimulationTimeStepFunction = [this](const SimulationTimeStep& simulationTimeStep) {
this->densityFittingSimulationParameters_.setSimulationTimeStep(simulationTimeStep.delta_t);
};
- notifier->notifier_.subscribe(setSimulationTimeStepFunction);
+ notifier->simulationSetupNotifications_.subscribe(setSimulationTimeStepFunction);
// adding output to energy file
const auto requestEnergyOutput =
[this](MdModulesEnergyOutputToDensityFittingRequestChecker* energyOutputRequest) {
this->setEnergyOutputRequest(energyOutputRequest);
};
- notifier->notifier_.subscribe(requestEnergyOutput);
+ notifier->simulationSetupNotifications_.subscribe(requestEnergyOutput);
// writing checkpoint data
const auto checkpointDataWriting = [this](MdModulesWriteCheckpointData checkpointData) {
this->writeCheckpointData(checkpointData);
};
- notifier->notifier_.subscribe(checkpointDataWriting);
+ notifier->checkpointingNotifications_.subscribe(checkpointDataWriting);
// reading checkpoint data
const auto checkpointDataReading = [this](MdModulesCheckpointReadingDataOnMaster checkpointData) {
this->readCheckpointDataOnMaster(checkpointData);
};
- notifier->notifier_.subscribe(checkpointDataReading);
+ notifier->checkpointingNotifications_.subscribe(checkpointDataReading);
// broadcasting checkpoint data
const auto checkpointDataBroadcast = [this](MdModulesCheckpointReadingBroadcast checkpointData) {
this->broadcastCheckpointData(checkpointData);
};
- notifier->notifier_.subscribe(checkpointDataBroadcast);
+ notifier->checkpointingNotifications_.subscribe(checkpointDataBroadcast);
}
//! From IMDModule
gmx::MdModulesCheckpointReadingDataOnMaster mdModuleCheckpointReadingDataOnMaster = {
mdModuleCheckpointParameterTree, fileVersion
};
- mdModulesNotifier.notifier_.notify(mdModuleCheckpointReadingDataOnMaster);
+ mdModulesNotifier.checkpointingNotifications_.notify(mdModuleCheckpointReadingDataOnMaster);
}
}
gmx::KeyValueTreeBuilder builder;
gmx::MdModulesWriteCheckpointData mdModulesWriteCheckpoint = { builder.rootObject(),
headerContents.file_version };
- mdModulesNotifier.notifier_.notify(mdModulesWriteCheckpoint);
+ mdModulesNotifier.checkpointingNotifications_.notify(mdModulesWriteCheckpoint);
auto tree = builder.build();
gmx::FileIOXdrSerializer serializer(fp);
gmx::serializeKeyValueTree(tree, &serializer);
{
gmx_bcast(sizeof(headerContents.step), &headerContents.step, cr);
gmx::MdModulesCheckpointReadingBroadcast broadcastCheckPointData = { *cr, headerContents.file_version };
- mdModulesNotifier.notifier_.notify(broadcastCheckPointData);
+ mdModulesNotifier.checkpointingNotifications_.notify(broadcastCheckPointData);
}
ir->bContinuation = TRUE;
// TODO Should the following condition be <=? Currently if you
{
gmx::KeyValueTreeBuilder internalParameterBuilder;
- mdModules.notifier().notifier_.notify(internalParameterBuilder.rootObject());
+ mdModules.notifier().preProcessingNotifications_.notify(internalParameterBuilder.rootObject());
ir->internalParameters =
std::make_unique<gmx::KeyValueTreeObject>(internalParameterBuilder.build());
}
// Inquire all MdModules, if their parameters match with the energy
// calculation frequency
gmx::EnergyCalculationFrequencyErrors energyCalculationFrequencyErrors(ir->nstcalcenergy);
- mdModulesNotifier.notifier_.notify(&energyCalculationFrequencyErrors);
+ mdModulesNotifier.preProcessingNotifications_.notify(&energyCalculationFrequencyErrors);
// Emit all errors from the energy calculation frequency checks
for (const std::string& energyFrequencyErrorMessage :
gmx::IndexGroupsAndNames defaultIndexGroupsAndNames(
*defaultIndexGroups, gmx::arrayRefFromArray(gnames, defaultIndexGroups->nr));
- notifier.notifier_.notify(defaultIndexGroupsAndNames);
+ notifier.preProcessingNotifications_.notify(defaultIndexGroupsAndNames);
auto accelerations = gmx::splitString(is->acc);
auto accelerationGroupNames = gmx::splitString(is->accgrps);
bEner_[F_COM_PULL] = ((ir->bPull && pull_have_potential(pull_work)) || ir->bRot);
MdModulesEnergyOutputToDensityFittingRequestChecker mdModulesAddOutputToDensityFittingFieldRequest;
- mdModulesNotifier.notifier_.notify(&mdModulesAddOutputToDensityFittingFieldRequest);
+ mdModulesNotifier.simulationSetupNotifications_.notify(&mdModulesAddOutputToDensityFittingFieldRequest);
bEner_[F_DENSITYFITTING] = mdModulesAddOutputToDensityFittingFieldRequest.energyOutputToDensityFitting_;
// TODO: Error handling
mdModules_->assignOptionsToModules(*inputrec->params, nullptr);
- const auto& mdModulesNotifier = mdModules_->notifier().notifier_;
+ const auto& mdModulesNotifier = mdModules_->notifier().simulationSetupNotifications_;
if (inputrec->internalParameters != nullptr)
{
{
mdModulesNotifier.notify(*cr);
mdModulesNotifier.notify(&atomSets);
- mdModulesNotifier.notify(PeriodicBoundaryConditionType{ inputrec->pbcType });
+ mdModulesNotifier.notify(inputrec->pbcType);
mdModulesNotifier.notify(SimulationTimeStep{ inputrec->delta_t });
/* Initiate forcerecord */
fr = new t_forcerec;
struct MdModulesCheckpointReadingDataOnMaster;
struct MdModulesCheckpointReadingBroadcast;
struct MdModulesWriteCheckpointData;
-struct PeriodicBoundaryConditionType
-{
- PbcType pbcType;
-};
struct MdModulesEnergyOutputToDensityFittingRequestChecker
{
const double delta_t;
};
+/*! \libinternal
+ * \brief Collection of callbacks to MDModules at differnt run-times.
+ *
+ * MDModules use members of this struct to sign up for callback functionality.
+ *
+ * The members of the struct represent callbacks at these run-times:
+ *
+ * When pre-processing the simulation data
+ * When reading and writing check-pointing data
+ * When setting up simulation after reading in the tpr file
+ *
+ * The template arguments to the members of this struct directly reflect
+ * the callback function signature. Arguments passed as pointers are always
+ * meant to be modified, but never meant to be stored (in line with the policy
+ * everywhere else).
+ */
struct MdModulesNotifier
{
- //! Register callback function types for MdModule
- registerMdModuleNotification<const t_commrec&,
- EnergyCalculationFrequencyErrors*,
- IndexGroupsAndNames,
- KeyValueTreeObjectBuilder,
- const KeyValueTreeObject&,
+ /*! \brief Pre-processing callback functions.
+ *
+ * EnergyCalculationFrequencyErrors* allows modules to check if they match
+ * their required calculation frequency
+ * and add their error message if needed
+ * to the collected error messages
+ * IndexGroupsAndNames provides modules with atom indices and their names
+ * KeyValueTreeObjectBuilder enables writing of module internal data to
+ * .tpr files.
+ */
+ registerMdModuleNotification<EnergyCalculationFrequencyErrors*, IndexGroupsAndNames, KeyValueTreeObjectBuilder>::type preProcessingNotifications_;
+
+ /*! \brief Checkpointing callback functions.
+ *
+ * MdModulesCheckpointReadingDataOnMaster provides modules with their
+ * checkpointed data on the master
+ * node and checkpoint file version
+ * MdModulesCheckpointReadingBroadcast provides modules with a communicator
+ * and the checkpoint file version to
+ * distribute their data
+ * MdModulesWriteCheckpointData provides the modules with a key-value-tree
+ * builder to store their checkpoint data and
+ * the checkpoint file version
+ */
+ registerMdModuleNotification<MdModulesCheckpointReadingDataOnMaster,
+ MdModulesCheckpointReadingBroadcast,
+ MdModulesWriteCheckpointData>::type checkpointingNotifications_;
+
+ /*! \brief Callbacks during simulation setup.
+ *
+ * const KeyValueTreeObject& provides modules with the internal data they
+ * wrote to .tpr files
+ * LocalAtomSetManager* enables modules to add atom indices to local atom sets
+ * to be managed
+ * MdModulesEnergyOutputToDensityFittingRequestChecker* enables modules to
+ * report if they want to write their energy output
+ * to the density fitting field in the energy files
+ * const PbcType& provides modules with the periodic boundary condition type
+ * that is used during the simulation
+ * const SimulationTimeStep& provides modules with the simulation time-step
+ * that allows them to interconvert between step
+ * time information
+ * const t_commrec& provides a communicator to the modules during simulation
+ * setup
+ */
+ registerMdModuleNotification<const KeyValueTreeObject&,
LocalAtomSetManager*,
MdModulesEnergyOutputToDensityFittingRequestChecker*,
- MdModulesCheckpointReadingDataOnMaster,
- MdModulesCheckpointReadingBroadcast,
- MdModulesWriteCheckpointData,
- PeriodicBoundaryConditionType,
- const SimulationTimeStep&>::type notifier_;
+ const PbcType&,
+ const SimulationTimeStep&,
+ const t_commrec&>::type simulationSetupNotifications_;
};
} // namespace gmx