--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+
+/*! \internal \file
+ * \brief Declares types and functions common to comparing either
+ * energies or trajectories produced by mdrun.
+ *
+ * \author Mark Abraham <mark.j.abraham@gmail.com>
+ * \ingroup module_mdrun_integration_tests
+ */
+#ifndef GMX_PROGRAMS_MDRUN_TESTS_COMPARISON_HELPERS_H
+#define GMX_PROGRAMS_MDRUN_TESTS_COMPARISON_HELPERS_H
+
+namespace gmx
+{
+
+namespace test
+{
+
+//! Enumeration controlling which trajectory frames are compared
+enum class FramesToCompare : int
+{
+ AllFrames,
+ OnlyFirstFrame, // e.g. because step-0 quantities are most useful to compare
+ Count
+};
+
+} // namespace test
+} // namespace gmx
+
+#endif
};
};
-EnergyComparison::EnergyComparison(const EnergyTermsToCompare& energyTermsToCompare) :
- energyTermsToCompare_(energyTermsToCompare)
+EnergyComparison::EnergyComparison(const EnergyTermsToCompare& energyTermsToCompare,
+ FramesToCompare framesToCompare) :
+ energyTermsToCompare_(energyTermsToCompare),
+ framesToCompare_(framesToCompare)
{
}
void EnergyComparison::operator()(const EnergyFrame& reference, const EnergyFrame& test) const
{
+ if (framesToCompare_ == FramesToCompare::OnlyFirstFrame && firstFrameHasBeenCompared_)
+ {
+ // Nothing should be compared
+ return;
+ }
+
SCOPED_TRACE("Comparing energy reference frame " + reference.frameName() + " and test frame "
+ test.frameName());
for (auto referenceIt = reference.begin(); referenceIt != reference.end(); ++referenceIt)
ADD_FAILURE() << "Could not find energy component from reference frame in test frame";
}
}
+ firstFrameHasBeenCompared_ = true;
}
void checkEnergiesAgainstReferenceData(const std::string& energyFilename,
if (thisRankChecks)
{
- EnergyComparison energyComparison(energyTermsToCompare);
+ EnergyComparison energyComparison(energyTermsToCompare, FramesToCompare::AllFrames);
auto energyReader = openEnergyFileToReadTerms(energyFilename, energyComparison.getEnergyNames());
std::unordered_map<std::string, TestReferenceChecker> checkers;
#include "testutils/testasserts.h"
+#include "comparison_helpers.h"
+
namespace gmx
{
//! Defaults for energy comparisons
static EnergyTermsToCompare defaultEnergyTermsToCompare();
//! Constructor
- EnergyComparison(const EnergyTermsToCompare& energyTermsToCompare);
+ EnergyComparison(const EnergyTermsToCompare& energyTermsToCompare, FramesToCompare framesToCompare);
/*! \brief Return the names of energies that will be compared
*
* This function can be used to provide an input for
* key. */
void operator()(const EnergyFrame& reference, const EnergyFrame& test) const;
+private:
//! Energy terms to match with given tolerances.
EnergyTermsToCompare energyTermsToCompare_;
+ //! Which frames should be compared.
+ FramesToCompare framesToCompare_ = FramesToCompare::AllFrames;
+ /*! \brief Whether the first frame has been compared yet
+ *
+ * This field is mutable because the need to update the flag
+ * after the first frame is merely an implementation detail,
+ * rather than a proper change of internal state triggered
+ * by the caller. */
+ mutable bool firstFrameHasBeenCompared_ = false;
};
/*! \brief Check a subset of the energies found in an energy file
// Build the functor that will compare energy frames on the chosen
// energy terms.
- EnergyComparison energyComparison(energyTermsToCompare);
+ EnergyComparison energyComparison(energyTermsToCompare, FramesToCompare::AllFrames);
// Build the manager that will present matching pairs of frames to compare.
//
//! Names for the output files from the reference mdrun call
ReferenceFileNames referenceFileNames_ = { fileManager_.getTemporaryFilePath("reference.edr") };
//! Functor for energy comparison
- EnergyComparison energyComparison_{ EnergyComparison::defaultEnergyTermsToCompare() };
+ EnergyComparison energyComparison_{ EnergyComparison::defaultEnergyTermsToCompare(),
+ FramesToCompare::AllFrames };
//! Names of energies compared by energyComparison_
std::vector<std::string> namesOfEnergiesToMatch_ = energyComparison_.getEnergyNames();
};
true,
ComparisonConditions::MustCompare,
ComparisonConditions::NoComparison,
- ComparisonConditions::MustCompare
+ ComparisonConditions::MustCompare,
+ FramesToCompare::AllFrames
};
void executeRerunTest(TestFileManager* fileManager,
true,
ComparisonConditions::MustCompare,
ComparisonConditions::MustCompare,
- ComparisonConditions::MustCompare };
+ ComparisonConditions::MustCompare,
+ FramesToCompare::AllFrames };
TrajectoryTolerances trajectoryTolerances = TrajectoryComparison::s_defaultTrajectoryTolerances;
if (simulationName != "argon12")
{
{
// Build the functor that will compare energy frames on the chosen
// energy terms.
- EnergyComparison energyComparison(energyTermsToCompare);
+ EnergyComparison energyComparison(energyTermsToCompare, FramesToCompare::AllFrames);
// Build the manager that will present matching pairs of frames to compare.
//
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,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.
void TrajectoryComparison::operator()(const TrajectoryFrame& reference, const TrajectoryFrame& test) const
{
+ if (matchSettings_.framesToCompare == FramesToCompare::OnlyFirstFrame && firstFrameHasBeenCompared_)
+ {
+ // Nothing should be compared
+ return;
+ }
SCOPED_TRACE("Comparing trajectory reference frame " + reference.frameName()
+ " and test frame " + test.frameName());
EXPECT_EQ(reference.step(), test.step());
compareCoordinates(reference, test, matchSettings_, tolerances_.coordinates);
compareVelocities(reference, test, matchSettings_, tolerances_.velocities);
compareForces(reference, test, matchSettings_, tolerances_.forces);
+ firstFrameHasBeenCompared_ = true;
}
} // namespace test
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,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.
#include "testutils/testasserts.h"
+#include "comparison_helpers.h"
+
namespace gmx
{
ComparisonConditions velocitiesComparison = ComparisonConditions::CompareIfBothFound;
//! Whether forces must be compared.
ComparisonConditions forcesComparison = ComparisonConditions::CompareIfBothFound;
+ //! Which frames will be compared
+ FramesToCompare framesToCompare = FramesToCompare::AllFrames;
};
/*! \internal
/*! \brief Compare reference with test given the \c
* matchSettings_ within \c tolerances_ */
void operator()(const TrajectoryFrame& reference, const TrajectoryFrame& test) const;
+
+private:
//! Specifies expected behavior in comparisons
TrajectoryFrameMatchSettings matchSettings_;
//! Trajectory fields to match with given tolerances.
TrajectoryTolerances tolerances_;
+ /*! \brief Whether the first frame has been compared yet
+ *
+ * This field is mutable because the need to update the flag
+ * after the first frame is merely an implementation detail,
+ * rather than a proper change of internal state triggered
+ * by the caller. */
+ mutable bool firstFrameHasBeenCompared_ = false;
};
} // namespace test