Introduce plumbing for ObservablesReducer
[alexxy/gromacs.git] / src / gromacs / mdlib / md_support.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014,2015,2016,2017 The GROMACS development team.
7  * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9  * and including many others, as listed in the AUTHORS file in the
10  * top-level source directory and at http://www.gromacs.org.
11  *
12  * GROMACS is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 2.1
15  * of the License, or (at your option) any later version.
16  *
17  * GROMACS is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with GROMACS; if not, see
24  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
26  *
27  * If you want to redistribute modifications to GROMACS, please
28  * consider that scientific software is very special. Version
29  * control is crucial - bugs must be traceable. We will be happy to
30  * consider code for inclusion in the official distribution, but
31  * derived work must not be called official GROMACS. Details are found
32  * in the README & COPYING files - if they are missing, get the
33  * official version at http://www.gromacs.org.
34  *
35  * To help us fund GROMACS development, we humbly ask that you cite
36  * the research papers on the package. Check out http://www.gromacs.org.
37  */
38 #ifndef GMX_MDLIB_MD_SUPPORT_H
39 #define GMX_MDLIB_MD_SUPPORT_H
40
41 #include <cstdint>
42
43 #include "gromacs/mdlib/vcm.h"
44 #include "gromacs/mdtypes/md_enums.h"
45 #include "gromacs/timing/wallcycle.h"
46
47 class gmx_ekindata_t;
48 struct gmx_enerdata_t;
49 struct gmx_global_stat;
50 struct gmx_signalling_t;
51 struct t_extmass;
52 struct t_forcerec;
53 struct t_grpopts;
54 struct t_inputrec;
55 struct t_nrnb;
56 class t_state;
57 struct t_trxframe;
58
59 namespace gmx
60 {
61 template<typename T>
62 class ArrayRef;
63 class Constraints;
64 class MDLogger;
65 class ObservablesReducer;
66 class SimulationSignaller;
67 } // namespace gmx
68
69 /* Define a number of flags to better control the information
70  * passed to compute_globals in md.c and global_stat.
71  */
72
73 /* we are computing the kinetic energy from average velocities */
74 #define CGLO_EKINAVEVEL (1u << 2u)
75 /* we are removing the center of mass momenta */
76 #define CGLO_STOPCM (1u << 3u)
77 /* bGStat is defined in do_md */
78 #define CGLO_GSTAT (1u << 4u)
79 /* Sum the energy terms in global computation */
80 #define CGLO_ENERGY (1u << 6u)
81 /* Sum the kinetic energy terms in global computation */
82 #define CGLO_TEMPERATURE (1u << 7u)
83 /* Sum the kinetic energy terms in global computation */
84 #define CGLO_PRESSURE (1u << 8u)
85 /* Sum the constraint term in global computation */
86 #define CGLO_CONSTRAINT (1u << 9u)
87 /* Reading ekin from the trajectory */
88 #define CGLO_READEKIN (1u << 10u)
89 /* we need to reset the ekin rescaling factor here */
90 #define CGLO_SCALEEKIN (1u << 11u)
91 /* After a new DD partitioning, we need to set a flag to schedule
92  * global reduction of the total number of bonded interactions that
93  * will be computed, to check none are missing. */
94 #define CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS (1u << 12u)
95
96 /*! \brief Return the number of steps that will take place between
97  * intra-simulation communications, given the constraints of the
98  * inputrec. */
99 int computeGlobalCommunicationPeriod(const t_inputrec* ir);
100
101 /*! \brief Return the number of steps that will take place between
102  * intra-simulation communications, given the constraints of the
103  * inputrec, and write information to log.
104  * Calls computeGlobalCommunicationPeriod(ir) internally. */
105 int computeGlobalCommunicationPeriod(const gmx::MDLogger& mdlog, const t_inputrec* ir, const t_commrec* cr);
106
107 void rerun_parallel_comm(t_commrec* cr, t_trxframe* fr, gmx_bool* bLastStep);
108
109 //! \brief Allocate and initialize node-local state entries
110 void set_state_entries(t_state* state, const t_inputrec* ir, bool useModularSimulator);
111
112 /* Compute global variables during integration
113  *
114  * Coordinates x are needed for kinetic energy calculation with cosine accelation
115  * and for COM removal with rotational and acceleration correction modes.
116  * Velocities v are needed for kinetic energy calculation and for COM removal.
117  */
118 void compute_globals(gmx_global_stat*               gstat,
119                      t_commrec*                     cr,
120                      const t_inputrec*              ir,
121                      t_forcerec*                    fr,
122                      gmx_ekindata_t*                ekind,
123                      gmx::ArrayRef<const gmx::RVec> x,
124                      gmx::ArrayRef<const gmx::RVec> v,
125                      const matrix                   box,
126                      const t_mdatoms*               mdatoms,
127                      t_nrnb*                        nrnb,
128                      t_vcm*                         vcm,
129                      gmx_wallcycle*                 wcycle,
130                      gmx_enerdata_t*                enerd,
131                      tensor                         force_vir,
132                      tensor                         shake_vir,
133                      tensor                         total_vir,
134                      tensor                         pres,
135                      gmx::ArrayRef<real>            constraintsRmsdData,
136                      gmx::SimulationSignaller*      signalCoordinator,
137                      const matrix                   lastbox,
138                      gmx_bool*                      bSumEkinhOld,
139                      int                            flags,
140                      int64_t                        step,
141                      gmx::ObservablesReducer*       observablesReducer);
142
143 #endif