Do not allow AtomLocality::All for coordinates and velocities transfer.
[alexxy/gromacs.git] / src / gromacs / mdtypes / locality.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019,2021, 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
36 /*! \libinternal \file
37  * \brief Defines atom and atom interaction locality enums
38  *
39  * \author Berk Hess <hess@kth.se>
40  * \ingroup module_mdtypes
41  */
42
43 #ifndef GMX_MDTYPES_LOCALITY_H
44 #define GMX_MDTYPES_LOCALITY_H
45
46 #include "gromacs/utility/enumerationhelpers.h"
47 #include "gromacs/utility/exceptions.h"
48
49 namespace gmx
50 {
51
52 /*! \brief Atom locality indicator: local, non-local, all.
53  *
54  * Used for calls to:
55  * gridding, force calculation, x/f buffer operations
56  */
57 enum class AtomLocality : int
58 {
59     Local    = 0, //!< Local atoms
60     NonLocal = 1, //!< Non-local atoms
61     All      = 2, //!< Both local and non-local atoms
62     Count    = 3  //!< The number of atom locality types
63 };
64
65 /*! \brief Get the human-friendly name for atom localities.
66  *
67  * \param[in] enumValue The enum value to get the name for.
68  */
69 [[maybe_unused]] static const char* enumValueToString(AtomLocality enumValue)
70 {
71     static constexpr gmx::EnumerationArray<AtomLocality, const char*> atomLocalityNames = {
72         "Local", "Non-local", "All"
73     };
74     return atomLocalityNames[enumValue];
75 }
76 /*! \brief Interaction locality indicator: local, non-local, all.
77  *
78  * Used for calls to:
79  * pair-search, force calculation, x/f buffer operations
80  */
81 enum class InteractionLocality : int
82 {
83     Local    = 0, //!< Interactions between local atoms only
84     NonLocal = 1, //!< Interactions between non-local and (non-)local atoms
85     Count    = 2  //!< The number of interaction locality types
86 };
87
88 /*! \brief Get the human-friendly name for interaction localities.
89  *
90  * \param[in] enumValue The enum value to get the name for.
91  */
92 [[maybe_unused]] static const char* enumValueToString(InteractionLocality enumValue)
93 {
94     static constexpr gmx::EnumerationArray<InteractionLocality, const char*> interactionLocalityNames = {
95         "Local", "Non-local"
96     };
97     return interactionLocalityNames[enumValue];
98 }
99
100 /*! \brief Convert atom locality to interaction locality.
101  *
102  *  In the current implementation the this is straightforward conversion:
103  *  local to local, non-local to non-local.
104  *
105  *  \param[in] atomLocality Atom locality specifier
106  *  \returns                Interaction locality corresponding to the atom locality passed.
107  */
108 static inline InteractionLocality atomToInteractionLocality(const AtomLocality atomLocality)
109 {
110
111     /* determine interaction locality from atom locality */
112     if (atomLocality == AtomLocality::Local)
113     {
114         return InteractionLocality::Local;
115     }
116     else if (atomLocality == AtomLocality::NonLocal)
117     {
118         return InteractionLocality::NonLocal;
119     }
120     else
121     {
122         GMX_THROW(gmx::InconsistentInputError(
123                 "Only Local and NonLocal atom locities can be converted to interaction locality."));
124     }
125 }
126
127 } // namespace gmx
128
129 #endif // GMX_MDTYPES_LOCALITY_H