Refactor virtual site interface
[alexxy/gromacs.git] / src / gromacs / modularsimulator / domdechelper.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 domain decomposition helper for the modular simulator
37  *
38  * \author Pascal Merz <pascal.merz@me.com>
39  * \ingroup module_modularsimulator
40  */
41
42 #ifndef GMX_MODULARSIMULATOR_DOMDECHELPER_H
43 #define GMX_MODULARSIMULATOR_DOMDECHELPER_H
44
45 #include "modularsimulatorinterfaces.h"
46
47 struct gmx_localtop_t;
48 struct gmx_wallcycle;
49 struct pull_t;
50 struct t_commrec;
51 struct t_forcerec;
52 struct t_inputrec;
53 struct t_nrnb;
54
55 namespace gmx
56 {
57 class Constraints;
58 class ImdSession;
59 class MDAtoms;
60 class MDLogger;
61 class StatePropagatorData;
62 class TopologyHolder;
63 class VirtualSitesHandler;
64
65 //! \addtogroup module_modularsimulator
66 //! \{
67
68 //! The function type allowing to request a check of the number of bonded interactions
69 typedef std::function<void()> CheckBondedInteractionsCallback;
70 //! Pointer to the function type allowing to request a check of the number of bonded interactions
71 typedef std::unique_ptr<CheckBondedInteractionsCallback> CheckBondedInteractionsCallbackPtr;
72
73 /*! \libinternal
74  * \brief Infrastructure element responsible for domain decomposition
75  *
76  * This encapsulates the function call to domain decomposition, which is
77  * important for performance but outside of the current scope of the modular
78  * simulator project. This relies on legacy data structures for the state
79  * and the topology.
80  *
81  * This element does not implement the ISimulatorElement interface, as
82  * the Simulator is calling it explicitly between task queue population
83  * steps. This allows elements to be aware of any changes before
84  * deciding what functionality they need to run.
85  */
86 class DomDecHelper final : public INeighborSearchSignallerClient
87 {
88 public:
89     //! Constructor
90     DomDecHelper(bool                               isVerbose,
91                  int                                verbosePrintInterval,
92                  StatePropagatorData*               statePropagatorData,
93                  TopologyHolder*                    topologyHolder,
94                  CheckBondedInteractionsCallbackPtr checkBondedInteractionsCallback,
95                  int                                nstglobalcomm,
96                  FILE*                              fplog,
97                  t_commrec*                         cr,
98                  const MDLogger&                    mdlog,
99                  Constraints*                       constr,
100                  t_inputrec*                        inputrec,
101                  MDAtoms*                           mdAtoms,
102                  t_nrnb*                            nrnb,
103                  gmx_wallcycle*                     wcycle,
104                  t_forcerec*                        fr,
105                  VirtualSitesHandler*               vsite,
106                  ImdSession*                        imdSession,
107                  pull_t*                            pull_work);
108
109     /*! \brief Run domain decomposition
110      *
111      * Does domain decomposition partitioning at neighbor searching steps
112      *
113      * @param step  The step number
114      * @param time  The time
115      */
116     void run(Step step, Time time);
117
118     /*! \brief The initial domain decomposition partitioning
119      *
120      */
121     void setup();
122
123 private:
124     //! INeighborSearchSignallerClient implementation
125     SignallerCallbackPtr registerNSCallback() override;
126
127     //! The next NS step
128     Step nextNSStep_;
129     //! Whether we're being verbose
130     const bool isVerbose_;
131     //! If we're being verbose, how often?
132     const int verbosePrintInterval_;
133     //! The global communication frequency
134     const int nstglobalcomm_;
135
136     //! Pointer to the micro state
137     StatePropagatorData* statePropagatorData_;
138     //! Pointer to the topology
139     TopologyHolder* topologyHolder_;
140     //! Pointer to the ComputeGlobalsHelper object - to ask for # of bonded interaction checking
141     CheckBondedInteractionsCallbackPtr checkBondedInteractionsCallback_;
142
143     // Access to ISimulator data
144     //! Handles logging.
145     FILE* fplog_;
146     //! Handles communication.
147     t_commrec* cr_;
148     //! Handles logging.
149     const MDLogger& mdlog_;
150     //! Handles constraints.
151     Constraints* constr_;
152     //! Contains user input mdp options.
153     t_inputrec* inputrec_;
154     //! Atom parameters for this domain.
155     MDAtoms* mdAtoms_;
156     //! Manages flop accounting.
157     t_nrnb* nrnb_;
158     //! Manages wall cycle accounting.
159     gmx_wallcycle* wcycle_;
160     //! Parameters for force calculations.
161     t_forcerec* fr_;
162     //! Handles virtual sites.
163     VirtualSitesHandler* vsite_;
164     //! The Interactive Molecular Dynamics session.
165     ImdSession* imdSession_;
166     //! The pull work object.
167     pull_t* pull_work_;
168 };
169
170 //! \}
171 } // namespace gmx
172
173 #endif // GMX_MODULARSIMULATOR_DOMDECHELPER_H