ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/StuntDouble.cpp
Revision: 1452
Committed: Mon Aug 23 15:11:36 2004 UTC (20 years, 8 months ago) by tim
File size: 18187 byte(s)
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "StuntDouble.hpp"
2 #include "Atom.hpp"
3 #include "DirectionalAtom.hpp"
4 #include "RigidBody.hpp"
5 #include "simError.h"
6
7 /*
8 "Don't move, or you're dead! Stand up! Captain, we've got them!"
9
10 "Spectacular stunt, my friends, but all for naught. Turn around
11 please. Ha. What a pity. What a pity. So, Princess, you thought
12 you could outwit the imperious forces of...."
13
14 "You idiots! These are not them. You've captured their stunt
15 doubles! Search the area. Find them! Find them!"
16
17 StuntDouble is a very strange idea. A StuntDouble stands in for
18 some object that can be manipulated by the Integrators or
19 Minimizers. Some of the manipulable objects are Atoms, some are
20 DirectionalAtoms, and some are RigidBodies. StuntDouble
21 provides an interface for the Integrators and Minimizers to use,
22 and does some preliminary sanity checking so that the program
23 doesn't try to do something stupid like torque an Atom. (The
24 quotes above are from Spaceballs...)
25
26 */
27
28 StuntDouble::~StuntDouble(){
29 map<string, GenericData*>::iterator iter;
30
31 for(iter = properties.begin(); iter != properties.end(); ++iter ){
32 delete iter->second;
33 properties.erase(iter);
34 }
35
36 }
37
38 int StuntDouble::getObjType(){
39 return objType;
40 }
41
42 double StuntDouble::getMass(){
43 switch (objType)
44 {
45 case OT_ATOM :
46 case OT_DATOM:
47 return ((Atom*)this)->getMass();
48 break;
49 case OT_RIGIDBODY:
50 return ((RigidBody*)this)->getMass();
51 break;
52 default:
53 sprintf( painCave.errMsg,
54 "Unrecognized ObjType (%d) in StuntDouble::getMass.\n",
55 objType );
56 painCave.isFatal = 1;
57 simError();
58 return 0.0;
59 }
60 }
61
62
63 void StuntDouble::getPos(double pos[3]){
64 switch (objType)
65 {
66 case OT_ATOM :
67 case OT_DATOM:
68 ((Atom*)this)->getPos(pos);
69 break;
70 case OT_RIGIDBODY:
71 ((RigidBody*)this)->getPos(pos);
72 break;
73 default:
74 sprintf( painCave.errMsg,
75 "Unrecognized ObjType (%d) in StuntDouble::getPos.\n",
76 objType );
77 painCave.isFatal = 1;
78 simError();
79 }
80 }
81
82 void StuntDouble::getVel(double vel[3]){
83 switch (objType)
84 {
85 case OT_ATOM :
86 case OT_DATOM:
87 ((Atom*)this)->getVel(vel);
88 break;
89 case OT_RIGIDBODY:
90 ((RigidBody*)this)->getVel(vel);
91 break;
92 default:
93 sprintf( painCave.errMsg,
94 "Unrecognized ObjType (%d) in StuntDouble::getVel.\n",
95 objType );
96 painCave.isFatal = 1;
97 simError();
98 }
99 }
100
101 void StuntDouble::getFrc(double frc[3]){
102 switch (objType)
103 {
104 case OT_ATOM :
105 case OT_DATOM:
106 ((Atom*)this)->getFrc(frc);
107 break;
108 case OT_RIGIDBODY:
109 ((RigidBody*)this)->getFrc(frc);
110 break;
111 default:
112 sprintf( painCave.errMsg,
113 "Unrecognized ObjType (%d) in StuntDouble::getFrc.\n",
114 objType );
115 painCave.isFatal = 1;
116 simError();
117 }
118 }
119
120
121 void StuntDouble::setPos(double pos[3]){
122 switch (objType)
123 {
124 case OT_ATOM :
125 case OT_DATOM:
126 ((Atom*)this)->setPos(pos);
127 break;
128 case OT_RIGIDBODY:
129 ((RigidBody*)this)->setPos(pos);
130 break;
131 default:
132 sprintf( painCave.errMsg,
133 "Unrecognized ObjType (%d) in StuntDouble::setPos.\n",
134 objType );
135 painCave.isFatal = 1;
136 simError();
137 }
138 }
139
140 void StuntDouble::setVel(double vel[3]){
141
142 switch (objType)
143 {
144 case OT_ATOM :
145 case OT_DATOM:
146 ((Atom*)this)->setVel(vel);
147 break;
148 case OT_RIGIDBODY:
149 ((RigidBody*)this)->setVel(vel);
150 break;
151 default:
152 sprintf( painCave.errMsg,
153 "Unrecognized ObjType (%d) in StuntDouble::setVel.\n",
154 objType );
155 painCave.isFatal = 1;
156 simError();
157 }
158 }
159
160 void StuntDouble::setFrc(double frc[3]){
161
162 switch (objType)
163 {
164 case OT_ATOM :
165 case OT_DATOM:
166 ((Atom*)this)->setFrc(frc);
167 break;
168 case OT_RIGIDBODY:
169 ((RigidBody*)this)->setFrc(frc);
170 break;
171 default:
172 sprintf( painCave.errMsg,
173 "Unrecognized ObjType (%d) in StuntDouble::setFrc.\n",
174 objType );
175 painCave.isFatal = 1;
176 simError();
177 }
178 }
179
180 void StuntDouble::addFrc(double frc[3]){
181 switch (objType)
182 {
183 case OT_ATOM :
184 case OT_DATOM:
185 ((Atom*)this)->addFrc(frc);
186 break;
187 case OT_RIGIDBODY:
188 ((RigidBody*)this)->addFrc(frc);
189 break;
190 default:
191 sprintf( painCave.errMsg,
192 "Unrecognized ObjType (%d) in StuntDouble::addFrc.\n",
193 objType );
194 painCave.isFatal = 1;
195 simError();
196 }
197 }
198
199 void StuntDouble::getA(double A[3][3]){
200 switch (objType)
201 {
202 case OT_ATOM:
203 sprintf( painCave.errMsg,
204 "StuntDouble::getA was called for a regular atom.\n"
205 "\tRegular Atoms don't have rotation matrices. Be smarter.\n");
206 painCave.isFatal = 0;
207 simError();
208 // Return unit matrix
209 A[0][0] = 1; A[0][1] = 0; A[0][2] = 0;
210 A[1][0] = 0; A[1][1] = 1; A[1][2] = 0;
211 A[2][0] = 0; A[2][1] = 0; A[2][2] = 1;
212 break;
213 case OT_DATOM:
214 ((DirectionalAtom*)this)->getA(A);
215 break;
216 case OT_RIGIDBODY:
217 ((RigidBody*)this)->getA(A);
218 break;
219 default:
220 sprintf( painCave.errMsg,
221 "Unrecognized ObjType (%d) in StuntDouble::getA.\n",
222 objType );
223 painCave.isFatal = 1;
224 simError();
225 }
226 }
227
228 void StuntDouble::setA(double A[3][3]){
229 switch (objType)
230 {
231 case OT_ATOM:
232 sprintf( painCave.errMsg,
233 "StuntDouble::setA was called for a regular atom.\n"
234 "\tRegular Atoms don't have rotation matrices. Be smarter.\n");
235 painCave.isFatal = 1;
236 simError();
237 break;
238 case OT_DATOM:
239 ((DirectionalAtom*)this)->setA(A);
240 break;
241 case OT_RIGIDBODY:
242 ((RigidBody*)this)->setA(A);
243 break;
244 default:
245 sprintf( painCave.errMsg,
246 "Unrecognized ObjType (%d) in StuntDouble::setA.\n",
247 objType );
248 painCave.isFatal = 1;
249 simError();
250 }
251 }
252
253 void StuntDouble::getJ(double j[3]){
254 switch (objType)
255 {
256 case OT_ATOM:
257 sprintf( painCave.errMsg,
258 "StuntDouble::getJ was called for a regular atom.\n"
259 "\tRegular Atoms don't have angular momentum. Be smarter.\n");
260 painCave.isFatal = 0;
261 simError();
262 // Return zeros.
263 j[0] = 0;
264 j[1] = 0;
265 j[2] = 0;
266 break;
267 case OT_DATOM:
268 ((DirectionalAtom*)this)->getJ(j);
269 break;
270 case OT_RIGIDBODY:
271 ((RigidBody*)this)->getJ(j);
272 break;
273 default:
274 sprintf( painCave.errMsg,
275 "Unrecognized ObjType (%d) in StuntDouble::getJ.\n",
276 objType );
277 painCave.isFatal = 1;
278 simError();
279 }
280 }
281
282 void StuntDouble::setJ(double j[3]){
283 switch (objType)
284 {
285 case OT_ATOM:
286 sprintf( painCave.errMsg,
287 "StuntDouble::setJ was called for a regular atom.\n"
288 "\tRegular Atoms don't have angular momentum. Be smarter.\n");
289 painCave.isFatal = 1;
290 simError();
291 break;
292 case OT_DATOM:
293 ((DirectionalAtom*)this)->setJ(j);
294 break;
295 case OT_RIGIDBODY:
296 ((RigidBody*)this)->setJ(j);
297 break;
298 default:
299 sprintf( painCave.errMsg,
300 "Unrecognized ObjType (%d) in StuntDouble::setJ.\n",
301 objType );
302 painCave.isFatal = 1;
303 simError();
304 }
305 }
306
307 void StuntDouble::getQ(double q[4] ){
308 switch (objType)
309 {
310 case OT_ATOM:
311 sprintf( painCave.errMsg,
312 "StuntDouble::getJ was called for a regular atom.\n"
313 "\tRegular Atoms don't have angular momentum. Be smarter.\n");
314 painCave.isFatal = 0;
315 simError();
316 // Return zeros.
317 q[0] = 0;
318 q[1] = 0;
319 q[2] = 0;
320 q[3] = 0;
321 break;
322 case OT_DATOM:
323 ((DirectionalAtom*)this)->getQ(q);
324 break;
325 case OT_RIGIDBODY:
326 ((RigidBody*)this)->getQ(q);
327 break;
328 default:
329 sprintf( painCave.errMsg,
330 "Unrecognized ObjType (%d) in StuntDouble::getJ.\n",
331 objType );
332 painCave.isFatal = 1;
333 simError();
334 }
335 }
336
337 void StuntDouble::setQ(double q[4] ){
338 switch (objType)
339 {
340 case OT_ATOM:
341 sprintf( painCave.errMsg,
342 "StuntDouble::setJ was called for a regular atom.\n"
343 "\tRegular Atoms don't have angular momentum. Be smarter.\n");
344 painCave.isFatal = 1;
345 simError();
346 break;
347 case OT_DATOM:
348 ((DirectionalAtom*)this)->setJ(q);
349 break;
350 case OT_RIGIDBODY:
351 ((RigidBody*)this)->setJ(q);
352 break;
353 default:
354 sprintf( painCave.errMsg,
355 "Unrecognized ObjType (%d) in StuntDouble::setJ.\n",
356 objType );
357 painCave.isFatal = 1;
358 simError();
359 }
360 }
361 void StuntDouble::getTrq(double trq[3]){
362 switch (objType)
363 {
364 case OT_ATOM:
365 sprintf( painCave.errMsg,
366 "StuntDouble::getTrq was called for a regular atom.\n"
367 "\tRegular Atoms don't have torques. Be smarter.\n");
368 painCave.isFatal = 0;
369 simError();
370 // Return zeros.
371 trq[0] = 0;
372 trq[1] = 0;
373 trq[2] = 0;
374 break;
375 case OT_DATOM:
376 ((DirectionalAtom*)this)->getTrq(trq);
377 break;
378 case OT_RIGIDBODY:
379 ((RigidBody*)this)->getTrq(trq);
380 break;
381 default:
382 sprintf( painCave.errMsg,
383 "Unrecognized ObjType (%d) in StuntDouble::getTrq.\n",
384 objType );
385 painCave.isFatal = 1;
386 simError();
387 }
388 }
389
390 void StuntDouble::setTrq(double trq[3]){
391 switch (objType)
392 {
393 case OT_ATOM:
394 sprintf( painCave.errMsg,
395 "StuntDouble::setTrq was called for a regular atom.\n"
396 "\tRegular Atoms don't have torques. Be smarter.\n");
397 painCave.isFatal = 1;
398 simError();
399 break;
400 case OT_DATOM:
401 ((DirectionalAtom*)this)->setTrq(trq);
402 break;
403 case OT_RIGIDBODY:
404 ((RigidBody*)this)->setTrq(trq);
405 break;
406 default:
407 sprintf( painCave.errMsg,
408 "Unrecognized ObjType (%d) in StuntDouble::addTrq.\n",
409 objType );
410 painCave.isFatal = 1;
411 simError();
412 }
413 }
414
415 void StuntDouble::addTrq(double trq[3]){
416 switch (objType)
417 {
418 case OT_ATOM:
419 sprintf( painCave.errMsg,
420 "StuntDouble::addTrq was called for a regular atom.\n"
421 "\tRegular Atoms don't have torques. Be smarter.\n");
422 painCave.isFatal = 1;
423 simError();
424 break;
425 case OT_DATOM:
426 ((DirectionalAtom*)this)->addTrq(trq);
427 break;
428 case OT_RIGIDBODY:
429 ((RigidBody*)this)->addTrq(trq);
430 break;
431 default:
432 sprintf( painCave.errMsg,
433 "Unrecognized ObjType (%d) in StuntDouble::addTrq.\n",
434 objType );
435 painCave.isFatal = 1;
436 simError();
437 }
438 }
439
440 void StuntDouble::getI(double I[3][3]){
441 switch (objType)
442 {
443 case OT_ATOM:
444 sprintf( painCave.errMsg,
445 "StuntDouble::getI was called for a regular atom.\n"
446 "\tRegular Atoms don't have moments of inertia. Be smarter.\n");
447 painCave.isFatal = 0;
448 simError();
449 // Return zero matrix
450 I[0][0] = 0; I[0][1] = 0; I[0][2] = 0;
451 I[1][0] = 0; I[1][1] = 0; I[1][2] = 0;
452 I[2][0] = 0; I[2][1] = 0; I[2][2] = 0;
453 break;
454 case OT_DATOM:
455 ((DirectionalAtom*)this)->getI(I);
456 break;
457 case OT_RIGIDBODY:
458 ((RigidBody*)this)->getI(I);
459 break;
460 default:
461 sprintf( painCave.errMsg,
462 "Unrecognized ObjType (%d) in StuntDouble::getI.\n",
463 objType );
464 painCave.isFatal = 1;
465 simError();
466 }
467 }
468
469 void StuntDouble::lab2Body(double vec[3]){
470 switch (objType)
471 {
472 case OT_ATOM:
473 sprintf( painCave.errMsg,
474 "StuntDouble::lab2Body was called for a regular atom.\n"
475 "\tRegular Atoms don't have reference frames. Be smarter.\n");
476 painCave.isFatal = 0;
477 simError();
478 break;
479 case OT_DATOM:
480 ((DirectionalAtom*)this)->lab2Body(vec);
481 break;
482 case OT_RIGIDBODY:
483 ((RigidBody*)this)->lab2Body(vec);
484 break;
485 default:
486 sprintf( painCave.errMsg,
487 "Unrecognized ObjType (%d) in StuntDouble::lab2Body.\n",
488 objType );
489 painCave.isFatal = 1;
490 simError();
491 }
492 }
493
494 void StuntDouble::getGrad(double grad[6]){
495 double frc[3];
496
497 switch (objType)
498 {
499 case OT_ATOM:
500 sprintf( painCave.errMsg,
501 "StuntDouble::getGrad was called for a regular atom.\n"
502 "\tRegular Atoms don't have 6 coordinates. Be smarter.\n");
503 painCave.isFatal = 0;
504 simError();
505 ((Atom*)this)->getFrc(frc);
506 grad[0] = -frc[0];
507 grad[1] = -frc[1];
508 grad[2] = -frc[2];
509 grad[3] = 0.0;
510 grad[4] = 0.0;
511 grad[5] = 0.0;
512 break;
513 case OT_DATOM:
514 ((DirectionalAtom*)this)->getGrad(grad);
515 break;
516 case OT_RIGIDBODY:
517 ((RigidBody*)this)->getGrad(grad);
518 break;
519 default:
520 sprintf( painCave.errMsg,
521 "Unrecognized ObjType (%d) in StuntDouble::getGrad.\n",
522 objType );
523 painCave.isFatal = 1;
524 simError();
525 }
526 }
527
528 void StuntDouble::setEuler(double phi, double theta, double psi){
529 switch (objType)
530 {
531 case OT_ATOM:
532 sprintf( painCave.errMsg,
533 "StuntDouble::setEuler was called for a regular atom.\n"
534 "\tRegular Atoms don't have Euler Angles. Be smarter.\n");
535 painCave.isFatal = 1;
536 simError();
537 break;
538 case OT_DATOM:
539 ((DirectionalAtom*)this)->setEuler(phi, theta, psi);
540 break;
541 case OT_RIGIDBODY:
542 ((RigidBody*)this)->setEuler(phi, theta, psi);
543 break;
544 default:
545 sprintf( painCave.errMsg,
546 "Unrecognized ObjType (%d) in StuntDouble::setA.\n",
547 objType );
548 painCave.isFatal = 1;
549 simError();
550 }
551 }
552
553 void StuntDouble::getEulerAngles(double eulers[3]){
554 switch (objType)
555 {
556 case OT_ATOM:
557 sprintf( painCave.errMsg,
558 "StuntDouble::getEulerAngles was called for a regular atom.\n"
559 "\tRegular Atoms don't have Euler angles. Be smarter.\n");
560 painCave.isFatal = 0;
561 simError();
562 // Return zeros.
563 eulers[0] = 0;
564 eulers[1] = 0;
565 eulers[2] = 0;
566 break;
567 case OT_DATOM:
568 ((DirectionalAtom*)this)->getEulerAngles(eulers);
569 break;
570 case OT_RIGIDBODY:
571 ((RigidBody*)this)->getEulerAngles(eulers);
572 break;
573 default:
574 sprintf( painCave.errMsg,
575 "Unrecognized ObjType (%d) in StuntDouble::getEulerAngles.\n",
576 objType );
577 painCave.isFatal = 1;
578 simError();
579 }
580 }
581
582 double StuntDouble::getZangle(){
583 switch (objType)
584 {
585 case OT_ATOM:
586 sprintf( painCave.errMsg,
587 "StuntDouble::getZangle was called for a regular atom.\n"
588 "\tRegular Atoms don't have zAngles. Be smarter.\n");
589 painCave.isFatal = 0;
590 simError();
591 // Return zeros.
592 return 0;
593 break;
594 case OT_DATOM:
595 return ((DirectionalAtom*)this)->getZangle();
596 break;
597 case OT_RIGIDBODY:
598 return ((RigidBody*)this)->getZangle();
599 break;
600 default:
601 sprintf( painCave.errMsg,
602 "Unrecognized ObjType (%d) in StuntDouble::getZangle.\n",
603 objType );
604 painCave.isFatal = 1;
605 simError();
606 return 0;
607 }
608 }
609
610 void StuntDouble::setZangle(double zAngle){
611 switch (objType)
612 {
613 case OT_ATOM:
614 sprintf( painCave.errMsg,
615 "StuntDouble::setZangle was called for a regular atom.\n"
616 "\tRegular Atoms don't have zAngles. Be smarter.\n");
617 painCave.isFatal = 1;
618 simError();
619 break;
620 case OT_DATOM:
621 ((DirectionalAtom*)this)->setZangle(zAngle);
622 break;
623 case OT_RIGIDBODY:
624 ((RigidBody*)this)->setZangle(zAngle);
625 break;
626 default:
627 sprintf( painCave.errMsg,
628 "Unrecognized ObjType (%d) in StuntDouble::setZangle.\n",
629 objType );
630 painCave.isFatal = 1;
631 simError();
632 }
633 }
634
635 void StuntDouble::addZangle(double zAngle){
636 switch (objType)
637 {
638 case OT_ATOM:
639 sprintf( painCave.errMsg,
640 "StuntDouble::addZangle was called for a regular atom.\n"
641 "\tRegular Atoms don't have zAngles. Be smarter.\n");
642 painCave.isFatal = 1;
643 simError();
644 break;
645 case OT_DATOM:
646 ((DirectionalAtom*)this)->addZangle(zAngle);
647 break;
648 case OT_RIGIDBODY:
649 ((RigidBody*)this)->addZangle(zAngle);
650 break;
651 default:
652 sprintf( painCave.errMsg,
653 "Unrecognized ObjType (%d) in StuntDouble::addZangle.\n",
654 objType );
655 painCave.isFatal = 1;
656 simError();
657 }
658 }
659
660 void StuntDouble::addProperty(GenericData* data){
661 map<string, GenericData*>::iterator result;
662 result = properties.find(data->getID());
663
664 //we can't simply use properties[prop->getID()] = prop,
665 //it will cause memory leak if we already contain a propery which has the same name of prop
666
667 if(result != properties.end()){
668 delete (*result).second;
669 (*result).second = data;
670 }
671 else
672 properties[data->getID()] = data;
673
674
675 }
676 void StuntDouble::removeProperty(const string& propName){
677 map<string, GenericData*>::iterator result;
678
679 result = properties.find(propName);
680
681 if(result != properties.end()){
682 delete result->second;
683 properties.erase(result);
684
685 }
686
687 }
688 GenericData* StuntDouble::getProperty(const string& propName){
689 map<string, GenericData*>::iterator result;
690
691
692 result = properties.find(propName);
693
694 if(result != properties.end())
695 return (*result).second;
696 else
697 return NULL;
698 }

Properties

Name Value
svn:executable *