221 |
|
Vector3d apos; |
222 |
|
Vector3d rpos; |
223 |
|
Vector3d frc(0.0); |
224 |
< |
Vector3d trq(0.0); |
224 |
> |
Vector3d trq(0.0); |
225 |
|
Vector3d pos = this->getPos(); |
226 |
|
for (int i = 0; i < atoms_.size(); i++) { |
227 |
|
|
241 |
|
if (atoms_[i]->isDirectional()) { |
242 |
|
atrq = atoms_[i]->getTrq(); |
243 |
|
trq += atrq; |
244 |
< |
} |
244 |
> |
} |
245 |
> |
} |
246 |
> |
addFrc(frc); |
247 |
> |
addTrq(trq); |
248 |
> |
} |
249 |
> |
|
250 |
> |
Mat3x3d RigidBody::calcForcesAndTorquesAndVirial() { |
251 |
> |
Vector3d afrc; |
252 |
> |
Vector3d atrq; |
253 |
> |
Vector3d apos; |
254 |
> |
Vector3d rpos; |
255 |
> |
Vector3d frc(0.0); |
256 |
> |
Vector3d trq(0.0); |
257 |
> |
Vector3d pos = this->getPos(); |
258 |
> |
Mat3x3d tau_(0.0); |
259 |
> |
|
260 |
> |
for (int i = 0; i < atoms_.size(); i++) { |
261 |
> |
|
262 |
> |
afrc = atoms_[i]->getFrc(); |
263 |
> |
apos = atoms_[i]->getPos(); |
264 |
> |
rpos = apos - pos; |
265 |
|
|
266 |
< |
} |
267 |
< |
|
266 |
> |
frc += afrc; |
267 |
> |
|
268 |
> |
trq[0] += rpos[1]*afrc[2] - rpos[2]*afrc[1]; |
269 |
> |
trq[1] += rpos[2]*afrc[0] - rpos[0]*afrc[2]; |
270 |
> |
trq[2] += rpos[0]*afrc[1] - rpos[1]*afrc[0]; |
271 |
> |
|
272 |
> |
// If the atom has a torque associated with it, then we also need to |
273 |
> |
// migrate the torques onto the center of mass: |
274 |
> |
|
275 |
> |
if (atoms_[i]->isDirectional()) { |
276 |
> |
atrq = atoms_[i]->getTrq(); |
277 |
> |
trq += atrq; |
278 |
> |
} |
279 |
> |
|
280 |
> |
tau_(0,0) -= rpos[0]*afrc[0]; |
281 |
> |
tau_(0,1) -= rpos[0]*afrc[1]; |
282 |
> |
tau_(0,2) -= rpos[0]*afrc[2]; |
283 |
> |
tau_(1,0) -= rpos[1]*afrc[0]; |
284 |
> |
tau_(1,1) -= rpos[1]*afrc[1]; |
285 |
> |
tau_(1,2) -= rpos[1]*afrc[2]; |
286 |
> |
tau_(2,0) -= rpos[2]*afrc[0]; |
287 |
> |
tau_(2,1) -= rpos[2]*afrc[1]; |
288 |
> |
tau_(2,2) -= rpos[2]*afrc[2]; |
289 |
> |
|
290 |
> |
} |
291 |
|
addFrc(frc); |
292 |
|
addTrq(trq); |
293 |
< |
|
293 |
> |
return tau_; |
294 |
|
} |
295 |
|
|
296 |
|
void RigidBody::updateAtoms() { |