Implement SimulatorBuilder.add() for BoxDeformationHandle.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Thu, 23 Apr 2020 15:34:32 +0000 (18:34 +0300)
committerJoe Jordan <ejjordan12@gmail.com>
Fri, 26 Jun 2020 10:54:09 +0000 (10:54 +0000)
Refs #3567

src/gromacs/mdrun/runner.cpp
src/gromacs/mdrun/simulatorbuilder.cpp
src/gromacs/mdrun/simulatorbuilder.h

index ba3f1bd737b48b57566a2685023f4cf6e1b07a5e..71accb8036a8631ecf33713f4050073dccfb5a8b 100644 (file)
@@ -1653,9 +1653,10 @@ int Mdrunner::mdrunner()
         // Todo move to an MDModule
         simulatorBuilder.add(IonSwapping(swap));
         simulatorBuilder.add(TopologyData(&mtop, mdAtoms.get()));
+        simulatorBuilder.add(BoxDeformationHandle(deform.get()));
 
         // build and run simulator object based on user-input
-        auto simulator = simulatorBuilder.build(useModularSimulator, deform.get());
+        auto simulator = simulatorBuilder.build(useModularSimulator);
         simulator->run();
 
         if (fr->pmePpCommGpu)
index 536c2c8c53813d8f690bfabc71f2b8f4c597b0d4..f69dd98139512fbc26eb571fd457fef0db42aa07 100644 (file)
@@ -56,8 +56,7 @@ namespace gmx
 {
 
 //! \brief Build a Simulator object
-std::unique_ptr<ISimulator> SimulatorBuilder::build(bool useModularSimulator, BoxDeformation* deform)
-
+std::unique_ptr<ISimulator> SimulatorBuilder::build(bool useModularSimulator)
 {
     // TODO: Reduce protocol complexity.
     //     Investigate individual paramters. Identify default-constructable parameters and clarify
@@ -126,11 +125,11 @@ std::unique_ptr<ISimulator> SimulatorBuilder::build(bool useModularSimulator, Bo
                 simulatorEnv_->fplog_, simulatorEnv_->commRec_, simulatorEnv_->multisimCommRec_,
                 simulatorEnv_->logger_, legacyInput_->numFile, legacyInput_->filenames,
                 simulatorEnv_->outputEnv_, simulatorConfig_->mdrunOptions_,
-                simulatorConfig_->startingBehavior_, constraintsParam_->vsite, constraintsParam_->constr,
-                constraintsParam_->enforcedRotation, deform, simulatorModules_->outputProvider,
-                simulatorModules_->mdModulesNotifier, legacyInput_->inputrec,
-                interactiveMD_->imdSession, centerOfMassPulling_->pull_work, ionSwapping_->ionSwap,
-                topologyData_->top_global, simulatorStateData_->globalState_p,
+                simulatorConfig_->startingBehavior_, constraintsParam_->vsite,
+                constraintsParam_->constr, constraintsParam_->enforcedRotation, boxDeformation_->deform,
+                simulatorModules_->outputProvider, simulatorModules_->mdModulesNotifier,
+                legacyInput_->inputrec, interactiveMD_->imdSession, centerOfMassPulling_->pull_work,
+                ionSwapping_->ionSwap, topologyData_->top_global, simulatorStateData_->globalState_p,
                 simulatorStateData_->observablesHistory_p, topologyData_->mdAtoms, profiling_->nrnb,
                 profiling_->wallCycle, legacyInput_->forceRec, simulatorStateData_->enerdata_p,
                 simulatorStateData_->ekindata_p, simulatorConfig_->runScheduleWork_,
@@ -142,12 +141,11 @@ std::unique_ptr<ISimulator> SimulatorBuilder::build(bool useModularSimulator, Bo
             simulatorEnv_->fplog_, simulatorEnv_->commRec_, simulatorEnv_->multisimCommRec_,
             simulatorEnv_->logger_, legacyInput_->numFile, legacyInput_->filenames,
             simulatorEnv_->outputEnv_, simulatorConfig_->mdrunOptions_,
-            simulatorConfig_->startingBehavior_, constraintsParam_->vsite, constraintsParam_->constr,
-            constraintsParam_->enforcedRotation, deform, simulatorModules_->outputProvider,
-            simulatorModules_->mdModulesNotifier, legacyInput_->inputrec,
-            interactiveMD_->imdSession, centerOfMassPulling_->pull_work, ionSwapping_->ionSwap,
-            topologyData_->top_global,
-            simulatorStateData_->globalState_p,
+            simulatorConfig_->startingBehavior_, constraintsParam_->vsite,
+            constraintsParam_->constr, constraintsParam_->enforcedRotation, boxDeformation_->deform,
+            simulatorModules_->outputProvider, simulatorModules_->mdModulesNotifier,
+            legacyInput_->inputrec, interactiveMD_->imdSession, centerOfMassPulling_->pull_work,
+            ionSwapping_->ionSwap, topologyData_->top_global, simulatorStateData_->globalState_p,
             simulatorStateData_->observablesHistory_p, topologyData_->mdAtoms, profiling_->nrnb,
             profiling_->wallCycle, legacyInput_->forceRec, simulatorStateData_->enerdata_p,
             simulatorStateData_->ekindata_p, simulatorConfig_->runScheduleWork_,
index 3677e384c5e7ec8dcf6bba6814dc95ab4646c0d6..f2487d703485a932d1f9208f339baff0cf15a1df 100644 (file)
@@ -180,10 +180,7 @@ public:
 class LegacyInput
 {
 public:
-    LegacyInput(int             filenamesSize,
-                const t_filenm* filenamesData,
-                t_inputrec*     inputRec,
-                t_forcerec*     forceRec) :
+    LegacyInput(int filenamesSize, const t_filenm* filenamesData, t_inputrec* inputRec, t_forcerec* forceRec) :
         numFile(filenamesSize),
         filenames(filenamesData),
         inputrec(inputRec),
@@ -253,6 +250,15 @@ public:
     MDAtoms*    mdAtoms;
 };
 
+// Design note: The client may own the BoxDeformation via std::unique_ptr, but we are not
+// transferring ownership at this time. (Maybe be the subject of future changes.)
+class BoxDeformationHandle
+{
+public:
+    BoxDeformationHandle(BoxDeformation* boxDeformation) : deform(boxDeformation) {}
+    BoxDeformation* deform;
+};
+
 /*! \libinternal
  * \brief Class preparing the creation of Simulator objects
  *
@@ -329,6 +335,11 @@ public:
         topologyData_ = std::make_unique<TopologyData>(topologyData);
     }
 
+    void add(BoxDeformationHandle&& boxDeformation)
+    {
+        boxDeformation_ = std::make_unique<BoxDeformationHandle>(boxDeformation);
+    }
+
     /*! \brief Build a Simulator object based on input data
      *
      * Return a pointer to a simulation object. The use of a parameter
@@ -339,7 +350,7 @@ public:
      *
      * \return  Unique pointer to a Simulator object
      */
-    std::unique_ptr<ISimulator> build(bool useModularSimulator, BoxDeformation* deform);
+    std::unique_ptr<ISimulator> build(bool useModularSimulator);
 
 private:
     // Note: we use std::unique_ptr instead of std::optional because we want to
@@ -358,6 +369,7 @@ private:
     std::unique_ptr<CenterOfMassPulling>       centerOfMassPulling_;
     std::unique_ptr<IonSwapping>               ionSwapping_;
     std::unique_ptr<TopologyData>              topologyData_;
+    std::unique_ptr<BoxDeformationHandle>      boxDeformation_;
 };
 
 } // namespace gmx