Split lines with many copyright years
[gromacs.git] / src / programs / mdrun / tests / multisimtest.cpp
blobb53756599b8a77727bcdf203a7a70764b9e5cb11
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2013,2014,2015,2016,2018 by the GROMACS development team.
5 * Copyright (c) 2019,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
37 /*! \internal \file
38 * \brief
39 * Tests for the mdrun multi-simulation functionality
41 * \author Mark Abraham <mark.j.abraham@gmail.com>
42 * \ingroup module_mdrun_integration_tests
44 #include "gmxpre.h"
46 #include "multisimtest.h"
48 #include <cmath>
50 #include <algorithm>
51 #include <string>
53 #include <gtest/gtest.h>
55 #include "gromacs/utility/basenetwork.h"
56 #include "gromacs/utility/path.h"
57 #include "gromacs/utility/real.h"
58 #include "gromacs/utility/stringutil.h"
60 #include "testutils/cmdlinetest.h"
62 #include "moduletest.h"
63 #include "terminationhelper.h"
65 namespace gmx
67 namespace test
70 MultiSimTest::MultiSimTest() :
71 size_(gmx_node_num()),
72 rank_(gmx_node_rank()),
73 mdrunCaller_(new CommandLine)
76 const char* directoryNameFormat = "sim_%d";
78 // Modify the file manager to have a temporary directory unique to
79 // each simulation. No need to have a mutex on this, nobody else
80 // can access the fileManager_ yet because we only just
81 // constructed it.
82 std::string originalTempDirectory = fileManager_.getOutputTempDirectory();
83 std::string newTempDirectory =
84 Path::join(originalTempDirectory, formatString(directoryNameFormat, rank_));
85 Directory::create(newTempDirectory);
86 fileManager_.setOutputTempDirectory(newTempDirectory);
88 mdrunCaller_->append("mdrun");
89 mdrunCaller_->addOption("-multidir");
90 for (int i = 0; i != size_; ++i)
92 mdrunCaller_->append(Path::join(originalTempDirectory, formatString(directoryNameFormat, i)));
96 void MultiSimTest::organizeMdpFile(SimulationRunner* runner, const char* controlVariable, int numSteps)
98 const real baseTemperature = 298;
99 const real basePressure = 1;
100 std::string mdpFileContents = formatString(
101 "nsteps = %d\n"
102 "nstlog = 1\n"
103 "nstcalcenergy = 1\n"
104 "tcoupl = v-rescale\n"
105 "tc-grps = System\n"
106 "tau-t = 1\n"
107 "ref-t = %f\n"
108 // pressure coupling (if active)
109 "tau-p = 1\n"
110 "ref-p = %f\n"
111 "compressibility = 4.5e-5\n"
112 // velocity generation
113 "gen-vel = yes\n"
114 "gen-temp = %f\n"
115 // control variable specification
116 "%s\n",
117 numSteps, baseTemperature + 0.0001 * rank_, basePressure * std::pow(1.01, rank_),
118 /* Set things up so that the initial KE decreases with
119 increasing replica number, so that the (identical)
120 starting PE decreases on the first step more for the
121 replicas with higher number, which will tend to force
122 replica exchange to occur. */
123 std::max(baseTemperature - 10 * rank_, real(0)), controlVariable);
124 runner->useStringAsMdpFile(mdpFileContents);
127 void MultiSimTest::runExitsNormallyTest()
129 if (size_ <= 1)
131 /* Can't test multi-sim without multiple ranks. */
132 return;
135 SimulationRunner runner(&fileManager_);
136 runner.useTopGroAndNdxFromDatabase("spc2");
138 const char* pcoupl = GetParam();
139 organizeMdpFile(&runner, pcoupl);
140 /* Call grompp on every rank - the standard callGrompp() only runs
141 grompp on rank 0. */
142 EXPECT_EQ(0, runner.callGromppOnThisRank());
144 ASSERT_EQ(0, runner.callMdrun(*mdrunCaller_));
147 void MultiSimTest::runMaxhTest()
149 if (size_ <= 1)
151 /* Can't test replica exchange without multiple ranks. */
152 return;
155 SimulationRunner runner(&fileManager_);
156 runner.useTopGroAndNdxFromDatabase("spc2");
158 TerminationHelper helper(&fileManager_, mdrunCaller_.get(), &runner);
159 // Make sure -maxh has a chance to propagate
160 int numSteps = 100;
161 organizeMdpFile(&runner, "pcoupl = no", numSteps);
162 /* Call grompp on every rank - the standard callGrompp() only runs
163 grompp on rank 0. */
164 EXPECT_EQ(0, runner.callGromppOnThisRank());
166 helper.runFirstMdrun(runner.cptFileName_);
167 helper.runSecondMdrun();
170 } // namespace test
171 } // namespace gmx