From f4903a7b46d4b92636c364fdd31ecbf8230e69a6 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Tue, 28 Apr 2020 20:08:18 +0200 Subject: [PATCH] Fixed several clang-tidy issues A static variable was vulnerable to static-init-order-fiasco. Tests will still perform OK even with constructing the default value multiple times, so converted to a getter. Closes #3498 --- src/gromacs/analysisdata/tests/datatest.cpp | 8 +++++--- src/gromacs/listed_forces/gpubonded.h | 2 +- src/programs/mdrun/tests/energycomparison.cpp | 19 +++++++++++-------- src/programs/mdrun/tests/energycomparison.h | 4 ++-- src/programs/mdrun/tests/periodicactions.cpp | 4 ++-- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/gromacs/analysisdata/tests/datatest.cpp b/src/gromacs/analysisdata/tests/datatest.cpp index b694d11941..e8009f40a1 100644 --- a/src/gromacs/analysisdata/tests/datatest.cpp +++ b/src/gromacs/analysisdata/tests/datatest.cpp @@ -207,7 +207,7 @@ void AnalysisDataTestFixture::presentAllData(const AnalysisDataTestInput& input, void AnalysisDataTestFixture::presentDataFrame(const AnalysisDataTestInput& input, int row, AnalysisDataHandle handle) { const AnalysisDataTestInputFrame& frame = input.frame(row); - handle.startFrame(row, frame.x(), frame.dx()); + handle.startFrame(row, frame.x(), AnalysisDataTestInputFrame::dx()); for (int i = 0; i < frame.pointSetCount(); ++i) { const AnalysisDataTestInputPointSet& points = frame.pointSet(i); @@ -216,11 +216,13 @@ void AnalysisDataTestFixture::presentDataFrame(const AnalysisDataTestInput& inpu { if (points.hasError(j)) { - handle.setPoint(j + points.firstColumn(), points.y(j), points.error(j), points.present(j)); + handle.setPoint(j + points.firstColumn(), points.y(j), points.error(j), + AnalysisDataTestInputPointSet::present(j)); } else { - handle.setPoint(j + points.firstColumn(), points.y(j), points.present(j)); + handle.setPoint(j + points.firstColumn(), points.y(j), + AnalysisDataTestInputPointSet::present(j)); } } if (input.isMultipoint()) diff --git a/src/gromacs/listed_forces/gpubonded.h b/src/gromacs/listed_forces/gpubonded.h index 9d7d668296..2ad8969019 100644 --- a/src/gromacs/listed_forces/gpubonded.h +++ b/src/gromacs/listed_forces/gpubonded.h @@ -119,7 +119,7 @@ public: * */ GpuBonded(const gmx_ffparams_t& ffparams, - const float electrostaticsScaleFactor, + float electrostaticsScaleFactor, const DeviceContext& deviceContext, const DeviceStream& deviceStream, gmx_wallcycle* wcycle); diff --git a/src/programs/mdrun/tests/energycomparison.cpp b/src/programs/mdrun/tests/energycomparison.cpp index aab2bbf27f..3112960f90 100644 --- a/src/programs/mdrun/tests/energycomparison.cpp +++ b/src/programs/mdrun/tests/energycomparison.cpp @@ -64,14 +64,17 @@ namespace gmx namespace test { -const EnergyTermsToCompare EnergyComparison::s_defaultEnergyTermsToCompare = { - { interaction_function[F_EPOT].longname, relativeToleranceAsUlp(10.0, 50) }, - { interaction_function[F_EKIN].longname, relativeToleranceAsUlp(10.0, 50) }, - // The pressure is very strongly affected by summation errors, - // so we need a large tolerance. - // The value of 15000 is calibrated for running a small water box for 16 steps. - // For a single frame for a water box a value of 150 could work. - { interaction_function[F_PRES].longname, relativeToleranceAsUlp(10.0, 15000) }, +EnergyTermsToCompare EnergyComparison::defaultEnergyTermsToCompare() +{ + return { + { interaction_function[F_EPOT].longname, relativeToleranceAsUlp(10.0, 50) }, + { interaction_function[F_EKIN].longname, relativeToleranceAsUlp(10.0, 50) }, + // The pressure is very strongly affected by summation errors, + // so we need a large tolerance. + // The value of 15000 is calibrated for running a small water box for 16 steps. + // For a single frame for a water box a value of 150 could work. + { interaction_function[F_PRES].longname, relativeToleranceAsUlp(10.0, 15000) }, + }; }; EnergyComparison::EnergyComparison(const EnergyTermsToCompare& energyTermsToCompare) : diff --git a/src/programs/mdrun/tests/energycomparison.h b/src/programs/mdrun/tests/energycomparison.h index 980f522371..c715e7acf5 100644 --- a/src/programs/mdrun/tests/energycomparison.h +++ b/src/programs/mdrun/tests/energycomparison.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 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. @@ -67,7 +67,7 @@ class EnergyComparison { public: //! Defaults for energy comparisons - static const EnergyTermsToCompare s_defaultEnergyTermsToCompare; + static EnergyTermsToCompare defaultEnergyTermsToCompare(); //! Constructor EnergyComparison(const EnergyTermsToCompare& energyTermsToCompare); /*! \brief Return the names of energies that will be compared diff --git a/src/programs/mdrun/tests/periodicactions.cpp b/src/programs/mdrun/tests/periodicactions.cpp index cd5180bd5c..7d145388c4 100644 --- a/src/programs/mdrun/tests/periodicactions.cpp +++ b/src/programs/mdrun/tests/periodicactions.cpp @@ -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. @@ -106,7 +106,7 @@ public: //! Names for the output files from the reference mdrun call ReferenceFileNames referenceFileNames_ = { fileManager_.getTemporaryFilePath("reference.edr") }; //! Functor for energy comparison - EnergyComparison energyComparison_{ EnergyComparison::s_defaultEnergyTermsToCompare }; + EnergyComparison energyComparison_{ EnergyComparison::defaultEnergyTermsToCompare() }; //! Names of energies compared by energyComparison_ std::vector namesOfEnergiesToMatch_ = energyComparison_.getEnergyNames(); }; -- 2.11.4.GIT