1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include "MakeStamps.hpp" |
6 |
#include "MoleculeStamp.hpp" |
7 |
#include "RigidBodyStamp.hpp" |
8 |
#include "simError.h" |
9 |
#ifdef IS_MPI |
10 |
#include "mpiBASS.h" |
11 |
#endif // is_mpi |
12 |
|
13 |
LinkedMolStamp::~LinkedMolStamp(){ |
14 |
if( mol_stamp != NULL ) delete mol_stamp; |
15 |
if( next != NULL ) delete next; |
16 |
} |
17 |
|
18 |
void LinkedMolStamp::add( LinkedMolStamp* newbie ){ |
19 |
|
20 |
if( next != NULL ) next->add( newbie ); |
21 |
else{ |
22 |
next = newbie; |
23 |
next->setPrev( this ); |
24 |
} |
25 |
} |
26 |
|
27 |
MoleculeStamp* LinkedMolStamp::match( char* id ){ |
28 |
|
29 |
if( mol_stamp != NULL ){ |
30 |
if(!strcmp( mol_stamp->getID(), id )){ |
31 |
|
32 |
// make sure we aren't hiding somebody else with the same name |
33 |
if(next != NULL ){ |
34 |
if( next->match( id ) != NULL){ |
35 |
sprintf( painCave.errMsg, |
36 |
"Molecule Stamp Error. Two separate of declarations of " |
37 |
"%s present.\n", |
38 |
id ); |
39 |
painCave.isFatal = 1; |
40 |
simError(); |
41 |
#ifdef IS_MPI |
42 |
if( painCave.isEventLoop ){ |
43 |
if( worldRank == 0 ) mpiInterfaceExit(); |
44 |
} |
45 |
#endif //is_mpi |
46 |
} |
47 |
else return mol_stamp; |
48 |
} |
49 |
else return mol_stamp; |
50 |
} |
51 |
} |
52 |
|
53 |
if( next != NULL ) return next->match( id ); |
54 |
|
55 |
return NULL; |
56 |
} |
57 |
|
58 |
LinkedMolStamp* LinkedMolStamp::extract( char* id ){ |
59 |
|
60 |
if( mol_stamp != NULL ){ |
61 |
if(!strcmp( mol_stamp->getID(), id )){ |
62 |
|
63 |
// make sure we aren't hiding somebody else with the same name |
64 |
if(next != NULL ){ |
65 |
if( next->match( id ) != NULL){ |
66 |
sprintf( painCave.errMsg, |
67 |
"Molecule Stamp Error. Two separate of declarations of " |
68 |
"%s present.\n", |
69 |
id ); |
70 |
painCave.isFatal = 1; |
71 |
simError(); |
72 |
#ifdef IS_MPI |
73 |
if( painCave.isEventLoop ){ |
74 |
if( worldRank == 0 ) mpiInterfaceExit(); |
75 |
} |
76 |
#endif //is_mpi |
77 |
} |
78 |
} |
79 |
|
80 |
prev->setNext( next ); |
81 |
if( next != NULL ) next->setPrev( prev ); |
82 |
return this; |
83 |
} |
84 |
} |
85 |
|
86 |
if( next != NULL ) return next->extract( id ); |
87 |
|
88 |
return NULL; |
89 |
} |
90 |
|
91 |
MakeStamps::MakeStamps(){ |
92 |
|
93 |
int i; |
94 |
|
95 |
hash_size = 47; |
96 |
hash_shift = 4; |
97 |
|
98 |
my_mols = new LinkedMolStamp*[hash_size]; |
99 |
for( i=0; i<hash_size; i++ ){ |
100 |
my_mols[i] = new LinkedMolStamp(); |
101 |
} |
102 |
|
103 |
} |
104 |
|
105 |
MakeStamps::~MakeStamps(){ |
106 |
|
107 |
int i; |
108 |
|
109 |
for( i=0; i<hash_size; i++ ){ |
110 |
if( my_mols[i] != NULL ) delete my_mols[i]; |
111 |
} |
112 |
delete[] my_mols; |
113 |
} |
114 |
|
115 |
int MakeStamps::hash( char* text ){ |
116 |
|
117 |
register unsigned short int i = 0; // loop counter |
118 |
int key = 0; // the hash key |
119 |
|
120 |
while( text[i] != '\0' ){ |
121 |
|
122 |
key = ( ( key << hash_shift ) + text[i] ) % hash_size; |
123 |
|
124 |
i++; |
125 |
} |
126 |
|
127 |
if( key < 0 ){ |
128 |
|
129 |
// if the key is less than zero, we've had an overflow error |
130 |
|
131 |
sprintf( painCave.errMsg, |
132 |
"There has been an overflow error in the MakeStamps hash key."); |
133 |
painCave.isFatal = 1; |
134 |
simError(); |
135 |
#ifdef IS_MPI |
136 |
if( painCave.isEventLoop ){ |
137 |
if( worldRank == 0 ) mpiInterfaceExit(); |
138 |
} |
139 |
#endif //is_mpi |
140 |
} |
141 |
|
142 |
return key; |
143 |
} |
144 |
|
145 |
LinkedMolStamp* MakeStamps::extractMolStamp( char* the_id ){ |
146 |
int key; |
147 |
|
148 |
key = hash( the_id ); |
149 |
if( my_mols[key] != NULL ){ |
150 |
return my_mols[key]->extract( the_id ); |
151 |
} |
152 |
|
153 |
return NULL; |
154 |
} |
155 |
|
156 |
void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){ |
157 |
|
158 |
int key; |
159 |
LinkedMolStamp* linked_mol; |
160 |
|
161 |
key = hash( the_stamp->getID() ); |
162 |
|
163 |
linked_mol = new LinkedMolStamp; |
164 |
linked_mol->setStamp( the_stamp ); |
165 |
|
166 |
my_mols[key]->add( linked_mol ); |
167 |
|
168 |
} |
169 |
|
170 |
|
171 |
int MakeStamps::newMolecule( event* the_event ){ |
172 |
|
173 |
current_mol = new MoleculeStamp; |
174 |
return 1; |
175 |
} |
176 |
|
177 |
int MakeStamps::moleculeAssign( event* the_event ){ |
178 |
|
179 |
switch( the_event->evt.asmt.asmt_type ){ |
180 |
|
181 |
case STRING: |
182 |
the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs, |
183 |
the_event->evt.asmt.rhs.sval ); |
184 |
break; |
185 |
|
186 |
case DOUBLE: |
187 |
the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs, |
188 |
the_event->evt.asmt.rhs.dval ); |
189 |
break; |
190 |
|
191 |
case INT: |
192 |
the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs, |
193 |
the_event->evt.asmt.rhs.ival ); |
194 |
break; |
195 |
|
196 |
default: |
197 |
the_event->err_msg = strdup( "MakeStamp error. Invalid molecule" |
198 |
" assignment type" ); |
199 |
return 0; |
200 |
break; |
201 |
} |
202 |
if( the_event->err_msg != NULL ) return 0; |
203 |
return 1; |
204 |
} |
205 |
|
206 |
int MakeStamps::moleculeEnd( event* the_event ){ |
207 |
|
208 |
the_event->err_msg = current_mol->checkMe(); |
209 |
// if err_msg is set, then something is wrong |
210 |
if( the_event->err_msg != NULL ) return 0; |
211 |
|
212 |
addMolStamp( current_mol ); |
213 |
return 1; |
214 |
} |
215 |
|
216 |
int MakeStamps::newRigidBody( event* the_event ){ |
217 |
|
218 |
current_rigidbody = new RigidBodyStamp; |
219 |
|
220 |
the_event->err_msg = current_mol->addRigidBody( current_rigidbody, |
221 |
the_event->evt.blk_index ); |
222 |
if( the_event->err_msg != NULL ) return 0; |
223 |
return 1; |
224 |
} |
225 |
|
226 |
int MakeStamps::rigidBodyAssign( event* the_event ){ |
227 |
|
228 |
switch( the_event->evt.asmt.asmt_type ){ |
229 |
|
230 |
case STRING: |
231 |
the_event->err_msg = |
232 |
current_rigidbody->assignString( the_event->evt.asmt.lhs, |
233 |
the_event->evt.asmt.rhs.sval ); |
234 |
if( the_event->err_msg != NULL ) return 0; |
235 |
return 1; |
236 |
break; |
237 |
|
238 |
case DOUBLE: |
239 |
the_event->err_msg = |
240 |
current_rigidbody->assignDouble( the_event->evt.asmt.lhs, |
241 |
the_event->evt.asmt.rhs.dval ); |
242 |
if( the_event->err_msg != NULL ) return 0; |
243 |
return 1; |
244 |
break; |
245 |
|
246 |
case INT: |
247 |
the_event->err_msg = |
248 |
current_rigidbody->assignInt( the_event->evt.asmt.lhs, |
249 |
the_event->evt.asmt.rhs.ival ); |
250 |
if( the_event->err_msg != NULL ) return 0; |
251 |
return 1; |
252 |
break; |
253 |
|
254 |
default: |
255 |
the_event->err_msg = strdup( "MakeStamp error. Invalid rigidBody" |
256 |
" assignment type" ); |
257 |
return 0; |
258 |
break; |
259 |
} |
260 |
return 0; |
261 |
} |
262 |
|
263 |
int MakeStamps::rigidBodyMember( event* the_event ){ |
264 |
|
265 |
current_member = new MemberStamp; |
266 |
|
267 |
the_event->err_msg = current_rigidbody->addMember( current_member, |
268 |
the_event->evt.blk_index ); |
269 |
|
270 |
if( the_event->err_msg != NULL ) return 0; |
271 |
return 1; |
272 |
|
273 |
} |
274 |
|
275 |
int MakeStamps::rigidBodyEnd( event* the_event ){ |
276 |
|
277 |
the_event->err_msg = current_rigidbody->checkMe(); |
278 |
if( the_event->err_msg != NULL ) return 0; |
279 |
|
280 |
return 1; |
281 |
} |
282 |
|
283 |
int MakeStamps::newAtom( event* the_event ){ |
284 |
|
285 |
current_atom = new AtomStamp; |
286 |
|
287 |
the_event->err_msg = current_mol->addAtom( current_atom, |
288 |
the_event->evt.blk_index ); |
289 |
|
290 |
if( the_event->err_msg != NULL ) return 0; |
291 |
return 1; |
292 |
} |
293 |
|
294 |
int MakeStamps::atomPosition( event* the_event ){ |
295 |
|
296 |
current_atom->setPosition( the_event->evt.pos.x, |
297 |
the_event->evt.pos.y, |
298 |
the_event->evt.pos.z ); |
299 |
return 1; |
300 |
} |
301 |
|
302 |
|
303 |
int MakeStamps::atomOrientation( event* the_event ){ |
304 |
|
305 |
current_atom->setOrientation( the_event->evt.ornt.x, |
306 |
the_event->evt.ornt.y, |
307 |
the_event->evt.ornt.z ); |
308 |
return 1; |
309 |
} |
310 |
|
311 |
int MakeStamps::atomAssign( event* the_event ){ |
312 |
|
313 |
switch( the_event->evt.asmt.asmt_type ){ |
314 |
|
315 |
case STRING: |
316 |
the_event->err_msg = |
317 |
current_atom->assignString( the_event->evt.asmt.lhs, |
318 |
the_event->evt.asmt.rhs.sval ); |
319 |
if( the_event->err_msg != NULL ) return 0; |
320 |
return 1; |
321 |
break; |
322 |
|
323 |
case DOUBLE: |
324 |
the_event->err_msg = |
325 |
current_atom->assignDouble( the_event->evt.asmt.lhs, |
326 |
the_event->evt.asmt.rhs.dval ); |
327 |
if( the_event->err_msg != NULL ) return 0; |
328 |
return 1; |
329 |
break; |
330 |
|
331 |
case INT: |
332 |
the_event->err_msg = |
333 |
current_atom->assignInt( the_event->evt.asmt.lhs, |
334 |
the_event->evt.asmt.rhs.ival ); |
335 |
if( the_event->err_msg != NULL ) return 0; |
336 |
return 1; |
337 |
break; |
338 |
|
339 |
default: |
340 |
the_event->err_msg = strdup( "MakeStamp error. Invalid atom" |
341 |
" assignment type" ); |
342 |
return 0; |
343 |
break; |
344 |
} |
345 |
return 0; |
346 |
} |
347 |
|
348 |
int MakeStamps::atomEnd( event* the_event ){ |
349 |
|
350 |
the_event->err_msg = current_atom->checkMe(); |
351 |
if( the_event->err_msg != NULL ) return 0; |
352 |
|
353 |
return 1; |
354 |
} |
355 |
|
356 |
int MakeStamps::newBond( event* the_event ){ |
357 |
|
358 |
current_bond = new BondStamp; |
359 |
|
360 |
the_event->err_msg = current_mol->addBond( current_bond, |
361 |
the_event->evt.blk_index ); |
362 |
if( the_event->err_msg != NULL ) return 0; |
363 |
|
364 |
return 1; |
365 |
} |
366 |
|
367 |
int MakeStamps::bondAssign( event* the_event ){ |
368 |
|
369 |
switch( the_event->evt.asmt.asmt_type ){ |
370 |
|
371 |
case STRING: |
372 |
current_bond->assignString( the_event->evt.asmt.lhs, |
373 |
the_event->evt.asmt.rhs.sval ); |
374 |
return 1; |
375 |
break; |
376 |
|
377 |
case DOUBLE: |
378 |
current_bond->assignDouble( the_event->evt.asmt.lhs, |
379 |
the_event->evt.asmt.rhs.dval ); |
380 |
return 1; |
381 |
break; |
382 |
|
383 |
case INT: |
384 |
current_bond->assignInt( the_event->evt.asmt.lhs, |
385 |
the_event->evt.asmt.rhs.ival ); |
386 |
return 1; |
387 |
break; |
388 |
|
389 |
default: |
390 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bond" |
391 |
" assignment type" ); |
392 |
return 0; |
393 |
break; |
394 |
} |
395 |
return 0; |
396 |
} |
397 |
|
398 |
int MakeStamps::bondMembers( event* the_event ){ |
399 |
|
400 |
current_bond->members( the_event->evt.mbrs.a, |
401 |
the_event->evt.mbrs.b ); |
402 |
return 1; |
403 |
} |
404 |
|
405 |
int MakeStamps::bondConstraint( event* the_event ){ |
406 |
|
407 |
current_bond->constrain( the_event->evt.cnstr ); |
408 |
return 1; |
409 |
} |
410 |
|
411 |
int MakeStamps::bondEnd( event* the_event ){ |
412 |
|
413 |
the_event->err_msg = current_bond->checkMe(); |
414 |
if( the_event->err_msg != NULL ) return 0; |
415 |
|
416 |
return 1; |
417 |
} |
418 |
|
419 |
int MakeStamps::newBend( event* the_event ){ |
420 |
|
421 |
current_bend = new BendStamp; |
422 |
|
423 |
the_event->err_msg = current_mol->addBend( current_bend, |
424 |
the_event->evt.blk_index ); |
425 |
if( the_event->err_msg != NULL ) return 0; |
426 |
|
427 |
return 1; |
428 |
} |
429 |
|
430 |
int MakeStamps::bendAssign( event* the_event ){ |
431 |
|
432 |
switch( the_event->evt.asmt.asmt_type ){ |
433 |
|
434 |
case STRING: |
435 |
current_bend->assignString( the_event->evt.asmt.lhs, |
436 |
the_event->evt.asmt.rhs.sval ); |
437 |
return 1; |
438 |
break; |
439 |
|
440 |
case DOUBLE: |
441 |
current_bend->assignDouble( the_event->evt.asmt.lhs, |
442 |
the_event->evt.asmt.rhs.dval ); |
443 |
return 1; |
444 |
break; |
445 |
|
446 |
case INT: |
447 |
current_bend->assignInt( the_event->evt.asmt.lhs, |
448 |
the_event->evt.asmt.rhs.ival ); |
449 |
return 1; |
450 |
break; |
451 |
|
452 |
default: |
453 |
the_event->err_msg = strdup( "MakeStamp error. Invalid bend" |
454 |
" assignment type" ); |
455 |
return 0; |
456 |
break; |
457 |
} |
458 |
return 0; |
459 |
} |
460 |
|
461 |
int MakeStamps::bendMembers( event* the_event ){ |
462 |
|
463 |
current_bend->members( the_event->evt.mbrs.a, |
464 |
the_event->evt.mbrs.b, |
465 |
the_event->evt.mbrs.c ); |
466 |
return 1; |
467 |
} |
468 |
|
469 |
int MakeStamps::bendConstraint( event* the_event ){ |
470 |
|
471 |
current_bend->constrain( the_event->evt.cnstr ); |
472 |
return 1; |
473 |
} |
474 |
|
475 |
int MakeStamps::bendEnd( event* the_event ){ |
476 |
|
477 |
the_event->err_msg = current_bend->checkMe(); |
478 |
if( the_event->err_msg != NULL ) return 0; |
479 |
|
480 |
return 1; |
481 |
} |
482 |
|
483 |
int MakeStamps::newTorsion( event* the_event ){ |
484 |
|
485 |
current_torsion = new TorsionStamp; |
486 |
|
487 |
the_event->err_msg = current_mol->addTorsion( current_torsion, |
488 |
the_event->evt.blk_index ); |
489 |
if( the_event->err_msg != NULL ) return 0; |
490 |
|
491 |
return 1; |
492 |
} |
493 |
|
494 |
int MakeStamps::torsionAssign( event* the_event ){ |
495 |
|
496 |
switch( the_event->evt.asmt.asmt_type ){ |
497 |
|
498 |
case STRING: |
499 |
current_torsion->assignString( the_event->evt.asmt.lhs, |
500 |
the_event->evt.asmt.rhs.sval ); |
501 |
return 1; |
502 |
break; |
503 |
|
504 |
case DOUBLE: |
505 |
current_torsion->assignDouble( the_event->evt.asmt.lhs, |
506 |
the_event->evt.asmt.rhs.dval ); |
507 |
return 1; |
508 |
break; |
509 |
|
510 |
case INT: |
511 |
current_torsion->assignInt( the_event->evt.asmt.lhs, |
512 |
the_event->evt.asmt.rhs.ival ); |
513 |
return 1; |
514 |
break; |
515 |
|
516 |
default: |
517 |
the_event->err_msg = strdup( "MakeStamp error. Invalid torsion" |
518 |
" assignment type" ); |
519 |
return 0; |
520 |
break; |
521 |
} |
522 |
return 0; |
523 |
} |
524 |
|
525 |
int MakeStamps::torsionMembers( event* the_event ){ |
526 |
|
527 |
current_torsion->members( the_event->evt.mbrs.a, |
528 |
the_event->evt.mbrs.b, |
529 |
the_event->evt.mbrs.c, |
530 |
the_event->evt.mbrs.d ); |
531 |
return 1; |
532 |
} |
533 |
|
534 |
int MakeStamps::torsionConstraint( event* the_event ){ |
535 |
|
536 |
current_torsion->constrain( the_event->evt.cnstr ); |
537 |
return 1; |
538 |
} |
539 |
|
540 |
int MakeStamps::torsionEnd( event* the_event ){ |
541 |
|
542 |
the_event->err_msg = current_torsion->checkMe(); |
543 |
if( the_event->err_msg != NULL ) return 0; |
544 |
|
545 |
return 1; |
546 |
} |
547 |
|
548 |
int MakeStamps::newMember( event* the_event ){ |
549 |
|
550 |
current_member = new MemberStamp; |
551 |
|
552 |
the_event->err_msg = current_rigidbody->addMember( current_member, |
553 |
the_event->evt.blk_index ); |
554 |
if( the_event->err_msg != NULL ) return 0; |
555 |
|
556 |
return 1; |
557 |
} |
558 |
|
559 |
int MakeStamps::memberAssign( event* the_event ){ |
560 |
|
561 |
switch( the_event->evt.asmt.asmt_type ){ |
562 |
|
563 |
case STRING: |
564 |
current_member->assignString( the_event->evt.asmt.lhs, |
565 |
the_event->evt.asmt.rhs.sval ); |
566 |
return 1; |
567 |
break; |
568 |
|
569 |
case DOUBLE: |
570 |
current_member->assignDouble( the_event->evt.asmt.lhs, |
571 |
the_event->evt.asmt.rhs.dval ); |
572 |
return 1; |
573 |
break; |
574 |
|
575 |
case INT: |
576 |
current_member->assignInt( the_event->evt.asmt.lhs, |
577 |
the_event->evt.asmt.rhs.ival ); |
578 |
return 1; |
579 |
break; |
580 |
|
581 |
default: |
582 |
the_event->err_msg = strdup( "MakeStamp error. Invalid member" |
583 |
" assignment type" ); |
584 |
return 0; |
585 |
break; |
586 |
} |
587 |
return 0; |
588 |
} |
589 |
|
590 |
int MakeStamps::memberEnd( event* the_event ){ |
591 |
|
592 |
the_event->err_msg = current_member->checkMe(); |
593 |
if( the_event->err_msg != NULL ) return 0; |
594 |
|
595 |
return 1; |
596 |
} |