ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/primitives/StuntDouble.hpp
Revision: 963
Committed: Wed May 17 21:51:42 2006 UTC (18 years, 11 months ago) by tim
File size: 29132 byte(s)
Log Message:
Adding single precision capabilities to c++ side

File Contents

# User Rev Content
1 gezelter 507 /*
2 gezelter 246 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
6     * redistribute this software in source and binary code form, provided
7     * that the following conditions are met:
8     *
9     * 1. Acknowledgement of the program authors must be made in any
10     * publication of scientific results based in part on use of the
11     * program. An acceptable form of acknowledgement is citation of
12     * the article in which the program was described (Matthew
13     * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14     * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15     * Parallel Simulation Engine for Molecular Dynamics,"
16     * J. Comput. Chem. 26, pp. 252-271 (2005))
17     *
18     * 2. Redistributions of source code must retain the above copyright
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41    
42     /**
43     * @file StuntDouble.hpp
44     * @author tlin
45     * @date 10/22/2004
46     * @version 1.0
47     */
48    
49 gezelter 507 #ifndef PRIMITIVES_STUNTDOUBLE_HPP
50     #define PRIMITIVES_STUNTDOUBLE_HPP
51 gezelter 2
52 gezelter 246 #include <vector>
53 gezelter 2
54 gezelter 246 #include "visitors/BaseVisitor.hpp"
55     #include "math/Quaternion.hpp"
56     #include "math/SquareMatrix3.hpp"
57     #include "math/Vector3.hpp"
58     #include "utils/PropertyMap.hpp"
59     #include "brains/Snapshot.hpp"
60     #include "brains/SnapshotManager.hpp"
61     namespace oopse{
62 gezelter 2
63 tim 132
64 gezelter 246
65     /**
66     * @class StuntDouble StuntDouble.hpp "Primitives/StuntDouble.hpp"
67     * @brief
68 gezelter 573 * "Don't move, or you're dead! Stand up! Captain, we've got them!"
69     *
70     * "Spectacular stunt, my friends, but all for naught. Turn around
71     * please. Ha. What a pity. What a pity. So, Princess, you thought
72     * you could outwit the imperious forces of...."
73     *
74     * "You idiots! These are not them. You've captured their stunt
75     * doubles! Search the area. Find them! Find them!"
76     *
77 gezelter 246 * StuntDouble is a very strange idea. A StuntDouble stands in for
78     * some object that can be manipulated by the Integrators or
79     * Minimizers. Some of the manipulable objects are Atoms, some are
80     * DirectionalAtoms, and some are RigidBodies. StuntDouble
81     * provides an interface for the Integrators and Minimizers to use,
82     * and does some preliminary sanity checking so that the program
83 gezelter 573 * doesn't try to do something stupid like torque an Atom (The
84     * quotes above are from Spaceballs...)
85     *
86 gezelter 246 * @note the dynamic data of stuntdouble will be stored outside of the class
87     */
88 gezelter 507 class StuntDouble{
89     public:
90 gezelter 2
91 gezelter 507 enum ObjectType{
92     otAtom,
93     otDAtom,
94     otRigidBody
95     };
96 gezelter 2
97 gezelter 507 virtual ~StuntDouble();
98 gezelter 246
99 gezelter 507 /**
100 tim 963 * Returns the global index of this stuntRealType.
101 gezelter 507 * @return the global index of this stuntdouble
102     */
103     int getGlobalIndex() {
104     return globalIndex_;
105     }
106 gezelter 2
107 gezelter 507 /**
108 tim 963 * Sets the global index of this stuntRealType.
109 gezelter 507 * @param new global index to be set
110     */
111     void setGlobalIndex(int index) {
112     globalIndex_ = index;
113     }
114 gezelter 246
115 gezelter 507 /**
116     * Returns the local index of this stuntdouble
117     * @return the local index of this stuntdouble
118     */
119     int getLocalIndex() {
120     return localIndex_;
121     }
122 gezelter 2
123 gezelter 507 /**
124     * Sets the local index of this stuntdouble
125     * @param index new index to be set
126     */
127     void setLocalIndex(int index) {
128     localIndex_ = index;
129     }
130 gezelter 2
131 gezelter 507 /**
132     * Sets the Snapshot Manager of this stuntdouble
133     */
134     void setSnapshotManager(SnapshotManager* sman) {
135     snapshotMan_ = sman;
136     }
137 gezelter 2
138 gezelter 507 /**
139     * Tests if this stuntdouble is an atom
140     * @return true is this stuntdouble is an atom(or a directional atom), return false otherwise
141     */
142     bool isAtom(){
143     return objType_ == otAtom || objType_ == otDAtom;
144     }
145 gezelter 2
146 gezelter 507 /**
147     * Tests if this stuntdouble is an directional atom
148     * @return true if this stuntdouble is an directional atom, return false otherwise
149     */
150     bool isDirectionalAtom(){
151     return objType_ == otDAtom;
152     }
153 gezelter 2
154 gezelter 507 /**
155     * Tests if this stuntdouble is a rigid body.
156     * @return true if this stuntdouble is a rigid body, otherwise return false
157     */
158     bool isRigidBody(){
159     return objType_ == otRigidBody;
160     }
161 gezelter 2
162 gezelter 507 /**
163     * Tests if this stuntdouble is a directional one.
164     * @return true is this stuntdouble is a directional atom or a rigid body, return false otherwise
165     */
166     bool isDirectional(){
167     return isDirectionalAtom() || isRigidBody();
168     }
169 gezelter 2
170 gezelter 507 /**
171 gezelter 945 * Freezes out all velocity, angular velocity, forces and torques
172     * on this StuntDouble. Also computes the number of frozen degrees
173     * of freedom.
174     * @return the total number of frozen degrees of freedom
175     */
176     int freeze() {
177    
178     int fdf = 3;
179    
180     setVel(V3Zero);
181     setFrc(V3Zero);
182     if (isDirectional()){
183     setJ(V3Zero);
184     setTrq(V3Zero);
185     if (isLinear())
186     fdf +=2;
187     else
188     fdf +=3;
189     }
190     return fdf;
191     }
192    
193     /**
194 gezelter 507 * Returns the previous position of this stuntdouble
195     * @return the position of this stuntdouble
196     */
197     Vector3d getPrevPos() {
198     return ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_];
199     }
200 gezelter 246
201 gezelter 507 /**
202     * Returns the current position of this stuntdouble
203     * @return the position of this stuntdouble
204     */
205     Vector3d getPos() {
206     return ((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_];
207     }
208 gezelter 2
209 gezelter 507 /**
210     * Returns the position of this stuntdouble in specified snapshot
211     * @return the position of this stuntdouble
212     * @param snapshotNo
213     */
214     Vector3d getPos(int snapshotNo) {
215     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_];
216     }
217 gezelter 2
218 gezelter 507 /**
219     * Sets the previous position of this stuntdouble
220     * @param pos new position
221     * @see #getPos
222     */
223     void setPrevPos(const Vector3d& pos) {
224     ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_] = pos;
225     }
226 gezelter 246
227 gezelter 507 /**
228     * Sets the current position of this stuntdouble
229     * @param pos new position
230     */
231     void setPos(const Vector3d& pos) {
232     DataStorage& data = snapshotMan_->getCurrentSnapshot()->*storage_;
233     data.position[localIndex_] = pos;
234     //((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_] = pos;
235     }
236 gezelter 2
237 gezelter 507 /**
238     * Sets the position of this stuntdouble in specified snapshot
239     * @param pos position to be set
240     * @param snapshotNo
241     * @see #getPos
242     */
243     void setPos(const Vector3d& pos, int snapshotNo) {
244 gezelter 2
245 gezelter 507 ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_] = pos;
246 gezelter 2
247 gezelter 507 }
248 gezelter 246
249 gezelter 507 /**
250     * Returns the previous velocity of this stuntdouble
251     * @return the velocity of this stuntdouble
252     */
253     Vector3d getPrevVel() {
254     return ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_];
255     }
256 gezelter 246
257 gezelter 507 /**
258     * Returns the current velocity of this stuntdouble
259     * @return the velocity of this stuntdouble
260     */
261     Vector3d getVel() {
262     return ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_];
263     }
264 gezelter 2
265 gezelter 507 /**
266     * Returns the velocity of this stuntdouble in specified snapshot
267     * @return the velocity of this stuntdouble
268     * @param snapshotNo
269     */
270     Vector3d getVel(int snapshotNo) {
271     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_];
272     }
273 gezelter 2
274 gezelter 507 /**
275     * Sets the previous velocity of this stuntdouble
276     * @param vel new velocity
277     * @see #getVel
278     */
279     void setPrevVel(const Vector3d& vel) {
280     ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_] = vel;
281     }
282 gezelter 246
283 gezelter 507 /**
284     * Sets the current velocity of this stuntdouble
285     * @param vel new velocity
286     */
287     void setVel(const Vector3d& vel) {
288     ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_] = vel;
289     }
290 gezelter 246
291 gezelter 507 /**
292     * Sets the velocity of this stuntdouble in specified snapshot
293     * @param vel velocity to be set
294     * @param snapshotNo
295     * @see #getVel
296     */
297     void setVel(const Vector3d& vel, int snapshotNo) {
298     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_] = vel;
299     }
300 gezelter 246
301 gezelter 507 /**
302     * Returns the previous rotation matrix of this stuntdouble
303     * @return the rotation matrix of this stuntdouble
304     */
305     RotMat3x3d getPrevA() {
306     return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_];
307     }
308 gezelter 246
309 gezelter 507 /**
310     * Returns the current rotation matrix of this stuntdouble
311     * @return the rotation matrix of this stuntdouble
312     */
313     RotMat3x3d getA() {
314     return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_];
315     }
316 gezelter 246
317 gezelter 507 /**
318     * Returns the rotation matrix of this stuntdouble in specified snapshot
319     *
320     * @return the rotation matrix of this stuntdouble
321     * @param snapshotNo
322     */
323     RotMat3x3d getA(int snapshotNo) {
324     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_];
325     }
326 gezelter 246
327 gezelter 507 /**
328     * Sets the previous rotation matrix of this stuntdouble
329     * @param a new rotation matrix
330     * @see #getA
331     */
332     virtual void setPrevA(const RotMat3x3d& a) {
333     ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = a;
334     }
335 gezelter 246
336 gezelter 507 /**
337     * Sets the current rotation matrix of this stuntdouble
338     * @param a new rotation matrix
339     */
340     virtual void setA(const RotMat3x3d& a) {
341     ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = a;
342     }
343 gezelter 246
344 gezelter 507 /**
345     * Sets the rotation matrix of this stuntdouble in specified snapshot
346     * @param a rotation matrix to be set
347     * @param snapshotNo
348     * @see #getA
349     */
350     virtual void setA(const RotMat3x3d& a, int snapshotNo) {
351     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = a;
352     }
353 gezelter 246
354 gezelter 507 /**
355     * Returns the previous angular momentum of this stuntdouble (body-fixed).
356     * @return the angular momentum of this stuntdouble
357     */
358     Vector3d getPrevJ() {
359     return ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_];
360     }
361 gezelter 246
362 gezelter 507 /**
363     * Returns the current angular momentum of this stuntdouble (body -fixed).
364     * @return the angular momentum of this stuntdouble
365     */
366     Vector3d getJ() {
367     return ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_];
368     }
369 gezelter 246
370 gezelter 507 /**
371     * Returns the angular momentum of this stuntdouble in specified snapshot (body-fixed).
372     * @return the angular momentum of this stuntdouble
373     * @param snapshotNo
374     */
375     Vector3d getJ(int snapshotNo) {
376     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_];
377     }
378 gezelter 246
379 gezelter 507 /**
380     * Sets the previous angular momentum of this stuntdouble (body-fixed).
381     * @param angMom new angular momentum
382     * @see #getJ
383     */
384     void setPrevJ(const Vector3d& angMom) {
385     ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_] = angMom;
386     }
387 gezelter 246
388 gezelter 507 /**
389     * Sets the current angular momentum of this stuntdouble (body-fixed).
390     * @param angMom new angular momentum
391     */
392     void setJ(const Vector3d& angMom) {
393     ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_] = angMom;
394     }
395 gezelter 246
396 gezelter 507 /**
397     * Sets the angular momentum of this stuntdouble in specified snapshot(body-fixed).
398     * @param angMom angular momentum to be set
399     * @param snapshotNo
400     * @see #getJ
401     */
402     void setJ(const Vector3d& angMom, int snapshotNo) {
403     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_] = angMom;
404     }
405 gezelter 246
406 gezelter 507 /**
407     * Returns the previous quaternion of this stuntdouble
408     * @return the quaternion of this stuntdouble
409     */
410     Quat4d getPrevQ() {
411     return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toQuaternion();
412     }
413 gezelter 246
414 gezelter 507 /**
415     * Returns the current quaternion of this stuntdouble
416     * @return the quaternion of this stuntdouble
417     */
418     Quat4d getQ() {
419     return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toQuaternion();
420     }
421 gezelter 246
422 gezelter 507 /**
423     * Returns the quaternion of this stuntdouble in specified snapshot
424     * @return the quaternion of this stuntdouble
425     * @param snapshotNo
426     */
427     Quat4d getQ(int snapshotNo) {
428     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toQuaternion();
429     }
430 gezelter 246
431 gezelter 507 /**
432     * Sets the previous quaternion of this stuntdouble
433     * @param q new quaternion
434     * @note actual storage data is rotation matrix
435     */
436     void setPrevQ(const Quat4d& q) {
437     setPrevA(q);
438     }
439 gezelter 246
440 gezelter 507 /**
441     * Sets the current quaternion of this stuntdouble
442     * @param q new quaternion
443     * @note actual storage data is rotation matrix
444     */
445     void setQ(const Quat4d& q) {
446     setA(q);
447     }
448 gezelter 246
449 gezelter 507 /**
450     * Sets the quaternion of this stuntdouble in specified snapshot
451     *
452     * @param q quaternion to be set
453     * @param snapshotNo
454     * @note actual storage data is rotation matrix
455     */
456     void setQ(const Quat4d& q, int snapshotNo) {
457     setA(q, snapshotNo);
458     }
459 gezelter 246
460 gezelter 507 /**
461     * Returns the previous euler angles of this stuntdouble
462     * @return the euler angles of this stuntdouble
463     */
464     Vector3d getPrevEuler() {
465     return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toEulerAngles();
466     }
467 gezelter 246
468 gezelter 507 /**
469     * Returns the current euler angles of this stuntdouble
470     * @return the euler angles of this stuntdouble
471     */
472     Vector3d getEuler() {
473     return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toEulerAngles();
474     }
475 gezelter 246
476 gezelter 507 /**
477     * Returns the euler angles of this stuntdouble in specified snapshot.
478     * @return the euler angles of this stuntdouble
479     * @param snapshotNo
480     */
481     Vector3d getEuler(int snapshotNo) {
482     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toEulerAngles();
483     }
484 gezelter 246
485 gezelter 507 /**
486 tim 963 * Sets the previous euler angles of this stuntRealType.
487 gezelter 507 * @param euler new euler angles
488     * @see #getEuler
489     * @note actual storage data is rotation matrix
490     */
491     void setPrevEuler(const Vector3d& euler) {
492     ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = euler;
493     }
494 gezelter 246
495 gezelter 507 /**
496     * Sets the current euler angles of this stuntdouble
497     * @param euler new euler angles
498     */
499     void setEuler(const Vector3d& euler) {
500     ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = euler;
501     }
502 gezelter 246
503 gezelter 507 /**
504     * Sets the euler angles of this stuntdouble in specified snapshot
505     *
506     * @param euler euler angles to be set
507     * @param snapshotNo
508     * @note actual storage data is rotation matrix
509     */
510     void setEuler(const Vector3d& euler, int snapshotNo) {
511     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = euler;
512     }
513 gezelter 246
514 gezelter 507 /**
515     * Returns the previous unit vectors of this stuntdouble
516     * @return the unit vectors of this stuntdouble
517     */
518     RotMat3x3d getPrevElectroFrame() {
519     return ((snapshotMan_->getPrevSnapshot())->*storage_).electroFrame[localIndex_];
520     }
521 gezelter 246
522 gezelter 507 /**
523     * Returns the current unit vectors of this stuntdouble
524     * @return the unit vectors of this stuntdouble
525     */
526     RotMat3x3d getElectroFrame() {
527     return ((snapshotMan_->getCurrentSnapshot())->*storage_).electroFrame[localIndex_];
528     }
529 gezelter 246
530 gezelter 507 /**
531     * Returns the unit vectors of this stuntdouble in specified snapshot
532     *
533     * @return the unit vectors of this stuntdouble
534     * @param snapshotNo
535     */
536     RotMat3x3d getElectroFrame(int snapshotNo) {
537     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).electroFrame[localIndex_];
538     }
539 gezelter 246
540 gezelter 507 /**
541     * Returns the previous force of this stuntdouble
542     * @return the force of this stuntdouble
543     */
544     Vector3d getPrevFrc() {
545     return ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_];
546     }
547 gezelter 246
548 gezelter 507 /**
549     * Returns the current force of this stuntdouble
550     * @return the force of this stuntdouble
551     */
552     Vector3d getFrc() {
553     return ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_];
554     }
555 gezelter 246
556 gezelter 507 /**
557     * Returns the force of this stuntdouble in specified snapshot
558     *
559     * @return the force of this stuntdouble
560     * @param snapshotNo
561     */
562     Vector3d getFrc(int snapshotNo) {
563     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_];
564     }
565 gezelter 246
566 gezelter 507 /**
567     * Sets the previous force of this stuntdouble
568     *
569     * @param frc new force
570     * @see #getFrc
571     */
572     void setPrevFrc(const Vector3d& frc) {
573     ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] = frc;
574     }
575 gezelter 246
576 gezelter 507 /**
577     * Sets the current force of this stuntdouble
578     * @param frc new force
579     */
580     void setFrc(const Vector3d& frc) {
581     ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] = frc;
582     }
583 gezelter 246
584 gezelter 507 /**
585     * Sets the force of this stuntdouble in specified snapshot
586     *
587     * @param frc force to be set
588     * @param snapshotNo
589     * @see #getFrc
590     */
591     void setFrc(const Vector3d& frc, int snapshotNo) {
592     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] = frc;
593     }
594 gezelter 246
595 gezelter 507 /**
596     * Adds force into the previous force of this stuntdouble
597     *
598     * @param frc new force
599     * @see #getFrc
600     */
601     void addPrevFrc(const Vector3d& frc) {
602     ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] += frc;
603     }
604 gezelter 246
605 gezelter 507 /**
606     * Adds force into the current force of this stuntdouble
607     * @param frc new force
608     */
609     void addFrc(const Vector3d& frc) {
610     ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] += frc;
611     }
612 gezelter 246
613 gezelter 507 /**
614     * Adds force into the force of this stuntdouble in specified snapshot
615     *
616     * @param frc force to be set
617     * @param snapshotNo
618     * @see #getFrc
619     */
620     void addFrc(const Vector3d& frc, int snapshotNo) {
621     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] += frc;
622     }
623 gezelter 246
624 gezelter 507 /**
625     * Returns the previous torque of this stuntdouble
626     * @return the torque of this stuntdouble
627     */
628     Vector3d getPrevTrq() {
629     return ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_];
630     }
631 gezelter 246
632 gezelter 507 /**
633     * Returns the current torque of this stuntdouble
634     * @return the torque of this stuntdouble
635     */
636     Vector3d getTrq() {
637     return ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_];
638     }
639 gezelter 246
640 gezelter 507 /**
641     * Returns the torque of this stuntdouble in specified snapshot
642     *
643     * @return the torque of this stuntdouble
644     * @param snapshotNo
645     */
646     Vector3d getTrq(int snapshotNo) {
647     return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_];
648     }
649 gezelter 246
650 gezelter 507 /**
651     * Sets the previous torque of this stuntdouble
652     *
653     * @param trq new torque
654     * @see #getTrq
655     */
656     void setPrevTrq(const Vector3d& trq) {
657     ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] = trq;
658     }
659 gezelter 246
660 gezelter 507 /**
661     * Sets the current torque of this stuntdouble
662     * @param trq new torque
663     */
664     void setTrq(const Vector3d& trq) {
665     ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] = trq;
666     }
667 gezelter 246
668 gezelter 507 /**
669     * Sets the torque of this stuntdouble in specified snapshot
670     *
671     * @param trq torque to be set
672     * @param snapshotNo
673     * @see #getTrq
674     */
675     void setTrq(const Vector3d& trq, int snapshotNo) {
676     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] = trq;
677     }
678 gezelter 246
679 gezelter 507 /**
680     * Adds torque into the previous torque of this stuntdouble
681     *
682     * @param trq new torque
683     * @see #getTrq
684     */
685     void addPrevTrq(const Vector3d& trq) {
686     ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] += trq;
687     }
688 gezelter 246
689 gezelter 507 /**
690     * Adds torque into the current torque of this stuntdouble
691     * @param trq new torque
692     */
693     void addTrq(const Vector3d& trq) {
694     ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] += trq;
695     }
696 gezelter 246
697 gezelter 507 /**
698     * Adds torque into the torque of this stuntdouble in specified snapshot
699     *
700     * @param trq torque to be add
701     * @param snapshotNo
702     * @see #getTrq
703     */
704     void addTrq(const Vector3d& trq, int snapshotNo) {
705     ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] += trq;
706     }
707 gezelter 246
708    
709 gezelter 507 /**
710     * Returns the previous z-angle of this stuntdouble
711     * @return the z-angle of this stuntdouble
712     */
713 tim 963 RealType getPrevZangle() {
714 gezelter 507 return ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_];
715     }
716 gezelter 246
717 gezelter 507 /**
718     * Returns the current z-angle of this stuntdouble
719     * @return the z-angle of this stuntdouble
720     */
721 tim 963 RealType getZangle() {
722 gezelter 507 return ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_];
723     }
724 gezelter 246
725 gezelter 507 /**
726     * Returns the z-angle of this stuntdouble in specified snapshot
727     * @return the z-angle of this stuntdouble
728     * @param snapshotNo
729     */
730 tim 963 RealType getZangle(int snapshotNo) {
731 gezelter 507 return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_];
732     }
733 gezelter 246
734 gezelter 507 /**
735     * Sets the previous z-angle of this stuntdouble
736     * @param angle new z-angle
737     * @see #getZangle
738     */
739 tim 963 void setPrevZangle(RealType angle) {
740 gezelter 507 ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] = angle;
741     }
742 gezelter 246
743 gezelter 507 /**
744     * Sets the current z-angle of this stuntdouble
745     * @param angle new z-angle
746     */
747 tim 963 void setZangle(RealType angle) {
748 gezelter 507 ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] = angle;
749     }
750 gezelter 246
751 gezelter 507 /**
752     * Sets the z-angle of this stuntdouble in specified snapshot
753     * @param angle z-angle to be set
754     * @param snapshotNo
755     * @see #getZangle
756     */
757 tim 963 void setZangle(RealType angle, int snapshotNo) {
758 gezelter 507 ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] = angle;
759     }
760 gezelter 246
761 gezelter 507 /**
762     * Adds z-angle into the previous z-angle of this stuntdouble
763     * @param angle new z-angle
764     * @see #getZangle
765     */
766 tim 963 void addPrevZangle(RealType angle) {
767 gezelter 507 ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] += angle;
768     }
769 gezelter 246
770 gezelter 507 /**
771     * Adds z-angle into the current z-angle of this stuntdouble
772     * @param angle new z-angle
773     */
774 tim 963 void addZangle(RealType angle) {
775 gezelter 507 ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] += angle;
776     }
777 gezelter 246
778 gezelter 507 /**
779     * Adds z-angle into the z-angle of this stuntdouble in specified snapshot
780     * @param angle z-angle to be add
781     * @param snapshotNo
782     * @see #getZangle
783     */
784 tim 963 void addZangle(RealType angle, int snapshotNo) {
785 gezelter 507 ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] += angle;
786     }
787 gezelter 246
788 gezelter 507 /** Set the force of this stuntdouble to zero */
789     void zeroForcesAndTorques();
790     /**
791     * Returns the inertia tensor of this stuntdouble
792     * @return the inertia tensor of this stuntdouble
793     */
794     virtual Mat3x3d getI() = 0;
795 gezelter 246
796 gezelter 507 /**
797     * Returns the gradient of this stuntdouble
798     * @return the gradient of this stuntdouble
799     */
800 tim 963 virtual std::vector<RealType> getGrad() = 0;
801 gezelter 246
802 gezelter 507 /**
803     * Tests the if this stuntdouble is a linear rigidbody
804     *
805     * @return true if this stuntdouble is a linear rigidbody, otherwise return false
806     * @note atom and directional atom will always return false
807     *
808     * @see #linearAxis
809     */
810     bool isLinear() {
811     return linear_;
812     }
813 gezelter 246
814 gezelter 507 /**
815     * Returns the linear axis of the rigidbody, atom and directional atom will always return -1
816     *
817     * @return the linear axis of the rigidbody
818     *
819     * @see #isLinear
820     */
821     int linearAxis() {
822     return linearAxis_;
823     }
824 gezelter 246
825 gezelter 507 /** Returns the mass of this stuntdouble */
826 tim 963 RealType getMass() {
827 gezelter 507 return mass_;
828     }
829 gezelter 246
830 gezelter 507 /**
831     * Sets the mass of this stuntdoulbe
832     * @param mass the mass to be set
833     */
834 tim 963 void setMass(RealType mass) {
835 gezelter 507 mass_ = mass;
836     }
837 gezelter 246
838 gezelter 507 /** Returns the name of this stuntdouble */
839     virtual std::string getType() = 0;
840 gezelter 246
841 tim 963 /** Sets the name of this stuntRealType*/
842 gezelter 507 virtual void setType(const std::string& name) {}
843 gezelter 246
844 gezelter 507 /**
845     * Converts a lab fixed vector to a body fixed vector.
846     * @return body fixed vector
847     * @param v lab fixed vector
848     */
849     Vector3d lab2Body(const Vector3d& v) {
850     return getA() * v;
851     }
852 gezelter 246
853 gezelter 507 Vector3d lab2Body(const Vector3d& v, int frame) {
854     return getA(frame) * v;
855     }
856 tim 334
857 gezelter 507 /**
858     * Converts a body fixed vector to a lab fixed vector.
859     * @return corresponding lab fixed vector
860     * @param v body fixed vector
861     */
862     Vector3d body2Lab(const Vector3d& v){
863     return getA().transpose() * v;
864     }
865 tim 334
866 gezelter 507 Vector3d body2Lab(const Vector3d& v, int frame){
867     return getA(frame).transpose() * v;
868     }
869     /**
870     * <p>
871     * The purpose of the Visitor Pattern is to encapsulate an operation that you want to perform on
872     * the elements of a data structure. In this way, you can change the operation being performed
873     * on a structure without the need of changing the classes of the elements that you are operating
874     * on. Using a Visitor pattern allows you to decouple the classes for the data structure and the
875     * algorithms used upon them
876     * </p>
877     * @param v visitor
878     */
879     virtual void accept(BaseVisitor* v) = 0;
880 gezelter 246
881 gezelter 507 //below functions are just forward functions
882     /**
883     * Adds property into property map
884     * @param genData GenericData to be added into PropertyMap
885     */
886     void addProperty(GenericData* genData);
887 gezelter 246
888 gezelter 507 /**
889     * Removes property from PropertyMap by name
890     * @param propName the name of property to be removed
891     */
892     void removeProperty(const std::string& propName);
893 gezelter 246
894 gezelter 507 /**
895     * clear all of the properties
896     */
897     void clearProperties();
898 gezelter 246
899 gezelter 507 /**
900     * Returns all names of properties
901     * @return all names of properties
902     */
903     std::vector<std::string> getPropertyNames();
904 gezelter 246
905 gezelter 507 /**
906     * Returns all of the properties in PropertyMap
907     * @return all of the properties in PropertyMap
908     */
909     std::vector<GenericData*> getProperties();
910 gezelter 246
911 gezelter 507 /**
912     * Returns property
913     * @param propName name of property
914     * @return a pointer point to property with propName. If no property named propName
915     * exists, return NULL
916     */
917     GenericData* getPropertyByName(const std::string& propName);
918 gezelter 246
919 gezelter 507 protected:
920 gezelter 246
921 gezelter 507 StuntDouble(ObjectType objType, DataStoragePointer storage);
922 gezelter 246
923 gezelter 507 StuntDouble(const StuntDouble& sd);
924     StuntDouble& operator=(const StuntDouble& sd);
925 gezelter 246
926 gezelter 507 ObjectType objType_;
927     DataStoragePointer storage_;
928     SnapshotManager* snapshotMan_;
929 gezelter 246
930 gezelter 507 bool linear_;
931     int linearAxis_;
932 gezelter 246
933    
934 gezelter 507 int globalIndex_;
935     int localIndex_;
936 gezelter 246
937    
938 tim 963 RealType mass_;
939 gezelter 246
940 gezelter 507 private:
941 gezelter 246
942 gezelter 507 PropertyMap properties_;
943     };
944 gezelter 2
945 gezelter 246 }//end namespace oopse
946     #endif //PRIMITIVES_STUNTDOUBLE_HPP

Properties

Name Value
svn:executable *