NAMD
GlobalMaster.h
Go to the documentation of this file.
1 
7 /* A ComputeGlobalMaster represents a bit of computation that needs to
8  be done on atoms or groups of atoms on several nodes. It is given
9  the positions of atoms and groups, and provides a list of requested
10  atoms, forces, and groups in return.
11 
12  I'm not going to do groups for now, because they were done badly
13  originally. A better solution is necessary. Hint: multiple
14  groups are required.
15 
16  The expected usage (by ComputeGlobalMasterServer) is:
17  1) receive and store the data message from all nodes
18  2) call processData with that data
19  3) collect new forces and atoms
20  4) send them as a message to all the nodes
21  Repeat until done.
22 */
23 
24 #ifndef GLOBALMASTER_H
25 #define GLOBALMASTER_H
26 
27 #include "NamdTypes.h"
28 class Lattice;
29 
30 class GlobalMaster {
31  public:
32 
33  /* This passes the atom and group data to the master, which then
34  performs any necessary calculations and updates its results. */
42  ForceList::iterator gtf_i,
43  ForceList::iterator gtf_e,
44  IntList::iterator goi_i,
45  IntList::iterator goi_e,
48  AtomIDList::iterator last_atoms_forced_i,
49  AtomIDList::iterator last_atoms_forced_e,
50  ForceList::iterator last_forces_i,
54 
55  int step; // set by server to current timestep before processData
56  int globalMasterStep; // set by server to current timestep / globalMasterFreq before processData
57  int old_num_groups_requested; // used for group forces
58 
59  bool changedAtoms(); // false if the atom IDs haven't changed
60  const AtomIDList &requestedAtoms(); // the atom ids requested
61  bool changedForces(); // false if the forces haven't changed
62  const AtomIDList &forcedAtoms(); // the atoms the forces are applied to
63  const ForceList &appliedForces(); // the corresponding applied forces
64  bool changedGroups(); // false if the groups haven't changed
65  const ResizeArray<AtomIDList> &requestedGroups(); // the requested groups
66  const ForceList &groupForces(); // the corresponding forces on groups
67  bool changedGridObjs(); // false if the groups haven't changed
68  const IntList &requestedGridObjs(); // the requested groups
69  const BigRealList &gridObjForces(); // the corresponding forces on groups
71 
72  /* sets changedAtoms and changedForces to false again */
73  void clearChanged();
74  virtual ~GlobalMaster() {}; // necessary for abstract classes '-P
75 
76  void check() const; // dies if there are problems with the rep invariants
77 
78  void setLattice(const Lattice *lat) { lattice = lat; }
79 
80  protected:
81  GlobalMaster();
82 
83  /* This will be called after the pointers to lists below have been
84  initialized correctly by processData. It should perform any
85  required caluation and update the atom/force lists. */
86  virtual void calculate();
87 
88  /* This function returns the list of requested atoms, but assumes
89  that you will change it. */
91 
92  /* These functions returns the list of requested forces, but assumes
93  that you will change it. The two lists must be kept at the same
94  length, since the forcedAtoms correspond directly to the
95  appliedForces. */
98 
99  /* This function lets you change the requested groups */
102 
103  /* Same here for grids */
106 
107  /* These return pointers to the lists of atom ids and positions, as
108  they were last passed to processData (see below) */
120 
121  /* these give you all the global forces being applied by masters */
122  /* again, here we only need one end iterator */
126 
127  /* These return the pointers to the lists of requested atom IDs
128  and total forces on these atoms */
132 
134  void requestTotalForce(bool yesno = true) { totalForceRequested = yesno; }
135 
136  /* This helpful function returns an array with the masses of each of
137  the groups whose positions we have. */
140 
141  protected:
142  const Lattice *lattice; // points to lattice in server
143 
144  /* These store the pointers to lists of atom ids and atom positions.
145  The list of atom positions has the same length as the list of
146  ids, so only three iterators are necessary. There are also
147  pointers to the beginning and end of the group position list
148  here. */
162 
163  /* these store all the global forces being applied by masters */
167 
168  /* These store all the total forces returned from the simulation */
172 
173  /* These store the requested atoms and forces, and the booleans
174  indicate whether they (may) have changed. */
176  AtomIDList reqAtoms; // atoms whose positions are requested
177 
179  AtomIDList fAtoms; // atoms that are being forced
180  ForceList appForces; // the corresponding forces
181 
183  ResizeArray<AtomIDList> reqGroups; // list of requested groups of atoms
184  ForceList grpForces; // the corresponding forces
185 
187  IntList reqGridObjs; // list of requested grids
188  BigRealList gridobjForces; // the corresponding forces
189 
190 };
191 
192 #endif
ForceList grpForces
Definition: GlobalMaster.h:184
ForceList & modifyAppliedForces()
Definition: GlobalMaster.C:163
int old_num_groups_requested
Definition: GlobalMaster.h:57
AtomIDList & modifyRequestedAtoms()
Definition: GlobalMaster.C:128
const ForceList & groupForces()
Definition: GlobalMaster.C:142
BigRealList & modifyGridObjForces()
Definition: GlobalMaster.C:180
Elem * iterator
Definition: ResizeArray.h:35
bool totalForceRequested
Definition: GlobalMaster.h:133
BigRealList::iterator gridObjValueEnd
Definition: GlobalMaster.h:161
IntList::iterator gridObjIndexBegin
Definition: GlobalMaster.h:158
AtomIDList::const_iterator getForceIdEnd()
Definition: GlobalMaster.C:261
AtomIDList::const_iterator getAtomIdBegin()
Definition: GlobalMaster.C:191
PositionList::const_iterator getGroupPositionEnd()
Definition: GlobalMaster.C:207
AtomIDList reqAtoms
Definition: GlobalMaster.h:176
ResizeArray< AtomIDList > reqGroups
Definition: GlobalMaster.h:183
bool changedAtoms()
Definition: GlobalMaster.C:108
ForceList::const_iterator getGroupTotalForceBegin()
Definition: GlobalMaster.C:211
bool requestedTotalForces()
Definition: GlobalMaster.h:70
ForceList::iterator totalForceBegin
Definition: GlobalMaster.h:171
AtomIDList::iterator lastAtomsForcedEnd
Definition: GlobalMaster.h:166
ForceList::iterator lastForcesBegin
Definition: GlobalMaster.h:165
PositionList::const_iterator getAtomPositionBegin()
Definition: GlobalMaster.C:199
ForceList appForces
Definition: GlobalMaster.h:180
bool reqGroupsChanged
Definition: GlobalMaster.h:182
AtomIDList::iterator lastAtomsForcedBegin
Definition: GlobalMaster.h:164
BigRealList::const_iterator getGroupMassEnd()
Definition: GlobalMaster.C:240
bool reqGridObjsChanged
Definition: GlobalMaster.h:186
const ResizeArray< AtomIDList > & requestedGroups()
Definition: GlobalMaster.C:150
BigRealList gridobjForces
Definition: GlobalMaster.h:188
void processData(AtomIDList::iterator a_i, AtomIDList::iterator a_e, PositionList::iterator p_i, PositionList::iterator g_i, PositionList::iterator g_e, BigRealList::iterator gm_i, BigRealList::iterator gm_e, ForceList::iterator gtf_i, ForceList::iterator gtf_e, IntList::iterator goi_i, IntList::iterator goi_e, BigRealList::iterator gov_i, BigRealList::iterator gov_e, AtomIDList::iterator last_atoms_forced_i, AtomIDList::iterator last_atoms_forced_e, ForceList::iterator last_forces_i, AtomIDList::iterator, AtomIDList::iterator, ForceList::iterator)
Definition: GlobalMaster.C:17
AtomIDList::const_iterator getForceIdBegin()
Definition: GlobalMaster.C:256
virtual void calculate()
Definition: GlobalMaster.C:81
const ForceList & appliedForces()
Definition: GlobalMaster.C:138
void setLattice(const Lattice *lat)
Definition: GlobalMaster.h:78
PositionList::iterator atomPositionBegin
Definition: GlobalMaster.h:151
ForceList::iterator groupTotalForceEnd
Definition: GlobalMaster.h:157
IntList::const_iterator getGridObjIndexBegin()
Definition: GlobalMaster.C:219
bool changedForces()
Definition: GlobalMaster.C:112
bool changedGridObjs()
Definition: GlobalMaster.C:120
const Elem * const_iterator
Definition: ResizeArray.h:38
BigRealList::iterator gridObjValueBegin
Definition: GlobalMaster.h:160
ForceList::const_iterator getLastForcesBegin()
Definition: GlobalMaster.C:252
bool reqAtomsChanged
Definition: GlobalMaster.h:175
AtomIDList::iterator atomIdEnd
Definition: GlobalMaster.h:150
IntList & modifyRequestedGridObjects()
Definition: GlobalMaster.C:174
BigRealList::iterator groupMassBegin
Definition: GlobalMaster.h:154
bool changedGroups()
Definition: GlobalMaster.C:116
AtomIDList & modifyForcedAtoms()
Definition: GlobalMaster.C:158
IntList reqGridObjs
Definition: GlobalMaster.h:187
ResizeArray< AtomIDList > & modifyRequestedGroups()
Definition: GlobalMaster.C:185
IntList::iterator gridObjIndexEnd
Definition: GlobalMaster.h:159
BigRealList::const_iterator getGroupMassBegin()
Definition: GlobalMaster.C:235
ForceList & modifyGroupForces()
Definition: GlobalMaster.C:168
AtomIDList::iterator atomIdBegin
Definition: GlobalMaster.h:149
BigRealList::const_iterator getGridObjValueBegin()
Definition: GlobalMaster.C:227
BigRealList::iterator groupMassEnd
Definition: GlobalMaster.h:155
IntList::const_iterator getGridObjIndexEnd()
Definition: GlobalMaster.C:223
virtual ~GlobalMaster()
Definition: GlobalMaster.h:74
const Lattice * lattice
Definition: GlobalMaster.h:142
PositionList::iterator groupPositionBegin
Definition: GlobalMaster.h:152
bool appForcesChanged
Definition: GlobalMaster.h:178
void requestTotalForce(bool yesno=true)
Definition: GlobalMaster.h:134
int globalMasterStep
Definition: GlobalMaster.h:56
AtomIDList::const_iterator getAtomIdEnd()
Definition: GlobalMaster.C:195
AtomIDList::iterator forceIdBegin
Definition: GlobalMaster.h:169
const BigRealList & gridObjForces()
Definition: GlobalMaster.C:146
AtomIDList::const_iterator getLastAtomsForcedBegin()
Definition: GlobalMaster.C:244
void clearChanged()
Definition: GlobalMaster.C:74
AtomIDList fAtoms
Definition: GlobalMaster.h:179
const IntList & requestedGridObjs()
Definition: GlobalMaster.C:154
AtomIDList::iterator forceIdEnd
Definition: GlobalMaster.h:170
AtomIDList::const_iterator getLastAtomsForcedEnd()
Definition: GlobalMaster.C:248
const AtomIDList & forcedAtoms()
Definition: GlobalMaster.C:134
void check() const
Definition: GlobalMaster.C:64
PositionList::const_iterator getGroupPositionBegin()
Definition: GlobalMaster.C:203
ForceList::const_iterator getTotalForce()
Definition: GlobalMaster.C:266
ForceList::iterator groupTotalForceBegin
Definition: GlobalMaster.h:156
PositionList::iterator groupPositionEnd
Definition: GlobalMaster.h:153
BigRealList::const_iterator getGridObjValueEnd()
Definition: GlobalMaster.C:231
ForceList::const_iterator getGroupTotalForceEnd()
Definition: GlobalMaster.C:215
const AtomIDList & requestedAtoms()
Definition: GlobalMaster.C:124