61 vptr = malloc(pm->
numatoms *
sizeof(
int));
63 pm->
next = (
int *) vptr;
71 const float *atom = pm->
atom_f;
83 int n, ib, jb, kb, index;
86 for (n = 0; n < numbins; n++) bin[n] = -1;
87 for (n = 0; n <
numatoms; n++) next[n] = -1;
89 for (n = 0; n <
numatoms; n++, atom += 4) {
91 d[
X] = atom[
X] - c[
X];
92 d[
Y] = atom[
Y] - c[
Y];
93 d[
Z] = atom[
Z] - c[
Z];
94 s[
X] = ru[
X] * d[
X] + ru[
Y] * d[
Y] + ru[
Z] * d[
Z];
95 s[
Y] = rv[
X] * d[
X] + rv[
Y] * d[
Y] + rv[
Z] * d[
Z];
96 s[
Z] = rw[
X] * d[
X] + rw[
Y] * d[
Y] + rw[
Z] * d[
Z];
98 ib = (int) floorf((s[
X] + 0.5f) * nbx);
99 jb = (int) floorf((s[
Y] + 0.5f) * nby);
100 kb = (int) floorf((s[
Z] + 0.5f) * nbz);
104 else if (ib >= nbx) ib = nbx - 1;
106 else if (jb >= nby) jb = nby - 1;
108 else if (kb >= nbz) kb = nbz - 1;
109 index = (kb*nby + jb)*nbx + ib;
110 next[n] = bin[index];
118 enum { NUM_NBRBINS = 14 };
119 int nbrbin[3*NUM_NBRBINS] = {
120 0,0,0, 1,0,0, -1,1,0, 0,1,0, 1,1,0, -1,-1,1, 0,-1,1,
121 1,-1,1, -1,0,1, 0,0,1, 1,0,1, -1,1,1, 0,1,1, 1,1,1
127 int ia, ja, ka, n, i, j;
135 const int *bin = pm->
bin;
137 const float *atom = pm->
atom_f;
139 float a2 = pm->
a_f * pm->
a_f;
140 float a_1 = 1 / pm->
a_f;
141 float a_2 = a_1 * a_1;
144 for (aindex = 0, ka = 0; ka < nbz; ka++) {
145 for (ja = 0; ja < nby; ja++) {
146 for (ia = 0; ia < nbx; ia++, aindex++) {
148 for (n = 0; n < NUM_NBRBINS; n++) {
150 float p[3] = { 0,0,0 };
152 int ib = ia + nbrbin[3*n +
X];
153 int jb = ja + nbrbin[3*n +
Y];
154 int kb = ka + nbrbin[3*n +
Z];
160 ib += nbx; p[
X] -= u[
X]; p[
Y] -= u[
Y]; p[
Z] -= u[
Z];
162 else if (ib >= nbx) {
163 ib -= nbx; p[
X] += u[
X]; p[
Y] += u[
Y]; p[
Z] += u[
Z];
166 else if (ib < 0 || ib >= nbx)
continue;
170 jb += nby; p[
X] -= v[
X]; p[
Y] -= v[
Y]; p[
Z] -= v[
Z];
172 else if (jb >= nby) {
173 jb -= nby; p[
X] += v[
X]; p[
Y] += v[
Y]; p[
Z] += v[
Z];
176 else if (jb < 0 || jb >= nby)
continue;
180 kb += nbz; p[
X] -= w[
X]; p[
Y] -= w[
Y]; p[
Z] -= w[
Z];
182 else if (kb >= nbz) {
183 kb -= nbz; p[
X] += w[
X]; p[
Y] += w[
Y]; p[
Z] += w[
Z];
186 else if (kb < 0 || kb >= nbz)
continue;
189 bindex = (kb*nby + jb)*nbx + ib;
191 for (j = bin[bindex]; j != -1; j = next[j]) {
192 float force_j[3] = { 0,0,0 };
194 float qj = atom[4*j +
Q];
197 atom_j[
X] = atom[4*j +
X] + p[
X];
198 atom_j[
Y] = atom[4*j +
Y] + p[
Y];
199 atom_j[
Z] = atom[4*j +
Z] + p[
Z];
203 if (n == 0) ihead = next[j];
205 for (i = ihead; i != -1; i = next[i]) {
209 rij[
X] = atom_j[
X] - atom[4*i +
X];
210 rij[
Y] = atom_j[
Y] - atom[4*i +
Y];
211 rij[
Z] = atom_j[
Z] - atom[4*i +
Z];
213 r2 = rij[
X] * rij[
X] + rij[
Y] * rij[
Y] + rij[
Z] * rij[
Z];
217 float qq = qj * atom[4*i +
Q];
235 ue = qq * (r_1 - a_1 * g);
236 due_r = qq * r_1 * (-r_2 - a_2 * dg);
238 fij[
X] = -rij[
X] * due_r;
239 fij[
Y] = -rij[
Y] * due_r;
240 fij[
Z] = -rij[
Z] * due_r;
241 force[3*i +
X] -= fij[
X];
242 force[3*i +
Y] -= fij[
Y];
243 force[3*i +
Z] -= fij[
Z];
244 force_j[
X] += fij[
X];
245 force_j[
Y] += fij[
Y];
246 force_j[
Z] += fij[
Z];
256 force[3*j +
X] += force_j[
X];
257 force[3*j +
Y] += force_j[
Y];
258 force[3*j +
Z] += force_j[
Z];
274 int *nbrhd = pm->
nbrhd;
280 int ia, ja, ka, n, i, j;
288 const int *bin = pm->
bin;
290 const float *atom = pm->
atom_f;
292 float a2 = pm->
a_f * pm->
a_f;
293 float a_1 = 1 / pm->
a_f;
294 float a_2 = a_1 * a_1;
297 for (aindex = 0, ka = 0; ka < nbz; ka++) {
298 for (ja = 0; ja < nby; ja++) {
299 for (ia = 0; ia < nbx; ia++, aindex++) {
301 for (n = 0; n < nbrhdlen; n++) {
303 float p[3] = { 0,0,0 };
305 int ib = ia + nbrhd[3*n +
X];
306 int jb = ja + nbrhd[3*n +
Y];
307 int kb = ka + nbrhd[3*n +
Z];
313 ib += nbx; p[
X] -= u[
X]; p[
Y] -= u[
Y]; p[
Z] -= u[
Z];
315 else if (ib >= nbx) {
316 ib -= nbx; p[
X] += u[
X]; p[
Y] += u[
Y]; p[
Z] += u[
Z];
319 else if (ib < 0 || ib >= nbx)
continue;
323 jb += nby; p[
X] -= v[
X]; p[
Y] -= v[
Y]; p[
Z] -= v[
Z];
325 else if (jb >= nby) {
326 jb -= nby; p[
X] += v[
X]; p[
Y] += v[
Y]; p[
Z] += v[
Z];
329 else if (jb < 0 || jb >= nby)
continue;
333 kb += nbz; p[
X] -= w[
X]; p[
Y] -= w[
Y]; p[
Z] -= w[
Z];
335 else if (kb >= nbz) {
336 kb -= nbz; p[
X] += w[
X]; p[
Y] += w[
Y]; p[
Z] += w[
Z];
339 else if (kb < 0 || kb >= nbz)
continue;
342 bindex = (kb*nby + jb)*nbx + ib;
344 for (j = bin[bindex]; j != -1; j = next[j]) {
345 float force_j[3] = { 0,0,0 };
347 float qj = atom[4*j +
Q];
350 atom_j[
X] = atom[4*j +
X] + p[
X];
351 atom_j[
Y] = atom[4*j +
Y] + p[
Y];
352 atom_j[
Z] = atom[4*j +
Z] + p[
Z];
356 if (n == 0) ihead = next[j];
358 for (i = ihead; i != -1; i = next[i]) {
362 rij[
X] = atom_j[
X] - atom[4*i +
X];
363 rij[
Y] = atom_j[
Y] - atom[4*i +
Y];
364 rij[
Z] = atom_j[
Z] - atom[4*i +
Z];
366 r2 = rij[
X] * rij[
X] + rij[
Y] * rij[
Y] + rij[
Z] * rij[
Z];
370 float qq = qj * atom[4*i +
Q];
388 ue = qq * (r_1 - a_1 * g);
389 due_r = qq * r_1 * (-r_2 - a_2 * dg);
391 fij[
X] = -rij[
X] * due_r;
392 fij[
Y] = -rij[
Y] * due_r;
393 fij[
Z] = -rij[
Z] * due_r;
394 force[3*i +
X] -= fij[
X];
395 force[3*i +
Y] -= fij[
Y];
396 force[3*i +
Z] -= fij[
Z];
397 force_j[
X] += fij[
X];
398 force_j[
Y] += fij[
Y];
399 force_j[
Z] += fij[
Z];
409 force[3*j +
X] += force_j[
X];
410 force[3*j +
Y] += force_j[
Y];
411 force[3*j +
Z] += force_j[
Z];
static int bin_evaluation_1away(NL_Msm *pm)
#define SPOLY_SPREC(pg, pdg, ra, split)
static int setup_bin_data(NL_Msm *pm)
static Units next(Units u)
int NL_msm_compute_short_range_sprec(NL_Msm *pm)
std::vector< std::string > split(const std::string &text, std::string delimiter)
static int bin_evaluation_k_away(NL_Msm *pm)
static int spatial_hashing(NL_Msm *pm)