ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/StuntDouble.cpp
Revision: 1097
Committed: Mon Apr 12 20:32:20 2004 UTC (20 years, 2 months ago) by gezelter
File size: 12407 byte(s)
Log Message:
Changes for RigidBody dynamics (Somewhat extensive)

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     void StuntDouble::getTrq(double trq[3]){
277     switch (objType)
278     {
279     case OT_ATOM:
280     sprintf( painCave.errMsg,
281     "StuntDouble::getTrq was called for a regular atom.\n"
282     "\tRegular Atoms don't have torques. Be smarter.\n");
283     painCave.isFatal = 0;
284     simError();
285     // Return zeros.
286     trq[0] = 0;
287     trq[1] = 0;
288     trq[2] = 0;
289     break;
290     case OT_DATOM:
291     ((DirectionalAtom*)this)->getTrq(trq);
292     break;
293     case OT_RIGIDBODY:
294     ((RigidBody*)this)->getTrq(trq);
295     break;
296     default:
297     sprintf( painCave.errMsg,
298     "Unrecognized ObjType (%d) in StuntDouble::getTrq.\n",
299     objType );
300     painCave.isFatal = 1;
301     simError();
302     }
303     }
304    
305     void StuntDouble::addTrq(double trq[3]){
306     switch (objType)
307     {
308     case OT_ATOM:
309     sprintf( painCave.errMsg,
310     "StuntDouble::addTrq was called for a regular atom.\n"
311     "\tRegular Atoms don't have torques. Be smarter.\n");
312     painCave.isFatal = 1;
313     simError();
314     break;
315     case OT_DATOM:
316     ((DirectionalAtom*)this)->addTrq(trq);
317     break;
318     case OT_RIGIDBODY:
319     ((RigidBody*)this)->addTrq(trq);
320     break;
321     default:
322     sprintf( painCave.errMsg,
323     "Unrecognized ObjType (%d) in StuntDouble::addTrq.\n",
324     objType );
325     painCave.isFatal = 1;
326     simError();
327     }
328     }
329    
330     void StuntDouble::getI(double I[3][3]){
331     switch (objType)
332     {
333     case OT_ATOM:
334     sprintf( painCave.errMsg,
335     "StuntDouble::getI was called for a regular atom.\n"
336     "\tRegular Atoms don't have moments of inertia. Be smarter.\n");
337     painCave.isFatal = 0;
338     simError();
339     // Return zero matrix
340     I[0][0] = 0; I[0][1] = 0; I[0][2] = 0;
341     I[1][0] = 0; I[1][1] = 0; I[1][2] = 0;
342     I[2][0] = 0; I[2][1] = 0; I[2][2] = 0;
343     break;
344     case OT_DATOM:
345     ((DirectionalAtom*)this)->getI(I);
346     break;
347     case OT_RIGIDBODY:
348     ((RigidBody*)this)->getI(I);
349     break;
350     default:
351     sprintf( painCave.errMsg,
352     "Unrecognized ObjType (%d) in StuntDouble::getI.\n",
353     objType );
354     painCave.isFatal = 1;
355     simError();
356     }
357     }
358    
359     void StuntDouble::lab2Body(double vec[3]){
360     switch (objType)
361     {
362     case OT_ATOM:
363     sprintf( painCave.errMsg,
364     "StuntDouble::lab2Body was called for a regular atom.\n"
365     "\tRegular Atoms don't have reference frames. Be smarter.\n");
366     painCave.isFatal = 0;
367     simError();
368     break;
369     case OT_DATOM:
370     ((DirectionalAtom*)this)->lab2Body(vec);
371     break;
372     case OT_RIGIDBODY:
373     ((RigidBody*)this)->lab2Body(vec);
374     break;
375     default:
376     sprintf( painCave.errMsg,
377     "Unrecognized ObjType (%d) in StuntDouble::lab2Body.\n",
378     objType );
379     painCave.isFatal = 1;
380     simError();
381     }
382     }
383    
384     void StuntDouble::getGrad(double grad[6]){
385     double frc[3];
386    
387     switch (objType)
388     {
389     case OT_ATOM:
390     sprintf( painCave.errMsg,
391     "StuntDouble::getGrad was called for a regular atom.\n"
392     "\tRegular Atoms don't have 6 coordinates. Be smarter.\n");
393     painCave.isFatal = 0;
394     simError();
395     ((Atom*)this)->getFrc(frc);
396     grad[0] = -frc[0];
397     grad[1] = -frc[1];
398     grad[2] = -frc[2];
399     grad[3] = 0.0;
400     grad[4] = 0.0;
401     grad[5] = 0.0;
402     break;
403     case OT_DATOM:
404     ((DirectionalAtom*)this)->getGrad(grad);
405     break;
406     case OT_RIGIDBODY:
407     ((RigidBody*)this)->getGrad(grad);
408     break;
409     default:
410     sprintf( painCave.errMsg,
411     "Unrecognized ObjType (%d) in StuntDouble::getGrad.\n",
412     objType );
413     painCave.isFatal = 1;
414     simError();
415     }
416     }
417    
418     void StuntDouble::setEuler(double phi, double theta, double psi){
419     switch (objType)
420     {
421     case OT_ATOM:
422     sprintf( painCave.errMsg,
423     "StuntDouble::setEuler was called for a regular atom.\n"
424     "\tRegular Atoms don't have Euler Angles. Be smarter.\n");
425     painCave.isFatal = 1;
426     simError();
427     break;
428     case OT_DATOM:
429     ((DirectionalAtom*)this)->setEuler(phi, theta, psi);
430     break;
431     case OT_RIGIDBODY:
432     ((RigidBody*)this)->setEuler(phi, theta, psi);
433     break;
434     default:
435     sprintf( painCave.errMsg,
436     "Unrecognized ObjType (%d) in StuntDouble::setA.\n",
437     objType );
438     painCave.isFatal = 1;
439     simError();
440     }
441     }
442    
443     void StuntDouble::getEulerAngles(double eulers[3]){
444     switch (objType)
445     {
446     case OT_ATOM:
447     sprintf( painCave.errMsg,
448     "StuntDouble::getEulerAngles was called for a regular atom.\n"
449     "\tRegular Atoms don't have Euler angles. Be smarter.\n");
450     painCave.isFatal = 0;
451     simError();
452     // Return zeros.
453     eulers[0] = 0;
454     eulers[1] = 0;
455     eulers[2] = 0;
456     break;
457     case OT_DATOM:
458     ((DirectionalAtom*)this)->getEulerAngles(eulers);
459     break;
460     case OT_RIGIDBODY:
461     ((RigidBody*)this)->getEulerAngles(eulers);
462     break;
463     default:
464     sprintf( painCave.errMsg,
465     "Unrecognized ObjType (%d) in StuntDouble::getEulerAngles.\n",
466     objType );
467     painCave.isFatal = 1;
468     simError();
469     }
470     }

Properties

Name Value
svn:executable *