00001
00007 #ifndef PATCHMAP_INL
00008 #define PATCHMAP_INL
00009
00010 #include "PatchMap.h"
00011 #include "AtomMap.h"
00012
00013
00014 inline PatchID PatchMap::assignToPatch(Position p, const Lattice &l)
00015 {
00016 int ai, bi, ci;
00017 ScaledPosition s = l.scale(p);
00018 ai = (int)floor(((BigReal)aDim)*((s.x-aOrigin)/aLength));
00019 bi = (int)floor(((BigReal)bDim)*((s.y-bOrigin)/bLength));
00020 ci = (int)floor(((BigReal)cDim)*((s.z-cOrigin)/cLength));
00021 return pid(ai,bi,ci);
00022 }
00023
00024
00025 #define MODULO(I,J) ( (I)<0 ? ((J)-(-1*(I))%(J))%(J) : (I)%(J) )
00026
00027 inline int PatchMap::pid(int aIndex, int bIndex, int cIndex)
00028 {
00029 if ( aPeriodic ) aIndex = MODULO(aIndex,aDim);
00030 else
00031 {
00032 if ( aIndex < 0 ) aIndex = 0;
00033 if ( aIndex >= aDim ) aIndex = aDim - 1;
00034 }
00035 if ( bPeriodic ) bIndex = MODULO(bIndex,bDim);
00036 else
00037 {
00038 if ( bIndex < 0 ) bIndex = 0;
00039 if ( bIndex >= bDim ) bIndex = bDim - 1;
00040 }
00041 if ( cPeriodic ) cIndex = MODULO(cIndex,cDim);
00042 else
00043 {
00044 if ( cIndex < 0 ) cIndex = 0;
00045 if ( cIndex >= cDim ) cIndex = cDim - 1;
00046 }
00047 return ((cIndex*bDim)+bIndex)*aDim + aIndex;
00048 }
00049
00050
00051 inline int PatchMap::downstream(int pid1, int pid2)
00052 {
00053 register int ds;
00054
00055 if ( pid1 == pid2 ) { ds = pid1; }
00056
00057 else if ( pid1 == notUsed || pid2 == notUsed ) { ds = notUsed; }
00058
00059 else {
00060 register PatchData *pdat1 = &(patchData[pid1]);
00061 register PatchData *pdat2 = &(patchData[pid2]);
00062
00063
00064 register int k = pdat1->cIndex;
00065 register int k2 = pdat2->cIndex;
00066 if ( ( k ? k : cMaxIndex ) == k2 + 1 ) k = k2;
00067
00068
00069 register int j = pdat1->bIndex;
00070 register int j2 = pdat2->bIndex;
00071 if ( ( j ? j : bMaxIndex ) == j2 + 1 ) j = j2;
00072
00073
00074 register int i = pdat1->aIndex;
00075 register int i2 = pdat2->aIndex;
00076 if ( ( i ? i : aMaxIndex ) == i2 + 1 ) i = i2;
00077
00078 ds = ((k*bDim)+j)*aDim + i;
00079 }
00080
00081 return ds;
00082 }
00083
00084
00085 inline int PatchMap::downstream2(int pid1, int pid2)
00086 {
00087 register int ds;
00088
00089 if ( pid1 == pid2 ) { ds = pid1; }
00090
00091 else if ( pid1 == notUsed || pid2 == notUsed ) { ds = notUsed; }
00092
00093 else {
00094 register PatchData *pdat1 = &(patchData[pid1]);
00095 register PatchData *pdat2 = &(patchData[pid2]);
00096
00097
00098 register int k = pdat1->cIndex;
00099 register int k2 = pdat2->cIndex;
00100 if ( ( k ? k : cMaxIndex ) == k2 + 1 ||
00101 ( k >= cAway ? k : cMaxIndex + k ) == k2 + cAway ) k = k2;
00102
00103
00104 register int j = pdat1->bIndex;
00105 register int j2 = pdat2->bIndex;
00106 if ( ( j ? j : bMaxIndex ) == j2 + 1 ||
00107 ( j >= bAway ? j : bMaxIndex + j ) == j2 + bAway ) j = j2;
00108
00109
00110 register int i = pdat1->aIndex;
00111 register int i2 = pdat2->aIndex;
00112 if ( ( i ? i : aMaxIndex ) == i2 + 1 ||
00113 ( i >= aAway ? i : aMaxIndex + i ) == i2 + aAway ) i = i2;
00114
00115 ds = ((k*bDim)+j)*aDim + i;
00116 }
00117
00118 return ds;
00119 }
00120
00121 #endif
00122