ComputeNonbondedUtil.h

Go to the documentation of this file.
00001 
00007 /*
00008    Common operations for ComputeNonbonded classes
00009 */
00010 
00011 #ifndef COMPUTENONBONDEDUTIL_H
00012 #define COMPUTENONBONDEDUTIL_H
00013 
00014 #include "NamdTypes.h"
00015 #include "ReductionMgr.h"
00016 #include "Molecule.h"
00017 
00018 class LJTable;
00019 class Molecule;
00020 class Random;
00021 
00022 #ifdef NAMD_CUDA
00023 void register_cuda_compute_self(ComputeID c, PatchID pid);
00024 void register_cuda_compute_pair(ComputeID c, PatchID pid[], int t[]);
00025 void unregister_cuda_compute(ComputeID c);
00026 #endif
00027 #ifdef NAMD_MIC
00028 void register_mic_compute_self(ComputeID c, PatchID pid, int part, int numParts);
00029 void register_mic_compute_pair(ComputeID c, PatchID pid[], int t[], int part, int numParts);
00030 void unregister_mic_compute(ComputeID c);
00031 #endif
00032 
00033 typedef unsigned short plint;
00034 
00035 class Pairlists {
00036   enum {initsize = 10};
00037   plint *data;
00038   int curpos;
00039   int size;
00040   Pairlists(const Pairlists&) { ; }
00041   Pairlists& operator=(const Pairlists&) { return *this; }
00042 public:
00043   Pairlists() : size(initsize) { data = new plint[initsize]; }
00044   ~Pairlists() { delete [] data; }
00045   plint *newlist(int max_size) {  // get a new list w/ room for max_size
00046     int reqnewsize = curpos + max_size + 1;
00047     int newsize = size;
00048     while ( newsize < reqnewsize ) { newsize += newsize >> 1; }
00049     if ( newsize > size ) {
00050       plint *newdata = new plint[newsize];
00051       CmiMemcpy(newdata,data,curpos*sizeof(plint));
00052       delete [] data;
00053       data = newdata;
00054       size = newsize;
00055     }
00056     return &data[curpos+1];
00057   }
00058 
00059   // don't specify size if previous allocation should have extra space
00060   plint *newlist() {  // get a new list assuming already allocated
00061     return &data[curpos+1];
00062   }
00063 
00064   void newsize(int list_size) {  // set the size of the last list gotten
00065     data[curpos] = list_size;
00066     curpos += list_size + 1;
00067   }
00068   void reset() { curpos = 0; }  // go back to the beginning
00069   void nextlist(plint **list, int *list_size) {  // get next list and size
00070     *list = &data[curpos+1];
00071     curpos += ( *list_size = data[curpos] ) + 1;
00072   }
00073   int getSize() { return size; }
00074 
00075   void addIndex() {  // assume space for index already allocated
00076     curpos++;
00077   }
00078   void setIndexValue(plint i) {  // assume no newsize since addIndex
00079     data[curpos-1] = i;
00080   }
00081 
00082   plint getIndexValue() {
00083     return data[curpos++];
00084   }
00085 
00086 };
00087 
00088 #define NBWORKARRAYSINIT(ARRAYS) \
00089   ComputeNonbondedWorkArrays* const computeNonbondedWorkArrays = ARRAYS;
00090 
00091 #ifdef __INTEL_COMPILER
00092 #define NBWORKARRAY(TYPE,NAME,SIZE) \
00093   computeNonbondedWorkArrays->NAME.resize(SIZE); \
00094   TYPE * const NAME = computeNonbondedWorkArrays->NAME.begin(); \
00095   __assume_aligned(NAME,64);
00096 #else
00097 #define NBWORKARRAY(TYPE,NAME,SIZE) \
00098   computeNonbondedWorkArrays->NAME.resize(SIZE); \
00099   TYPE * const NAME = computeNonbondedWorkArrays->NAME.begin();
00100 #endif
00101 
00102 class ComputeNonbondedWorkArrays {
00103 public:
00104   ResizeArray<int> pairlisti;
00105   ResizeArray<BigReal> r2list;
00106 #ifdef NAMD_KNL
00107   ResizeArray<float> r2list_f;
00108   ResizeArray<float> xlist;
00109   ResizeArray<float> ylist;
00110   ResizeArray<float> zlist;
00111 #endif
00112 
00113   // DMK - Atom Sort
00114   // NOTE : TODO : For pair nonbonded compute objects, these arrays are needed
00115   //   for the atom sorting code.  However, grouplist and fixglist will not be
00116   //   used if these arrays are so they could overlap in memory.  TODO: Find a
00117   //   way to allow them to use the same memory.  For now, it's not much memory
00118   //   so just keep them separate because of the type differences.  I haven't
00119   //   looked through all the details yet, but could probably just use the
00120   //   larger type and cast the pointer type as needed for the other one to
00121   //   ensure there is enough memory in both cases.
00122   #if NAMD_ComputeNonbonded_SortAtoms != 0
00123     ResizeArray<SortEntry> atomSort_0_sortValues__;
00124     ResizeArray<SortEntry> atomSort_1_sortValues__;
00125     ResizeArray<BigReal> p_0_sortValues;
00126   #endif
00127 
00128   ResizeArray<int> grouplist;
00129   ResizeArray<int> fixglist;
00130   ResizeArray<int> goodglist;
00131   ResizeArray<plint> pairlistx;
00132   ResizeArray<plint> pairlistm;
00133 
00134   ResizeArray<plint> pairlistnAlch;
00135   ResizeArray<plint> pairlistnA0;
00136   ResizeArray<plint> pairlistnA1;
00137   ResizeArray<plint> pairlistxA1;
00138   ResizeArray<plint> pairlistmA1;
00139   ResizeArray<plint> pairlistnA2;
00140   ResizeArray<plint> pairlistxA2;
00141   ResizeArray<plint> pairlistmA2;
00142   
00143   ResizeArray<int> pairlist;
00144   ResizeArray<int> pairlist2;
00145   ResizeArray<Force> f_0;
00146   ResizeArray<Force> fullf_0;
00147 };
00148 
00149 //struct sent to CalcGBIS
00150 struct GBISParamStruct {
00151   int cid;
00152   int patchID[2];
00153   int sequence;
00154   int doSmoothing;
00155   int doGBIS;
00156   int numPatches;
00157   int gbisPhase;
00158   Real *intRad[2];
00159   GBReal *psiSum[2];
00160   Real *bornRad[2];
00161   GBReal *dEdaSum[2];
00162   Real *dHdrPrefix[2];
00163   BigReal epsilon_s;
00164   BigReal epsilon_p;
00165   BigReal rho_0;
00166   BigReal kappa;
00167   BigReal cutoff;
00168   BigReal a_cut;
00169   BigReal fsMax;
00170   BigReal delta;
00171   BigReal beta;
00172   BigReal gamma;
00173   BigReal alpha_max;
00174   BigReal gbSelfEnergy;
00175   BigReal gbInterEnergy;
00176   int doFullElectrostatics;
00177   int doEnergy;
00178   Pairlists *gbisStepPairlists[4];
00179   BigReal maxGroupRadius;
00180 };
00181 
00182 // function arguments
00183 struct nonbonded {
00184   CompAtom* p[2];
00185 #ifdef NAMD_KNL
00186   CompAtomFlt *pFlt[2];
00187 #endif
00188   CompAtomExt *pExt[2];
00189   // BEGIN LA
00190   CompAtom* v[2];
00191   // END LA
00192   Force* ff[2];
00193   // for full electrostatics
00194   Force* fullf [2];
00195 
00196   int numAtoms[2];
00197 
00198   Vector offset;
00199   Vector offset_f;
00200 
00201   // DMK - Atom Separation (water vs. non-water)
00202   #if NAMD_SeparateWaters != 0
00203     int numWaterAtoms[2];
00204   #endif
00205 
00206   BigReal *reduction;
00207   BigReal *pressureProfileReduction;
00208 
00209   Parameters *parameters;
00210   SimParameters *simParameters;
00211   Random *random;
00212 
00213   ComputeNonbondedWorkArrays *workArrays;
00214 
00215   Pairlists *pairlists;
00216   int savePairlists;
00217   int usePairlists;
00218   BigReal plcutoff;
00219   BigReal groupplcutoff;
00220 
00221   // BEGIN LA
00222   int doLoweAndersen;
00223   // END LA
00224   
00225   int minPart;
00226   int maxPart;
00227   int numParts;
00228   int step;
00229 
00230   #if NAMD_ComputeNonbonded_SortAtoms != 0
00231     Vector projLineVec;
00232   #endif
00233 };
00234 
00235 class ComputeNonbondedUtil {
00236 
00237 public:
00238 
00239   ComputeNonbondedUtil() {}
00240   ~ComputeNonbondedUtil() {}
00241   static void select(void);
00242 
00243   static void (*calcPair)(nonbonded *);
00244   static void (*calcPairEnergy)(nonbonded *);
00245   static void (*calcSelf)(nonbonded *);
00246   static void (*calcSelfEnergy)(nonbonded *);
00247 
00248   static void (*calcFullPair)(nonbonded *);
00249   static void (*calcFullPairEnergy)(nonbonded *);
00250   static void (*calcFullSelf)(nonbonded *);
00251   static void (*calcFullSelfEnergy)(nonbonded *);
00252 
00253   static void (*calcMergePair)(nonbonded *);
00254   static void (*calcMergePairEnergy)(nonbonded *);
00255   static void (*calcMergeSelf)(nonbonded *);
00256   static void (*calcMergeSelfEnergy)(nonbonded *);
00257 
00258   static void (*calcSlowPair)(nonbonded *);
00259   static void (*calcSlowPairEnergy)(nonbonded *);
00260   static void (*calcSlowSelf)(nonbonded *);
00261   static void (*calcSlowSelfEnergy)(nonbonded *);
00262 
00263   // Below modified by JLai -- Look at bottom 3rd line
00264   enum { exclChecksumIndex, pairlistWarningIndex,
00265          electEnergyIndex, fullElectEnergyIndex, vdwEnergyIndex,
00266          goNativeEnergyIndex, goNonnativeEnergyIndex, groLJEnergyIndex, groGaussEnergyIndex,
00267 //sd-db
00268          electEnergyIndex_s, fullElectEnergyIndex_s, vdwEnergyIndex_s, vdwEnergyIndex_s_Left,
00269          electEnergyIndex_ti_1, fullElectEnergyIndex_ti_1, vdwEnergyIndex_ti_1,
00270          electEnergyIndex_ti_2, fullElectEnergyIndex_ti_2, vdwEnergyIndex_ti_2,
00271 //sd-de
00272          TENSOR(virialIndex), TENSOR(fullElectVirialIndex),
00273          VECTOR(pairVDWForceIndex), VECTOR(pairElectForceIndex),
00274          reductionDataSize };
00275   static void submitReductionData(BigReal*,SubmitReduction*);
00276   static void submitPressureProfileData(BigReal*,SubmitReduction*);
00277 
00278   static Bool commOnly;
00279   static Bool fixedAtomsOn;
00280   static Bool qmForcesOn ;
00281   static BigReal cutoff;
00282   static BigReal cutoff2;
00283   static float cutoff2_f;
00284   static BigReal dielectric_1;
00285   static const LJTable* ljTable;
00286   static const Molecule* mol;
00287   static BigReal r2_delta, r2_delta_1;
00288   static int rowsize;
00289   static int columnsize;
00290   static int r2_delta_exp;
00291   static BigReal *table_alloc;
00292   static BigReal *table_ener;
00293   static BigReal *table_short;
00294   static BigReal *table_noshort;
00295   static BigReal *fast_table;
00296   static BigReal *scor_table;
00297   static BigReal *slow_table;
00298   static BigReal *corr_table;
00299   static BigReal *full_table;
00300   static BigReal *vdwa_table;
00301   static BigReal *vdwb_table;
00302   static BigReal *r2_table;
00303   static int table_length;
00304   #if defined(NAMD_MIC)
00305     static BigReal *mic_table_base_ptr; // DMK - NOTE : Duplicate but, use so that nothing breaks if the ordering of sub-arrays changes
00306     static int mic_table_n;
00307     static int mic_table_n_16;
00308   #endif
00309   #ifdef NAMD_KNL
00310   #define KNL_TABLE_SIZE (4080+2)
00311   static float *knl_table_alloc;
00312   static float *knl_fast_ener_table;
00313   static float *knl_fast_grad_table;
00314   static float *knl_scor_ener_table;
00315   static float *knl_scor_grad_table;
00316   static float *knl_slow_ener_table;
00317   static float *knl_slow_grad_table;
00318   static float *knl_corr_ener_table;
00319   static float *knl_corr_grad_table;
00320   static float *knl_full_ener_table;
00321   static float *knl_full_grad_table;
00322   #endif
00323   static BigReal scaling;
00324   static BigReal scale14;
00325   static BigReal switchOn;
00326   static BigReal switchOn_1;
00327   static BigReal switchOn2;
00328   static BigReal v_vdwa;
00329   static BigReal v_vdwb;
00330   static BigReal k_vdwa;
00331   static BigReal k_vdwb;
00332   static BigReal cutoff_3;
00333   static BigReal cutoff_6;
00334   static float   v_vdwa_f;
00335   static float   v_vdwb_f;
00336   static float   k_vdwa_f;
00337   static float   k_vdwb_f;
00338   static float   cutoff_3_f;
00339   static float   cutoff_6_f;
00340   static float   switchOn_f;
00341   static float   A6_f;
00342   static float   B6_f;
00343   static float   C6_f;
00344   static float   A12_f;
00345   static float   B12_f;
00346   static float   C12_f;
00347   static BigReal c0;
00348   static BigReal c1;
00349   static BigReal c3;
00350   static BigReal c5;
00351   static BigReal c6;
00352   static BigReal c7;
00353   static BigReal c8;
00354   // static BigReal d0;
00355 //sd-db
00356   static Bool alchFepOn;
00357   static Bool alchThermIntOn;
00358   static BigReal alchLambda2;
00359   static BigReal alchVdwShiftCoeff;
00360   static Bool vdwForceSwitching;
00361   static Bool LJcorrection;
00362   static Bool Fep_WCA_repuOn;
00363   static Bool Fep_WCA_dispOn;
00364   static Bool Fep_ElecOn;
00365   static Bool Fep_Wham;
00366   static BigReal WCA_rcut1;
00367   static BigReal WCA_rcut2; 
00368   static BigReal WCA_rcut3; 
00369   static Bool alchDecouple;
00370   static BigReal alchRepLambda;
00371   static BigReal alchDispLambda;
00372   static BigReal alchElecLambda;
00373 //sd-de
00374   static Bool lesOn;
00375   static int lesFactor;
00376   static BigReal lesScaling;
00377 
00378   static BigReal *lambda_table;
00379 
00380   static Bool pairInteractionOn;
00381   static Bool pairInteractionSelf;
00382 
00383   static Bool pressureProfileOn;
00384   static int pressureProfileSlabs;
00385   static int pressureProfileAtomTypes;
00386   static BigReal pressureProfileThickness;
00387   static BigReal pressureProfileMin;
00388 
00389   static Bool accelMDOn;
00390 
00391   static Bool drudeNbthole;
00392 
00393   // for particle mesh Ewald
00394   static BigReal ewaldcof;
00395   static BigReal pi_ewaldcof;
00396 
00397   // need macros for preprocessor
00398   #define VDW_SWITCH_MODE_ENERGY  0
00399   #define VDW_SWITCH_MODE_MARTINI 1
00400   #define VDW_SWITCH_MODE_FORCE   2
00401   static int vdw_switch_mode;
00402 
00403   // Ported by JLai -- JE - Go
00404   static Bool goGroPair;
00405   static Bool goForcesOn;
00406   static int goMethod; //6.3.11
00407   // End of port -- JL
00408 
00409   // for simplifying some common functions
00410   inline static BigReal square( const BigReal &x,
00411                                 const BigReal &y,
00412                                 const BigReal &z)
00413         {
00414         return(x*x+y*y+z*z);
00415         }
00416 
00417   static void calc_error(nonbonded *);
00418 
00419   static void calc_pair(nonbonded *);
00420   static void calc_pair_energy(nonbonded *);
00421   static void calc_pair_fullelect(nonbonded *);
00422   static void calc_pair_energy_fullelect(nonbonded *);
00423   static void calc_pair_merge_fullelect(nonbonded *);
00424   static void calc_pair_energy_merge_fullelect(nonbonded *);
00425   static void calc_pair_slow_fullelect(nonbonded *);
00426   static void calc_pair_energy_slow_fullelect(nonbonded *);
00427 
00428   static void calc_self(nonbonded *);
00429   static void calc_self_energy(nonbonded *);
00430   static void calc_self_fullelect(nonbonded *);
00431   static void calc_self_energy_fullelect(nonbonded *);
00432   static void calc_self_merge_fullelect(nonbonded *);
00433   static void calc_self_energy_merge_fullelect(nonbonded *);
00434   static void calc_self_slow_fullelect(nonbonded *);
00435   static void calc_self_energy_slow_fullelect(nonbonded *);
00436 
00437 //alchemical fep calcualtion
00438   static void calc_pair_energy_fep(nonbonded *);
00439   static void calc_pair_energy_fullelect_fep (nonbonded *);
00440   static void calc_pair_energy_merge_fullelect_fep (nonbonded *);
00441   static void calc_pair_energy_slow_fullelect_fep (nonbonded *);
00442   static void calc_self_energy_fep (nonbonded *);
00443   static void calc_self_energy_fullelect_fep (nonbonded *);
00444   static void calc_self_energy_merge_fullelect_fep (nonbonded *);
00445   static void calc_self_energy_slow_fullelect_fep (nonbonded *);
00446 
00447   static void calc_pair_energy_ti(nonbonded *);
00448   static void calc_pair_ti(nonbonded *);
00449   static void calc_pair_energy_fullelect_ti (nonbonded *);
00450   static void calc_pair_fullelect_ti (nonbonded *);
00451   static void calc_pair_energy_merge_fullelect_ti (nonbonded *);
00452   static void calc_pair_merge_fullelect_ti (nonbonded *);
00453   static void calc_pair_energy_slow_fullelect_ti (nonbonded *);
00454   static void calc_pair_slow_fullelect_ti (nonbonded *);
00455   static void calc_self_energy_ti (nonbonded *);
00456   static void calc_self_ti (nonbonded *);
00457   static void calc_self_energy_fullelect_ti (nonbonded *);
00458   static void calc_self_fullelect_ti (nonbonded *);
00459   static void calc_self_energy_merge_fullelect_ti (nonbonded *);
00460   static void calc_self_merge_fullelect_ti (nonbonded *);
00461   static void calc_self_energy_slow_fullelect_ti (nonbonded *);
00462   static void calc_self_slow_fullelect_ti (nonbonded *);
00463   
00464 //locally enhanced sampling calcualtion
00465   static void calc_pair_les(nonbonded *);
00466   static void calc_pair_energy_les(nonbonded *);
00467   static void calc_pair_fullelect_les (nonbonded *);
00468   static void calc_pair_energy_fullelect_les (nonbonded *);
00469   static void calc_pair_merge_fullelect_les (nonbonded *);
00470   static void calc_pair_energy_merge_fullelect_les (nonbonded *);
00471   static void calc_pair_slow_fullelect_les (nonbonded *);
00472   static void calc_pair_energy_slow_fullelect_les (nonbonded *);
00473   static void calc_self_les (nonbonded *);
00474   static void calc_self_energy_les (nonbonded *);
00475   static void calc_self_fullelect_les (nonbonded *);
00476   static void calc_self_energy_fullelect_les (nonbonded *);
00477   static void calc_self_merge_fullelect_les (nonbonded *);
00478   static void calc_self_energy_merge_fullelect_les (nonbonded *);
00479   static void calc_self_slow_fullelect_les (nonbonded *);
00480   static void calc_self_energy_slow_fullelect_les (nonbonded *);
00481 
00482 //pair interaction calcualtion
00483   static void calc_pair_energy_int(nonbonded *);
00484   static void calc_pair_energy_fullelect_int(nonbonded *);
00485   static void calc_pair_energy_merge_fullelect_int(nonbonded *);
00486   static void calc_self_energy_int (nonbonded *);
00487   static void calc_self_energy_fullelect_int(nonbonded *);
00488   static void calc_self_energy_merge_fullelect_int(nonbonded *);
00489 
00490 //pressure profile calcualtion
00491   static void calc_pair_pprof(nonbonded *);
00492   static void calc_pair_energy_pprof(nonbonded *);
00493   static void calc_pair_fullelect_pprof(nonbonded *);
00494   static void calc_pair_energy_fullelect_pprof(nonbonded *);
00495   static void calc_pair_merge_fullelect_pprof(nonbonded *);
00496   static void calc_pair_energy_merge_fullelect_pprof(nonbonded *);
00497   static void calc_pair_slow_fullelect_pprof(nonbonded *);
00498   static void calc_pair_energy_slow_fullelect_pprof(nonbonded *);
00499   static void calc_self_pprof(nonbonded *);
00500   static void calc_self_energy_pprof(nonbonded *);
00501   static void calc_self_fullelect_pprof (nonbonded *);
00502   static void calc_self_energy_fullelect_pprof (nonbonded *);
00503   static void calc_self_merge_fullelect_pprof (nonbonded *);
00504   static void calc_self_energy_merge_fullelect_pprof (nonbonded *);
00505   static void calc_self_slow_fullelect_pprof (nonbonded *);
00506   static void calc_self_energy_slow_fullelect_pprof (nonbonded *);
00507  
00508   //tabulated potential nonbonded calcs
00509   static void calc_pair_tabener(nonbonded *);
00510   static void calc_pair_energy_tabener(nonbonded *);
00511   static void calc_pair_fullelect_tabener(nonbonded *);
00512   static void calc_pair_energy_fullelect_tabener(nonbonded *);
00513   static void calc_pair_merge_fullelect_tabener(nonbonded *);
00514   static void calc_pair_energy_merge_fullelect_tabener(nonbonded *);
00515   static void calc_pair_slow_fullelect_tabener(nonbonded *);
00516   static void calc_pair_energy_slow_fullelect_tabener(nonbonded *);
00517   static void calc_self_tabener(nonbonded *);
00518   static void calc_self_energy_tabener(nonbonded *);
00519   static void calc_self_fullelect_tabener (nonbonded *);
00520   static void calc_self_energy_fullelect_tabener (nonbonded *);
00521   static void calc_self_merge_fullelect_tabener (nonbonded *);
00522   static void calc_self_energy_merge_fullelect_tabener (nonbonded *);
00523   static void calc_self_slow_fullelect_tabener (nonbonded *);
00524   static void calc_self_energy_slow_fullelect_tabener (nonbonded *);
00525 
00526   //Go forces nonbonded calcs
00527   static void calc_pair_go(nonbonded *);
00528   static void calc_pair_energy_go(nonbonded *);
00529   static void calc_pair_fullelect_go(nonbonded *);
00530   static void calc_pair_energy_fullelect_go(nonbonded *);
00531   static void calc_pair_merge_fullelect_go(nonbonded *);
00532   static void calc_pair_energy_merge_fullelect_go(nonbonded *);
00533   static void calc_pair_slow_fullelect_go(nonbonded *);
00534   static void calc_pair_energy_slow_fullelect_go(nonbonded *);
00535   static void calc_self_go(nonbonded *);
00536   static void calc_self_energy_go(nonbonded *);
00537   static void calc_self_fullelect_go(nonbonded *);
00538   static void calc_self_energy_fullelect_go(nonbonded *);
00539   static void calc_self_merge_fullelect_go(nonbonded *);
00540   static void calc_self_energy_merge_fullelect_go(nonbonded *);
00541   static void calc_self_slow_fullelect_go(nonbonded *);
00542   static void calc_self_energy_slow_fullelect_go(nonbonded *);
00543 
00544   void calcGBIS(nonbonded *params, GBISParamStruct *gbisParams);
00545 };
00546 
00547 #endif
00548 

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