Compare trajectories to reference data
[alexxy/gromacs.git] / src / programs / mdrun / tests / trajectorycomparison.h
index 9e2847f7388589046f595aef4d311df1620b3d7e..d2cc51495f0547c0b92f144478ee3a20f4116b09 100644 (file)
@@ -38,6 +38,7 @@
  * produced by mdrun.
  *
  * \author Mark Abraham <mark.j.abraham@gmail.com>
+ * \author Pascal Merz <pascal.merz@me.com>
  * \ingroup module_mdrun_integration_tests
  */
 #ifndef GMX_PROGRAMS_MDRUN_TESTS_TRAJECTORYCOMPARISON_H
@@ -55,6 +56,8 @@ class TrajectoryFrame;
 namespace test
 {
 
+class TestReferenceChecker;
+
 /*! \internal
  * \brief Helper struct for testing different trajectory components with different tolerances. */
 struct TrajectoryTolerances
@@ -104,10 +107,10 @@ struct TrajectoryFrameMatchSettings
 };
 
 /*! \internal
- * \brief Function object to compare the fields of the two frames for
- * equality given the \c matchSettings_ and \c tolerances_.
+ * \brief Function object to compare the fields of two frames vs each others or one
+ * frame vs reference data for equality given the \c matchSettings_ and \c tolerances_.
  *
- * The two frames are required to have valid and matching values for
+ * If using two frames, they are required to have valid and matching values for
  * time and step. According to \c matchSettings_, box, position coordinates,
  * velocities and/or forces will be compared between frames, using the
  * \c tolerances_. Comparisons will only occur when both frames have
@@ -116,7 +119,16 @@ struct TrajectoryFrameMatchSettings
  * GoogleTest expectation failure will be given. If a comparison is
  * required by \c matchSettings_ but cannot be done because either (or
  * both) frames lack the requisite data, descriptive expectation
- * failures will be given. */
+ * failures will be given.
+ *
+ * When comparing a frame to reference data, according to \c matchSettings_,
+ * box, position coordinates, velocities and/or forces will be compared to
+ * reference data, using the \c tolerances_. If a comparison fails, a
+ * GoogleTest expectation failure will be given. If a comparison is
+ * required by \c matchSettings_ but cannot be done because the
+ * frame lacks the requisite data, descriptive expectation
+ * failures will be given.
+ */
 class TrajectoryComparison
 {
 public:
@@ -128,6 +140,9 @@ public:
     /*! \brief Compare reference with test given the \c
      * matchSettings_ within \c tolerances_ */
     void operator()(const TrajectoryFrame& reference, const TrajectoryFrame& test) const;
+    /*! \brief Compare frame to reference given the \c
+     * matchSettings_ within \c tolerances_ */
+    void operator()(const TrajectoryFrame& frame, TestReferenceChecker* checker) const;
 
 private:
     //! Specifies expected behavior in comparisons
@@ -143,6 +158,27 @@ private:
     mutable unsigned int numComparedFrames_ = 0;
 };
 
+/*! \internal
+ * \brief Helper function comparing a trajectory to reference.
+ *
+ * This opens a trajectory file, loops over its frames, and uses the
+ * \c trajectoryComparison and \c checker arguments to check each frame
+ * to reference data.
+ *
+ * Optionally, the max number of trajectory frames to be compared can
+ * be specified to allow to only test the first few frames of a
+ * simulation, e.g. to avoid failures due to numerical divergence.
+ */
+//! \{
+void checkTrajectoryAgainstReferenceData(const std::string&          trajectoryFilename,
+                                         const TrajectoryComparison& trajectoryComparison,
+                                         TestReferenceChecker*       checker);
+void checkTrajectoryAgainstReferenceData(const std::string&          trajectoryFilename,
+                                         const TrajectoryComparison& trajectoryComparison,
+                                         TestReferenceChecker*       checker,
+                                         MaxNumFrames                maxNumFrames);
+//! \}
+
 } // namespace test
 } // namespace gmx