ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/primitives/StuntDouble.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/primitives/StuntDouble.cpp (file contents):
Revision 1691, Thu Oct 28 22:34:02 2004 UTC vs.
Revision 1692 by tim, Mon Nov 1 20:15:58 2004 UTC

# Line 1 | Line 1
1 < #include "primitives/StuntDouble.hpp"
2 < #include "primitives/Atom.hpp"
3 < #include "primitives/DirectionalAtom.hpp"
4 < #include "primitives/RigidBody.hpp"
5 < #include "utils/simError.h"
1 > /*
2 > * Copyright (C) 2000-2004  Object Oriented Parallel Simulation Engine (OOPSE) project
3 > *
4 > * Contact: oopse@oopse.org
5 > *
6 > * This program is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public License
8 > * as published by the Free Software Foundation; either version 2.1
9 > * of the License, or (at your option) any later version.
10 > * All we ask is that proper credit is given for our work, which includes
11 > * - but is not limited to - adding the above copyright notice to the beginning
12 > * of your source code files, and to any copyright notice that you may distribute
13 > * with programs based on this work.
14 > *
15 > * This program is distributed in the hope that it will be useful,
16 > * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 > * GNU Lesser General Public License for more details.
19 > *
20 > * You should have received a copy of the GNU Lesser General Public License
21 > * along with this program; if not, write to the Free Software
22 > * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 > *
24 > */
25  
26 < /*  
27 <        "Don't move, or you're dead! Stand up! Captain, we've got them!"
28 <    
29 <        "Spectacular stunt, my friends, but all for naught. Turn around
30 <         please. Ha. What a pity. What a pity. So, Princess, you thought
31 <         you could outwit the imperious forces of...."
26 > /**
27 > * @file StuntDouble.cpp
28 > * @author    tlin
29 > * @date  10/22/2004
30 > * @version 1.0
31 > */
32  
33 <        "You idiots! These are not them. You've captured their stunt
15 <         doubles! Search the area. Find them! Find them!"
33 > #include "primitives/StuntDouble.hpp"
34  
35 <      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...)
35 > namespace oopse {
36  
37 < */
38 <
39 < 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 <    
37 > StuntDouble::StuntDouble(ObjectType objType, DataStoragePointer storage) :
38 >    objType_(objType), storage_(storage),    
39 >    linear_(false), linearAxis_(-1), globalIndex_(-1), localIndex_(-1), snapshotMan_(NULL){
40   }
41  
42 < int StuntDouble::getObjType(){
39 <  return objType;
40 < }
42 > StuntDouble::~StuntDouble() {
43  
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    }
44   }
45  
46 <
47 < 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 <    }  
46 > void StuntDouble::zeroForces() {
47 >    setFrc(V3Zero);
48   }
49 <
50 < 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 <    }  
49 > void StuntDouble::addProperty(GenericData* genData) {
50 >    properties_.addProperty(genData);  
51   }
52  
53 < void StuntDouble::getFrc(double frc[3]){
54 <  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 <    }  
53 > void StuntDouble::removeProperty(std::string& propName) {
54 >    properties_.removeProperty(propName);  
55   }
56  
57 <
58 < 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 <    }  
57 > void StuntDouble::clearProperties() {
58 >    properties_.clearProperties();
59   }
60  
61 < void StuntDouble::setVel(double vel[3]){
62 <
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 <    }  
61 > std::vector<std::string> StuntDouble::getPropertyNames() {
62 >    return properties_.getPropertyNames();  
63   }
64 <
65 < void StuntDouble::addFrc(double frc[3]){
66 <  switch (objType)
162 <    {
163 <    case OT_ATOM :
164 <    case OT_DATOM:      
165 <      ((Atom*)this)->addFrc(frc);
166 <      break;
167 <    case OT_RIGIDBODY:
168 <      ((RigidBody*)this)->addFrc(frc);
169 <      break;      
170 <    default:
171 <      sprintf( painCave.errMsg,
172 <               "Unrecognized ObjType (%d) in StuntDouble::addFrc.\n",
173 <               objType );
174 <      painCave.isFatal = 1;
175 <      simError();    
176 <    }  
177 < }
178 <
179 < void StuntDouble::getA(double A[3][3]){
180 <  switch (objType)
181 <    {
182 <    case OT_ATOM:
183 <      sprintf( painCave.errMsg,
184 <               "StuntDouble::getA was called for a regular atom.\n"
185 <               "\tRegular Atoms don't have rotation matrices.  Be smarter.\n");
186 <      painCave.isFatal = 0;
187 <      simError();
188 <      // Return unit matrix
189 <      A[0][0] = 1;  A[0][1] = 0;  A[0][2] = 0;
190 <      A[1][0] = 0;  A[1][1] = 1;  A[1][2] = 0;
191 <      A[2][0] = 0;  A[2][1] = 0;  A[2][2] = 1;
192 <      break;
193 <    case OT_DATOM:
194 <      ((DirectionalAtom*)this)->getA(A);
195 <    break;
196 <    case OT_RIGIDBODY:
197 <      ((RigidBody*)this)->getA(A);
198 <    break;
199 <    default:
200 <      sprintf( painCave.errMsg,
201 <               "Unrecognized ObjType (%d) in StuntDouble::getA.\n",
202 <               objType );
203 <      painCave.isFatal = 1;
204 <      simError();    
205 <  }
206 < }
207 <
208 < void StuntDouble::setA(double A[3][3]){
209 <  switch (objType)
210 <    {
211 <    case OT_ATOM:
212 <      sprintf( painCave.errMsg,
213 <               "StuntDouble::setA was called for a regular atom.\n"
214 <               "\tRegular Atoms don't have rotation matrices.  Be smarter.\n");
215 <      painCave.isFatal = 1;
216 <      simError();
217 <      break;
218 <    case OT_DATOM:
219 <      ((DirectionalAtom*)this)->setA(A);
220 <    break;
221 <    case OT_RIGIDBODY:
222 <      ((RigidBody*)this)->setA(A);
223 <    break;
224 <    default:
225 <      sprintf( painCave.errMsg,
226 <               "Unrecognized ObjType (%d) in StuntDouble::setA.\n",
227 <               objType );
228 <      painCave.isFatal = 1;
229 <      simError();    
230 <    }
231 < }
232 <
233 < void StuntDouble::getJ(double j[3]){
234 <  switch (objType)
235 <    {
236 <    case OT_ATOM:
237 <      sprintf( painCave.errMsg,
238 <               "StuntDouble::getJ was called for a regular atom.\n"
239 <               "\tRegular Atoms don't have angular momentum.  Be smarter.\n");
240 <      painCave.isFatal = 0;
241 <      simError();
242 <      // Return zeros.
243 <      j[0] = 0;
244 <      j[1] = 0;
245 <      j[2] = 0;
246 <      break;
247 <    case OT_DATOM:
248 <      ((DirectionalAtom*)this)->getJ(j);
249 <    break;
250 <    case OT_RIGIDBODY:
251 <      ((RigidBody*)this)->getJ(j);
252 <    break;
253 <    default:
254 <      sprintf( painCave.errMsg,
255 <               "Unrecognized ObjType (%d) in StuntDouble::getJ.\n",
256 <               objType );
257 <      painCave.isFatal = 1;
258 <      simError();    
259 <  }
260 < }
261 <
262 < void StuntDouble::setJ(double j[3]){
263 <  switch (objType)
264 <    {
265 <    case OT_ATOM:
266 <      sprintf( painCave.errMsg,
267 <               "StuntDouble::setJ was called for a regular atom.\n"
268 <               "\tRegular Atoms don't have angular momentum.  Be smarter.\n");
269 <      painCave.isFatal = 1;
270 <      simError();
271 <      break;
272 <    case OT_DATOM:
273 <      ((DirectionalAtom*)this)->setJ(j);
274 <    break;
275 <    case OT_RIGIDBODY:
276 <      ((RigidBody*)this)->setJ(j);
277 <    break;
278 <    default:
279 <      sprintf( painCave.errMsg,
280 <               "Unrecognized ObjType (%d) in StuntDouble::setJ.\n",
281 <               objType );
282 <      painCave.isFatal = 1;
283 <      simError();    
284 <    }
285 < }
286 <
287 < void StuntDouble::getQ(double q[4] ){
288 <  switch (objType)
289 <    {
290 <    case OT_ATOM:
291 <      sprintf( painCave.errMsg,
292 <               "StuntDouble::getJ was called for a regular atom.\n"
293 <               "\tRegular Atoms don't have angular momentum.  Be smarter.\n");
294 <      painCave.isFatal = 0;
295 <      simError();
296 <      // Return zeros.
297 <      q[0] = 0;
298 <      q[1] = 0;
299 <      q[2] = 0;
300 <      q[3] = 0;
301 <      break;
302 <    case OT_DATOM:
303 <      ((DirectionalAtom*)this)->getQ(q);
304 <    break;
305 <    case OT_RIGIDBODY:
306 <      ((RigidBody*)this)->getQ(q);
307 <    break;
308 <    default:
309 <      sprintf( painCave.errMsg,
310 <               "Unrecognized ObjType (%d) in StuntDouble::getJ.\n",
311 <               objType );
312 <      painCave.isFatal = 1;
313 <      simError();    
314 <  }
64 >      
65 > std::vector<GenericData*> StuntDouble::getProperties() {
66 >    return properties_.getProperties();
67   }
68  
69 < void StuntDouble::setQ(double q[4] ){
70 <  switch (objType)
319 <    {
320 <    case OT_ATOM:
321 <      sprintf( painCave.errMsg,
322 <               "StuntDouble::setJ was called for a regular atom.\n"
323 <               "\tRegular Atoms don't have angular momentum.  Be smarter.\n");
324 <      painCave.isFatal = 1;
325 <      simError();
326 <      break;
327 <    case OT_DATOM:
328 <      ((DirectionalAtom*)this)->setJ(q);
329 <    break;
330 <    case OT_RIGIDBODY:
331 <      ((RigidBody*)this)->setJ(q);
332 <    break;
333 <    default:
334 <      sprintf( painCave.errMsg,
335 <               "Unrecognized ObjType (%d) in StuntDouble::setJ.\n",
336 <               objType );
337 <      painCave.isFatal = 1;
338 <      simError();    
339 <    }
69 > GenericData* StuntDouble::getPropertyByName(std::string& propName) {
70 >    return properties_.getPropertyByName(propName);
71   }
341 void StuntDouble::getTrq(double trq[3]){
342  switch (objType)
343    {
344    case OT_ATOM:
345      sprintf( painCave.errMsg,
346               "StuntDouble::getTrq was called for a regular atom.\n"
347               "\tRegular Atoms don't have torques.  Be smarter.\n");
348      painCave.isFatal = 0;
349      simError();
350      // Return zeros.
351      trq[0] = 0;
352      trq[1] = 0;
353      trq[2] = 0;
354      break;
355    case OT_DATOM:
356      ((DirectionalAtom*)this)->getTrq(trq);
357    break;
358    case OT_RIGIDBODY:
359      ((RigidBody*)this)->getTrq(trq);
360    break;
361    default:
362      sprintf( painCave.errMsg,
363               "Unrecognized ObjType (%d) in StuntDouble::getTrq.\n",
364               objType );
365      painCave.isFatal = 1;
366      simError();    
367  }
368 }
72  
370 void StuntDouble::addTrq(double trq[3]){
371  switch (objType)
372    {
373    case OT_ATOM:
374      sprintf( painCave.errMsg,
375               "StuntDouble::addTrq was called for a regular atom.\n"
376               "\tRegular Atoms don't have torques.  Be smarter.\n");
377      painCave.isFatal = 1;
378      simError();
379      break;
380    case OT_DATOM:
381      ((DirectionalAtom*)this)->addTrq(trq);
382    break;
383    case OT_RIGIDBODY:
384      ((RigidBody*)this)->addTrq(trq);
385    break;
386    default:
387      sprintf( painCave.errMsg,
388               "Unrecognized ObjType (%d) in StuntDouble::addTrq.\n",
389               objType );
390      painCave.isFatal = 1;
391      simError();    
392    }
393 }
73  
395 void StuntDouble::getI(double I[3][3]){
396  switch (objType)
397    {
398    case OT_ATOM:
399      sprintf( painCave.errMsg,
400               "StuntDouble::getI was called for a regular atom.\n"
401               "\tRegular Atoms don't have moments of inertia.  Be smarter.\n");
402      painCave.isFatal = 0;
403      simError();
404      // Return zero matrix
405      I[0][0] = 0;  I[0][1] = 0;  I[0][2] = 0;
406      I[1][0] = 0;  I[1][1] = 0;  I[1][2] = 0;
407      I[2][0] = 0;  I[2][1] = 0;  I[2][2] = 0;
408      break;
409    case OT_DATOM:
410      ((DirectionalAtom*)this)->getI(I);
411    break;
412    case OT_RIGIDBODY:
413      ((RigidBody*)this)->getI(I);
414    break;
415    default:
416      sprintf( painCave.errMsg,
417               "Unrecognized ObjType (%d) in StuntDouble::getI.\n",
418               objType );
419      painCave.isFatal = 1;
420      simError();    
421  }
74   }
423
424 void StuntDouble::lab2Body(double vec[3]){
425  switch (objType)
426    {
427    case OT_ATOM:
428      sprintf( painCave.errMsg,
429               "StuntDouble::lab2Body was called for a regular atom.\n"
430               "\tRegular Atoms don't have reference frames.  Be smarter.\n");
431      painCave.isFatal = 0;
432      simError();
433      break;
434    case OT_DATOM:
435      ((DirectionalAtom*)this)->lab2Body(vec);
436    break;
437    case OT_RIGIDBODY:
438      ((RigidBody*)this)->lab2Body(vec);
439    break;
440    default:
441      sprintf( painCave.errMsg,
442               "Unrecognized ObjType (%d) in StuntDouble::lab2Body.\n",
443               objType );
444      painCave.isFatal = 1;
445      simError();    
446  }
447 }
448
449 void StuntDouble::getGrad(double grad[6]){
450  double frc[3];
451
452  switch (objType)
453    {
454    case OT_ATOM:
455      sprintf( painCave.errMsg,
456               "StuntDouble::getGrad was called for a regular atom.\n"
457               "\tRegular Atoms don't have 6 coordinates.  Be smarter.\n");
458      painCave.isFatal = 0;
459      simError();
460      ((Atom*)this)->getFrc(frc);
461      grad[0] = -frc[0];
462      grad[1] = -frc[1];
463      grad[2] = -frc[2];
464      grad[3] = 0.0;
465      grad[4] = 0.0;
466      grad[5] = 0.0;
467      break;
468    case OT_DATOM:
469      ((DirectionalAtom*)this)->getGrad(grad);
470    break;
471    case OT_RIGIDBODY:
472      ((RigidBody*)this)->getGrad(grad);
473    break;
474    default:
475      sprintf( painCave.errMsg,
476               "Unrecognized ObjType (%d) in StuntDouble::getGrad.\n",
477               objType );
478      painCave.isFatal = 1;
479      simError();    
480  }
481 }
482
483 void StuntDouble::setEuler(double phi, double theta, double psi){
484  switch (objType)
485    {
486    case OT_ATOM:
487      sprintf( painCave.errMsg,
488               "StuntDouble::setEuler was called for a regular atom.\n"
489               "\tRegular Atoms don't have Euler Angles.  Be smarter.\n");
490      painCave.isFatal = 1;
491      simError();
492      break;
493    case OT_DATOM:
494      ((DirectionalAtom*)this)->setEuler(phi, theta, psi);
495    break;
496    case OT_RIGIDBODY:
497      ((RigidBody*)this)->setEuler(phi, theta, psi);
498    break;
499    default:
500      sprintf( painCave.errMsg,
501               "Unrecognized ObjType (%d) in StuntDouble::setA.\n",
502               objType );
503      painCave.isFatal = 1;
504      simError();    
505    }
506 }
507
508 void StuntDouble::getEulerAngles(double eulers[3]){
509  switch (objType)
510    {
511    case OT_ATOM:
512      sprintf( painCave.errMsg,
513               "StuntDouble::getEulerAngles was called for a regular atom.\n"
514               "\tRegular Atoms don't have Euler angles.  Be smarter.\n");
515      painCave.isFatal = 0;
516      simError();
517      // Return zeros.
518      eulers[0] = 0;
519      eulers[1] = 0;
520      eulers[2] = 0;
521      break;
522    case OT_DATOM:
523      ((DirectionalAtom*)this)->getEulerAngles(eulers);
524    break;
525    case OT_RIGIDBODY:
526      ((RigidBody*)this)->getEulerAngles(eulers);
527    break;
528    default:
529      sprintf( painCave.errMsg,
530               "Unrecognized ObjType (%d) in StuntDouble::getEulerAngles.\n",
531               objType );
532      painCave.isFatal = 1;
533      simError();    
534  }
535 }
536
537 double StuntDouble::getZangle(){
538  switch (objType)
539    {
540    case OT_ATOM:
541      sprintf( painCave.errMsg,
542               "StuntDouble::getZangle was called for a regular atom.\n"
543               "\tRegular Atoms don't have zAngles.  Be smarter.\n");
544      painCave.isFatal = 0;
545      simError();
546      // Return zeros.
547      return 0;
548      break;
549    case OT_DATOM:
550      return ((DirectionalAtom*)this)->getZangle();
551    break;
552    case OT_RIGIDBODY:
553      return ((RigidBody*)this)->getZangle();
554    break;
555    default:
556      sprintf( painCave.errMsg,
557               "Unrecognized ObjType (%d) in StuntDouble::getZangle.\n",
558               objType );
559      painCave.isFatal = 1;
560      simError();    
561      return 0;
562  }
563 }
564
565 void StuntDouble::setZangle(double zAngle){
566  switch (objType)
567    {
568    case OT_ATOM:
569      sprintf( painCave.errMsg,
570               "StuntDouble::setZangle was called for a regular atom.\n"
571               "\tRegular Atoms don't have zAngles.  Be smarter.\n");
572      painCave.isFatal = 1;
573      simError();
574      break;
575    case OT_DATOM:
576      ((DirectionalAtom*)this)->setZangle(zAngle);
577    break;
578    case OT_RIGIDBODY:
579      ((RigidBody*)this)->setZangle(zAngle);
580    break;
581    default:
582      sprintf( painCave.errMsg,
583               "Unrecognized ObjType (%d) in StuntDouble::setZangle.\n",
584               objType );
585      painCave.isFatal = 1;
586      simError();    
587    }
588 }
589
590 void StuntDouble::addZangle(double zAngle){
591  switch (objType)
592    {
593    case OT_ATOM:
594      sprintf( painCave.errMsg,
595               "StuntDouble::addZangle was called for a regular atom.\n"
596               "\tRegular Atoms don't have zAngles.  Be smarter.\n");
597      painCave.isFatal = 1;
598      simError();
599      break;
600    case OT_DATOM:
601      ((DirectionalAtom*)this)->addZangle(zAngle);
602    break;
603    case OT_RIGIDBODY:
604      ((RigidBody*)this)->addZangle(zAngle);
605    break;
606    default:
607      sprintf( painCave.errMsg,
608               "Unrecognized ObjType (%d) in StuntDouble::addZangle.\n",
609               objType );
610      painCave.isFatal = 1;
611      simError();    
612    }
613 }
614
615 void StuntDouble::addProperty(GenericData* data){
616  map<string, GenericData*>::iterator result;
617  result = properties.find(data->getID());
618  
619  //we can't simply use  properties[prop->getID()] = prop,
620  //it will cause memory leak if we already contain a propery which has the same name of prop
621  
622  if(result != properties.end()){
623    delete (*result).second;
624    (*result).second = data;      
625  }
626  else
627    properties[data->getID()] = data;
628
629  
630 }
631 void StuntDouble::removeProperty(const string& propName){
632  map<string, GenericData*>::iterator result;
633    
634  result = properties.find(propName);
635  
636  if(result != properties.end()){
637    delete result->second;
638    properties.erase(result);
639    
640  }
641  
642 }
643 GenericData* StuntDouble::getProperty(const string& propName){
644  map<string, GenericData*>::iterator result;
645  
646  
647  result = properties.find(propName);
648  
649  if(result != properties.end())
650    return (*result).second;  
651  else  
652    return NULL;    
653 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines