//! The function type that allows to register run functions
typedef std::function<void(SimulatorRunFunction)> RegisterRunFunction;
+//! The function type scheduling run functions for a step / time using a RegisterRunFunction reference
+typedef std::function<void(Step, Time, const RegisterRunFunction&)> SchedulingFunction;
/*! \internal
* \brief The general interface for elements of the modular simulator
// register pre-step (task queue is local, so no problem with `this`)
registerRunFunction([this, step, time, isNSStep]() { preStep(step, time, isNSStep); });
+ // register pre step functions
+ for (const auto& schedulingFunction : preStepScheduling_)
+ {
+ schedulingFunction(step_, time, registerRunFunction);
+ }
// register elements for step
for (auto& element : elementCallList_)
{
element->scheduleTask(step_, time, registerRunFunction);
}
+ // register post step functions
+ for (const auto& schedulingFunction : postStepScheduling_)
+ {
+ schedulingFunction(step_, time, registerRunFunction);
+ }
// register post-step (task queue is local, so no problem with `this`)
registerRunFunction([this, step, time]() { postStep(step, time); });
// Move setup / teardown list
algorithm.elementSetupTeardownList_ = std::move(setupAndTeardownList_);
+ // Move pre- / post-step scheduling lists
+ algorithm.preStepScheduling_ = std::move(preStepScheduling_);
+ algorithm.postStepScheduling_ = std::move(postStepScheduling_);
// Create element list
// Checkpoint helper needs to be in the call list (as first element!) to react to last step
return builder_->elementExists(element);
}
+[[maybe_unused]] void ModularSimulatorAlgorithmBuilderHelper::registerPreStepScheduling(SchedulingFunction schedulingFunction)
+{
+ builder_->preStepScheduling_.emplace_back(std::move(schedulingFunction));
+}
+
+[[maybe_unused]] void ModularSimulatorAlgorithmBuilderHelper::registerPostStepScheduling(SchedulingFunction schedulingFunction)
+{
+ builder_->postStepScheduling_.emplace_back(std::move(schedulingFunction));
+}
+
std::optional<std::any> ModularSimulatorAlgorithmBuilderHelper::builderData(const std::string& key) const
{
const auto iter = builder_->builderData_.find(key);
std::vector<ISimulatorElement*> elementCallList_;
//! List of schedulerElements (setup / teardown calling sequence)
std::vector<ISimulatorElement*> elementSetupTeardownList_;
+ //! List of pre-step scheduling functions
+ std::vector<SchedulingFunction> preStepScheduling_;
+ //! List of post-step scheduling functions
+ std::vector<SchedulingFunction> postStepScheduling_;
// Infrastructure elements
//! The domain decomposition element
Element* storeElement(std::unique_ptr<Element> element);
//! Check if an element is stored in the ModularSimulatorAlgorithmBuilder
bool elementIsStored(const ISimulatorElement* element) const;
+ /*! \brief Register callback to schedule a pre-step run
+ *
+ * This allows elements to schedule a function call before the integration step.
+ * The function call is guaranteed to happen before any functions scheduled for
+ * the integration step. It is not guaranteed to happen in any specific order
+ * compared to other elements registering a pre-step scheduling function.
+ */
+ void registerPreStepScheduling(SchedulingFunction schedulingFunction);
+ /*! \brief Register callback to schedule a post-step run
+ *
+ * This allows elements to schedule a function call after the integration step.
+ * The function call is guaranteed to happen after all functions scheduled for
+ * the integration step. It is not guaranteed to happen in any specific order
+ * compared to other elements registering a post-step scheduling function.
+ */
+ void registerPostStepScheduling(SchedulingFunction schedulingFunction);
/*! \brief Set arbitrary data in the ModularSimulatorAlgorithmBuilder
*
* Allows to store arbitrary data with lifetime equal to the builder. Functionality is used
* Elements should only appear once in this list
*/
std::vector<ISimulatorElement*> setupAndTeardownList_;
+ //! List of pre-step scheduling functions
+ std::vector<SchedulingFunction> preStepScheduling_;
+ //! List of post-step scheduling functions
+ std::vector<SchedulingFunction> postStepScheduling_;
//! Builder for the NeighborSearchSignaller
SignallerBuilder<NeighborSearchSignaller> neighborSearchSignallerBuilder_;