594c18b5c2169f1028c704d4d728d096ac9e686d
[alexxy/gromacs.git] / src / gromacs / domdec / localatomset.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2018,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 /*! \file
36  * \libinternal \brief
37  * Declares gmx::LocalAtomSet.
38  *
39  * \author Christian Blau <cblau@gwdg.de>
40  * \inlibraryapi
41  * \ingroup module_domdec
42  */
43 #ifndef GMX_DOMDEC_LOCALATOMSET_H
44 #define GMX_DOMDEC_LOCALATOMSET_H
45
46 #include "gromacs/utility/arrayref.h"
47
48 namespace gmx
49 {
50
51 namespace internal
52 {
53 class LocalAtomSetData;
54 } // namespace internal
55 /*! \libinternal \brief
56  * A local atom set collects local, global and collective indices of
57  * the home atoms on a rank. The indices of the home atoms are automatically
58  * updated during domain decomposition, thus gmx::LocalAtomSet::localIndex
59  * enables iteration over local atoms properties like coordinates or forces.
60  * TODO: add a LocalAtomSet iterator.
61  *
62  * To generate a LocalAtomSet call gmx::LocalAtomSetManger::add and keep the
63  * handle to the LocalAtomSet returned from this call.
64  *
65  * \inlibraryapi
66  * \ingroup module_domdec
67  */
68 class LocalAtomSet
69 {
70 public:
71     friend class LocalAtomSetManager;
72     /*! \brief Maps indices on rank [0..numAtomsLocal_) to global atom indicices.
73      *
74      * \returns the collective index.
75      */
76     ArrayRef<const int> collectiveIndex() const;
77     /*! \brief Global indices of the atoms in this set.
78      *
79      * \note For best performance, store and use a local copy of the arrayref.
80      *
81      * \returns the global index.
82      */
83     ArrayRef<const int> globalIndex() const;
84     /*! \brief Local indices of the atoms.
85      *
86      * For example, the i-th local atom coordinate of this set is
87      * x[atomSet.localIndex()[i]].
88      *
89      * When using in a loop other than a range-based for loop,
90      * performance may improve if the ArrayRef is stored in
91      * a local variable before the loop is entered.
92      * Updated within domain-decomposition.
93      *
94      * \note For best performance, store and use a local copy of the ArrayRef.
95      *
96      * \returns the local index.
97      */
98     ArrayRef<const int> localIndex() const;
99     /*! \brief The number of atoms from this group index on this rank.
100      *
101      * \note For best performance, store and use a local copy of the ArrayRef.
102      */
103     std::size_t numAtomsLocal() const;
104     /*! \brief The number of all atoms from this group index on all ranks together.
105      *
106      * \note For best performance, store and use a local copy.
107      */
108     std::size_t numAtomsGlobal() const;
109
110 private:
111     /*! \brief Constructs a new atom set by setting a reference to its
112      * internal data.
113      * \param[in] data The data for the atom set is stored
114      * in LocalAtomSetData, which is manged by \ref gmx::LocalAtomSetManager.
115      */
116     explicit LocalAtomSet(const internal::LocalAtomSetData& data);
117
118     const internal::LocalAtomSetData* data_;
119 };
120
121 } // namespace gmx
122
123 #endif