2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * \brief Declares Andersen temperature coupling for the modular simulator
38 * \author Pascal Merz <pascal.merz@me.com>
39 * \ingroup module_modularsimulator
42 #ifndef GMX_MODULARSIMULATOR_ANDERSENTHERMOSTAT_H
43 #define GMX_MODULARSIMULATOR_ANDERSENTHERMOSTAT_H
45 #include "gromacs/utility/arrayref.h"
47 #include "energydata.h"
48 #include "modularsimulatorinterfaces.h"
49 #include "propagator.h"
58 * \ingroup module_modularsimulator
59 * \brief Element implementing the Andersen thermostat
62 class AndersenTemperatureCoupling final : public ISimulatorElement
66 AndersenTemperatureCoupling(double simulationTimestep,
69 ArrayRef<const real> referenceTemperature,
70 ArrayRef<const real> couplingTime,
71 StatePropagatorData* statePropagatorData,
72 const MDAtoms* mdAtoms,
75 /*! \brief Register run function for step / time
77 * \param step The step number
78 * \param time The time
79 * \param registerRunFunction Function allowing to register a run function
81 void scheduleTask(Step step, Time time, const RegisterRunFunction& registerRunFunction) override;
83 //! Sanity check at setup time
84 void elementSetup() override;
85 //! No element teardown needed
86 void elementTeardown() override {}
88 /*! \brief Factory method implementation
90 * \param legacySimulatorData Pointer allowing access to simulator level data
91 * \param builderHelper ModularSimulatorAlgorithmBuilder helper object
92 * \param statePropagatorData Pointer to the \c StatePropagatorData object
93 * \param energyData Pointer to the \c EnergyData object
94 * \param freeEnergyPerturbationData Pointer to the \c FreeEnergyPerturbationData object
95 * \param globalCommunicationHelper Pointer to the \c GlobalCommunicationHelper object
96 * \param observablesReducer Pointer to the \c ObservablesReducer object
98 * \return Pointer to the element to be added. Element needs to have been stored using \c storeElement
100 static ISimulatorElement* getElementPointerImpl(LegacySimulatorData* legacySimulatorData,
101 ModularSimulatorAlgorithmBuilderHelper* builderHelper,
102 StatePropagatorData* statePropagatorData,
103 EnergyData* energyData,
104 FreeEnergyPerturbationData* freeEnergyPerturbationData,
105 GlobalCommunicationHelper* globalCommunicationHelper,
106 ObservablesReducer* observablesReducer);
108 //! Returns the frequency at which temperature coupling is performed
109 [[nodiscard]] int frequency() const;
112 //! Update the reference temperature
113 static void updateReferenceTemperature(ArrayRef<const real> temperatures,
114 ReferenceTemperatureChangeAlgorithm algorithm);
116 //! Whether we're doing massive Andersen thermostatting
117 const bool doMassive_;
119 const real randomizationRate_;
120 //! The frequency at which the thermostat is applied
121 const int couplingFrequency_;
124 //! Coupling temperature per group
125 ArrayRef<const real> referenceTemperature_;
126 //! Coupling time per group
127 ArrayRef<const real> couplingTime_;
129 // TODO: Clarify relationship to data objects and find a more robust alternative to raw pointers (#3583)
130 //! Pointer to the micro state
131 StatePropagatorData* statePropagatorData_;
132 //! Atom parameters for this domain.
133 const t_mdatoms* mdAtoms_;
134 //! Handles communication.
135 const t_commrec* cr_;
137 //! Apply the thermostat at step
138 void apply(Step step);
143 #endif // GMX_MODULARSIMULATOR_ANDERSENTHERMOSTAT_H