ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/StuntDouble.cpp
Revision: 1187
Committed: Sat May 22 18:16:18 2004 UTC (20 years, 3 months ago) by chrisfen
File size: 16835 byte(s)
Log Message:
Fixed Thermodynamic integration code.

File Contents

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

Properties

Name Value
svn:executable *