NAMD
ComputeNonbondedUtil.h
Go to the documentation of this file.
1 
7 /*
8  Common operations for ComputeNonbonded classes
9 */
10 
11 #ifndef COMPUTENONBONDEDUTIL_H
12 #define COMPUTENONBONDEDUTIL_H
13 
14 #include "NamdTypes.h"
15 #include "ReductionMgr.h"
16 #include "Molecule.h"
17 
18 class LJTable;
19 class Molecule;
20 class Random;
21 
22 #ifdef NAMD_MIC
23 void register_mic_compute_self(ComputeID c, PatchID pid, int part, int numParts);
24 void register_mic_compute_pair(ComputeID c, PatchID pid[], int t[], int part, int numParts);
25 void unregister_mic_compute(ComputeID c);
26 #endif
27 
28 typedef unsigned short plint;
29 
30 class Pairlists {
31  enum {initsize = 10};
32  plint *data;
33  int curpos;
34  int size;
35  Pairlists(const Pairlists&) { ; }
36  Pairlists& operator=(const Pairlists&) { return *this; }
37 public:
38  Pairlists() : size(initsize) { data = new plint[initsize]; }
39  ~Pairlists() { delete [] data; }
40  plint *newlist(int max_size) { // get a new list w/ room for max_size
41  int reqnewsize = curpos + max_size + 1;
42  int newsize = size;
43  while ( newsize < reqnewsize ) { newsize += newsize >> 1; }
44  if ( newsize > size ) {
45  plint *newdata = new plint[newsize];
46  CmiMemcpy(newdata,data,curpos*sizeof(plint));
47  delete [] data;
48  data = newdata;
49  size = newsize;
50  }
51  return &data[curpos+1];
52  }
53 
54  // don't specify size if previous allocation should have extra space
55  plint *newlist() { // get a new list assuming already allocated
56  return &data[curpos+1];
57  }
58 
59  void newsize(int list_size) { // set the size of the last list gotten
60  data[curpos] = list_size;
61  curpos += list_size + 1;
62  }
63  void reset() { curpos = 0; } // go back to the beginning
64  void nextlist(plint **list, int *list_size) { // get next list and size
65  *list = &data[curpos+1];
66  curpos += ( *list_size = data[curpos] ) + 1;
67  }
68  int getSize() { return size; }
69 
70  void addIndex() { // assume space for index already allocated
71  curpos++;
72  }
73  void setIndexValue(plint i) { // assume no newsize since addIndex
74  data[curpos-1] = i;
75  }
76 
78  return data[curpos++];
79  }
80 
81 };
82 
83 #define NBWORKARRAYSINIT(ARRAYS) \
84  ComputeNonbondedWorkArrays* const computeNonbondedWorkArrays = ARRAYS;
85 
86 #ifdef __INTEL_COMPILER
87 #define NBWORKARRAY(TYPE,NAME,SIZE) \
88  computeNonbondedWorkArrays->NAME.resize(SIZE); \
89  TYPE * const NAME = computeNonbondedWorkArrays->NAME.begin(); \
90  __assume_aligned(NAME,64);
91 #else
92 #define NBWORKARRAY(TYPE,NAME,SIZE) \
93  computeNonbondedWorkArrays->NAME.resize(SIZE); \
94  TYPE * const NAME = computeNonbondedWorkArrays->NAME.begin();
95 #endif
96 
98 public:
101 #ifdef NAMD_KNL
102  ResizeArray<float> r2list_f;
103  ResizeArray<float> xlist;
104  ResizeArray<float> ylist;
105  ResizeArray<float> zlist;
106 #endif
107 
108  // DMK - Atom Sort
109  // NOTE : TODO : For pair nonbonded compute objects, these arrays are needed
110  // for the atom sorting code. However, grouplist and fixglist will not be
111  // used if these arrays are so they could overlap in memory. TODO: Find a
112  // way to allow them to use the same memory. For now, it's not much memory
113  // so just keep them separate because of the type differences. I haven't
114  // looked through all the details yet, but could probably just use the
115  // larger type and cast the pointer type as needed for the other one to
116  // ensure there is enough memory in both cases.
117  #if NAMD_ComputeNonbonded_SortAtoms != 0
121  #endif
122 
128 
130 
131  // n = normal, x = excluded, m = modified
132  // A[1-4] = alchemical partition 1-4
147 
152 };
153 
154 //struct sent to CalcGBIS
156  int cid;
157  int patchID[2];
158  int sequence;
160  int doGBIS;
182  int doEnergy;
185 };
186 
187 // function arguments
188 struct nonbonded {
189  CompAtom* p[2];
190 #ifdef NAMD_KNL
191  CompAtomFlt *pFlt[2];
192 #endif
194  // BEGIN LA
195  CompAtom* v[2];
196  // END LA
197  Force* ff[2];
198  // for full electrostatics
199  Force* fullf [2];
200 
201  int numAtoms[2];
202 
205 
206  // DMK - Atom Separation (water vs. non-water)
207  #if NAMD_SeparateWaters != 0
208  int numWaterAtoms[2];
209  #endif
210 
213 
217 
219 
225 
226  // BEGIN LA
228  // END LA
229 
230  int minPart;
231  int maxPart;
232  int numParts;
233  int step;
234 
235  #if NAMD_ComputeNonbonded_SortAtoms != 0
237  #endif
238 };
239 
241 
242 public:
243 
246  static void select(void);
247 
248  static void (*calcPair)(nonbonded *);
249  static void (*calcPairEnergy)(nonbonded *);
250  static void (*calcSelf)(nonbonded *);
251  static void (*calcSelfEnergy)(nonbonded *);
252 
253  static void (*calcFullPair)(nonbonded *);
254  static void (*calcFullPairEnergy)(nonbonded *);
255  static void (*calcFullSelf)(nonbonded *);
256  static void (*calcFullSelfEnergy)(nonbonded *);
257 
258  static void (*calcMergePair)(nonbonded *);
259  static void (*calcMergePairEnergy)(nonbonded *);
260  static void (*calcMergeSelf)(nonbonded *);
261  static void (*calcMergeSelfEnergy)(nonbonded *);
262 
263  static void (*calcSlowPair)(nonbonded *);
264  static void (*calcSlowPairEnergy)(nonbonded *);
265  static void (*calcSlowSelf)(nonbonded *);
266  static void (*calcSlowSelfEnergy)(nonbonded *);
267 
268  // Below modified by JLai -- Look at bottom 3rd line
272 //sd-db
276 //sd-de
277  TENSOR(virialIndex), TENSOR(fullElectVirialIndex),
278  VECTOR(pairVDWForceIndex), VECTOR(pairElectForceIndex),
282 
283  static Bool commOnly;
285  static Bool qmForcesOn ;
286  static BigReal cutoff;
287  static BigReal cutoff2;
288  static float cutoff2_f;
290  static const LJTable* ljTable;
291  static const Molecule* mol;
293  static int rowsize;
294  static int columnsize;
295  static int r2_delta_exp;
307  static BigReal *r2_table;
308  static int table_length;
309  #if defined(NAMD_MIC)
310  static BigReal *mic_table_base_ptr; // DMK - NOTE : Duplicate but, use so that nothing breaks if the ordering of sub-arrays changes
311  static int mic_table_n;
312  static int mic_table_n_16;
313  #endif
314 
315  #ifdef NAMD_AVXTILES
316  // 0 - Tiles mode disabled
317  // 1 - C1 switching, arithmetic LJ w/ no user specified mix values
318  // 2 - C1 switching with LJTable lookup for parameters
319  // 3 - Interpolation supporting any switch options (including none)
320  static int avxTilesMode;
321  // Additional tiles data structures for explicit LJ mixing in force calc
322  static float *avx_tiles_eps4_sigma;
323  static float *avx_tiles_eps4_sigma_14;
324  #endif
325 
326  #if defined(NAMD_KNL) || defined(NAMD_AVXTILES)
327  // Table interpolation is truncated at 1/r > KNL_TABLE_MAX_R_1
328  // KNL_TABLE_MAX_R_1 must be at least 1.f
329  // KNL_TABLE_FACTOR = floor(KNL_TABLE_SIZE / KNL_TABLE_MAX_R_1)
330  // Sanity checks for preprocessor defines are in ComputeNonbondedUtil.C
331  // For Tiles build, increase KNL_TABLE_MAX_R_1 for excluded/modified
332  #define KNL_TABLE_SIZE (4693+2)
333  #define KNL_TABLE_MAX_R_1 1.15f
334  #define KNL_TABLE_FACTOR (4080+2)
335  static float *knl_table_alloc;
336  static float *knl_fast_ener_table;
337  static float *knl_fast_grad_table;
338  static float *knl_scor_ener_table;
339  static float *knl_scor_grad_table;
340  static float *knl_slow_ener_table;
341  static float *knl_slow_grad_table;
342  static float *knl_excl_ener_table;
343  static float *knl_excl_grad_table;
344  #ifdef NAMD_KNL
345  static float *knl_corr_ener_table;
346  static float *knl_corr_grad_table;
347  #endif
348  #endif
349  static BigReal scaling;
350  static BigReal scale14;
354  static BigReal v_vdwa;
355  static BigReal v_vdwb;
356  static BigReal k_vdwa;
357  static BigReal k_vdwb;
360  static float v_vdwa_f;
361  static float v_vdwb_f;
362  static float k_vdwa_f;
363  static float k_vdwb_f;
364  static float cutoff_3_f;
365  static float cutoff_6_f;
366  static float switchOn_f;
367  static float A6_f;
368  static float B6_f;
369  static float C6_f;
370  static float A12_f;
371  static float B12_f;
372  static float C12_f;
373  static BigReal c0;
374  static BigReal c1;
375  static BigReal c3;
376  static BigReal c5;
377  static BigReal c6;
378  static BigReal c7;
379  static BigReal c8;
380  // static BigReal d0;
381 //sd-db
382  static Bool alchFepOn;
384  static Bool alchWCAOn;
388 //sd-de
389  static Bool lesOn;
390  static int lesFactor;
392 
394 
397 
403 
404  static Bool accelMDOn;
405 
407 
408  // for particle mesh Ewald
411 
412  // need macros for preprocessor
413  #define VDW_SWITCH_MODE_ENERGY 0
414  #define VDW_SWITCH_MODE_MARTINI 1
415  #define VDW_SWITCH_MODE_FORCE 2
416  static int vdw_switch_mode;
417 
418  // Ported by JLai -- JE - Go
419  static Bool goGroPair;
420  static Bool goForcesOn;
421  static int goMethod; //6.3.11
422  // End of port -- JL
423 
424  // for simplifying some common functions
425  inline static BigReal square( const BigReal &x,
426  const BigReal &y,
427  const BigReal &z)
428  {
429  return(x*x+y*y+z*z);
430  }
431 
432  static void calc_error(nonbonded *);
433 
434  static void calc_pair(nonbonded *);
435  static void calc_pair_energy(nonbonded *);
436  static void calc_pair_fullelect(nonbonded *);
437  static void calc_pair_energy_fullelect(nonbonded *);
438  static void calc_pair_merge_fullelect(nonbonded *);
440  static void calc_pair_slow_fullelect(nonbonded *);
442 
443  static void calc_self(nonbonded *);
444  static void calc_self_energy(nonbonded *);
445  static void calc_self_fullelect(nonbonded *);
446  static void calc_self_energy_fullelect(nonbonded *);
447  static void calc_self_merge_fullelect(nonbonded *);
449  static void calc_self_slow_fullelect(nonbonded *);
451 
452 //alchemical fep calcualtion
453  static void calc_pair_energy_fep(nonbonded *);
457  static void calc_self_energy_fep (nonbonded *);
461 
462  static void calc_pair_energy_ti(nonbonded *);
463  static void calc_pair_ti(nonbonded *);
465  static void calc_pair_fullelect_ti (nonbonded *);
467  static void calc_pair_merge_fullelect_ti (nonbonded *);
469  static void calc_pair_slow_fullelect_ti (nonbonded *);
470  static void calc_self_energy_ti (nonbonded *);
471  static void calc_self_ti (nonbonded *);
473  static void calc_self_fullelect_ti (nonbonded *);
475  static void calc_self_merge_fullelect_ti (nonbonded *);
477  static void calc_self_slow_fullelect_ti (nonbonded *);
478 
479 //locally enhanced sampling calcualtion
480  static void calc_pair_les(nonbonded *);
481  static void calc_pair_energy_les(nonbonded *);
482  static void calc_pair_fullelect_les (nonbonded *);
486  static void calc_pair_slow_fullelect_les (nonbonded *);
488  static void calc_self_les (nonbonded *);
489  static void calc_self_energy_les (nonbonded *);
490  static void calc_self_fullelect_les (nonbonded *);
494  static void calc_self_slow_fullelect_les (nonbonded *);
496 
497 //pair interaction calcualtion
498  static void calc_pair_energy_int(nonbonded *);
501  static void calc_self_energy_int (nonbonded *);
504 
505 //pressure profile calcualtion
506  static void calc_pair_pprof(nonbonded *);
507  static void calc_pair_energy_pprof(nonbonded *);
508  static void calc_pair_fullelect_pprof(nonbonded *);
514  static void calc_self_pprof(nonbonded *);
515  static void calc_self_energy_pprof(nonbonded *);
516  static void calc_self_fullelect_pprof (nonbonded *);
522 
523  //tabulated potential nonbonded calcs
524  static void calc_pair_tabener(nonbonded *);
525  static void calc_pair_energy_tabener(nonbonded *);
526  static void calc_pair_fullelect_tabener(nonbonded *);
532  static void calc_self_tabener(nonbonded *);
533  static void calc_self_energy_tabener(nonbonded *);
534  static void calc_self_fullelect_tabener (nonbonded *);
540 
541  //Go forces nonbonded calcs
542  static void calc_pair_go(nonbonded *);
543  static void calc_pair_energy_go(nonbonded *);
544  static void calc_pair_fullelect_go(nonbonded *);
548  static void calc_pair_slow_fullelect_go(nonbonded *);
550  static void calc_self_go(nonbonded *);
551  static void calc_self_energy_go(nonbonded *);
552  static void calc_self_fullelect_go(nonbonded *);
556  static void calc_self_slow_fullelect_go(nonbonded *);
558 
559  void calcGBIS(nonbonded *params, GBISParamStruct *gbisParams);
560 };
561 
562 #endif
563 
ResizeArray< plint > pairlistmA3
ResizeArray< BigReal > p_0_sortValues
Pairlists * pairlists
static void calc_pair_fullelect_pprof(nonbonded *)
static BigReal * fast_table
static void calc_pair_energy_merge_fullelect_tabener(nonbonded *)
static void calc_self_energy_go(nonbonded *)
static void calc_self_energy_merge_fullelect_ti(nonbonded *)
static BigReal * scor_table
static void calc_pair_les(nonbonded *)
static void calc_self_energy_slow_fullelect_fep(nonbonded *)
static void calc_pair_merge_fullelect(nonbonded *)
static void calc_self_energy_merge_fullelect_int(nonbonded *)
static void calc_self_energy_slow_fullelect(nonbonded *)
ResizeArray< SortEntry > atomSort_0_sortValues__
static void calc_self_energy_merge_fullelect_tabener(nonbonded *)
static void calc_self_energy_slow_fullelect_ti(nonbonded *)
static void calc_self_energy_fullelect_int(nonbonded *)
static void submitReductionData(BigReal *, SubmitReduction *)
Parameters * parameters
static void calc_self_ti(nonbonded *)
static void calc_self_fullelect_pprof(nonbonded *)
static void calc_self_tabener(nonbonded *)
static void calc_self_energy_fullelect(nonbonded *)
static void calc_pair_slow_fullelect_ti(nonbonded *)
int32 ComputeID
Definition: NamdTypes.h:278
static void(* calcSelf)(nonbonded *)
static void calc_pair_merge_fullelect_tabener(nonbonded *)
static BigReal square(const BigReal &x, const BigReal &y, const BigReal &z)
ResizeArray< plint > pairlistnA3
CompAtom * p[2]
static void calc_self_les(nonbonded *)
void calcGBIS(nonbonded *params, GBISParamStruct *gbisParams)
Definition: ComputeGBIS.C:261
Definition: Vector.h:72
static void calc_pair_merge_fullelect_go(nonbonded *)
static void calc_pair_slow_fullelect_pprof(nonbonded *)
static void calc_pair_energy_merge_fullelect(nonbonded *)
static const Molecule * mol
static void calc_pair_energy_fullelect_fep(nonbonded *)
static void calc_self_energy_fullelect_pprof(nonbonded *)
float Real
Definition: common.h:118
static void calc_self_energy_fullelect_les(nonbonded *)
static void calc_self_energy_fullelect_ti(nonbonded *)
CompAtom * v[2]
static void calc_self_fullelect(nonbonded *)
static void calc_self_energy_ti(nonbonded *)
static BigReal * vdwa_table
static void calc_self_energy_int(nonbonded *)
BigReal * reduction
static void submitPressureProfileData(BigReal *, SubmitReduction *)
static BigReal pressureProfileThickness
static void calc_pair_slow_fullelect(nonbonded *)
static void calc_pair(nonbonded *)
static void calc_self_go(nonbonded *)
static void(* calcMergePair)(nonbonded *)
static void calc_pair_energy_tabener(nonbonded *)
static void calc_self_slow_fullelect_pprof(nonbonded *)
static void calc_pair_energy_slow_fullelect_go(nonbonded *)
static void calc_self_energy_merge_fullelect_fep(nonbonded *)
ResizeArray< plint > pairlistxA2
static void(* calcMergePairEnergy)(nonbonded *)
static void calc_pair_energy_go(nonbonded *)
static void calc_pair_merge_fullelect_ti(nonbonded *)
SimParameters * simParameters
Molecule stores the structural information for the system.
Definition: Molecule.h:175
static BigReal * full_table
static void calc_pair_merge_fullelect_les(nonbonded *)
ResizeArray< plint > pairlistnA1
static void calc_pair_slow_fullelect_go(nonbonded *)
static void calc_pair_energy_merge_fullelect_fep(nonbonded *)
static void(* calcSlowPairEnergy)(nonbonded *)
ResizeArray< plint > pairlistm
ResizeArray< plint > pairlistnA0
ResizeArray< plint > pairlistxA1
static void(* calcPair)(nonbonded *)
static void(* calcSlowPair)(nonbonded *)
ResizeArray< BigReal > r2list
static void calc_pair_energy_fullelect_go(nonbonded *)
ResizeArray< plint > pairlistxA4
unsigned short plint
static void calc_pair_energy_slow_fullelect_tabener(nonbonded *)
Definition: Random.h:37
plint getIndexValue()
void nextlist(plint **list, int *list_size)
static void calc_self_slow_fullelect(nonbonded *)
static void calc_self_energy_les(nonbonded *)
static void calc_pair_energy_fep(nonbonded *)
static void(* calcMergeSelfEnergy)(nonbonded *)
static void calc_pair_tabener(nonbonded *)
ResizeArray< plint > pairlistxA3
static void calc_pair_energy_pprof(nonbonded *)
static BigReal * table_noshort
Pairlists * gbisStepPairlists[4]
static void calc_self_energy_slow_fullelect_tabener(nonbonded *)
static void calc_self_energy_fullelect_tabener(nonbonded *)
static void calc_pair_energy_int(nonbonded *)
static BigReal pressureProfileMin
ResizeArray< plint > pairlistmA2
static void calc_self_slow_fullelect_tabener(nonbonded *)
static void calc_pair_energy_slow_fullelect_les(nonbonded *)
static void calc_pair_energy_ti(nonbonded *)
static void calc_pair_energy_slow_fullelect_fep(nonbonded *)
static void calc_self_slow_fullelect_ti(nonbonded *)
static void calc_pair_slow_fullelect_les(nonbonded *)
ResizeArray< plint > pairlistx
static void calc_pair_fullelect_ti(nonbonded *)
static void calc_pair_energy(nonbonded *)
static BigReal * table_ener
int Bool
Definition: common.h:142
static void calc_pair_pprof(nonbonded *)
static void calc_pair_energy_fullelect_ti(nonbonded *)
static void calc_self_energy_merge_fullelect_les(nonbonded *)
static void calc_self_slow_fullelect_go(nonbonded *)
static void calc_pair_energy_merge_fullelect_go(nonbonded *)
CompAtomExt * pExt[2]
static void calc_error(nonbonded *)
ResizeArray< plint > pairlistnAlch
static void calc_self_energy_fullelect_go(nonbonded *)
static void calc_self_fullelect_tabener(nonbonded *)
static void(* calcFullSelf)(nonbonded *)
ResizeArray< plint > pairlistnA2
static void calc_self_merge_fullelect_ti(nonbonded *)
static void(* calcSlowSelf)(nonbonded *)
static void calc_self_fullelect_les(nonbonded *)
static void calc_self_merge_fullelect_go(nonbonded *)
plint * newlist()
static void calc_self_energy_merge_fullelect_go(nonbonded *)
static void calc_self_energy_merge_fullelect(nonbonded *)
static void select(void)
static void calc_pair_energy_fullelect_int(nonbonded *)
static void calc_pair_energy_merge_fullelect_pprof(nonbonded *)
static BigReal * lambda_table
static void calc_self_energy_fep(nonbonded *)
static void(* calcSlowSelfEnergy)(nonbonded *)
ResizeArray< SortEntry > atomSort_1_sortValues__
static void calc_pair_energy_slow_fullelect_pprof(nonbonded *)
static BigReal * slow_table
static void(* calcSelfEnergy)(nonbonded *)
static void(* calcPairEnergy)(nonbonded *)
static void calc_pair_fullelect_les(nonbonded *)
static void calc_pair_energy_les(nonbonded *)
ResizeArray< plint > pairlistmA1
static void calc_self_merge_fullelect(nonbonded *)
static void calc_self_energy_tabener(nonbonded *)
static void calc_pair_energy_merge_fullelect_int(nonbonded *)
static void calc_self_energy_slow_fullelect_pprof(nonbonded *)
static void calc_self_energy_pprof(nonbonded *)
ResizeArray< plint > pairlistnA4
static void calc_pair_energy_fullelect_pprof(nonbonded *)
static void calc_pair_fullelect_go(nonbonded *)
static void calc_pair_energy_slow_fullelect(nonbonded *)
static void calc_pair_energy_fullelect_les(nonbonded *)
static BigReal * vdwb_table
static void calc_pair_energy_fullelect_tabener(nonbonded *)
static void(* calcFullPair)(nonbonded *)
static void calc_pair_merge_fullelect_pprof(nonbonded *)
static const LJTable * ljTable
static void calc_self_energy_merge_fullelect_pprof(nonbonded *)
ResizeArray< plint > pairlistmA4
static void(* calcFullPairEnergy)(nonbonded *)
void newsize(int list_size)
static BigReal * corr_table
static BigReal * table_short
void setIndexValue(plint i)
static void calc_self(nonbonded *)
static void calc_self_fullelect_ti(nonbonded *)
static void calc_pair_fullelect_tabener(nonbonded *)
static void calc_pair_energy_merge_fullelect_ti(nonbonded *)
static BigReal * table_alloc
Force * fullf[2]
static void calc_self_energy_fullelect_fep(nonbonded *)
ResizeArray< char > excl_flags_buff
static void calc_self_merge_fullelect_tabener(nonbonded *)
static BigReal alchVdwShiftCoeff
static void calc_pair_go(nonbonded *)
BigReal * pressureProfileReduction
plint * newlist(int max_size)
static void calc_pair_ti(nonbonded *)
static void calc_self_energy(nonbonded *)
static void calc_self_fullelect_go(nonbonded *)
static void calc_pair_energy_merge_fullelect_les(nonbonded *)
int32 PatchID
Definition: NamdTypes.h:277
static void calc_self_pprof(nonbonded *)
static void calc_self_merge_fullelect_les(nonbonded *)
static void calc_pair_slow_fullelect_tabener(nonbonded *)
static void calc_pair_energy_fullelect(nonbonded *)
static void calc_self_merge_fullelect_pprof(nonbonded *)
static void calc_self_energy_slow_fullelect_go(nonbonded *)
static void calc_pair_energy_slow_fullelect_ti(nonbonded *)
ComputeNonbondedWorkArrays * workArrays
static void(* calcMergeSelf)(nonbonded *)
static void calc_self_energy_slow_fullelect_les(nonbonded *)
double BigReal
Definition: common.h:123
static void(* calcFullSelfEnergy)(nonbonded *)
float GBReal
Definition: ComputeGBIS.inl:17
static void calc_pair_fullelect(nonbonded *)
static void calc_self_slow_fullelect_les(nonbonded *)