GlobalMaster.h

Go to the documentation of this file.
00001 
00007 /* A ComputeGlobalMaster represents a bit of computation that needs to
00008    be done on atoms or groups of atoms on several nodes.  It is given
00009    the positions of atoms and groups, and provides a list of requested
00010    atoms, forces, and groups in return.
00011    
00012    I'm not going to do groups for now, because they were done badly
00013    originally.  A better solution is necessary.  Hint: multiple
00014    groups are required.
00015 
00016    The expected usage (by ComputeGlobalMasterServer) is:
00017    1) receive and store the data message from all nodes
00018    2) call processData with that data
00019    3) collect new forces and atoms
00020    4) send them as a message to all the nodes
00021    Repeat until done.
00022 */
00023 
00024 #ifndef GLOBALMASTER_H
00025 #define GLOBALMASTER_H
00026 
00027 #include "NamdTypes.h"
00028 class Lattice;
00029 
00030 class GlobalMaster {
00031  public:
00032 
00033   /* This passes the atom and group data to the master, which then
00034      performs any necessary calculations and updates its results. */
00035   void processData(AtomIDList::iterator a_i,
00036                    AtomIDList::iterator a_e,
00037                    PositionList::iterator p_i,
00038                    PositionList::iterator g_i,
00039                    PositionList::iterator g_e,
00040                    BigRealList::iterator gm_i,
00041                    BigRealList::iterator gm_e,
00042                    ForceList::iterator gtf_i,
00043                    ForceList::iterator gtf_e,
00044                    AtomIDList::iterator last_atoms_forced_i,
00045                    AtomIDList::iterator last_atoms_forced_e,
00046                    ForceList::iterator last_forces_i,
00047                    AtomIDList::iterator,
00048                    AtomIDList::iterator,
00049                    ForceList::iterator);
00050 
00051   int step;  // set by server to current timestep before processData
00052   int old_num_groups_requested;  // used for group forces
00053 
00054   bool changedAtoms(); // false if the atom IDs haven't changed
00055   const AtomIDList &requestedAtoms(); // the atom ids requested
00056   bool changedForces(); // false if the forces haven't changed
00057   const AtomIDList &forcedAtoms(); // the atoms the forces are applied to
00058   const ForceList &appliedForces(); // the corresponding applied forces
00059   bool changedGroups(); // false if the groups haven't changed
00060   const ResizeArray<AtomIDList> &requestedGroups(); // the requested groups
00061   const ForceList &groupForces(); // the corresponding forces on groups
00062   bool requestedTotalForces() { return totalForceRequested; }
00063 
00064   /* sets changedAtoms and changedForces to false again */
00065   void clearChanged(); 
00066   virtual ~GlobalMaster() {}; // necessary for abstract classes '-P
00067 
00068   void check() const; // dies if there are problems with the rep invariants
00069 
00070   void setLattice(const Lattice *lat) { lattice = lat; }
00071   
00072  protected:
00073   GlobalMaster();
00074 
00075   /* This will be called after the pointers to lists below have been
00076      initialized correctly by processData.  It should perform any
00077      required caluation and update the atom/force lists. */
00078   virtual void calculate();
00079 
00080   /* This function returns the list of requested atoms, but assumes
00081      that you will change it. */
00082   AtomIDList &modifyRequestedAtoms();
00083 
00084   /* These functions returns the list of requested forces, but assumes
00085      that you will change it.  The two lists must be kept at the same
00086      length, since the forcedAtoms correspond directly to the
00087      appliedForces. */
00088   AtomIDList &modifyForcedAtoms();
00089   ForceList &modifyAppliedForces();
00090 
00091   /* This function lets you change the requested groups */
00092   ResizeArray<AtomIDList> &modifyRequestedGroups();
00093   ForceList &modifyGroupForces();
00094 
00095   /* These return pointers to the lists of atom ids and positions, as
00096      they were last passed to processData (see below) */
00097   AtomIDList::const_iterator getAtomIdBegin();
00098   AtomIDList::const_iterator getAtomIdEnd();
00099   PositionList::const_iterator getAtomPositionBegin();
00100   PositionList::const_iterator getGroupPositionBegin();
00101   PositionList::const_iterator getGroupPositionEnd();
00102   ForceList::const_iterator getGroupTotalForceBegin();
00103   ForceList::const_iterator getGroupTotalForceEnd();
00104   
00105   /* these give you all the global forces being applied by masters */
00106   /* again, here we only need one end iterator */
00107   AtomIDList::const_iterator getLastAtomsForcedBegin();
00108   AtomIDList::const_iterator getLastAtomsForcedEnd();
00109   ForceList::const_iterator getLastForcesBegin();
00110   
00111   /* These return the pointers to the lists of requested atom IDs
00112      and total forces on these atoms */
00113   AtomIDList::const_iterator getForceIdBegin();
00114   AtomIDList::const_iterator getForceIdEnd();
00115   ForceList::const_iterator getTotalForce();
00116 
00117   bool totalForceRequested;
00118   void requestTotalForce(bool yesno = true) { totalForceRequested = yesno; }
00119   
00120   /* This helpful function returns an array with the masses of each of
00121      the groups whose positions we have.  */
00122   BigRealList::const_iterator getGroupMassBegin();
00123   BigRealList::const_iterator getGroupMassEnd();
00124 
00125  protected:
00126   const Lattice *lattice;  // points to lattice in server
00127 
00128   /* These store the pointers to lists of atom ids and atom positions.
00129      The list of atom positions has the same length as the list of
00130      ids, so only three iterators are necessary.   There are also
00131      pointers to the beginning and end of the group position list
00132      here. */
00133   AtomIDList::iterator atomIdBegin;
00134   AtomIDList::iterator atomIdEnd;
00135   PositionList::iterator atomPositionBegin;
00136   PositionList::iterator groupPositionBegin;
00137   PositionList::iterator groupPositionEnd;
00138   BigRealList::iterator groupMassBegin;
00139   BigRealList::iterator groupMassEnd;
00140   ForceList::iterator groupTotalForceBegin;
00141   ForceList::iterator groupTotalForceEnd;
00142 
00143   /* these store all the global forces being applied by masters */
00144   AtomIDList::iterator lastAtomsForcedBegin;
00145   ForceList::iterator lastForcesBegin;
00146   AtomIDList::iterator lastAtomsForcedEnd;
00147   
00148   /* These store all the total forces returned from the simulation */
00149   AtomIDList::iterator forceIdBegin;
00150   AtomIDList::iterator forceIdEnd;
00151   ForceList::iterator totalForceBegin;
00152 
00153   /* These store the requested atoms and forces, and the booleans
00154      indicate whether they (may) have changed. */
00155   bool reqAtomsChanged;
00156   AtomIDList reqAtoms; // atoms whose positions are requested
00157 
00158   bool appForcesChanged;
00159   AtomIDList fAtoms; // atoms that are being forced
00160   ForceList appForces; // the corresponding forces
00161 
00162   bool reqGroupsChanged;
00163   ResizeArray<AtomIDList> reqGroups; // list of requested groups of atoms 
00164   ForceList grpForces; // the corresponding forces
00165 };
00166 
00167 #endif

Generated on Mon Nov 20 01:17:12 2017 for NAMD by  doxygen 1.4.7