ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/types/MakeStamps.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/types/MakeStamps.cpp (file contents):
Revision 1490 by gezelter, Fri Sep 24 04:16:43 2004 UTC vs.
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC

# Line 1 | Line 1
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 "MakeStamps.hpp"
47 < #include "MoleculeStamp.hpp"
48 < #include "RigidBodyStamp.hpp"
49 < #include "CutoffGroupStamp.hpp"
50 < #include "simError.h"
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 "mpiBASS.h"
52 > #include "io/mpiBASS.h"
53   #endif // is_mpi
54  
55 < LinkedMolStamp::~LinkedMolStamp(){
15 <  if( mol_stamp != NULL ) delete mol_stamp;
16 <  if( next != NULL ) delete next;
55 > MakeStamps::MakeStamps(){
56   }
57  
58 < void LinkedMolStamp::add( LinkedMolStamp* newbie ){
58 > MakeStamps::~MakeStamps(){
59    
60 <  if( next != NULL ) next->add( newbie );
61 <  else{
62 <    next = newbie;
63 <    next->setPrev( this );
60 >  std::map<std::string, MoleculeStamp*>::iterator iter;
61 >
62 >  for (iter=my_mols.begin(); iter!=my_mols.end(); ++iter) {
63 >    delete iter->second;
64    }
26 }
65  
66 < MoleculeStamp* LinkedMolStamp::match( char* id ){
66 >  my_mols.clear();
67  
30  if( mol_stamp != NULL ){
31    if(!strcmp( mol_stamp->getID(), id )){
32      
33      // make sure we aren't hiding somebody else with the same name
34      if(next != NULL ){
35        if( next->match( id ) != NULL){
36          sprintf( painCave.errMsg,
37                   "Molecule Stamp Error. Two separate of declarations of "
38                   "%s present.\n",
39                   id );
40          painCave.isFatal = 1;
41          simError();
42 #ifdef IS_MPI
43          if( painCave.isEventLoop ){
44            if( worldRank == 0 ) mpiInterfaceExit();
45          }
46 #endif //is_mpi
47        }
48        else return mol_stamp;
49      }
50      else  return mol_stamp;
51    }
52  }
53  
54  if( next != NULL ) return next->match( id );
55  
56  return NULL;
68   }
69  
70 < LinkedMolStamp* LinkedMolStamp::extract( char* id ){
70 > MoleculeStamp* MakeStamps::getMolStamp( std::string the_id ){
71  
72 <  if( mol_stamp != NULL ){
62 <    if(!strcmp( mol_stamp->getID(), id )){
63 <      
64 <      // make sure we aren't hiding somebody else with the same name
65 <      if(next != NULL ){
66 <        if( next->match( id ) != NULL){
67 <          sprintf( painCave.errMsg,
68 <                   "Molecule Stamp Error. Two separate of declarations of "
69 <                   "%s present.\n",
70 <                   id );
71 <          painCave.isFatal = 1;
72 <          simError();
73 < #ifdef IS_MPI
74 <          if( painCave.isEventLoop ){
75 <            if( worldRank == 0 ) mpiInterfaceExit();
76 <          }
77 < #endif //is_mpi
78 <        }
79 <      }
80 <          
81 <      prev->setNext( next );
82 <      if( next != NULL ) next->setPrev( prev );
83 <      return this;
84 <    }
85 <  }
72 >  std::map<std::string, MoleculeStamp*>::iterator iter;
73    
74 <  if( next != NULL ) return next->extract( id );
88 <  
89 <  return NULL;
90 < }
74 >  iter = my_mols.find(the_id);
75  
76 < MakeStamps::MakeStamps(){
77 <  
78 <  int i;
79 <
96 <  hash_size = 47;
97 <  hash_shift = 4;
98 <  
99 <  my_mols = new LinkedMolStamp*[hash_size];
100 <  for( i=0; i<hash_size; i++ ){
101 <    my_mols[i] = new LinkedMolStamp();
76 >  if (iter == my_mols.end()) {
77 >    return NULL;
78 >  } else {
79 >    return iter->second;
80    }
81  
82   }
83  
84 < MakeStamps::~MakeStamps(){
84 > void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
85    
86 <  int i;
86 >  std::map<std::string, MoleculeStamp*>::iterator iter;
87  
88 <  for( i=0; i<hash_size; i++ ){
111 <    if( my_mols[i] != NULL ) delete my_mols[i];
112 <  }
113 <  delete[] my_mols;
114 < }
88 >  std::string molStampName(the_stamp->getID());
89  
90 < int MakeStamps::hash( char* text ){
90 >  iter = my_mols.find(molStampName);
91  
92 <  register unsigned short int i = 0; // loop counter
119 <  int key = 0; // the hash key
120 <
121 <  while( text[i] != '\0' ){
122 <
123 <    key = ( ( key << hash_shift ) + text[i] ) % hash_size;
124 <    
125 <    i++;
126 <  }
127 <  
128 <  if( key < 0 ){
129 <
130 <    // if the key is less than zero, we've had an overflow error
131 <
92 >  if (iter != my_mols.end()) {
93      sprintf( painCave.errMsg,
94 <             "There has been an overflow error in the MakeStamps hash key.");
94 >             "Molecule Stamp Error. Two separate of declarations of "
95 >             "%s present.\n",
96 >             the_stamp->getID());
97      painCave.isFatal = 1;
98      simError();
99   #ifdef IS_MPI
# Line 138 | Line 101 | int MakeStamps::hash( char* text ){
101        if( worldRank == 0 ) mpiInterfaceExit();
102      }
103   #endif //is_mpi
104 +    
105 +  } else {
106 +    my_mols.insert(std::map<std::string, MoleculeStamp*>::value_type(molStampName, the_stamp));
107    }
142  
143  return key;
108   }
109  
146 LinkedMolStamp* MakeStamps::extractMolStamp( char* the_id ){
147  int key;
148  
149  key = hash( the_id );
150  if( my_mols[key] != NULL ){
151    return my_mols[key]->extract( the_id );
152  }
153  
154  return NULL;
155 }
110  
157 void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
158
159  int key;
160  LinkedMolStamp* linked_mol;
161  
162  key = hash( the_stamp->getID() );
163
164  linked_mol = new LinkedMolStamp;
165  linked_mol->setStamp( the_stamp );
166
167  my_mols[key]->add( linked_mol );
168
169 }
170
171
111   int MakeStamps::newMolecule( event* the_event ){
112    
113    current_mol = new MoleculeStamp;
# Line 181 | Line 120 | int MakeStamps::moleculeAssign( event* the_event ){
120      
121    case STRING:
122      the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs,
123 <                                      the_event->evt.asmt.rhs.sval );
123 >                                                    the_event->evt.asmt.rhs.sval );
124      break;
125  
126    case DOUBLE:
127      the_event->err_msg = current_mol->assignDouble( the_event->evt.asmt.lhs,
128 <                                      the_event->evt.asmt.rhs.dval );
128 >                                                    the_event->evt.asmt.rhs.dval );
129      break;
130      
131    case INT:
132      the_event->err_msg = current_mol->assignInt( the_event->evt.asmt.lhs,
133 <                                   the_event->evt.asmt.rhs.ival );
133 >                                                 the_event->evt.asmt.rhs.ival );
134      break;
135  
136    default:
# Line 454 | Line 393 | int MakeStamps::bondAssign( event* the_event ){
393      
394    case STRING:
395      current_bond->assignString( the_event->evt.asmt.lhs,
396 <                               the_event->evt.asmt.rhs.sval );
396 >                                the_event->evt.asmt.rhs.sval );
397      return 1;
398      break;
399  
400    case DOUBLE:
401      current_bond->assignDouble( the_event->evt.asmt.lhs,
402 <                               the_event->evt.asmt.rhs.dval );
402 >                                the_event->evt.asmt.rhs.dval );
403      return 1;
404      break;
405  
406    case INT:
407      current_bond->assignInt( the_event->evt.asmt.lhs,
408 <                            the_event->evt.asmt.rhs.ival );
408 >                             the_event->evt.asmt.rhs.ival );
409      return 1;
410      break;
411  
# Line 527 | Line 466 | int MakeStamps::bendAssign( event* the_event ){
466      
467    case STRING:
468      current_bend->assignString( the_event->evt.asmt.lhs,
469 <                               the_event->evt.asmt.rhs.sval );
469 >                                the_event->evt.asmt.rhs.sval );
470      return 1;
471      break;
472  
473    case DOUBLE:
474      current_bend->assignDouble( the_event->evt.asmt.lhs,
475 <                               the_event->evt.asmt.rhs.dval );
475 >                                the_event->evt.asmt.rhs.dval );
476      return 1;
477      break;
478  
479    case INT:
480      current_bend->assignInt( the_event->evt.asmt.lhs,
481 <                            the_event->evt.asmt.rhs.ival );
481 >                             the_event->evt.asmt.rhs.ival );
482      return 1;
483      break;
484  
# Line 608 | Line 547 | int MakeStamps::torsionAssign( event* the_event ){
547      
548    case STRING:
549      current_torsion->assignString( the_event->evt.asmt.lhs,
550 <                               the_event->evt.asmt.rhs.sval );
550 >                                   the_event->evt.asmt.rhs.sval );
551      return 1;
552      break;
553  
554    case DOUBLE:
555      current_torsion->assignDouble( the_event->evt.asmt.lhs,
556 <                               the_event->evt.asmt.rhs.dval );
556 >                                   the_event->evt.asmt.rhs.dval );
557      return 1;
558      break;
559  
560    case INT:
561      current_torsion->assignInt( the_event->evt.asmt.lhs,
562 <                            the_event->evt.asmt.rhs.ival );
562 >                                the_event->evt.asmt.rhs.ival );
563      return 1;
564      break;
565  
# Line 635 | Line 574 | int MakeStamps::torsionMembers( event* the_event ){
574  
575   int MakeStamps::torsionMembers( event* the_event ){
576  
577 <  if( the_event->evt.mbrs.nMembers == 4 ){
577 >
578 >  switch( the_event->evt.mbrs.nMembers ) {
579 >  case 4:
580      
581      current_torsion->members( the_event->evt.mbrs.memberList[0],
582                                the_event->evt.mbrs.memberList[1],
583                                the_event->evt.mbrs.memberList[2],
584                                the_event->evt.mbrs.memberList[3]);
585      return 1;
586 +    break;
587 +  case 3:
588 +
589      
590 <  } else {
590 >    current_torsion->members( the_event->evt.mbrs.memberList[0],
591 >                              the_event->evt.mbrs.memberList[1],
592 >                              the_event->evt.mbrs.memberList[2],
593 >                              -1);
594 >    
595 >    return 1;
596 >    break;
597 >  default:      
598      the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
599 <                                 " in torsion");
599 >                                 "in torsion.");
600      return 0;
601 <
601 >    break;
602    }
603 +  return 0;
604 +  
605   }
606  
607   int MakeStamps::torsionConstraint( event* the_event ){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines