Now that we use newer infrastructure, we can use lambdas.
Also made FramePairManager and ContinuationFramePairManager
more consistent.
Change-Id: I8ccc9dd3134e5e188c3ea2b8b6ab335b4f267b10
const EnergyTolerances &energiesToMatch,
TestReferenceChecker *checker);
-/*! \internal
- * \brief Functor for comparing reference and test frames on
- * particular energies to match. */
-class EnergyComparator
-{
- public:
- //! Constructor
- EnergyComparator(const EnergyTolerances &energiesToMatch)
- : energiesToMatch_(energiesToMatch) {}
- //! The functor method.
- void operator()(const EnergyFrame &reference, const EnergyFrame &test)
- {
- compareEnergyFrames(reference, test, energiesToMatch_);
- }
- //! Container of the energies to match and the tolerance required.
- const EnergyTolerances &energiesToMatch_;
-};
-
} // namespace test
} // namespace gmx
* one- or two-part run.
*
* \todo This class has a similar interface with one in
- * mdcomparison.cpp, but not enough to warrant extracting an interface
+ * mdcomparison.h, but not enough to warrant extracting an interface
* class. Perhaps parts of this should be cast as a class that returns
* iterators to successive frames, so that the fancy footwork for
* pretending a two-part run is one sequence is separate from the
{
while (shouldContinueComparing())
{
- Frame firstFrame = full_->frame();
- Frame secondFrame = isFirstPart_ ? firstPart_->frame() : secondPart_->frame();
+ EnergyFrame firstFrame = full_->frame();
+ EnergyFrame secondFrame = isFirstPart_ ? firstPart_->frame() : secondPart_->frame();
SCOPED_TRACE("Comparing frames from two runs '" + firstFrame.frameName() + "' and '" + secondFrame.frameName() + "'");
compareTwoFrames(firstFrame, secondFrame);
}
secondPartRunEdrFileName += ".part0002.edr";
}
- // Build the functor that will compare reference and test
- // energy frames on the chosen energy fields.
- //
- // TODO It would be less code if we used a lambda for this, but either
- // clang 3.4 or libstdc++ 5.2.1 have an issue with capturing a
- // std::unordered_map
- EnergyComparator energyComparator(energiesToMatch);
+ // Build the functor that will compare energy frames on the chosen
+ // energy fields.
+ auto energyComparator = [&energiesToMatch](const EnergyFrame &fullRun, const EnergyFrame &twoPartRun)
+ {
+ compareEnergyFrames(fullRun, twoPartRun, energiesToMatch);
+ };
// Build the manager that will present matching pairs of frames to compare.
//
// TODO Here is an unnecessary copy of keys (ie. the energy field
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018,2019, 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.
/*! \internal
* \brief Manages returning a pair of frames from two
- * equivalent simulations that are meaningful to compare. */
-template <class FrameReader, class Frame>
+ * equivalent simulations that are meaningful to compare.
+ *
+ * \todo This is largely duplicated by ContinuationFrameManager. These
+ * could be refactored into components that compare iterators to
+ * frames.
+ *
+ * \tparam FrameReader Has readNextFrame() and frame() methods
+ * useful for returning successive Frame objects */
+template <class FrameReader>
class FramePairManager
{
public:
return false;
}
public:
- //! Compare all possible pairs of frames using \c compareTwoFrames.
+ /*! \brief Compare all possible pairs of frames using \c compareTwoFrames.
+ *
+ * \tparam Frame The type of frame used in the comparison (returned
+ * by FrameReader and used by compareTwoFrames). */
+ template <class Frame>
void compareAllFramePairs(std::function<void(const Frame &, const Frame &)> compareTwoFrames)
{
while (shouldContinueComparing())
{
- auto firstFrame = first_->frame();
- auto secondFrame = second_->frame();
+ Frame firstFrame = first_->frame();
+ Frame secondFrame = second_->frame();
SCOPED_TRACE("Comparing frames from two runs '" + firstFrame.frameName() + "' and '" + secondFrame.frameName() + "'");
compareTwoFrames(firstFrame, secondFrame);
}
namespace
{
-//! Functor for comparing reference and test frames on particular energies to match.
-class EnergyComparator
-{
- public:
- //! Constructor
- explicit EnergyComparator(const EnergyTolerances &energiesToMatch)
- : energiesToMatch_(energiesToMatch) {}
- //! The functor method.
- void operator()(const EnergyFrame &reference, const EnergyFrame &test)
- {
- compareEnergyFrames(reference, test, energiesToMatch_);
- }
- //! Container of the energies to match and the tolerance required.
- const EnergyTolerances &energiesToMatch_;
-};
-
//! Run grompp and mdrun for both sets of mdp field values
template <bool doEnvironmentVariable, bool doRerun>
void executeSimulatorComparisonTestImpl(
}
}
- // Build the functor that will compare reference and test
- // energy frames on the chosen energy fields.
- //
- // TODO It would be less code if we used a lambda for this, but either
- // clang 3.4 or libstdc++ 5.2.1 have an issue with capturing a
- // std::unordered_map
- EnergyComparator energyComparator(energiesToMatch);
+ // Build the functor that will compare energy frames on the chosen
+ // energy fields.
+ auto energyComparator = [&energiesToMatch](const EnergyFrame &first, const EnergyFrame &second)
+ {
+ compareEnergyFrames(first, second, energiesToMatch);
+ };
// Build the manager that will present matching pairs of frames to compare.
//
// TODO Here is an unnecessary copy of keys (ie. the energy field
// names), for convenience. In the future, use a range.
auto namesOfEnergiesToMatch = getKeys(energiesToMatch);
- FramePairManager<EnergyFrameReader, EnergyFrame>
+ FramePairManager<EnergyFrameReader>
energyManager(
openEnergyFileToReadFields(simulator1EdrFileName, namesOfEnergiesToMatch),
openEnergyFileToReadFields(simulator2EdrFileName, namesOfEnergiesToMatch));
// Compare the energy frames.
- energyManager.compareAllFramePairs(energyComparator);
+ energyManager.compareAllFramePairs<EnergyFrame>(energyComparator);
// Specify how trajectory frame matching must work.
TrajectoryFrameMatchSettings trajectoryMatchSettings {
compareTrajectoryFrames(reference, test, trajectoryMatchSettings, trajectoryTolerances);
};
// Build the manager that will present matching pairs of frames to compare
- FramePairManager<TrajectoryFrameReader, TrajectoryFrame>
+ FramePairManager<TrajectoryFrameReader>
trajectoryManager(std::make_unique<TrajectoryFrameReader>(simulator1TrajectoryFileName),
std::make_unique<TrajectoryFrameReader>(simulator2TrajectoryFileName));
// Compare the trajectory frames.
- trajectoryManager.compareAllFramePairs(trajectoryComparator);
+ trajectoryManager.compareAllFramePairs<TrajectoryFrame>(trajectoryComparator);
}
} // namespace