local void sumcell(cellptr start, cellptr finish, vector pos0, real *phi0, vector acc0) { real eps2, eps2thrd, dr2, dr2i, dr1i, mdr1i, mdr3i, qdr2, dr5i, phi_q; vector dr, qdr; eps2 = eps * eps; // premultiply softening eps2thrd = eps2 / 3.0; // predivide for soft corr for (cellptr p = start; p < finish; p++) { // loop over node list DOTPSUBV(dr2, dr, Pos(p), pos0); // do mono part of force dr2i = ((real) 1.0) / (dr2 + eps2); // perform only division dr1i = rsqrt(dr2i); // set inverse soft distance mdr1i = Mass(p) * dr1i; // form mono potential mdr3i = mdr1i * dr2i; // get scale factor for dr DOTPMULMV(qdr2, qdr, Quad(p), dr); // do quad part of force #if defined(SOFTCORR) qdr2 -= eps2thrd * Trace(p); // apply Keigo's correction #endif dr5i = ((real) 3.0) * dr2i * dr2i * dr1i; // factor 3 saves a multiply phi_q = ((real) 0.5) * dr5i * qdr2; // form quad potential mdr3i += ((real) 5.0) * phi_q * dr2i; // adjust radial term *phi0 -= mdr1i + phi_q; // sum mono and quad pot ADDMULVS2(acc0, dr, mdr3i, qdr, - dr5i); // sum mono and quad acc } }
local void sumcell(cellptr start, cellptr finish, vector pos0, real *phi0, vector acc0) { cellptr p; real eps2, dr2, drab, phi_p, mr3i, drqdr, dr5i, phi_q; vector dr, qdr; eps2 = eps * eps; for (p = start; p < finish; p++) { /* loop over node list */ DOTPSUBV(dr2, dr, Pos(p), pos0); /* do mono part of force */ dr2 += eps2; drab = rsqrt(dr2); phi_p = Mass(p) / drab; mr3i = phi_p / dr2; DOTPMULMV(drqdr, qdr, Quad(p), dr); /* do quad part of force */ dr5i = ((real) 1.0) / (dr2 * dr2 * drab); phi_q = ((real) 0.5) * dr5i * drqdr; *phi0 -= phi_p + phi_q; /* add mono and quad pot */ mr3i += ((real) 5.0) * phi_q / dr2; ADDMULVS2(acc0, dr, mr3i, qdr, -dr5i); /* add mono and quad acc */ } }