# | Line 51 | Line 51 | namespace oopse { | |
---|---|---|
51 | ||
52 | void RigidBody::setPrevA(const RotMat3x3d& a) { | |
53 | ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = a; | |
54 | – | //((snapshotMan_->getPrevSnapshot())->*storage_).electroFrame[localIndex_] = a.transpose() * sU_; |
54 | ||
55 | for (int i =0 ; i < atoms_.size(); ++i){ | |
56 | if (atoms_[i]->isDirectional()) { | |
57 | < | atoms_[i]->setPrevA(a * refOrients_[i]); |
57 | > | atoms_[i]->setPrevA(refOrients_[i].transpose() * a); |
58 | } | |
59 | } | |
60 | ||
# | Line 64 | Line 63 | namespace oopse { | |
63 | ||
64 | void RigidBody::setA(const RotMat3x3d& a) { | |
65 | ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = a; | |
67 | – | //((snapshotMan_->getCurrentSnapshot())->*storage_).electroFrame[localIndex_] = a.transpose() * sU_; |
66 | ||
67 | for (int i =0 ; i < atoms_.size(); ++i){ | |
68 | if (atoms_[i]->isDirectional()) { | |
69 | < | atoms_[i]->setA(a * refOrients_[i]); |
69 | > | atoms_[i]->setA(refOrients_[i].transpose() * a); |
70 | } | |
71 | } | |
72 | } | |
# | Line 79 | Line 77 | namespace oopse { | |
77 | ||
78 | for (int i =0 ; i < atoms_.size(); ++i){ | |
79 | if (atoms_[i]->isDirectional()) { | |
80 | < | atoms_[i]->setA(a * refOrients_[i], snapshotNo); |
80 | > | atoms_[i]->setA(refOrients_[i].transpose() * a, snapshotNo); |
81 | } | |
82 | } | |
83 | ||
# | Line 89 | Line 87 | namespace oopse { | |
87 | return inertiaTensor_; | |
88 | } | |
89 | ||
90 | < | std::vector<double> RigidBody::getGrad() { |
91 | < | std::vector<double> grad(6, 0.0); |
90 | > | std::vector<RealType> RigidBody::getGrad() { |
91 | > | std::vector<RealType> grad(6, 0.0); |
92 | Vector3d force; | |
93 | Vector3d torque; | |
94 | Vector3d myEuler; | |
95 | < | double phi, theta, psi; |
96 | < | double cphi, sphi, ctheta, stheta; |
95 | > | RealType phi, theta, psi; |
96 | > | RealType cphi, sphi, ctheta, stheta; |
97 | Vector3d ephi; | |
98 | Vector3d etheta; | |
99 | Vector3d epsi; | |
# | Line 148 | Line 146 | namespace oopse { | |
146 | ||
147 | /**@todo need modification */ | |
148 | void RigidBody::calcRefCoords() { | |
149 | < | double mtmp; |
149 | > | RealType mtmp; |
150 | Vector3d refCOM(0.0); | |
151 | mass_ = 0.0; | |
152 | for (std::size_t i = 0; i < atoms_.size(); ++i) { | |
# | Line 169 | Line 167 | namespace oopse { | |
167 | Mat3x3d IAtom(0.0); | |
168 | mtmp = atoms_[i]->getMass(); | |
169 | IAtom -= outProduct(refCoords_[i], refCoords_[i]) * mtmp; | |
170 | < | double r2 = refCoords_[i].lengthSquare(); |
170 | > | RealType r2 = refCoords_[i].lengthSquare(); |
171 | IAtom(0, 0) += mtmp * r2; | |
172 | IAtom(1, 1) += mtmp * r2; | |
173 | IAtom(2, 2) += mtmp * r2; | |
174 | + | Itmp += IAtom; |
175 | ||
176 | //project the inertial moment of directional atoms into this rigid body | |
177 | if (atoms_[i]->isDirectional()) { | |
178 | < | IAtom += atoms_[i]->getI(); |
179 | < | Itmp += refOrients_[i].transpose() * IAtom * refOrients_[i]; |
181 | < | } else { |
182 | < | Itmp += IAtom; |
183 | < | } |
178 | > | Itmp += refOrients_[i].transpose() * atoms_[i]->getI() * refOrients_[i]; |
179 | > | } |
180 | } | |
181 | ||
182 | + | // std::cout << Itmp << std::endl; |
183 | + | |
184 | //diagonalize | |
185 | Vector3d evals; | |
186 | Mat3x3d::diagonalize(Itmp, evals, sU_); | |
# | Line 223 | Line 221 | namespace oopse { | |
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 | ||
# | Line 243 | Line 241 | namespace oopse { | |
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 | < | |
268 | < | setFrc(frc); |
269 | < | setTrq(trq); |
270 | < | |
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 | > | return tau_; |
294 | } | |
295 | ||
296 | void RigidBody::updateAtoms() { | |
# | Line 271 | Line 312 | namespace oopse { | |
312 | if (atoms_[i]->isDirectional()) { | |
313 | ||
314 | dAtom = (DirectionalAtom *) atoms_[i]; | |
315 | < | dAtom->setA(refOrients_[i] * a); |
315 | > | dAtom->setA(refOrients_[i].transpose() * a); |
316 | } | |
317 | ||
318 | } | |
# | Line 298 | Line 339 | namespace oopse { | |
339 | if (atoms_[i]->isDirectional()) { | |
340 | ||
341 | dAtom = (DirectionalAtom *) atoms_[i]; | |
342 | < | dAtom->setA(refOrients_[i] * a, frame); |
342 | > | dAtom->setA(refOrients_[i].transpose() * a, frame); |
343 | } | |
344 | ||
345 | } | |
# | Line 483 | Line 524 | namespace oopse { | |
524 | "RigidBody error.\n" | |
525 | "\tAtom %s does not have a position specified.\n" | |
526 | "\tThis means RigidBody cannot set up reference coordinates.\n", | |
527 | < | ats->getType() ); |
527 | > | ats->getType().c_str() ); |
528 | painCave.isFatal = 1; | |
529 | simError(); | |
530 | } | |
# | Line 503 | Line 544 | namespace oopse { | |
544 | "RigidBody error.\n" | |
545 | "\tAtom %s does not have an orientation specified.\n" | |
546 | "\tThis means RigidBody cannot set up reference orientations.\n", | |
547 | < | ats->getType() ); |
547 | > | ats->getType().c_str() ); |
548 | painCave.isFatal = 1; | |
549 | simError(); | |
550 | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |