Add class ListedForces
[alexxy/gromacs.git] / src / gromacs / modularsimulator / forceelement.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019,2020, 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 force element for the modular simulator
37  *
38  * This element calculates the forces, with or without shells or
39  * flexible constraints.
40  *
41  * \author Pascal Merz <pascal.merz@me.com>
42  * \ingroup module_modularsimulator
43  */
44
45 #ifndef GMX_MODULARSIMULATOR_FORCEELEMENT_H
46 #define GMX_MODULARSIMULATOR_FORCEELEMENT_H
47
48 #include <array>
49
50 #include "gromacs/domdec/dlbtiming.h"
51 #include "gromacs/mdtypes/md_enums.h"
52 #include "gromacs/utility/real.h"
53
54 #include "modularsimulatorinterfaces.h"
55 #include "topologyholder.h"
56
57 struct gmx_enfrot;
58 struct gmx_shellfc_t;
59 struct gmx_wallcycle;
60 struct pull_t;
61 struct t_nrnb;
62
63 namespace gmx
64 {
65 class Awh;
66 class EnergyElement;
67 class FreeEnergyPerturbationElement;
68 class ImdSession;
69 class MDAtoms;
70 class MdrunScheduleWorkload;
71 class StatePropagatorData;
72 class VirtualSitesHandler;
73
74 /*! \libinternal
75  * \ingroup module_modularsimulator
76  * \brief Force element
77  *
78  * The force element manages the call to either
79  * do_force(...) or relax_shell_flexcon(...)
80  */
81 class ForceElement final :
82     public ISimulatorElement,
83     public ITopologyHolderClient,
84     public INeighborSearchSignallerClient,
85     public IEnergySignallerClient
86 {
87 public:
88     //! Constructor
89     ForceElement(StatePropagatorData*           statePropagatorData,
90                  EnergyElement*                 energyElement,
91                  FreeEnergyPerturbationElement* freeEnergyPerturbationElement,
92                  bool                           isVerbose,
93                  bool                           isDynamicBox,
94                  FILE*                          fplog,
95                  const t_commrec*               cr,
96                  const t_inputrec*              inputrec,
97                  const MDAtoms*                 mdAtoms,
98                  t_nrnb*                        nrnb,
99                  t_forcerec*                    fr,
100                  gmx_wallcycle*                 wcycle,
101                  MdrunScheduleWorkload*         runScheduleWork,
102                  VirtualSitesHandler*           vsite,
103                  ImdSession*                    imdSession,
104                  pull_t*                        pull_work,
105                  Constraints*                   constr,
106                  const gmx_mtop_t*              globalTopology,
107                  gmx_enfrot*                    enforcedRotation);
108
109     /*! \brief Register force calculation for step / time
110      *
111      * @param step                 The step number
112      * @param time                 The time
113      * @param registerRunFunction  Function allowing to register a run function
114      */
115     void scheduleTask(Step step, Time time, const RegisterRunFunctionPtr& registerRunFunction) override;
116
117     //! Check that we got the local topology
118     void elementSetup() override;
119     //! Print some final output
120     void elementTeardown() override;
121
122 private:
123     //! ITopologyHolderClient implementation
124     void setTopology(const gmx_localtop_t* top) override;
125     //! INeighborSearchSignallerClient implementation
126     SignallerCallbackPtr registerNSCallback() override;
127     //! IEnergySignallerClient implementation
128     SignallerCallbackPtr registerEnergyCallback(EnergySignallerEvent event) override;
129     //! The actual do_force call
130     template<bool doShellFC>
131     void run(Step step, Time time, unsigned int flags);
132
133     //! The shell / FC helper struct
134     gmx_shellfc_t* shellfc_;
135     //! Whether shells or flexible constraints are present
136     const bool doShellFC_;
137
138     //! The next NS step
139     Step nextNSStep_;
140     //! The next energy calculation step
141     Step nextEnergyCalculationStep_;
142     //! The next energy calculation step
143     Step nextVirialCalculationStep_;
144     //! The next free energy calculation step
145     Step nextFreeEnergyCalculationStep_;
146
147     //! Pointer to the micro state
148     StatePropagatorData* statePropagatorData_;
149     //! Pointer to the energy element
150     EnergyElement* energyElement_;
151     //! Pointer to the free energy perturbation element
152     FreeEnergyPerturbationElement* freeEnergyPerturbationElement_;
153
154     //! The local topology - updated by Topology via Client system
155     const gmx_localtop_t* localTopology_;
156
157     //! Whether we're having a dynamic box
158     const bool isDynamicBox_;
159     //! Whether we're being verbose
160     const bool isVerbose_;
161     //! The number of shell relaxation steps we did
162     Step nShellRelaxationSteps_;
163
164     //! DD / DLB helper object
165     const DDBalanceRegionHandler ddBalanceRegionHandler_;
166
167     /* \brief The FEP lambda vector
168      *
169      * Used if FEP is off, since do_force
170      * requires lambda to be allocated anyway
171      */
172     std::array<real, efptNR> lambda_;
173
174     // Access to ISimulator data
175     //! Handles logging.
176     FILE* fplog_;
177     //! Handles communication.
178     const t_commrec* cr_;
179     //! Contains user input mdp options.
180     const t_inputrec* inputrec_;
181     //! Atom parameters for this domain.
182     const MDAtoms* mdAtoms_;
183     //! Manages flop accounting.
184     t_nrnb* nrnb_;
185     //! Manages wall cycle accounting.
186     gmx_wallcycle* wcycle_;
187     //! Parameters for force calculations.
188     t_forcerec* fr_;
189     //! Handles virtual sites.
190     VirtualSitesHandler* vsite_;
191     //! The Interactive Molecular Dynamics session.
192     ImdSession* imdSession_;
193     //! The pull work object.
194     pull_t* pull_work_;
195     //! Schedule of work for each MD step for this task.
196     MdrunScheduleWorkload* runScheduleWork_;
197     //! Handles constraints.
198     Constraints* constr_;
199     //! Handles enforced rotation.
200     gmx_enfrot* enforcedRotation_;
201 };
202
203 } // namespace gmx
204
205 #endif // GMX_MODULARSIMULATOR_FORCEELEMENT_H