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

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

Generated on Fri May 25 04:07:14 2012 for NAMD by  doxygen 1.3.9.1