ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/StuntDouble.cpp
Revision: 1118
Committed: Mon Apr 19 03:52:27 2004 UTC (20 years, 2 months ago) by tim
File size: 14733 byte(s)
Log Message:
new implement of quickLate using visitor and composite pattern

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 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::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 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
526 void StuntDouble::addProperty(GenericData* data){
527 map<string, GenericData*>::iterator result;
528 result = properties.find(data->getID());
529
530 //we can't simply use properties[prop->getID()] = prop,
531 //it will cause memory leak if we already contain a propery which has the same name of prop
532
533 if(result != properties.end()){
534 delete (*result).second;
535 (*result).second = data;
536 }
537 else
538 properties[data->getID()] = data;
539
540
541 }
542 void StuntDouble::removeProperty(const string& propName){
543 map<string, GenericData*>::iterator result;
544
545 result = properties.find(propName);
546
547 if(result != properties.end())
548 properties.erase(result);
549
550 }
551 GenericData* StuntDouble::getProperty(const string& propName){
552 map<string, GenericData*>::iterator result;
553
554
555 result = properties.find(propName);
556
557 if(result != properties.end())
558 return (*result).second;
559 else
560 return NULL;
561 }

Properties

Name Value
svn:executable *