ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/types/MakeStamps.cpp
Revision: 2187
Committed: Wed Apr 13 18:41:17 2005 UTC (19 years, 3 months ago) by tim
File size: 15596 byte(s)
Log Message:
more memory leak are fixed

File Contents

# User Rev Content
1 gezelter 1930 /*
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 gezelter 1490 #include <stdlib.h>
43     #include <stdio.h>
44     #include <string.h>
45    
46 tim 1492 #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 gezelter 1490 #ifdef IS_MPI
52 tim 1492 #include "io/mpiBASS.h"
53 gezelter 1490 #endif // is_mpi
54    
55 tim 2187 MakeStamps::MakeStamps(){
56 gezelter 1490 }
57    
58 tim 2187 MakeStamps::~MakeStamps(){
59 gezelter 1490
60 tim 2187 std::map<std::string, MoleculeStamp*>::iterator iter;
61    
62     for (iter=my_mols.begin(); iter!=my_mols.end(); ++iter) {
63     delete iter->second;
64 gezelter 1490 }
65    
66 tim 2187 my_mols.clear();
67 gezelter 1490
68     }
69    
70 tim 2187 MoleculeStamp* MakeStamps::getMolStamp( std::string the_id ){
71 gezelter 1490
72 tim 2187 std::map<std::string, MoleculeStamp*>::iterator iter;
73 gezelter 1490
74 tim 2187 iter = my_mols.find(the_id);
75 gezelter 1490
76 tim 2187 if (iter == my_mols.end()) {
77     return NULL;
78     } else {
79     return iter->second;
80 gezelter 1490 }
81    
82     }
83    
84 tim 2187 void MakeStamps::addMolStamp( MoleculeStamp* the_stamp ){
85 gezelter 1490
86 tim 2187 std::map<std::string, MoleculeStamp*>::iterator iter;
87 gezelter 1490
88 tim 2187 std::string molStampName(the_stamp->getID());
89 gezelter 1490
90 tim 2187 iter = my_mols.find(molStampName);
91 gezelter 1490
92 tim 2187 if (iter != my_mols.end()) {
93 gezelter 1490 sprintf( painCave.errMsg,
94 tim 2187 "Molecule Stamp Error. Two separate of declarations of "
95     "%s present.\n",
96     the_stamp->getID());
97 gezelter 1490 painCave.isFatal = 1;
98     simError();
99     #ifdef IS_MPI
100     if( painCave.isEventLoop ){
101     if( worldRank == 0 ) mpiInterfaceExit();
102     }
103     #endif //is_mpi
104 tim 2187
105     } else {
106     my_mols.insert(std::map<std::string, MoleculeStamp*>::value_type(molStampName, the_stamp));
107 gezelter 1490 }
108     }
109    
110    
111     int MakeStamps::newMolecule( event* the_event ){
112    
113     current_mol = new MoleculeStamp;
114     return 1;
115     }
116    
117     int MakeStamps::moleculeAssign( event* the_event ){
118    
119     switch( the_event->evt.asmt.asmt_type ){
120    
121     case STRING:
122     the_event->err_msg = current_mol->assignString( the_event->evt.asmt.lhs,
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 );
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 );
134     break;
135    
136     default:
137     the_event->err_msg = strdup( "MakeStamp error. Invalid molecule"
138     " assignment type" );
139     return 0;
140     break;
141     }
142     if( the_event->err_msg != NULL ) return 0;
143     return 1;
144     }
145    
146     int MakeStamps::moleculeEnd( event* the_event ){
147    
148     the_event->err_msg = current_mol->checkMe();
149     // if err_msg is set, then something is wrong
150     if( the_event->err_msg != NULL ) return 0;
151    
152     addMolStamp( current_mol );
153     return 1;
154     }
155    
156     int MakeStamps::newRigidBody( event* the_event ){
157    
158     current_rigidbody = new RigidBodyStamp;
159    
160     the_event->err_msg = current_mol->addRigidBody( current_rigidbody,
161     the_event->evt.blk_index );
162     if( the_event->err_msg != NULL ) return 0;
163     return 1;
164     }
165    
166     int MakeStamps::rigidBodyAssign( event* the_event ){
167    
168     switch( the_event->evt.asmt.asmt_type ){
169    
170     case STRING:
171     the_event->err_msg =
172     current_rigidbody->assignString( the_event->evt.asmt.lhs,
173     the_event->evt.asmt.rhs.sval );
174     if( the_event->err_msg != NULL ) return 0;
175     return 1;
176     break;
177    
178     case DOUBLE:
179     the_event->err_msg =
180     current_rigidbody->assignDouble( the_event->evt.asmt.lhs,
181     the_event->evt.asmt.rhs.dval );
182     if( the_event->err_msg != NULL ) return 0;
183     return 1;
184     break;
185    
186     case INT:
187     the_event->err_msg =
188     current_rigidbody->assignInt( the_event->evt.asmt.lhs,
189     the_event->evt.asmt.rhs.ival );
190     if( the_event->err_msg != NULL ) return 0;
191     return 1;
192     break;
193    
194     default:
195     the_event->err_msg = strdup( "MakeStamp error. Invalid rigidBody"
196     " assignment type" );
197     return 0;
198     break;
199     }
200     return 0;
201     }
202    
203     int MakeStamps::rigidBodyMembers( event* the_event ){
204    
205     int i;
206    
207     if( the_event->evt.mbrs.nMembers > 0 ){
208    
209     for (i = 0; i < the_event->evt.mbrs.nMembers; i++) {
210     current_rigidbody->addMember(the_event->evt.mbrs.memberList[i]);
211     }
212    
213     return 1;
214    
215     } else {
216     the_event->err_msg = strdup( "MakeStamp error. No members in memberList "
217     " for this rigidBody.");
218     return 0;
219    
220     }
221     }
222    
223     int MakeStamps::rigidBodyEnd( event* the_event ){
224    
225     the_event->err_msg = current_rigidbody->checkMe();
226     if( the_event->err_msg != NULL ) return 0;
227    
228     return 1;
229     }
230    
231     int MakeStamps::newCutoffGroup( event* the_event ){
232    
233     current_cutoffgroup = new CutoffGroupStamp;
234    
235     the_event->err_msg = current_mol->addCutoffGroup( current_cutoffgroup,
236     the_event->evt.blk_index );
237     if( the_event->err_msg != NULL ) return 0;
238     return 1;
239     }
240    
241     int MakeStamps::cutoffGroupAssign( event* the_event ){
242    
243     switch( the_event->evt.asmt.asmt_type ){
244    
245     case STRING:
246     the_event->err_msg =
247     current_cutoffgroup->assignString( the_event->evt.asmt.lhs,
248     the_event->evt.asmt.rhs.sval );
249     if( the_event->err_msg != NULL ) return 0;
250     return 1;
251     break;
252    
253     case DOUBLE:
254     the_event->err_msg =
255     current_cutoffgroup->assignDouble( the_event->evt.asmt.lhs,
256     the_event->evt.asmt.rhs.dval );
257     if( the_event->err_msg != NULL ) return 0;
258     return 1;
259     break;
260    
261     case INT:
262     the_event->err_msg =
263     current_cutoffgroup->assignInt( the_event->evt.asmt.lhs,
264     the_event->evt.asmt.rhs.ival );
265     if( the_event->err_msg != NULL ) return 0;
266     return 1;
267     break;
268    
269     default:
270     the_event->err_msg = strdup( "MakeStamp error. Invalid CutoffGroup"
271     " assignment type" );
272     return 0;
273     break;
274     }
275     return 0;
276     }
277    
278     int MakeStamps::cutoffGroupMembers( event* the_event ){
279    
280     int i;
281    
282     if( the_event->evt.mbrs.nMembers > 0 ){
283    
284     for (i = 0; i < the_event->evt.mbrs.nMembers; i++) {
285     current_cutoffgroup->addMember(the_event->evt.mbrs.memberList[i]);
286     }
287    
288     return 1;
289    
290     } else {
291     the_event->err_msg = strdup( "MakeStamp error. No members in memberList "
292     " for this CutoffGroup.");
293     return 0;
294    
295     }
296     }
297    
298     int MakeStamps::cutoffGroupEnd( event* the_event ){
299    
300     the_event->err_msg = current_cutoffgroup->checkMe();
301     if( the_event->err_msg != NULL ) return 0;
302    
303     return 1;
304     }
305    
306     int MakeStamps::newAtom( event* the_event ){
307    
308     current_atom = new AtomStamp;
309    
310     the_event->err_msg = current_mol->addAtom( current_atom,
311     the_event->evt.blk_index );
312    
313     if( the_event->err_msg != NULL ) return 0;
314     return 1;
315     }
316    
317     int MakeStamps::atomPosition( event* the_event ){
318    
319     current_atom->setPosition( the_event->evt.pos.x,
320     the_event->evt.pos.y,
321     the_event->evt.pos.z );
322     return 1;
323     }
324    
325    
326     int MakeStamps::atomOrientation( event* the_event ){
327    
328     current_atom->setOrientation( the_event->evt.ornt.phi,
329     the_event->evt.ornt.theta,
330     the_event->evt.ornt.psi );
331     return 1;
332     }
333    
334     int MakeStamps::atomAssign( event* the_event ){
335    
336     switch( the_event->evt.asmt.asmt_type ){
337    
338     case STRING:
339     the_event->err_msg =
340     current_atom->assignString( the_event->evt.asmt.lhs,
341     the_event->evt.asmt.rhs.sval );
342     if( the_event->err_msg != NULL ) return 0;
343     return 1;
344     break;
345    
346     case DOUBLE:
347     the_event->err_msg =
348     current_atom->assignDouble( the_event->evt.asmt.lhs,
349     the_event->evt.asmt.rhs.dval );
350     if( the_event->err_msg != NULL ) return 0;
351     return 1;
352     break;
353    
354     case INT:
355     the_event->err_msg =
356     current_atom->assignInt( the_event->evt.asmt.lhs,
357     the_event->evt.asmt.rhs.ival );
358     if( the_event->err_msg != NULL ) return 0;
359     return 1;
360     break;
361    
362     default:
363     the_event->err_msg = strdup( "MakeStamp error. Invalid atom"
364     " assignment type" );
365     return 0;
366     break;
367     }
368     return 0;
369     }
370    
371     int MakeStamps::atomEnd( event* the_event ){
372    
373     the_event->err_msg = current_atom->checkMe();
374     if( the_event->err_msg != NULL ) return 0;
375    
376     return 1;
377     }
378    
379     int MakeStamps::newBond( event* the_event ){
380    
381     current_bond = new BondStamp;
382    
383     the_event->err_msg = current_mol->addBond( current_bond,
384     the_event->evt.blk_index );
385     if( the_event->err_msg != NULL ) return 0;
386    
387     return 1;
388     }
389    
390     int MakeStamps::bondAssign( event* the_event ){
391    
392     switch( the_event->evt.asmt.asmt_type ){
393    
394     case STRING:
395     current_bond->assignString( the_event->evt.asmt.lhs,
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 );
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 );
409     return 1;
410     break;
411    
412     default:
413     the_event->err_msg = strdup( "MakeStamp error. Invalid bond"
414     " assignment type" );
415     return 0;
416     break;
417     }
418     return 0;
419     }
420    
421     int MakeStamps::bondMembers( event* the_event ){
422    
423     if( the_event->evt.mbrs.nMembers == 2 ){
424    
425     current_bond->members( the_event->evt.mbrs.memberList[0],
426     the_event->evt.mbrs.memberList[1] );
427     return 1;
428    
429     } else {
430     the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
431     " in bond");
432     return 0;
433    
434     }
435    
436     }
437    
438     int MakeStamps::bondConstraint( event* the_event ){
439    
440     current_bond->constrain( the_event->evt.cnstr );
441     return 1;
442     }
443    
444     int MakeStamps::bondEnd( event* the_event ){
445    
446     the_event->err_msg = current_bond->checkMe();
447     if( the_event->err_msg != NULL ) return 0;
448    
449     return 1;
450     }
451    
452     int MakeStamps::newBend( event* the_event ){
453    
454     current_bend = new BendStamp;
455    
456     the_event->err_msg = current_mol->addBend( current_bend,
457     the_event->evt.blk_index );
458     if( the_event->err_msg != NULL ) return 0;
459    
460     return 1;
461     }
462    
463     int MakeStamps::bendAssign( event* the_event ){
464    
465     switch( the_event->evt.asmt.asmt_type ){
466    
467     case STRING:
468     current_bend->assignString( the_event->evt.asmt.lhs,
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 );
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 );
482     return 1;
483     break;
484    
485     default:
486     the_event->err_msg = strdup( "MakeStamp error. Invalid bend"
487     " assignment type" );
488     return 0;
489     break;
490     }
491     return 0;
492     }
493    
494     int MakeStamps::bendMembers( event* the_event ){
495    
496    
497     switch( the_event->evt.mbrs.nMembers ) {
498     case 3:
499     current_bend->members( the_event->evt.mbrs.memberList[0],
500     the_event->evt.mbrs.memberList[1],
501     the_event->evt.mbrs.memberList[2]);
502     return 1;
503     break;
504     case 2:
505     current_bend->members( the_event->evt.mbrs.memberList[0],
506     the_event->evt.mbrs.memberList[1],
507     0 );
508     return 1;
509     break;
510     default:
511     the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
512     "in bend.");
513     return 0;
514     break;
515     }
516     return 0;
517     }
518    
519     int MakeStamps::bendConstraint( event* the_event ){
520    
521     current_bend->constrain( the_event->evt.cnstr );
522     return 1;
523     }
524    
525     int MakeStamps::bendEnd( event* the_event ){
526    
527     the_event->err_msg = current_bend->checkMe();
528     if( the_event->err_msg != NULL ) return 0;
529    
530     return 1;
531     }
532    
533     int MakeStamps::newTorsion( event* the_event ){
534    
535     current_torsion = new TorsionStamp;
536    
537     the_event->err_msg = current_mol->addTorsion( current_torsion,
538     the_event->evt.blk_index );
539     if( the_event->err_msg != NULL ) return 0;
540    
541     return 1;
542     }
543    
544     int MakeStamps::torsionAssign( event* the_event ){
545    
546     switch( the_event->evt.asmt.asmt_type ){
547    
548     case STRING:
549     current_torsion->assignString( the_event->evt.asmt.lhs,
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 );
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 );
563     return 1;
564     break;
565    
566     default:
567     the_event->err_msg = strdup( "MakeStamp error. Invalid torsion"
568     " assignment type" );
569     return 0;
570     break;
571     }
572     return 0;
573     }
574    
575     int MakeStamps::torsionMembers( event* the_event ){
576    
577 tim 1957
578     switch( the_event->evt.mbrs.nMembers ) {
579     case 4:
580 gezelter 1490
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 tim 1957 break;
587     case 3:
588    
589 gezelter 1490
590 tim 1957 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 gezelter 1490 the_event->err_msg = strdup( "MakeStamp error. Wrong number of members "
599 tim 1957 "in torsion.");
600 gezelter 1490 return 0;
601 tim 1957 break;
602 gezelter 1490 }
603 tim 1957 return 0;
604    
605 gezelter 1490 }
606    
607     int MakeStamps::torsionConstraint( event* the_event ){
608    
609     current_torsion->constrain( the_event->evt.cnstr );
610     return 1;
611     }
612    
613     int MakeStamps::torsionEnd( event* the_event ){
614    
615     the_event->err_msg = current_torsion->checkMe();
616     if( the_event->err_msg != NULL ) return 0;
617    
618     return 1;
619     }