Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / modularsimulator / parrinellorahmanbarostat.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \libinternal \file
36  * \brief Declares the Parrinello-Rahman barostat for the modular simulator
37  *
38  * \author Pascal Merz <pascal.merz@me.com>
39  * \ingroup module_modularsimulator
40  */
41
42 #ifndef GMX_MODULARSIMULATOR_PARRINELLORAHMANBAROSTAT_H
43 #define GMX_MODULARSIMULATOR_PARRINELLORAHMANBAROSTAT_H
44
45 #include "gromacs/math/vectypes.h"
46
47 #include "modularsimulatorinterfaces.h"
48 #include "propagator.h"
49
50 struct t_inputrec;
51 struct t_commrec;
52
53 namespace gmx
54 {
55 class EnergyElement;
56 class MDAtoms;
57 class StatePropagatorData;
58
59 /*! \libinternal
60  * \ingroup module_modularsimulator
61  * \brief Element implementing the Parrinello-Rahman barostat
62  *
63  * This element
64  *   * integrates the Parrinello-Rahman box velocity equations,
65  *   * takes a callback to the propagator to update the velocity
66  *     scaling factor, and
67  *   * scales the box and the positions of the system.
68  */
69 class ParrinelloRahmanBarostat final : public ISimulatorElement, public ICheckpointHelperClient
70 {
71 public:
72     //! Constructor
73     ParrinelloRahmanBarostat(int                   nstpcouple,
74                              int                   offset,
75                              real                  couplingTimeStep,
76                              Step                  initStep,
77                              ArrayRef<rvec>        scalingTensor,
78                              PropagatorCallbackPtr propagatorCallback,
79                              StatePropagatorData*  statePropagatorData,
80                              EnergyElement*        energyElement,
81                              FILE*                 fplog,
82                              const t_inputrec*     inputrec,
83                              const MDAtoms*        mdAtoms,
84                              const t_state*        globalState,
85                              t_commrec*            cr,
86                              bool                  isRestart);
87
88     /*! \brief Register run function for step / time
89      *
90      * @param step                 The step number
91      * @param time                 The time
92      * @param registerRunFunction  Function allowing to register a run function
93      */
94     void scheduleTask(Step step, Time time, const RegisterRunFunctionPtr& registerRunFunction) override;
95
96     //! Fix relative box shape
97     void elementSetup() override;
98     //! No element teardown needed
99     void elementTeardown() override {}
100
101     //! Getter for the box velocities
102     const rvec* boxVelocities() const;
103
104 private:
105     //! The frequency at which the barostat is applied
106     const int nstpcouple_;
107     //! If != 0, offset the step at which the barostat is applied
108     const int offset_;
109     //! The coupling time step - simulation time step x nstcouple_
110     const real couplingTimeStep_;
111     //! The first step of the simulation
112     const Step initStep_;
113
114     //! Whether this is the first step
115     bool isInitStep_;
116
117     //! View on the velocity scaling tensor (owned by the propagator)
118     ArrayRef<rvec> scalingTensor_;
119     //! Callback to let propagator know that we updated lambda
120     PropagatorCallbackPtr propagatorCallback_;
121
122     //! Relative change in box before - after barostatting
123     matrix mu_;
124     //! Relative box shape
125     tensor boxRel_;
126     //! Box velocity
127     tensor boxVelocity_;
128
129     //! Pointer to the micro state
130     StatePropagatorData* statePropagatorData_;
131     //! Pointer to the energy element
132     EnergyElement* energyElement_;
133
134     //! Integrate the PR box vector equations of motion - does not alter state
135     void integrateBoxVelocityEquations(Step step);
136     //! Scale box and positions
137     void scaleBoxAndPositions();
138
139     //! ICheckpointHelperClient implementation
140     void writeCheckpoint(t_state* localState, t_state* globalState) override;
141
142     // Access to ISimulator data
143     //! Handles logging.
144     FILE* fplog_;
145     //! Contains user input mdp options.
146     const t_inputrec* inputrec_;
147     //! Atom parameters for this domain.
148     const MDAtoms* mdAtoms_;
149 };
150
151 } // namespace gmx
152
153 #endif // GMX_MODULARSIMULATOR_PARRINELLORAHMANBAROSTAT_H