HomePatch.h

Go to the documentation of this file.
00001 
00007 /*
00008    HomePatch is the key distributed source/sink of Atom data
00009    including positions, velocities and forces applied
00010 */
00011 
00012 #ifndef HOMEPATCH_H
00013 #define HOMEPATCH_H
00014 
00015 #include "charm++.h"
00016 
00017 #include "NamdTypes.h"
00018 #include "Patch.h"
00019 #include "PatchMap.h"
00020 
00021 #include "MigrateAtomsMsg.h"
00022 #include "main.h"
00023 #include "common.h"
00024 #include "Migration.h"
00025 #include "Settle.h"
00026 
00027 #include <string>
00028 #include <map>
00029 
00030 class RegisterProxyMsg;
00031 class UnregisterProxyMsg;
00032 class ProxyResultVarsizeMsg;
00033 class ProxyResultMsg;
00034 class ProxyCombinedResultRawMsg;
00035 class Sequencer;
00036 class SubmitReduction;
00037 class ProxyGBISP1ResultMsg;
00038 class ProxyGBISP2ResultMsg;
00039 class CheckpointAtomsMsg;
00040 class ExchangeAtomsMsg;
00041 
00042 class ProxyNodeAwareSpanningTreeMsg;
00043 
00044 class ComputeQMMgr;
00045 
00046 class HomePatch : public Patch {
00047   friend class PatchMgr;
00048   friend class Sequencer;
00049   friend class ComputeGlobal;
00050 
00051 private: 
00052 
00053   HomePatch(PatchID, int atomCnt);
00054   // for PatchMgr to use only
00055   HomePatch(PatchID, FullAtomList&);
00056 
00057 //  HomePatch(PatchID, int atomCnt);
00058 
00059   void reinitAtoms(FullAtomList&);
00060   ScaledPosition min, max, center;
00061   BigReal aAwayDist, bAwayDist, cAwayDist;
00062 
00063   Bool doAtomUpdate;  // atom changes other than migration
00064 
00065   //Note: If new proxies are added to this HomePatch
00066   // after load balancing, and it is not the immediate step
00067   // after atom migration (where ProxyAllMsg will be sent), 
00068   // then the CompAtomExt list has to be resent with the 
00069   // ProxyDataMsg (the normal proxy msg when atoms don't 
00070   // migrate), otherwise, program will crash without such 
00071   // information when doing force calculations --Chao Mei
00072   Bool isNewProxyAdded;
00073   int numGBISP1Arrived, numGBISP2Arrived, numGBISP3Arrived;
00074   bool phase1BoxClosedCalled;
00075   bool phase2BoxClosedCalled;
00076   bool phase3BoxClosedCalled;
00077 
00078 public:
00079   ~HomePatch();
00080 
00081   // Message from ProxyPatch (via ProxyMgr) which registers its existence
00082   void registerProxy(RegisterProxyMsg *);
00083   // opposite of above
00084   void unregisterProxy(UnregisterProxyMsg *);
00085 
00086   // ProxyPatch sends Forces back to here (via ProxyMgr)  
00087   void receiveResults(ProxyResultVarsizeMsg *msg);
00088   void receiveResults(ProxyResultMsg *msg);     
00089   //gbis receiving results from intermediate phases
00090   void receiveResult(ProxyGBISP1ResultMsg *msg);//after P1
00091   void receiveResult(ProxyGBISP2ResultMsg *msg);//after P2
00092   
00093   //direct function calls, not as entry methods
00094   void receiveResults(ProxyCombinedResultRawMsg *msg);
00095 
00096   // AtomMigration messages passes from neighbor HomePatches to here.
00097   void depositMigration(MigrateAtomsMsg *);
00098 
00099   // Bind a Sequencer to this HomePatch
00100   void useSequencer(Sequencer *sequencerPtr);
00101   // start simulation over this Patch of atoms
00102   void runSequencer(void);
00103   
00104   //--------------------------------------------------------------------
00105   // methods for Sequencer to use
00106   //
00107 
00108   // Signal HomePatch that positions stored are to be now to be used
00109   void positionsReady(int doMigration=0);
00110   int marginViolations;
00111 
00112   // methods to implement integration
00113   void saveForce(const int ftag = Results::normal);
00114   void addForceToMomentum(const BigReal, const int ftag = Results::normal,
00115                                 const int useSaved = 0);
00116   void addForceToMomentum3(const BigReal timestep1, const int ftag1, const int useSaved1,
00117     const BigReal timestep2, const int ftag2, const int useSaved2,
00118     const BigReal timestep3, const int ftag3, const int useSaved3);
00119   void addVelocityToPosition(const BigReal);
00120 
00121   // impose hard wall constraint on Drude bond length
00122   int hardWallDrude(const BigReal, Tensor *virial, SubmitReduction *);
00123 
00124   // methods for rigidBonds
00125   struct RattleList {
00126     int ig;
00127     int icnt;
00128   };
00129 
00130   std::vector<int> settleList;
00131   std::vector<RattleList> rattleList;
00132   std::vector<RattleParam> rattleParam;
00133   std::vector<int> noconstList;
00134 
00135   bool rattleListValid;
00136 
00137   // Array to store new positions and velocities. Allocated in "buildRattleList" to size numAtoms
00138   std::vector<Vector> velNew;
00139   std::vector<Vector> posNew;
00140 
00141   void addRattleForce(const BigReal invdt, Tensor& wc);
00142 
00143   void buildRattleList();
00144   int rattle1old(const BigReal, Tensor *virial, SubmitReduction *);
00145   int rattle1(const BigReal, Tensor *virial, SubmitReduction *);
00146   void rattle2(const BigReal, Tensor *virial);
00147   void minimize_rattle2(const BigReal, Tensor *virial, bool forces=false);
00148 
00149   // methods for mollified impluse (MOLLY)
00150   void mollyAverage();
00151   void mollyMollify(Tensor *virial);
00152 //  Bool average(Vector qtilde[],const Vector q[],BigReal lambda[],const int n,const int m, const BigReal imass[], const BigReal length2[], const int ial[], const int ilb[], const Vector qji[], const BigReal tolf, const int ntrial);
00153 //  void mollify(Vector qtilde[],const Vector q0[],const BigReal lambda[], Vector force[],const int n, const int m, const BigReal imass[],const int ial[],const int ibl[],const Vector refab[]); 
00154   
00155   // BEGIN LA
00156   void loweAndersenVelocities();
00157   void loweAndersenFinish();
00158   // END LA
00159 
00160   void setGBISIntrinsicRadii();
00161   void gbisComputeAfterP1();//calculate bornRad
00162   void gbisComputeAfterP2();//calculate dHdrPrefix or self energies
00163   void gbisP2Ready();
00164   void gbisP3Ready();
00165 
00166   //LCPO
00167   void setLcpoType();
00168 
00169   // methods for CONTRA, etc
00170   void checkpoint(void);
00171   void revert(void);
00172 
00173   void exchangeCheckpoint(int scriptTask, int &bpc);
00174   void recvCheckpointReq(int task, const char *key, int replica, int pe);
00175   void recvCheckpointLoad(CheckpointAtomsMsg *msg);
00176   void recvCheckpointStore(CheckpointAtomsMsg *msg);
00177   void recvCheckpointAck();
00178   int checkpoint_task;
00179   struct checkpoint_t {
00180     Lattice lattice;
00181     int berendsenPressure_count;
00182     int numAtoms;
00183     ResizeArray<FullAtom> atoms;
00184   };
00185   std::map<std::string,checkpoint_t*> checkpoints;
00186 
00187   // replica exchange
00188   void exchangeAtoms(int scriptTask);
00189   void recvExchangeReq(int req);
00190   void recvExchangeMsg(ExchangeAtomsMsg *msg);
00191   int exchange_dst;
00192   int exchange_src;
00193   int exchange_req;
00194   ExchangeAtomsMsg *exchange_msg;
00195 
00196   // methods for QM (ExtForces replacement)
00197   void replaceForces(ExtForce *f);
00198 
00199   void qmSwapAtoms();
00200   
00201   // load-balancing trigger
00202   void submitLoadStats(int timestep);
00203 
00204   // for ComputeHomePatches
00205   FullAtomList &getAtomList() { return (atom); }
00206 
00207 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00208   // build spanning tree for proxy nodes
00209   void buildNodeAwareSpanningTree(void);
00210   void setupChildrenFromProxySpanningTree();
00211 #else
00212     // build spanning tree for proxy nodes
00213   void buildSpanningTree(void);
00214 #endif
00215 
00216   void sendNodeAwareSpanningTree();
00217   void recvNodeAwareSpanningTree(ProxyNodeAwareSpanningTreeMsg *msg);
00218 
00219   void sendSpanningTree();
00220   void recvSpanningTree(int *t, int n);
00221 
00222 
00223   void sendProxies();
00224 
00225 #if USE_TOPOMAP 
00226   int findSubroots(int dim, int* subroots, int psize, int* pidscopy);
00227 #endif
00228 
00229   LDObjHandle ldObjHandle;
00230 protected:
00231   virtual void boxClosed(int);
00232 
00233   // Internal Atom Migration methods and data
00234   void doPairlistCheck();
00235   void doGroupSizeCheck();
00236   void doMarginCheck();
00237   void doAtomMigration();
00238   int inMigration;
00239   int numMlBuf;
00240   MigrateAtomsMsg *msgbuf[PatchMap::MaxOneAway];
00241   
00242 private:
00243   // Store of Atom-wise variables
00244   FullAtomList  atom;
00245   ForceList f_saved[Results::maxNumForces];
00246   ExtForce *replacementForces;
00247 
00248   CudaAtomList cudaAtomList;
00249 
00250   // DMK - Atom Separation (water vs. non-water)
00251   #if NAMD_SeparateWaters != 0
00252     FullAtomList tempAtom;  // A temporary array used to sort waters
00253                             //   from non-waters in the atom array
00254     void separateAtoms();   // Function to separate the atoms currently in atoms.
00255     void mergeAtomList(FullAtomList &al);  // Function to combine and separate
00256                                            //   the atoms in al with atoms.
00257   #endif
00258 
00259 
00260   // checkpointed state
00261   FullAtomList  checkpoint_atom;
00262   Lattice  checkpoint_lattice;
00263 
00264   // DMK - Atom Separation (water vs. non-water)
00265   #if NAMD_SeparateWaters != 0
00266     int checkpoint_numWaterAtoms;
00267   #endif
00268 
00269 
00270   // checkPairlist data
00271   CompAtomList doPairlistCheck_positions;
00272   Lattice doPairlistCheck_lattice;
00273   BigReal doPairlistCheck_newTolerance;
00274 
00275   // MOLLY data
00276   ResizeArray<BigReal> molly_lambda;
00277   
00278   // List of Proxies
00279   NodeIDList proxy;
00280   
00281   Sequencer  *sequencer;
00282 
00283   // Needed for initialization
00284   int patchMapRead;
00285   void readPatchMap();
00286 
00287   // Atom Migration internals
00288   int allMigrationIn;
00289   int migrationSuspended;
00290   int patchMigrationCounter;
00291   int numNeighbors;
00292   MigrationInfo realInfo[PatchMap::MaxOneAway];
00293   MigrationInfo *mInfo[3][3][3];
00294 
00295 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00296   //the whole spanning tree for all the proxies this home patch has
00297   proxyTreeNodeList ptnTree;
00298   //the immediate children (recording pe ids) containing two parts: 
00299   //one part of them all belong to the physical node this home patch
00300   // resides on; the other part of pes belong to all external nodes.
00301   /* Moved to Patch.h */ 
00302   //int *children;
00303   //int numChild;
00304 #else
00305   NodeIDList tree;              // the whole tree
00306   int *child;   // spanning tree of proxies - immediate children
00307   int nChild;
00308 #endif
00309 
00310   // Cached settle1 parameters
00311   int settle_initialized;
00312   BigReal settle_mOrmT; BigReal settle_mHrmT; BigReal settle_ra;
00313   BigReal settle_rb; BigReal settle_rc; BigReal settle_rra;
00314 
00315   // Drude lone pairs
00316   void redistrib_lonepair_forces(const int, Tensor *);
00317 
00318   // PLF -- for TIP4P
00319   //void redistrib_tip4p_force(Vector&, Vector&, Vector&, Vector&, int, Tensor*);
00320   void redistrib_tip4p_forces(const int, Tensor*);
00321   void tip4_omrepos(Vector*, Vector*, Vector*, BigReal);
00322   void init_tip4();
00323 
00324   // Drude SWM4
00325   void redistrib_swm4_forces(const int, Tensor*);
00326   void swm4_omrepos(Vector*, Vector*, Vector*, BigReal);
00327   void init_swm4();
00328 
00329   // reposition a lone pair using its host atoms and additional parameters
00330   void reposition_lonepair(
00331       Vector& ri, const Vector& rj, const Vector& rk, const Vector& rl,
00332       Real distance, Real angle, Real dihedral);
00333 
00334   void reposition_all_lonepairs(void);
00335 
00336   // general redistribution of lone pair forces to host atoms
00337   void redistrib_lp_force(
00338       Vector& fi, Vector& fj, Vector& fk, Vector& fl,
00339       const Vector& ri, const Vector& rj, const Vector& rk, const Vector& rl,
00340       Tensor *virial, int midpt);
00341 
00342   // use for both TIP4P and SWM4 water
00343   void redistrib_lp_water_force(
00344       Vector& f_ox, Vector& f_h1, Vector& f_h2, Vector& f_lp,
00345       const Vector& p_ox, const Vector& p_h1, const Vector& p_h2,
00346       const Vector& p_lp, Tensor *virial);
00347 
00348   BigReal r_om, r_ohc;
00349   void write_tip4_props(void);
00350 
00351   int isProxyChanged;
00352 
00353 #if CMK_PERSISTENT_COMM
00354   PersistentHandle *localphs;
00355   int nphs;
00356 #endif
00357 };
00358 
00359 #endif
00360 

Generated on Tue Sep 19 01:17:12 2017 for NAMD by  doxygen 1.4.7