NAMD
PatchMap.inl
Go to the documentation of this file.
1 
7 #ifndef PATCHMAP_INL
8 #define PATCHMAP_INL
9 
10 #include "PatchMap.h"
11 #include "AtomMap.h"
12 
13 //----------------------------------------------------------------------
15 {
16  int ai, bi, ci;
17  ScaledPosition s = l.scale(p);
18  ai = (int)floor(((BigReal)aDim)*((s.x-aOrigin)/aLength));
19  bi = (int)floor(((BigReal)bDim)*((s.y-bOrigin)/bLength));
20  ci = (int)floor(((BigReal)cDim)*((s.z-cOrigin)/cLength));
21  return pid(ai,bi,ci);
22 }
23 
24 //----------------------------------------------------------------------
25 #define MODULO(I,J) ( (I)<0 ? ((J)-(-1*(I))%(J))%(J) : (I)%(J) )
26 
27 inline int PatchMap::pid(int aIndex, int bIndex, int cIndex)
28 {
29  if ( aPeriodic ) aIndex = MODULO(aIndex,aDim);
30  else
31  {
32  if ( aIndex < 0 ) aIndex = 0;
33  if ( aIndex >= aDim ) aIndex = aDim - 1;
34  }
35  if ( bPeriodic ) bIndex = MODULO(bIndex,bDim);
36  else
37  {
38  if ( bIndex < 0 ) bIndex = 0;
39  if ( bIndex >= bDim ) bIndex = bDim - 1;
40  }
41  if ( cPeriodic ) cIndex = MODULO(cIndex,cDim);
42  else
43  {
44  if ( cIndex < 0 ) cIndex = 0;
45  if ( cIndex >= cDim ) cIndex = cDim - 1;
46  }
47  return ((cIndex*bDim)+bIndex)*aDim + aIndex;
48 }
49 
50 //----------------------------------------------------------------------
51 inline int PatchMap::downstream(int pid1, int pid2)
52 {
53  register int ds;
54 
55  if ( pid1 == pid2 ) { ds = pid1; }
56 
57  else if ( pid1 == notUsed || pid2 == notUsed ) { ds = notUsed; }
58 
59  else {
60  register PatchData *pdat1 = &(patchData[pid1]);
61  register PatchData *pdat2 = &(patchData[pid2]);
62 
63  // c
64  register int k = pdat1->cIndex;
65  register int k2 = pdat2->cIndex;
66  if ( ( k ? k : cMaxIndex ) == k2 + 1 ) k = k2;
67 
68  // b
69  register int j = pdat1->bIndex;
70  register int j2 = pdat2->bIndex;
71  if ( ( j ? j : bMaxIndex ) == j2 + 1 ) j = j2;
72 
73  // a
74  register int i = pdat1->aIndex;
75  register int i2 = pdat2->aIndex;
76  if ( ( i ? i : aMaxIndex ) == i2 + 1 ) i = i2;
77 
78  ds = ((k*bDim)+j)*aDim + i;
79  }
80 
81  return ds;
82 }
83 
84 #endif
85 
PatchID assignToPatch(Position p, const Lattice &l)
Definition: PatchMap.inl:14
Definition: Vector.h:64
BigReal z
Definition: Vector.h:66
int downstream(int pid1, int pid2)
Definition: PatchMap.inl:51
BigReal x
Definition: Vector.h:66
int PatchID
Definition: NamdTypes.h:182
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
BigReal y
Definition: Vector.h:66
ScaledPosition scale(Position p) const
Definition: Lattice.h:83
#define MODULO(I, J)
Definition: PatchMap.inl:25
double BigReal
Definition: common.h:114