Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

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 
00026 class RegisterProxyMsg;
00027 class UnregisterProxyMsg;
00028 class ProxyResultVarsizeMsg;
00029 class ProxyResultMsg;
00030 class ProxyCombinedResultRawMsg;
00031 class Sequencer;
00032 class SubmitReduction;
00033 class ProxyGBISP1ResultMsg;
00034 class ProxyGBISP2ResultMsg;
00035 
00036 class ProxyNodeAwareSpanningTreeMsg;
00037 
00038 class HomePatch : public Patch {
00039   friend class PatchMgr;
00040   friend class Sequencer;
00041   friend class ComputeGlobal;
00042 
00043 private: 
00044 
00045   HomePatch(PatchID, int atomCnt);
00046   // for PatchMgr to use only
00047   HomePatch(PatchID, FullAtomList&);
00048 
00049 //  HomePatch(PatchID, int atomCnt);
00050 
00051   void reinitAtoms(FullAtomList&);
00052   ScaledPosition min, max, center;
00053   BigReal aAwayDist, bAwayDist, cAwayDist;
00054 
00055   //Note: If new proxies are added to this HomePatch
00056   // after load balancing, and it is not the immediate step
00057   // after atom migration (where ProxyAllMsg will be sent), 
00058   // then the CompAtomExt list has to be resent with the 
00059   // ProxyDataMsg (the normal proxy msg when atoms don't 
00060   // migrate), otherwise, program will crash without such 
00061   // information when doing force calculations --Chao Mei
00062   Bool isNewProxyAdded;
00063   int numGBISP1Arrived, numGBISP2Arrived, numGBISP3Arrived;
00064   bool phase1BoxClosedCalled;
00065   bool phase2BoxClosedCalled;
00066   bool phase3BoxClosedCalled;
00067 
00068 public:
00069   ~HomePatch();
00070 
00071   // Message from ProxyPatch (via ProxyMgr) which registers its existence
00072   void registerProxy(RegisterProxyMsg *);
00073   // opposite of above
00074   void unregisterProxy(UnregisterProxyMsg *);
00075 
00076   // ProxyPatch sends Forces back to here (via ProxyMgr)  
00077   void receiveResults(ProxyResultVarsizeMsg *msg);
00078   void receiveResults(ProxyResultMsg *msg);     
00079   //gbis receiving results from intermediate phases
00080   void receiveResult(ProxyGBISP1ResultMsg *msg);//after P1
00081   void receiveResult(ProxyGBISP2ResultMsg *msg);//after P2
00082   
00083   //direct function calls, not as entry methods
00084   void receiveResults(ProxyCombinedResultRawMsg *msg);
00085 
00086   // AtomMigration messages passes from neighbor HomePatches to here.
00087   void depositMigration(MigrateAtomsMsg *);
00088 
00089   // Bind a Sequencer to this HomePatch
00090   void useSequencer(Sequencer *sequencerPtr);
00091   // start simulation over this Patch of atoms
00092   void runSequencer(void);
00093   
00094   //--------------------------------------------------------------------
00095   // methods for Sequencer to use
00096   //
00097 
00098   // Signal HomePatch that positions stored are to be now to be used
00099   void positionsReady(int doMigration=0);
00100   int marginViolations;
00101 
00102   // methods to implement integration
00103   void saveForce(const int ftag = Results::normal);
00104   void addForceToMomentum(const BigReal, const int ftag = Results::normal,
00105                                 const int useSaved = 0);
00106   void addVelocityToPosition(const BigReal);
00107 
00108   // impose hard wall constraint on Drude bond length
00109   int hardWallDrude(const BigReal, Tensor *virial, SubmitReduction *);
00110 
00111   // methods for rigidBonds
00112   int rattle1(const BigReal, Tensor *virial, SubmitReduction *);
00113   void rattle2(const BigReal, Tensor *virial);
00114 
00115   // methods for mollified impluse (MOLLY)
00116   void mollyAverage();
00117   void mollyMollify(Tensor *virial);
00118 //  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);
00119 //  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[]); 
00120   
00121   // BEGIN LA
00122   void loweAndersenVelocities();
00123   void loweAndersenFinish();
00124   // END LA
00125 
00126   void setGBISIntrinsicRadii();
00127   void gbisComputeAfterP1();//calculate bornRad
00128   void gbisComputeAfterP2();//calculate dHdrPrefix or self energies
00129   void gbisP2Ready();
00130   void gbisP3Ready();
00131 
00132   //LCPO
00133   void setLcpoType();
00134 
00135   // methods for CONTRA, etc
00136   void checkpoint(void);
00137   void revert(void);
00138 
00139   // methods for QM (ExtForces replacement)
00140   void replaceForces(ExtForce *f);
00141 
00142   // load-balancing trigger
00143   void submitLoadStats(int timestep);
00144 
00145   // for ComputeHomePatches
00146   FullAtomList &getAtomList() { return (atom); }
00147 
00148 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00149   // build spanning tree for proxy nodes
00150   void buildNodeAwareSpanningTree(void);
00151   void setupChildrenFromProxySpanningTree();
00152 #else
00153     // build spanning tree for proxy nodes
00154   void buildSpanningTree(void);
00155 #endif
00156 
00157   void sendNodeAwareSpanningTree();
00158   void recvNodeAwareSpanningTree(ProxyNodeAwareSpanningTreeMsg *msg);
00159 
00160   void sendSpanningTree();
00161   void recvSpanningTree(int *t, int n);
00162 
00163 
00164   void sendProxies();
00165 
00166 #if USE_TOPOMAP 
00167   int findSubroots(int dim, int* subroots, int psize, int* pidscopy);
00168 #endif
00169 
00170   LDObjHandle ldObjHandle;
00171 protected:
00172   virtual void boxClosed(int);
00173 
00174   // Internal Atom Migration methods and data
00175   void doPairlistCheck();
00176   void doGroupSizeCheck();
00177   void doMarginCheck();
00178   void doAtomMigration();
00179   int inMigration;
00180   int numMlBuf;
00181   MigrateAtomsMsg *msgbuf[PatchMap::MaxOneAway];
00182   
00183 private:
00184   // Store of Atom-wise variables
00185   FullAtomList  atom;
00186   ForceList f_saved[Results::maxNumForces];
00187   ExtForce *replacementForces;
00188 
00189   CudaAtomList cudaAtomList;
00190 
00191   // DMK - Atom Separation (water vs. non-water)
00192   #if NAMD_SeparateWaters != 0
00193     FullAtomList tempAtom;  // A temporary array used to sort waters
00194                             //   from non-waters in the atom array
00195     void separateAtoms();   // Function to separate the atoms currently in atoms.
00196     void mergeAtomList(FullAtomList &al);  // Function to combine and separate
00197                                            //   the atoms in al with atoms.
00198   #endif
00199 
00200 
00201   // checkpointed state
00202   FullAtomList  checkpoint_atom;
00203   Lattice  checkpoint_lattice;
00204 
00205   // DMK - Atom Separation (water vs. non-water)
00206   #if NAMD_SeparateWaters != 0
00207     int checkpoint_numWaterAtoms;
00208   #endif
00209 
00210 
00211   // checkPairlist data
00212   CompAtomList doPairlistCheck_positions;
00213   Lattice doPairlistCheck_lattice;
00214   BigReal doPairlistCheck_newTolerance;
00215 
00216   // MOLLY data
00217   ResizeArray<BigReal> molly_lambda;
00218   
00219   // List of Proxies
00220   NodeIDList proxy;
00221   
00222   Sequencer  *sequencer;
00223 
00224   // Needed for initialization
00225   int patchMapRead;
00226   void readPatchMap();
00227 
00228   // Atom Migration internals
00229   int allMigrationIn;
00230   int migrationSuspended;
00231   int patchMigrationCounter;
00232   int numNeighbors;
00233   MigrationInfo realInfo[PatchMap::MaxOneAway];
00234   MigrationInfo *mInfo[3][3][3];
00235 
00236 #ifdef NODEAWARE_PROXY_SPANNINGTREE
00237   //the whole spanning tree for all the proxies this home patch has
00238   proxyTreeNodeList ptnTree;
00239   //the immediate children (recording pe ids) containing two parts: 
00240   //one part of them all belong to the physical node this home patch
00241   // resides on; the other part of pes belong to all external nodes.
00242   /* Moved to Patch.h */ 
00243   //int *children;
00244   //int numChild;
00245 #else
00246   NodeIDList tree;              // the whole tree
00247   int *child;   // spanning tree of proxies - immediate children
00248   int nChild;
00249 #endif
00250 
00251   // Cached settle1 parameters
00252   int settle_initialized;
00253   BigReal settle_mOrmT; BigReal settle_mHrmT; BigReal settle_ra;
00254   BigReal settle_rb; BigReal settle_rc; BigReal settle_rra;
00255 
00256   // Drude lone pairs
00257   void redistrib_lonepair_forces(const int, Tensor *);
00258 
00259   // PLF -- for TIP4P
00260   //void redistrib_tip4p_force(Vector&, Vector&, Vector&, Vector&, int, Tensor*);
00261   void redistrib_tip4p_forces(const int, Tensor*);
00262   void tip4_omrepos(Vector*, Vector*, Vector*, BigReal);
00263   void init_tip4();
00264 
00265   // Drude SWM4
00266   void redistrib_swm4_forces(const int, Tensor*);
00267   void swm4_omrepos(Vector*, Vector*, Vector*, BigReal);
00268   void init_swm4();
00269 
00270   // reposition a lone pair using its host atoms and additional parameters
00271   void reposition_lonepair(
00272       Vector& ri, const Vector& rj, const Vector& rk, const Vector& rl,
00273       Real distance, Real angle, Real dihedral);
00274 
00275   void reposition_all_lonepairs(void);
00276 
00277   // general redistribution of lone pair forces to host atoms
00278   void redistrib_lp_force(
00279       Vector& fi, Vector& fj, Vector& fk, Vector& fl,
00280       const Vector& ri, const Vector& rj, const Vector& rk, const Vector& rl,
00281       Tensor *virial, int midpt);
00282 
00283   // use for both TIP4P and SWM4 water
00284   void redistrib_lp_water_force(
00285       Vector& f_ox, Vector& f_h1, Vector& f_h2, Vector& f_lp,
00286       const Vector& p_ox, const Vector& p_h1, const Vector& p_h2,
00287       const Vector& p_lp, Tensor *virial);
00288 
00289   BigReal r_om, r_ohc;
00290   void write_tip4_props(void);
00291 
00292   int isProxyChanged;
00293 
00294 #if CMK_PERSISTENT_COMM
00295   PersistentHandle *localphs;
00296   int nphs;
00297 #endif
00298 };
00299 
00300 #endif
00301 

Generated on Thu May 23 04:07:16 2013 for NAMD by  doxygen 1.3.9.1