Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / modularsimulator / constraintelement.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 constraint element for the modular simulator
37  *
38  * \author Pascal Merz <pascal.merz@me.com>
39  * \ingroup module_modularsimulator
40  */
41
42 #ifndef GMX_MODULARSIMULATOR_CONSTRAINTELEMENT_H
43 #define GMX_MODULARSIMULATOR_CONSTRAINTELEMENT_H
44
45 #include "gromacs/mdlib/constr.h"
46
47 #include "modularsimulatorinterfaces.h"
48
49 namespace gmx
50 {
51 class Constraints;
52 class EnergyElement;
53 class FreeEnergyPerturbationElement;
54 class StatePropagatorData;
55
56 /*! \libinternal
57  * \ingroup module_modularsimulator
58  * \brief Constraints element
59  *
60  * The ConstraintsElement is implemented for the position-and-velocity and the
61  * velocity-only case. It does not change the constraint implementation itself,
62  * but uses the current constraints implementation and the data management
63  * introduced with the modular simulator.
64  *
65  * @tparam variable  The constraining variable
66  */
67 template<ConstraintVariable variable>
68 class ConstraintsElement final :
69     public ISimulatorElement,
70     public IEnergySignallerClient,
71     public ITrajectorySignallerClient,
72     public ILoggingSignallerClient
73 {
74 public:
75     //! Constructor
76     ConstraintsElement(Constraints*                   constr,
77                        StatePropagatorData*           statePropagatorData,
78                        EnergyElement*                 energyElement,
79                        FreeEnergyPerturbationElement* freeEnergyPerturbationElement,
80                        bool                           isMaster,
81                        FILE*                          fplog,
82                        const t_inputrec*              inputrec,
83                        const t_mdatoms*               mdAtoms);
84
85     /*! \brief Register constraining function for step / time
86      *
87      * Under LF, this is expected to be run once, constraining positions and velocities
88      * Under VV, this is expected to be run twice, once contraining velocities only,
89      * a second time constraining positions and velocities.
90      *
91      * @param step                 The step number
92      * @param time                 The time
93      * @param registerRunFunction  Function allowing to register a run function
94      */
95     void scheduleTask(Step step, Time time, const RegisterRunFunctionPtr& registerRunFunction) override;
96
97     /*! \brief Performs inital constraining
98      *  \todo Should this rather happen at grompp time? Right position of this operation is currently
99      *        depending on the integrator algorithm (after domdec, before compute globals...),
100      *        so doing this earlier would be much more stable!
101      */
102     void elementSetup() override;
103     //! No element teardown needed
104     void elementTeardown() override {}
105
106 private:
107     //! The actual constraining computation
108     void apply(Step step, bool calculateVirial, bool writeLog, bool writeEnergy);
109
110     //! IEnergySignallerClient implementation
111     SignallerCallbackPtr registerEnergyCallback(EnergySignallerEvent event) override;
112     //! ITrajectorySignallerClient implementation
113     SignallerCallbackPtr registerTrajectorySignallerCallback(TrajectoryEvent event) override;
114     //! ILoggingSignallerClient implementation
115     SignallerCallbackPtr registerLoggingCallback() override;
116
117     //! The next energy calculation step
118     Step nextVirialCalculationStep_;
119     //! The next energy writing step
120     Step nextEnergyWritingStep_;
121     //! The next logging step
122     Step nextLogWritingStep_;
123
124     //! Whether we're master rank
125     const bool isMasterRank_;
126
127     //! Pointer to the micro state
128     StatePropagatorData* statePropagatorData_;
129     //! Pointer to the energy element
130     EnergyElement* energyElement_;
131     //! Pointer to the free energy perturbation element (only for initial constraining)
132     FreeEnergyPerturbationElement* freeEnergyPerturbationElement_;
133
134     // Access to ISimulator data
135     //! Handles constraints.
136     Constraints* constr_;
137     //! Handles logging.
138     FILE* fplog_;
139     //! Contains user input mdp options.
140     const t_inputrec* inputrec_;
141     //! Atom parameters for this domain.
142     const t_mdatoms* mdAtoms_;
143 };
144
145 } // namespace gmx
146
147 #endif // GMX_MODULARSIMULATOR_CONSTRAINTELEMENT_H