-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphysics.h
136 lines (124 loc) · 4.47 KB
/
physics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef __PHYSICS_H__
#define __PHYSICS_H__
#include "ckmulticast.h"
extern /* readonly */ CkGroupID mCastGrpID;
extern /* readonly */ int patchArrayDimX; // Number of Chare Rows
extern /* readonly */ int patchArrayDimY; // Number of Chare Columns
extern /* readonly */ int patchArrayDimZ;
extern /* readonly */ int finalStepCount;
#define BLOCK_SIZE 512
//function to calculate forces among 2 lists of atoms
inline double calcPairForces(ParticleDataMsg* first, ParticleDataMsg* second, CkSectionInfo* mcast1, CkSectionInfo* mcast2, int stepCount) {
int i, j, jpart, ptpCutOffSqd, diff;
int firstLen = first->lengthAll;
int secondLen = second->lengthAll;
double powTwenty, powTen, r, rsqd, f, fr;
vec3 separation, force;
double rSix, rTwelve;
double energy = 0;
int doEnergy = 0;
if(stepCount == 1 || stepCount == finalStepCount)
doEnergy = 1;
vec3 *firstmsg = new vec3[firstLen];
vec3 *secondmsg = new vec3[secondLen];
//check for wrap around and adjust locations accordingly
if (abs(first->x - second->x) > 1){
diff = PATCH_SIZE_X * patchArrayDimX;
if (second->x < first->x)
diff = -1 * diff;
for (i = 0; i < firstLen; i++)
first->part[i].x += diff;
}
if (abs(first->y - second->y) > 1){
diff = PATCH_SIZE_Y * patchArrayDimY;
if (second->y < first->y)
diff = -1 * diff;
for (i = 0; i < firstLen; i++)
first->part[i].y += diff;
}
if (abs(first->z - second->z) > 1){
diff = PATCH_SIZE_Z * patchArrayDimZ;
if (second->z < first->z)
diff = -1 * diff;
for (i = 0; i < firstLen; i++)
first->part[i].z += diff;
}
ptpCutOffSqd = PTP_CUT_OFF * PTP_CUT_OFF;
powTen = pow(10.0, -10);
powTwenty = pow(10.0, -20);
int i1, j1;
for(i1 = 0; i1 < firstLen; i1=i1+BLOCK_SIZE)
for(j1 = 0; j1 < secondLen; j1=j1+BLOCK_SIZE)
for(i = i1; i < i1+BLOCK_SIZE && i < firstLen; i++) {
for(jpart = j1; jpart < j1+BLOCK_SIZE && jpart < secondLen; jpart++) {
separation = first->part[i] - second->part[jpart];
rsqd = dot(separation, separation);
if (rsqd >= 0.001 && rsqd < ptpCutOffSqd) {
rsqd = rsqd * powTwenty;
r = sqrt(rsqd);
rSix = ((double)rsqd) * rsqd * rsqd;
rTwelve = rSix * rSix;
f = (double)(VDW_A / rTwelve - VDW_B / rSix);
if(doEnergy)
energy += (double)( VDW_A / (12*rTwelve) - VDW_B / (6*rSix));
fr = f /r;
force = separation * (fr * powTen);
firstmsg[i] += force;
secondmsg[jpart] -= force;
}
}
}
CkMulticastMgr *mCastGrp = CProxy_CkMulticastMgr(mCastGrpID).ckLocalBranch();
CkGetSectionInfo(*mcast1, first);
mCastGrp->contribute(sizeof(vec3)*firstLen, firstmsg, CkReduction::sum_double, *mcast1);
CkGetSectionInfo(*mcast2, second);
mCastGrp->contribute(sizeof(vec3)*secondLen, secondmsg, CkReduction::sum_double, *mcast2);
delete [] firstmsg;
delete [] secondmsg;
delete first;
delete second;
return energy;
}
//function to calculate forces among atoms in a single list
inline double calcInternalForces(ParticleDataMsg* first, CkSectionInfo *mcast1, int stepCount) {
int i, j, ptpCutOffSqd;
int firstLen = first->lengthAll;
double powTwenty, powTen, firstx, firsty, firstz, rx, ry, rz, r, rsqd, fx, fy, fz, f, fr;
vec3 firstpos, separation, force;
double rSix, rTwelve;
double energy = 0;
int doEnergy = 0;
if(stepCount == 1 || stepCount == finalStepCount)
doEnergy = 1;
vec3 *firstmsg = new vec3[firstLen];
ptpCutOffSqd = PTP_CUT_OFF * PTP_CUT_OFF;
powTen = pow(10.0, -10);
powTwenty = pow(10.0, -20);
for(i = 0; i < firstLen; i++){
firstpos = first->part[i];
for(j = i+1; j < firstLen; j++) {
// computing base values
separation = firstpos - first->part[j];
rsqd = dot(separation, separation);
if(rsqd >= 0.001 && rsqd < ptpCutOffSqd){
rsqd = rsqd * powTwenty;
r = sqrt(rsqd);
rSix = ((double)rsqd) * rsqd * rsqd;
rTwelve = rSix * rSix;
f = (double)(VDW_A / rTwelve - VDW_B / rSix);
if(doEnergy)
energy += (double)( VDW_A / (12*rTwelve) - VDW_B / (6*rSix));
fr = f /r;
force = separation * (fr * powTen);
firstmsg[j] += force;
firstmsg[i] -= force;
}
}
}
CkMulticastMgr *mCastGrp = CProxy_CkMulticastMgr(mCastGrpID).ckLocalBranch();
mCastGrp->contribute(sizeof(vec3)*firstLen, firstmsg, CkReduction::sum_double, *mcast1);
delete [] firstmsg;
delete first;
return energy;
}
#endif