OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
ForceDecomposition.hpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#ifndef PARALLEL_FORCEDECOMPOSITION_HPP
49#define PARALLEL_FORCEDECOMPOSITION_HPP
50
51#include "brains/SimInfo.hpp"
53#include "nonbonded/InteractionManager.hpp"
54#include "nonbonded/NonBondedInteraction.hpp"
55
56using namespace std;
57namespace OpenMD {
58
59 /**
60 * @class ForceDecomposition
61 *
62 * ForceDecomposition is an interface for passing out and collecting
63 * information from many processors at various stages of the main
64 * non-bonded ForceLoop.
65 *
66 * The pairwise force calculation has an outer-running loop (the "I"
67 * loop) and an inner-running loop (the "J" loop). In parallel
68 * decompositions, these loop over different groups of atoms on
69 * different processors. Between each set of computations on the
70 * local processor, data must be exchanged among the processors.
71 * This can happen at different times in the calculation:
72 *
73 * distributeInitialData (parallel communication - one time only)
74 * distributeData (parallel communication - every ForceLoop)
75 *
76 * loop iLoop over nLoops (nLoops may be 1, 2, or until self consistent)
77 * | loop over i
78 * | | loop over j
79 * | | | localComputation
80 * | | end
81 * | end
82 * | if (nLoops > 1):
83 * | | collectIntermediateData (parallel communication)
84 * | | distributeIntermediateData (parallel communication)
85 * | endif
86 * end
87 * collectData (parallel communication)
88 * loop over i
89 * | localComputation
90 * end
91 * collectSelfData (parallel communication)
92 *
93 * ForceDecomposition provides the interface for ForceLoop to do the
94 * communication steps and to iterate using the correct set of atoms
95 * and cutoff groups.
96 */
97 class ForceDecomposition {
98 public:
99 ForceDecomposition(SimInfo* info, InteractionManager* iMan);
100 virtual ~ForceDecomposition() {}
101
102 virtual void setSnapshot(Snapshot* snap) { snap_ = snap; }
103
104 virtual void distributeInitialData() = 0;
105 virtual void distributeData() = 0;
106 virtual void zeroWorkArrays() = 0;
107 virtual void collectIntermediateData() = 0;
108 virtual void distributeIntermediateData() = 0;
109 virtual void collectData() = 0;
110 virtual void collectSelfData() = 0;
111 virtual potVec getSelfPotential() { return selfPot; }
112 virtual potVec getPairwisePotential() { return pairwisePot; }
113 virtual potVec getExcludedPotential() { return excludedPot; }
114 virtual potVec getSelectedPotential() { return selectedPot; }
115 virtual potVec getExcludedSelfPotential() { return excludedSelfPot; }
116 virtual potVec getSelectedSelfPotential() { return selectedSelfPot; }
117
118 // neighbor list routines
119 virtual bool checkNeighborList(vector<Vector3d> savedPositions);
120 virtual void buildNeighborList(vector<int>& neighborList,
121 vector<int>& point,
122 vector<Vector3d>& savedPositions) = 0;
123
124 void setCutoffRadius(RealType rCut);
125
126 // group bookkeeping
127 virtual Vector3d& getGroupVelocityColumn(int atom2) = 0;
128
129 // Group->atom bookkeeping
130 virtual vector<int>& getAtomsInGroupRow(int cg1) = 0;
131 virtual vector<int>& getAtomsInGroupColumn(int cg2) = 0;
132
133 virtual Vector3d getAtomToGroupVectorRow(int atom1, int cg1) = 0;
134 virtual Vector3d getAtomToGroupVectorColumn(int atom2, int cg2) = 0;
135 virtual RealType& getMassFactorRow(int atom1) = 0;
136 virtual RealType& getMassFactorColumn(int atom2) = 0;
137
138 // spatial data
139 virtual Vector3d getIntergroupVector(int cg1, int cg2) = 0;
140 virtual Vector3d getInteratomicVector(int atom1, int atom2) = 0;
141
142 // atom bookkeeping
143 virtual int& getNAtomsInRow() = 0;
144 virtual vector<int>& getExcludesForAtom(int atom1) = 0;
145 virtual bool skipAtomPair(int atom1, int atom2, int cg1, int cg2) = 0;
146 virtual bool excludeAtomPair(int atom1, int atom2) = 0;
147 virtual int getGlobalIDRow(int atom1) = 0;
148 virtual int getGlobalIDCol(int atom2) = 0;
149 virtual int getGlobalID(int atom1) = 0;
150
151 virtual int getTopologicalDistance(int atom1, int atom2) = 0;
152 virtual void addForceToAtomRow(int atom1, Vector3d fg) = 0;
153 virtual void addForceToAtomColumn(int atom2, Vector3d fg) = 0;
154 virtual Vector3d& getAtomVelocityColumn(int atom2) = 0;
155
156 // filling & unpacking interaction data from Snapshot or Row/Col data
157 virtual void fillInteractionData(InteractionData& idat, int atom1,
158 int atom2, bool newAtom1 = true) = 0;
159 virtual void unpackPrePairData(InteractionData& idat, int atom1,
160 int atom2) = 0;
161 virtual void unpackInteractionData(InteractionData& idat, int atom1,
162 int atom2) = 0;
163
164 // filling & unpacking self data from Snapshot data
165 virtual void fillSelfData(SelfData& sdat, int atom);
166 virtual void unpackSelfData(SelfData& sdat, int atom);
167
168 virtual void fillPreForceData(SelfData& sdat, int atom);
169 virtual void unpackPreForceData(SelfData& sdat, int atom);
170
171 virtual void addToHeatFlux(Vector3d hf);
172 virtual void setHeatFlux(Vector3d hf);
173
174 protected:
175 SimInfo* info_ {nullptr};
176 SnapshotManager* sman_;
177 Snapshot* snap_;
178 ForceField* ff_;
179 InteractionManager* interactionMan_;
180
181 int atomStorageLayout_;
182 int rigidBodyStorageLayout_;
183 int cutoffGroupStorageLayout_;
184 bool needVelocities_;
185 bool usePeriodicBoundaryConditions_;
186 RealType skinThickness_; /**< Verlet neighbor list skin thickness */
187 RealType rCut_;
188 RealType rList_;
189 RealType rListSq_;
190
191 vector<int> idents;
192 vector<int> regions;
193 potVec pairwisePot;
194 potVec selfPot;
195 potVec excludedPot;
196 potVec excludedSelfPot;
197 potVec selectedPot;
198 potVec selectedSelfPot;
199
200 /**
201 * The topological distance between two atomic sites is handled
202 * via two vector structures for speed. These structures agnostic
203 * regarding the parallel decomposition. The index for
204 * toposForAtom could be local or row, while the values could be
205 * local or column. It will be up to the specific decomposition
206 * method to fill these.
207 */
208 vector<vector<int>> toposForAtom;
209 vector<vector<int>> topoDist;
210 vector<vector<int>> excludesForAtom;
211 vector<vector<int>> groupList_;
212 vector<RealType> massFactors;
213 vector<AtomType*> atypesLocal;
214
215 vector<Vector3i> cellOffsets_;
216 Vector3i nCells_;
217 vector<vector<int>> cellList_;
218 };
219} // namespace OpenMD
220
221#endif
RealType skinThickness_
Verlet neighbor list skin thickness.
vector< vector< int > > toposForAtom
The topological distance between two atomic sites is handled via two vector structures for speed.
InteractionManager is responsible for keeping track of the non-bonded interactions (C++).
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
The Snapshot class is a repository storing dynamic data during a Simulation.
Definition Snapshot.hpp:166
SnapshotManager class is an abstract class which maintains a series of snapshots.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
The InteractionData struct.
The SelfData struct.