Extract helper force buffers to a separate class
[alexxy/gromacs.git] / src / gromacs / mdtypes / forceoutput.h
index f17e61deebabff8e82bf52debfbc49830b77d131..6152a68f2d7af75f38d3e4c645110fdc6319c246 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2019, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -83,6 +83,8 @@ public:
         computeVirial_(computeVirial),
         shiftForces_(computeVirial ? shiftForces : gmx::ArrayRef<gmx::RVec>())
     {
+        GMX_ASSERT(!computeVirial || !shiftForces.empty(),
+                   "We need a valid shift force buffer when computing the virial");
     }
 
     //! Returns an arrayref to the force buffer without padding
@@ -193,8 +195,11 @@ class ForceOutputs
 {
 public:
     //! Constructor
-    ForceOutputs(const ForceWithShiftForces& forceWithShiftForces, const ForceWithVirial& forceWithVirial) :
+    ForceOutputs(const ForceWithShiftForces& forceWithShiftForces,
+                 bool                        haveForceWithVirial,
+                 const ForceWithVirial&      forceWithVirial) :
         forceWithShiftForces_(forceWithShiftForces),
+        haveForceWithVirial_(haveForceWithVirial),
         forceWithVirial_(forceWithVirial)
     {
     }
@@ -202,12 +207,17 @@ public:
     //! Returns a reference to the force with shift forces object
     ForceWithShiftForces& forceWithShiftForces() { return forceWithShiftForces_; }
 
+    //! Return whether there are forces with direct virial contributions
+    bool haveForceWithVirial() const { return haveForceWithVirial_; }
+
     //! Returns a reference to the force with virial object
     ForceWithVirial& forceWithVirial() { return forceWithVirial_; }
 
 private:
     //! Force output buffer used by legacy modules (without SIMD padding)
     ForceWithShiftForces forceWithShiftForces_;
+    //! Whether we have forces with direct virial contributions
+    bool haveForceWithVirial_;
     //! Force with direct virial contribution (if there are any; without SIMD padding)
     ForceWithVirial forceWithVirial_;
 };