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 old_num_groups_requested; // used for group forces
57 
58  bool changedAtoms(); // false if the atom IDs haven't changed
59  const AtomIDList &requestedAtoms(); // the atom ids requested
60  bool changedForces(); // false if the forces haven't changed
61  const AtomIDList &forcedAtoms(); // the atoms the forces are applied to
62  const ForceList &appliedForces(); // the corresponding applied forces
63  bool changedGroups(); // false if the groups haven't changed
64  const ResizeArray<AtomIDList> &requestedGroups(); // the requested groups
65  const ForceList &groupForces(); // the corresponding forces on groups
66  bool changedGridObjs(); // false if the groups haven't changed
67  const IntList &requestedGridObjs(); // the requested groups
68  const BigRealList &gridObjForces(); // the corresponding forces on groups
70 
71  /* sets changedAtoms and changedForces to false again */
72  void clearChanged();
73  virtual ~GlobalMaster() {}; // necessary for abstract classes '-P
74 
75  void check() const; // dies if there are problems with the rep invariants
76 
77  void setLattice(const Lattice *lat) { lattice = lat; }
78 
79  protected:
80  GlobalMaster();
81 
82  /* This will be called after the pointers to lists below have been
83  initialized correctly by processData. It should perform any
84  required caluation and update the atom/force lists. */
85  virtual void calculate();
86 
87  /* This function returns the list of requested atoms, but assumes
88  that you will change it. */
90 
91  /* These functions returns the list of requested forces, but assumes
92  that you will change it. The two lists must be kept at the same
93  length, since the forcedAtoms correspond directly to the
94  appliedForces. */
97 
98  /* This function lets you change the requested groups */
101 
102  /* Same here for grids */
105 
106  /* These return pointers to the lists of atom ids and positions, as
107  they were last passed to processData (see below) */
119 
120  /* these give you all the global forces being applied by masters */
121  /* again, here we only need one end iterator */
125 
126  /* These return the pointers to the lists of requested atom IDs
127  and total forces on these atoms */
131 
133  void requestTotalForce(bool yesno = true) { totalForceRequested = yesno; }
134 
135  /* This helpful function returns an array with the masses of each of
136  the groups whose positions we have. */
139 
140  protected:
141  const Lattice *lattice; // points to lattice in server
142 
143  /* These store the pointers to lists of atom ids and atom positions.
144  The list of atom positions has the same length as the list of
145  ids, so only three iterators are necessary. There are also
146  pointers to the beginning and end of the group position list
147  here. */
161 
162  /* these store all the global forces being applied by masters */
166 
167  /* These store all the total forces returned from the simulation */
171 
172  /* These store the requested atoms and forces, and the booleans
173  indicate whether they (may) have changed. */
175  AtomIDList reqAtoms; // atoms whose positions are requested
176 
178  AtomIDList fAtoms; // atoms that are being forced
179  ForceList appForces; // the corresponding forces
180 
182  ResizeArray<AtomIDList> reqGroups; // list of requested groups of atoms
183  ForceList grpForces; // the corresponding forces
184 
186  IntList reqGridObjs; // list of requested grids
187  BigRealList gridobjForces; // the corresponding forces
188 
189 };
190 
191 #endif
ForceList grpForces
Definition: GlobalMaster.h:183
ForceList & modifyAppliedForces()
Definition: GlobalMaster.C:162
int old_num_groups_requested
Definition: GlobalMaster.h:56
AtomIDList & modifyRequestedAtoms()
Definition: GlobalMaster.C:127
const ForceList & groupForces()
Definition: GlobalMaster.C:141
BigRealList & modifyGridObjForces()
Definition: GlobalMaster.C:179
const Elem * const_iterator
Definition: ResizeArray.h:38
bool totalForceRequested
Definition: GlobalMaster.h:132
BigRealList::iterator gridObjValueEnd
Definition: GlobalMaster.h:160
IntList::iterator gridObjIndexBegin
Definition: GlobalMaster.h:157
AtomIDList::const_iterator getForceIdEnd()
Definition: GlobalMaster.C:260
AtomIDList::const_iterator getAtomIdBegin()
Definition: GlobalMaster.C:190
PositionList::const_iterator getGroupPositionEnd()
Definition: GlobalMaster.C:206
AtomIDList reqAtoms
Definition: GlobalMaster.h:175
ResizeArray< AtomIDList > reqGroups
Definition: GlobalMaster.h:182
bool changedAtoms()
Definition: GlobalMaster.C:107
ForceList::const_iterator getGroupTotalForceBegin()
Definition: GlobalMaster.C:210
bool requestedTotalForces()
Definition: GlobalMaster.h:69
ForceList::iterator totalForceBegin
Definition: GlobalMaster.h:170
AtomIDList::iterator lastAtomsForcedEnd
Definition: GlobalMaster.h:165
ForceList::iterator lastForcesBegin
Definition: GlobalMaster.h:164
PositionList::const_iterator getAtomPositionBegin()
Definition: GlobalMaster.C:198
Elem * iterator
Definition: ResizeArray.h:35
ForceList appForces
Definition: GlobalMaster.h:179
bool reqGroupsChanged
Definition: GlobalMaster.h:181
AtomIDList::iterator lastAtomsForcedBegin
Definition: GlobalMaster.h:163
BigRealList::const_iterator getGroupMassEnd()
Definition: GlobalMaster.C:239
bool reqGridObjsChanged
Definition: GlobalMaster.h:185
const ResizeArray< AtomIDList > & requestedGroups()
Definition: GlobalMaster.C:149
BigRealList gridobjForces
Definition: GlobalMaster.h:187
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:16
AtomIDList::const_iterator getForceIdBegin()
Definition: GlobalMaster.C:255
virtual void calculate()
Definition: GlobalMaster.C:80
const ForceList & appliedForces()
Definition: GlobalMaster.C:137
void setLattice(const Lattice *lat)
Definition: GlobalMaster.h:77
PositionList::iterator atomPositionBegin
Definition: GlobalMaster.h:150
ForceList::iterator groupTotalForceEnd
Definition: GlobalMaster.h:156
IntList::const_iterator getGridObjIndexBegin()
Definition: GlobalMaster.C:218
bool changedForces()
Definition: GlobalMaster.C:111
bool changedGridObjs()
Definition: GlobalMaster.C:119
BigRealList::iterator gridObjValueBegin
Definition: GlobalMaster.h:159
ForceList::const_iterator getLastForcesBegin()
Definition: GlobalMaster.C:251
bool reqAtomsChanged
Definition: GlobalMaster.h:174
AtomIDList::iterator atomIdEnd
Definition: GlobalMaster.h:149
IntList & modifyRequestedGridObjects()
Definition: GlobalMaster.C:173
BigRealList::iterator groupMassBegin
Definition: GlobalMaster.h:153
bool changedGroups()
Definition: GlobalMaster.C:115
AtomIDList & modifyForcedAtoms()
Definition: GlobalMaster.C:157
IntList reqGridObjs
Definition: GlobalMaster.h:186
ResizeArray< AtomIDList > & modifyRequestedGroups()
Definition: GlobalMaster.C:184
IntList::iterator gridObjIndexEnd
Definition: GlobalMaster.h:158
BigRealList::const_iterator getGroupMassBegin()
Definition: GlobalMaster.C:234
ForceList & modifyGroupForces()
Definition: GlobalMaster.C:167
AtomIDList::iterator atomIdBegin
Definition: GlobalMaster.h:148
BigRealList::const_iterator getGridObjValueBegin()
Definition: GlobalMaster.C:226
BigRealList::iterator groupMassEnd
Definition: GlobalMaster.h:154
IntList::const_iterator getGridObjIndexEnd()
Definition: GlobalMaster.C:222
virtual ~GlobalMaster()
Definition: GlobalMaster.h:73
const Lattice * lattice
Definition: GlobalMaster.h:141
PositionList::iterator groupPositionBegin
Definition: GlobalMaster.h:151
bool appForcesChanged
Definition: GlobalMaster.h:177
void requestTotalForce(bool yesno=true)
Definition: GlobalMaster.h:133
AtomIDList::const_iterator getAtomIdEnd()
Definition: GlobalMaster.C:194
AtomIDList::iterator forceIdBegin
Definition: GlobalMaster.h:168
void check() const
Definition: GlobalMaster.C:63
const BigRealList & gridObjForces()
Definition: GlobalMaster.C:145
AtomIDList::const_iterator getLastAtomsForcedBegin()
Definition: GlobalMaster.C:243
void clearChanged()
Definition: GlobalMaster.C:73
AtomIDList fAtoms
Definition: GlobalMaster.h:178
const IntList & requestedGridObjs()
Definition: GlobalMaster.C:153
AtomIDList::iterator forceIdEnd
Definition: GlobalMaster.h:169
AtomIDList::const_iterator getLastAtomsForcedEnd()
Definition: GlobalMaster.C:247
const AtomIDList & forcedAtoms()
Definition: GlobalMaster.C:133
PositionList::const_iterator getGroupPositionBegin()
Definition: GlobalMaster.C:202
ForceList::const_iterator getTotalForce()
Definition: GlobalMaster.C:265
ForceList::iterator groupTotalForceBegin
Definition: GlobalMaster.h:155
PositionList::iterator groupPositionEnd
Definition: GlobalMaster.h:152
BigRealList::const_iterator getGridObjValueEnd()
Definition: GlobalMaster.C:230
ForceList::const_iterator getGroupTotalForceEnd()
Definition: GlobalMaster.C:214
const AtomIDList & requestedAtoms()
Definition: GlobalMaster.C:123