ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/types/MakeStamps.cpp
Revision: 1957
Committed: Tue Jan 25 17:45:23 2005 UTC (19 years, 5 months ago) by tim
File size: 17542 byte(s)
Log Message:
(1) complete section parser's error message
(2) add GhostTorsion
(3) accumulate inertial tensor from the directional atoms before calculate rigidbody's inertial tensor

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Acknowledgement of the program authors must be made in any
10 * publication of scientific results based in part on use of the
11 * program. An acceptable form of acknowledgement is citation of
12 * the article in which the program was described (Matthew
13 * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 * Parallel Simulation Engine for Molecular Dynamics,"
16 * J. Comput. Chem. 26, pp. 252-271 (2005))
17 *
18 * 2. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 3. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * This software is provided "AS IS," without a warranty of any
27 * kind. All express or implied conditions, representations and
28 * warranties, including any implied warranty of merchantability,
29 * fitness for a particular purpose or non-infringement, are hereby
30 * excluded. The University of Notre Dame and its licensors shall not
31 * be liable for any damages suffered by licensee as a result of
32 * using, modifying or distributing the software or its
33 * derivatives. In no event will the University of Notre Dame or its
34 * licensors be liable for any lost revenue, profit or data, or for
35 * direct, indirect, special, consequential, incidental or punitive
36 * damages, however caused and regardless of the theory of liability,
37 * arising out of the use of or inability to use software, even if the
38 * University of Notre Dame has been advised of the possibility of
39 * such damages.
40 */
41
42 #include <stdlib.h>
43 #include <stdio.h>
44 #include <string.h>
45
46 #include "types/MakeStamps.hpp"
47 #include "types/MoleculeStamp.hpp"
48 #include "types/RigidBodyStamp.hpp"
49 #include "types/CutoffGroupStamp.hpp"
50 #include "utils/simError.h"
51 #ifdef IS_MPI
52 #include "io/mpiBASS.h"
53 #endif // is_mpi
54
55 LinkedMolStamp::~LinkedMolStamp(){
56 if( mol_stamp != NULL ) delete mol_stamp;
57 if( next != NULL ) delete next;
58 }
59
60 void LinkedMolStamp::add( LinkedMolStamp* newbie ){
61
62 if( next != NULL ) next->add( newbie );
63 else{
64 next = newbie;
65 next->setPrev( this );
66 }
67 }
68
69 MoleculeStamp* LinkedMolStamp::match( char* id ){
70
71 if( mol_stamp != NULL ){
72 if(!strcmp( mol_stamp->getID(), id )){
73
74 // make sure we aren't hiding somebody else with the same name
75 if(next != NULL ){
76 if( next->match( id ) != NULL){
77 sprintf( painCave.errMsg,
78 "Molecule Stamp Error. Two separate of declarations of "
79 "%s present.\n",
80 id );
81 painCave.isFatal = 1;
82 simError();
83 #ifdef IS_MPI
84 if( painCave.isEventLoop ){
85 if( worldRank == 0 ) mpiInterfaceExit();
86 }
87 #endif //is_mpi
88 }
89 else return mol_stamp;
90 }
91 else return mol_stamp;
92 }
93 }
94
95 if( next != NULL ) return next->match( id );
96
97 return NULL;
98 }
99
100 LinkedMolStamp* LinkedMolStamp::extract( char* id ){
101
102 if( mol_stamp != NULL ){
103 if(!strcmp( mol_stamp->getID(), id )){
104
105 // make sure we aren't hiding somebody else with the same name
106 if(next != NULL ){
107 if( next->match( id ) != NULL){
108 sprintf( painCave.errMsg,
109 "Molecule Stamp Error. Two separate of declarations of "
110 "%s present.\n",
111 id );
112 painCave.isFatal = 1;
113 simError();
114 #ifdef IS_MPI
115 if( painCave.isEventLoop ){
116 if( worldRank == 0 ) mpiInterfaceExit();
117 }
118 #endif //is_mpi
119 }
120 }
121
122 prev->setNext( next );
123 if( next != NULL ) next->setPrev( prev );
124 return this;
125 }
126 }
127
128 if( next != NULL ) return next->extract( id );
129
130 return NULL;
131 }
132
133 MakeStamps::MakeStamps(){
134
135 int i;
136
137 hash_size = 47;
138 hash_shift = 4;
139
140 my_mols = new LinkedMolStamp*[hash_size];
141 for( i=0; i<hash_size; i++ ){
142 my_mols[i] = new LinkedMolStamp();
143 }
144
145 }
146
147 MakeStamps::~MakeStamps(){
148
149 int i;
150
151 for( i=0; i<hash_size; i++ ){
152 if( my_mols[i] != NULL ) delete my_mols[i];
153 }
154 delete[] my_mols;
155 }
156
157 int MakeStamps::hash( char* text ){
158
159 register unsigned short int i = 0; // loop counter
160 int key = 0; // the hash key
161
162 while( text[i] != '\0' ){
163
164 key = ( ( key << hash_shift ) + text[i] ) % hash_size;
165
166 i++;
167 }
168
169 if( key < 0 ){
170
171 // if the key is less than zero, we've had an overflow error
172
173 sprintf( painCave.errMsg,
174 "There has been an overflow error in the MakeStamps hash key.");
175 painCave.isFatal = 1;
176 simError();
177 #ifdef IS_MPI
178 if( painCave.isEventLoop ){
179 if( worldRank == 0 ) mpiInterfaceExit();
180 }
181 #endif //is_mpi
182 }
183
184 return key;
185 }
186
187 LinkedMolStamp* MakeStamps::extractMolStamp( char* the_id ){
188 int key;
189
190 key = hash( the_id );
191 if( my_mols[key] != NULL ){
192 return my_mols[key]->extract( the_id );
193 }
194
195 return NULL;
196 }
197
198 void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
199
200 int key;
201 LinkedMolStamp* linked_mol;
202
203 key = hash( the_stamp->getID() );
204
205 linked_mol = new LinkedMolStamp;
206 linked_mol->setStamp( the_stamp );
207
208 my_mols[key]->add( linked_mol );
209
210 }
211
212
213 int MakeStamps::newMolecule( event* the_event ){
214
215 current_mol = new MoleculeStamp;
216 return 1;
217 }
218
219 int MakeStamps::moleculeAssign( event* the_event ){
220
221 switch( the_event->evt.asmt.asmt_type ){
222
223 case STRING:
224 the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs,
225 the_event->evt.asmt.rhs.sval );
226 break;
227
228 case DOUBLE:
229 the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs,
230 the_event->evt.asmt.rhs.dval );
231 break;
232
233 case INT:
234 the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs,
235 the_event->evt.asmt.rhs.ival );
236 break;
237
238 default:
239 the_event->err_msg = strdup( "MakeStamp error. Invalid molecule"
240 " assignment type" );
241 return 0;
242 break;
243 }
244 if( the_event->err_msg != NULL ) return 0;
245 return 1;
246 }
247
248 int MakeStamps::moleculeEnd( event* the_event ){
249
250 the_event->err_msg = current_mol->checkMe();
251 // if err_msg is set, then something is wrong
252 if( the_event->err_msg != NULL ) return 0;
253
254 addMolStamp( current_mol );
255 return 1;
256 }
257
258 int MakeStamps::newRigidBody( event* the_event ){
259
260 current_rigidbody = new RigidBodyStamp;
261
262 the_event->err_msg = current_mol->addRigidBody( current_rigidbody,
263 the_event->evt.blk_index );
264 if( the_event->err_msg != NULL ) return 0;
265 return 1;
266 }
267
268 int MakeStamps::rigidBodyAssign( event* the_event ){
269
270 switch( the_event->evt.asmt.asmt_type ){
271
272 case STRING:
273 the_event->err_msg =
274 current_rigidbody->assignString( the_event->evt.asmt.lhs,
275 the_event->evt.asmt.rhs.sval );
276 if( the_event->err_msg != NULL ) return 0;
277 return 1;
278 break;
279
280 case DOUBLE:
281 the_event->err_msg =
282 current_rigidbody->assignDouble( the_event->evt.asmt.lhs,
283 the_event->evt.asmt.rhs.dval );
284 if( the_event->err_msg != NULL ) return 0;
285 return 1;
286 break;
287
288 case INT:
289 the_event->err_msg =
290 current_rigidbody->assignInt( the_event->evt.asmt.lhs,
291 the_event->evt.asmt.rhs.ival );
292 if( the_event->err_msg != NULL ) return 0;
293 return 1;
294 break;
295
296 default:
297 the_event->err_msg = strdup( "MakeStamp error. Invalid rigidBody"
298 " assignment type" );
299 return 0;
300 break;
301 }
302 return 0;
303 }
304
305 int MakeStamps::rigidBodyMembers( event* the_event ){
306
307 int i;
308
309 if( the_event->evt.mbrs.nMembers > 0 ){
310
311 for (i = 0; i < the_event->evt.mbrs.nMembers; i++) {
312 current_rigidbody->addMember(the_event->evt.mbrs.memberList[i]);
313 }
314
315 return 1;
316
317 } else {
318 the_event->err_msg = strdup( "MakeStamp error. No members in memberList "
319 " for this rigidBody.");
320 return 0;
321
322 }
323 }
324
325 int MakeStamps::rigidBodyEnd( event* the_event ){
326
327 the_event->err_msg = current_rigidbody->checkMe();
328 if( the_event->err_msg != NULL ) return 0;
329
330 return 1;
331 }
332
333 int MakeStamps::newCutoffGroup( event* the_event ){
334
335 current_cutoffgroup = new CutoffGroupStamp;
336
337 the_event->err_msg = current_mol->addCutoffGroup( current_cutoffgroup,
338 the_event->evt.blk_index );
339 if( the_event->err_msg != NULL ) return 0;
340 return 1;
341 }
342
343 int MakeStamps::cutoffGroupAssign( event* the_event ){
344
345 switch( the_event->evt.asmt.asmt_type ){
346
347 case STRING:
348 the_event->err_msg =
349 current_cutoffgroup->assignString( the_event->evt.asmt.lhs,
350 the_event->evt.asmt.rhs.sval );
351 if( the_event->err_msg != NULL ) return 0;
352 return 1;
353 break;
354
355 case DOUBLE:
356 the_event->err_msg =
357 current_cutoffgroup->assignDouble( the_event->evt.asmt.lhs,
358 the_event->evt.asmt.rhs.dval );
359 if( the_event->err_msg != NULL ) return 0;
360 return 1;
361 break;
362
363 case INT:
364 the_event->err_msg =
365 current_cutoffgroup->assignInt( the_event->evt.asmt.lhs,
366 the_event->evt.asmt.rhs.ival );
367 if( the_event->err_msg != NULL ) return 0;
368 return 1;
369 break;
370
371 default:
372 the_event->err_msg = strdup( "MakeStamp error. Invalid CutoffGroup"
373 " assignment type" );
374 return 0;
375 break;
376 }
377 return 0;
378 }
379
380 int MakeStamps::cutoffGroupMembers( event* the_event ){
381
382 int i;
383
384 if( the_event->evt.mbrs.nMembers > 0 ){
385
386 for (i = 0; i < the_event->evt.mbrs.nMembers; i++) {
387 current_cutoffgroup->addMember(the_event->evt.mbrs.memberList[i]);
388 }
389
390 return 1;
391
392 } else {
393 the_event->err_msg = strdup( "MakeStamp error. No members in memberList "
394 " for this CutoffGroup.");
395 return 0;
396
397 }
398 }
399
400 int MakeStamps::cutoffGroupEnd( event* the_event ){
401
402 the_event->err_msg = current_cutoffgroup->checkMe();
403 if( the_event->err_msg != NULL ) return 0;
404
405 return 1;
406 }
407
408 int MakeStamps::newAtom( event* the_event ){
409
410 current_atom = new AtomStamp;
411
412 the_event->err_msg = current_mol->addAtom( current_atom,
413 the_event->evt.blk_index );
414
415 if( the_event->err_msg != NULL ) return 0;
416 return 1;
417 }
418
419 int MakeStamps::atomPosition( event* the_event ){
420
421 current_atom->setPosition( the_event->evt.pos.x,
422 the_event->evt.pos.y,
423 the_event->evt.pos.z );
424 return 1;
425 }
426
427
428 int MakeStamps::atomOrientation( event* the_event ){
429
430 current_atom->setOrientation( the_event->evt.ornt.phi,
431 the_event->evt.ornt.theta,
432 the_event->evt.ornt.psi );
433 return 1;
434 }
435
436 int MakeStamps::atomAssign( event* the_event ){
437
438 switch( the_event->evt.asmt.asmt_type ){
439
440 case STRING:
441 the_event->err_msg =
442 current_atom->assignString( the_event->evt.asmt.lhs,
443 the_event->evt.asmt.rhs.sval );
444 if( the_event->err_msg != NULL ) return 0;
445 return 1;
446 break;
447
448 case DOUBLE:
449 the_event->err_msg =
450 current_atom->assignDouble( the_event->evt.asmt.lhs,
451 the_event->evt.asmt.rhs.dval );
452 if( the_event->err_msg != NULL ) return 0;
453 return 1;
454 break;
455
456 case INT:
457 the_event->err_msg =
458 current_atom->assignInt( the_event->evt.asmt.lhs,
459 the_event->evt.asmt.rhs.ival );
460 if( the_event->err_msg != NULL ) return 0;
461 return 1;
462 break;
463
464 default:
465 the_event->err_msg = strdup( "MakeStamp error. Invalid atom"
466 " assignment type" );
467 return 0;
468 break;
469 }
470 return 0;
471 }
472
473 int MakeStamps::atomEnd( event* the_event ){
474
475 the_event->err_msg = current_atom->checkMe();
476 if( the_event->err_msg != NULL ) return 0;
477
478 return 1;
479 }
480
481 int MakeStamps::newBond( event* the_event ){
482
483 current_bond = new BondStamp;
484
485 the_event->err_msg = current_mol->addBond( current_bond,
486 the_event->evt.blk_index );
487 if( the_event->err_msg != NULL ) return 0;
488
489 return 1;
490 }
491
492 int MakeStamps::bondAssign( event* the_event ){
493
494 switch( the_event->evt.asmt.asmt_type ){
495
496 case STRING:
497 current_bond->assignString( the_event->evt.asmt.lhs,
498 the_event->evt.asmt.rhs.sval );
499 return 1;
500 break;
501
502 case DOUBLE:
503 current_bond->assignDouble( the_event->evt.asmt.lhs,
504 the_event->evt.asmt.rhs.dval );
505 return 1;
506 break;
507
508 case INT:
509 current_bond->assignInt( the_event->evt.asmt.lhs,
510 the_event->evt.asmt.rhs.ival );
511 return 1;
512 break;
513
514 default:
515 the_event->err_msg = strdup( "MakeStamp error. Invalid bond"
516 " assignment type" );
517 return 0;
518 break;
519 }
520 return 0;
521 }
522
523 int MakeStamps::bondMembers( event* the_event ){
524
525 if( the_event->evt.mbrs.nMembers == 2 ){
526
527 current_bond->members( the_event->evt.mbrs.memberList[0],
528 the_event->evt.mbrs.memberList[1] );
529 return 1;
530
531 } else {
532 the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
533 " in bond");
534 return 0;
535
536 }
537
538 }
539
540 int MakeStamps::bondConstraint( event* the_event ){
541
542 current_bond->constrain( the_event->evt.cnstr );
543 return 1;
544 }
545
546 int MakeStamps::bondEnd( event* the_event ){
547
548 the_event->err_msg = current_bond->checkMe();
549 if( the_event->err_msg != NULL ) return 0;
550
551 return 1;
552 }
553
554 int MakeStamps::newBend( event* the_event ){
555
556 current_bend = new BendStamp;
557
558 the_event->err_msg = current_mol->addBend( current_bend,
559 the_event->evt.blk_index );
560 if( the_event->err_msg != NULL ) return 0;
561
562 return 1;
563 }
564
565 int MakeStamps::bendAssign( event* the_event ){
566
567 switch( the_event->evt.asmt.asmt_type ){
568
569 case STRING:
570 current_bend->assignString( the_event->evt.asmt.lhs,
571 the_event->evt.asmt.rhs.sval );
572 return 1;
573 break;
574
575 case DOUBLE:
576 current_bend->assignDouble( the_event->evt.asmt.lhs,
577 the_event->evt.asmt.rhs.dval );
578 return 1;
579 break;
580
581 case INT:
582 current_bend->assignInt( the_event->evt.asmt.lhs,
583 the_event->evt.asmt.rhs.ival );
584 return 1;
585 break;
586
587 default:
588 the_event->err_msg = strdup( "MakeStamp error. Invalid bend"
589 " assignment type" );
590 return 0;
591 break;
592 }
593 return 0;
594 }
595
596 int MakeStamps::bendMembers( event* the_event ){
597
598
599 switch( the_event->evt.mbrs.nMembers ) {
600 case 3:
601 current_bend->members( the_event->evt.mbrs.memberList[0],
602 the_event->evt.mbrs.memberList[1],
603 the_event->evt.mbrs.memberList[2]);
604 return 1;
605 break;
606 case 2:
607 current_bend->members( the_event->evt.mbrs.memberList[0],
608 the_event->evt.mbrs.memberList[1],
609 0 );
610 return 1;
611 break;
612 default:
613 the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
614 "in bend.");
615 return 0;
616 break;
617 }
618 return 0;
619 }
620
621 int MakeStamps::bendConstraint( event* the_event ){
622
623 current_bend->constrain( the_event->evt.cnstr );
624 return 1;
625 }
626
627 int MakeStamps::bendEnd( event* the_event ){
628
629 the_event->err_msg = current_bend->checkMe();
630 if( the_event->err_msg != NULL ) return 0;
631
632 return 1;
633 }
634
635 int MakeStamps::newTorsion( event* the_event ){
636
637 current_torsion = new TorsionStamp;
638
639 the_event->err_msg = current_mol->addTorsion( current_torsion,
640 the_event->evt.blk_index );
641 if( the_event->err_msg != NULL ) return 0;
642
643 return 1;
644 }
645
646 int MakeStamps::torsionAssign( event* the_event ){
647
648 switch( the_event->evt.asmt.asmt_type ){
649
650 case STRING:
651 current_torsion->assignString( the_event->evt.asmt.lhs,
652 the_event->evt.asmt.rhs.sval );
653 return 1;
654 break;
655
656 case DOUBLE:
657 current_torsion->assignDouble( the_event->evt.asmt.lhs,
658 the_event->evt.asmt.rhs.dval );
659 return 1;
660 break;
661
662 case INT:
663 current_torsion->assignInt( the_event->evt.asmt.lhs,
664 the_event->evt.asmt.rhs.ival );
665 return 1;
666 break;
667
668 default:
669 the_event->err_msg = strdup( "MakeStamp error. Invalid torsion"
670 " assignment type" );
671 return 0;
672 break;
673 }
674 return 0;
675 }
676
677 int MakeStamps::torsionMembers( event* the_event ){
678
679
680 switch( the_event->evt.mbrs.nMembers ) {
681 case 4:
682
683 current_torsion->members( the_event->evt.mbrs.memberList[0],
684 the_event->evt.mbrs.memberList[1],
685 the_event->evt.mbrs.memberList[2],
686 the_event->evt.mbrs.memberList[3]);
687 return 1;
688 break;
689 case 3:
690
691
692 current_torsion->members( the_event->evt.mbrs.memberList[0],
693 the_event->evt.mbrs.memberList[1],
694 the_event->evt.mbrs.memberList[2],
695 -1);
696
697 return 1;
698 break;
699 default:
700 the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
701 "in torsion.");
702 return 0;
703 break;
704 }
705 return 0;
706
707 }
708
709 int MakeStamps::torsionConstraint( event* the_event ){
710
711 current_torsion->constrain( the_event->evt.cnstr );
712 return 1;
713 }
714
715 int MakeStamps::torsionEnd( event* the_event ){
716
717 the_event->err_msg = current_torsion->checkMe();
718 if( the_event->err_msg != NULL ) return 0;
719
720 return 1;
721 }