ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/SimSetup.cpp
(Generate patch)

Comparing trunk/mdtools/interface_implementation/SimSetup.cpp (file contents):
Revision 124 by chuckv, Mon Sep 30 20:35:42 2002 UTC vs.
Revision 202 by mmeineke, Tue Dec 10 21:41:26 2002 UTC

# Line 6 | Line 6
6   #include "parse_me.h"
7   #include "LRI.hpp"
8   #include "Integrator.hpp"
9 < #include "mpiInterface.h"
9 > #include "simError.h"
10  
11 + #ifdef IS_MPI
12 + #include "mpiBASS.h"
13 + #include "bassDiag.hpp"
14 + #endif
15 +
16   SimSetup::SimSetup(){
17    stamps = new MakeStamps();
18    globals = new Globals();
19 +  
20 + #ifdef IS_MPI
21 +  strcpy( checkPointMsg, "SimSetup creation successful" );
22 +  MPIcheckPoint();
23 + #endif // IS_MPI
24   }
25  
26   SimSetup::~SimSetup(){
# Line 20 | Line 30 | void SimSetup::parseFile( char* fileName ){
30  
31   void SimSetup::parseFile( char* fileName ){
32  
33 <  inFileName = fileName;
34 <  set_interface_stamps( stamps, globals );
35 < #ifdef MPI
36 <  mpiEventInit();
33 > #ifdef IS_MPI
34 >  if( worldRank == 0 ){
35 > #endif // is_mpi
36 >    
37 >    inFileName = fileName;
38 >    set_interface_stamps( stamps, globals );
39 >    
40 > #ifdef IS_MPI
41 >    mpiEventInit();
42   #endif
43 <  yacc_BASS( fileName );
44 < #ifdef MPI
45 <  throwMPIEvent(NULL);
43 >
44 >    yacc_BASS( fileName );
45 >
46 > #ifdef IS_MPI
47 >    throwMPIEvent(NULL);
48 >  }
49 >  else receiveParse();
50   #endif
51  
52   }
53  
54 < #ifdef MPI
54 > #ifdef IS_MPI
55   void SimSetup::receiveParse(void){
56  
57      set_interface_stamps( stamps, globals );
58      mpiEventInit();
59 +    MPIcheckPoint();
60      mpiEventLoop();
61  
62   }
63 +
64 +
65 + void SimSetup::testMe(void){
66 +  bassDiag* dumpMe = new bassDiag(globals,stamps);
67 +  dumpMe->dumpStamps();
68 +  delete dumpMe;
69 + }
70   #endif
71  
72   void SimSetup::createSim( void ){
73  
74    MakeStamps *the_stamps;
75    Globals* the_globals;
76 <  int i;
76 >  int i, j;
77  
78    // get the stamps and globals;
79    the_stamps = stamps;
# Line 66 | Line 93 | void SimSetup::createSim( void ){
93    else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF();
94    else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF();
95    else{
96 <    std::cerr<< "SimSetup Error. Unrecognized force field -> "
97 <             << force_field << "\n";
98 <    exit(8);
96 >    sprintf( painCave.errMsg,
97 >             "SimSetup Error. Unrecognized force field -> %s\n",
98 >             force_field );
99 >    painCave.isFatal = 1;
100 >    simError();
101    }
102  
103 + #ifdef IS_MPI
104 +  strcpy( checkPointMsg, "ForceField creation successful" );
105 +  MPIcheckPoint();
106 + #endif // is_mpi
107 +
108    // get the components and calculate the tot_nMol and indvidual n_mol
109    the_components = the_globals->getComponents();
110    components_nmol = new int[n_components];
# Line 85 | Line 119 | void SimSetup::createSim( void ){
119  
120        if( !the_components[i]->haveNMol() ){
121          // we have a problem
122 <        std::cerr << "SimSetup Error. No global NMol or component NMol"
123 <                  << " given. Cannot calculate the number of atoms.\n";
124 <        exit( 8 );
122 >        sprintf( painCave.errMsg,
123 >                 "SimSetup Error. No global NMol or component NMol"
124 >                 " given. Cannot calculate the number of atoms.\n" );
125 >        painCave.isFatal = 1;
126 >        simError();
127        }
128  
129        tot_nmol += the_components[i]->getNMol();
# Line 95 | Line 131 | void SimSetup::createSim( void ){
131      }
132    }
133    else{
134 <    std::cerr << "NOT A SUPPORTED FEATURE\n";
134 >    sprintf( painCave.errMsg,
135 >             "SimSetup error.\n"
136 >             "\tSorry, the ability to specify total"
137 >             " nMols and then give molfractions in the components\n"
138 >             "\tis not currently supported."
139 >             " Please give nMol in the components.\n" );
140 >    painCave.isFatal = 1;
141 >    simError();
142 >    
143 >    
144 >    //     tot_nmol = the_globals->getNMol();
145 >    
146 >    //   //we have the total number of molecules, now we check for molfractions
147 >    //     for( i=0; i<n_components; i++ ){
148 >    
149 >    //       if( !the_components[i]->haveMolFraction() ){
150 >    
151 >    //  if( !the_components[i]->haveNMol() ){
152 >    //    //we have a problem
153 >    //    std::cerr << "SimSetup error. Neither molFraction nor "
154 >    //              << " nMol was given in component
155 >    
156 >  }
157  
158 < //     tot_nmol = the_globals->getNMol();
158 > #ifdef IS_MPI
159 >  strcpy( checkPointMsg, "Have the number of components" );
160 >  MPIcheckPoint();
161 > #endif // is_mpi
162  
163 < //     //we have the total number of molecules, now we check for molfractions
164 < //     for( i=0; i<n_components; i++ ){
163 >  // make an array of molecule stamps that match the components used.
164 >  // also extract the used stamps out into a separate linked list
165  
166 < //       if( !the_components[i]->haveMolFraction() ){
166 >  simnfo->nComponents = n_components;
167 >  simnfo->componentsNmol = components_nmol;
168 >  simnfo->compStamps = comp_stamps;
169 >  simnfo->headStamp = new LinkedMolStamp();
170 >  
171 >  char* id;
172 >  LinkedMolStamp* headStamp = simnfo->headStamp;
173 >  LinkedMolStamp* currentStamp = NULL;
174 >  for( i=0; i<n_components; i++ ){
175  
176 < //      if( !the_components[i]->haveNMol() ){
177 < //        //we have a problem
178 < //        std::cerr << "SimSetup error. Neither molFraction nor "
179 < //                  << " nMol was given in component
176 >    id = the_components[i]->getType();
177 >    comp_stamps[i] = NULL;
178 >    
179 >    // check to make sure the component isn't already in the list
180  
181 +    comp_stamps[i] = headStamp->match( id );
182 +    if( comp_stamps[i] == NULL ){
183 +      
184 +      // extract the component from the list;
185 +      
186 +      currentStamp = the_stamps->extractMolStamp( id );
187 +      if( currentStamp == NULL ){
188 +        sprintf( painCave.errMsg,
189 +                 "SimSetup error: Component \"%s\" was not found in the "
190 +                 "list of declared molecules\n"
191 +                 id );
192 +        painCave.isFatal = 1;
193 +        simError();
194 +      }
195 +      
196 +      headStamp->add( currentStamp );
197 +      comp_stamps[i] = headStamp->match( id );
198 +    }
199    }
200  
201 <  // make an array of molecule stamps that match the components used.
201 > #ifdef IS_MPI
202 >  strcpy( checkPointMsg, "Component stamps successfully extracted\n" );
203 >  MPIcheckPoint();
204 > #endif // is_mpi
205 >  
206  
116  for( i=0; i<n_components; i++ ){
207  
118    comp_stamps[i] =
119      the_stamps->getMolecule( the_components[i]->getType() );
120  }
208  
122
123
209    // caclulate the number of atoms, bonds, bends and torsions
210  
211    tot_atoms = 0;
# Line 128 | Line 213 | void SimSetup::createSim( void ){
213    tot_bends = 0;
214    tot_torsions = 0;
215    for( i=0; i<n_components; i++ ){
216 <
217 <    tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
218 <    tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
219 <    tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
216 >    
217 >    tot_atoms +=    components_nmol[i] * comp_stamps[i]->getNAtoms();
218 >    tot_bonds +=    components_nmol[i] * comp_stamps[i]->getNBonds();
219 >    tot_bends +=    components_nmol[i] * comp_stamps[i]->getNBends();
220      tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
221    }
222  
# Line 142 | Line 227 | void SimSetup::createSim( void ){
227    simnfo->n_bends = tot_bends;
228    simnfo->n_torsions = tot_torsions;
229    simnfo->n_SRI = tot_SRI;
230 +  simnfo->n_mol = tot_nmol;
231  
232 +  
233 + #ifdef IS_MPI
234 +
235 +  // divide the molecules among processors here.
236 +  
237 +  mpiSimulation* mpiSim = new mpiSimulation( simnfo );
238 +  
239 +  mpiSim->divideLabor();
240 +
241 +  // set up the local variables
242 +  
243 +  int localMol;
244 +  int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
245 +  
246 +  localMol = 0;
247 +  local_atoms = 0;
248 +  local_bonds = 0;
249 +  local_bends = 0;
250 +  local_torsions = 0;
251 +  for( i=0; i<n_components; i++ ){
252 +
253 +    for( j=0; j<components_nmol[i]; j++ ){
254 +      
255 +      if( mpiSim->getMyMolStart() <= j &&
256 +          j <= mpiSim->getMyMolEnd() ){
257 +        
258 +        local_atoms +=    comp_stamps[i]->getNAtoms();
259 +        local_bonds +=    comp_stamps[i]->getNBonds();
260 +        local_bends +=    comp_stamps[i]->getNBends();
261 +        local_torsions += comp_stamps[i]->getNTorsions();
262 +        localMol++;
263 +      }      
264 +    }
265 +  }
266 +
267 +  
268 +
269 +  simnfo->n_atoms = mpiSim->getMyNlocal();  
270 +  
271 +
272 + #endif // is_mpi
273 +  
274 +
275    // create the atom and short range interaction arrays
276  
277 <  the_atoms = new Atom*[tot_atoms];
278 <  the_molecules = new Molecule[tot_nmol];
277 >  Atom::createArrays(simnfo->n_atoms);
278 >  the_atoms = new Atom*[simnfo->n_atoms];
279 >  the_molecules = new Molecule[simnfo->n_mol];
280  
281  
282 <  if( tot_SRI ){
283 <    the_sris = new SRI*[tot_SRI];
284 <    the_excludes = new ex_pair[tot_SRI];
282 >  if( simnfo->n_SRI ){
283 >    the_sris = new SRI*[simnfo->n_SRI];
284 >    the_excludes = new ex_pair[simnfo->n_SRI];
285    }
286  
287    // set the arrays into the SimInfo object
# Line 180 | Line 310 | void SimSetup::createSim( void ){
310      makeTorsions();
311    }
312  
183  //  makeMolecules();
313  
314    // get some of the tricky things that may still be in the globals
315  
316    if( simnfo->n_dipoles ){
317  
318      if( !the_globals->haveRRF() ){
319 <      std::cerr << "SimSetup Error, system has dipoles, but no rRF was set.\n";
320 <      exit(8);
319 >      sprintf( painCave.errMsg,
320 >               "SimSetup Error, system has dipoles, but no rRF was set.\n");
321 >      painCave.isFatal = 1;
322 >      simError();
323      }
324      if( !the_globals->haveDielectric() ){
325 <      std::cerr << "SimSetup Error, system has dipoles, but no"
326 <                << " dielectric was set.\n";
327 <      exit(8);
325 >      sprintf( painCave.errMsg,
326 >               "SimSetup Error, system has dipoles, but no"
327 >               " dielectric was set.\n" );
328 >      painCave.isFatal = 1;
329 >      simError();
330      }
331  
332      simnfo->rRF        = the_globals->getRRF();
333      simnfo->dielectric = the_globals->getDielectric();
334    }
335  
336 + #ifdef IS_MPI
337 +  strcpy( checkPointMsg, "rRf and dielectric check out" );
338 +  MPIcheckPoint();
339 + #endif // is_mpi
340 +  
341    if( the_globals->haveBox() ){
342      simnfo->box_x = the_globals->getBox();
343      simnfo->box_y = the_globals->getBox();
# Line 215 | Line 353 | void SimSetup::createSim( void ){
353    }
354    else{
355      if( !the_globals->haveBoxX() ){
356 <      std::cerr << "SimSetup error, no periodic BoxX size given.\n";
357 <      exit(8);
356 >      sprintf( painCave.errMsg,
357 >               "SimSetup error, no periodic BoxX size given.\n" );
358 >      painCave.isFatal = 1;
359 >      simError();
360      }
361      simnfo->box_x = the_globals->getBoxX();
362  
363      if( !the_globals->haveBoxY() ){
364 <      std::cerr << "SimSetup error, no periodic BoxY size given.\n";
365 <      exit(8);
364 >      sprintf( painCave.errMsg,
365 >               "SimSetup error, no periodic BoxY size given.\n" );
366 >      painCave.isFatal = 1;
367 >      simError();
368      }
369      simnfo->box_y = the_globals->getBoxY();
370  
371      if( !the_globals->haveBoxZ() ){
372 <      std::cerr << "SimSetup error, no periodic BoxZ size given.\n";
373 <      exit(8);
372 >      sprintf( painCave.errMsg,
373 >               "SimSetup error, no periodic BoxZ size given.\n" );
374 >      painCave.isFatal = 1;
375 >      simError();
376      }
377      simnfo->box_z = the_globals->getBoxZ();
378    }
379  
380 + #ifdef IS_MPI
381 +  strcpy( checkPointMsg, "Box size set up" );
382 +  MPIcheckPoint();
383 + #endif // is_mpi
384  
385 +
386 +
387   //   if( the_globals->haveInitialConfig() ){
388   //        InitializeFromFile* fileInit;
389   //     fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
# Line 244 | Line 394 | void SimSetup::createSim( void ){
394   //   }
395   //   else{
396  
397 <    initFromBass();
397 > #ifdef IS_MPI
398  
399 +  // no init from bass
400 +  
401 +  sprintf( painCave.errMsg,
402 +           "Cannot intialize a parallel simulation without an initial configuration file.\n" );
403 +  painCave.isFatal;
404 +  simError();
405 +  
406 + #else
407  
408 < //   }
408 >  initFromBass();
409  
410 < //   if( the_globals->haveFinalConfig() ){
411 < //     strcpy( simnfo->finalName, the_globals->getFinalConfig() );
412 < //   }
413 < //   else{
414 < //     strcpy( simnfo->finalName, inFileName );
415 < //     char* endTest;
258 < //     int nameLength = strlen( simnfo->finalName );
259 < //     endTest = &(simnfo->finalName[nameLength - 5]);
260 < //     if( !strcmp( endTest, ".bass" ) ){
261 < //       strcpy( endTest, ".eor" );
262 < //     }
263 < //     else if( !strcmp( endTest, ".BASS" ) ){
264 < //       strcpy( endTest, ".eor" );
265 < //     }
266 < //     else{
267 < //       endTest = &(simnfo->finalName[nameLength - 4]);
268 < //       if( !strcmp( endTest, ".bss" ) ){
269 < //      strcpy( endTest, ".eor" );
270 < //       }
271 < //       else if( !strcmp( endTest, ".mdl" ) ){
272 < //      strcpy( endTest, ".eor" );
273 < //       }
274 < //       else{
275 < //      strcat( simnfo->finalName, ".eor" );
276 < //       }
277 < //     }
278 < //   }
410 > #endif // is_mpi
411 >
412 > #ifdef IS_MPI
413 >  strcpy( checkPointMsg, "Successfully read in the initial configuration" );
414 >  MPIcheckPoint();
415 > #endif // is_mpi
416  
280 //   // make the sample and status out names
417  
418 < //   strcpy( simnfo->sampleName, inFileName );
419 < //   char* endTest;
420 < //   int nameLength = strlen( simnfo->sampleName );
421 < //   endTest = &(simnfo->sampleName[nameLength - 5]);
422 < //   if( !strcmp( endTest, ".bass" ) ){
423 < //     strcpy( endTest, ".dump" );
424 < //   }
425 < //   else if( !strcmp( endTest, ".BASS" ) ){
426 < //     strcpy( endTest, ".dump" );
427 < //   }
428 < //   else{
429 < //     endTest = &(simnfo->sampleName[nameLength - 4]);
430 < //     if( !strcmp( endTest, ".bss" ) ){
431 < //       strcpy( endTest, ".dump" );
432 < //     }
433 < //     else if( !strcmp( endTest, ".mdl" ) ){
434 < //       strcpy( endTest, ".dump" );
435 < //     }
436 < //     else{
437 < //       strcat( simnfo->sampleName, ".dump" );
438 < //     }
439 < //   }
440 <
441 < //   strcpy( simnfo->statusName, inFileName );
442 < //   nameLength = strlen( simnfo->statusName );
443 < //   endTest = &(simnfo->statusName[nameLength - 5]);
444 < //   if( !strcmp( endTest, ".bass" ) ){
445 < //     strcpy( endTest, ".stat" );
446 < //   }
447 < //   else if( !strcmp( endTest, ".BASS" ) ){
448 < //     strcpy( endTest, ".stat" );
449 < //   }
450 < //   else{
451 < //     endTest = &(simnfo->statusName[nameLength - 4]);
452 < //     if( !strcmp( endTest, ".bss" ) ){
453 < //       strcpy( endTest, ".stat" );
454 < //     }
455 < //     else if( !strcmp( endTest, ".mdl" ) ){
456 < //       strcpy( endTest, ".stat" );
457 < //     }
458 < //     else{
459 < //       strcat( simnfo->statusName, ".stat" );
460 < //     }
461 < //   }
462 <
463 <
418 >  
419 >
420 >  
421 >  //   }
422 >  
423 > #ifdef IS_MPI
424 >  if( worldRank == 0 ){
425 > #endif // is_mpi
426 >    
427 >    if( the_globals->haveFinalConfig() ){
428 >      strcpy( simnfo->finalName, the_globals->getFinalConfig() );
429 >    }
430 >    else{
431 >      strcpy( simnfo->finalName, inFileName );
432 >      char* endTest;
433 >      int nameLength = strlen( simnfo->finalName );
434 >      endTest = &(simnfo->finalName[nameLength - 5]);
435 >      if( !strcmp( endTest, ".bass" ) ){
436 >        strcpy( endTest, ".eor" );
437 >      }
438 >      else if( !strcmp( endTest, ".BASS" ) ){
439 >        strcpy( endTest, ".eor" );
440 >      }
441 >      else{
442 >        endTest = &(simnfo->finalName[nameLength - 4]);
443 >        if( !strcmp( endTest, ".bss" ) ){
444 >          strcpy( endTest, ".eor" );
445 >        }
446 >        else if( !strcmp( endTest, ".mdl" ) ){
447 >          strcpy( endTest, ".eor" );
448 >        }
449 >        else{
450 >          strcat( simnfo->finalName, ".eor" );
451 >        }
452 >      }
453 >    }
454 >    
455 >    // make the sample and status out names
456 >    
457 >    strcpy( simnfo->sampleName, inFileName );
458 >    char* endTest;
459 >    int nameLength = strlen( simnfo->sampleName );
460 >    endTest = &(simnfo->sampleName[nameLength - 5]);
461 >    if( !strcmp( endTest, ".bass" ) ){
462 >      strcpy( endTest, ".dump" );
463 >    }
464 >    else if( !strcmp( endTest, ".BASS" ) ){
465 >      strcpy( endTest, ".dump" );
466 >    }
467 >    else{
468 >      endTest = &(simnfo->sampleName[nameLength - 4]);
469 >      if( !strcmp( endTest, ".bss" ) ){
470 >        strcpy( endTest, ".dump" );
471 >      }
472 >      else if( !strcmp( endTest, ".mdl" ) ){
473 >        strcpy( endTest, ".dump" );
474 >      }
475 >      else{
476 >        strcat( simnfo->sampleName, ".dump" );
477 >      }
478 >    }
479 >    
480 >    strcpy( simnfo->statusName, inFileName );
481 >    nameLength = strlen( simnfo->statusName );
482 >    endTest = &(simnfo->statusName[nameLength - 5]);
483 >    if( !strcmp( endTest, ".bass" ) ){
484 >      strcpy( endTest, ".stat" );
485 >    }
486 >    else if( !strcmp( endTest, ".BASS" ) ){
487 >      strcpy( endTest, ".stat" );
488 >    }
489 >    else{
490 >      endTest = &(simnfo->statusName[nameLength - 4]);
491 >      if( !strcmp( endTest, ".bss" ) ){
492 >        strcpy( endTest, ".stat" );
493 >      }
494 >      else if( !strcmp( endTest, ".mdl" ) ){
495 >        strcpy( endTest, ".stat" );
496 >      }
497 >      else{
498 >        strcat( simnfo->statusName, ".stat" );
499 >      }
500 >    }
501 >    
502 > #ifdef IS_MPI
503 >  }
504 > #endif // is_mpi
505 >  
506    // set the status, sample, and themal kick times
507 <
507 >  
508    if( the_globals->haveSampleTime() ){
509      simnfo->sampleTime = the_globals->getSampleTime();
510      simnfo->statusTime = simnfo->sampleTime;
# Line 382 | Line 560 | void SimSetup::makeAtoms( void ){
560          current_atom = comp_stamps[i]->getAtom( k );
561          if( current_atom->haveOrientation() ){
562  
563 <          dAtom = new DirectionalAtom;
563 >          dAtom = new DirectionalAtom(index);
564            simnfo->n_oriented++;
565            the_atoms[index] = dAtom;
566  
# Line 402 | Line 580 | void SimSetup::makeAtoms( void ){
580            dAtom->setSUz( uz );
581          }
582          else{
583 <          the_atoms[index] = new GeneralAtom;
583 >          the_atoms[index] = new GeneralAtom(index);
584          }
585          the_atoms[index]->setType( current_atom->getType() );
586          the_atoms[index]->setIndex( index );
# Line 415 | Line 593 | void SimSetup::makeAtoms( void ){
593        the_molecules[molIndex].setNMembers( nMemb );
594        the_molecules[molIndex].setStartAtom( molStart );
595        the_molecules[molIndex].setEndAtom( molEnd );
596 +      the_molecules[molIndex].setStampID( i );
597        molIndex++;
598  
599      }
# Line 549 | Line 728 | void SimSetup::initFromBass( void ){
728      n_per_extra = (int)ceil( temp1 );
729  
730      if( n_per_extra > 4){
731 <      std::cerr << "THere has been an error in constructing the non-complete lattice.\n";
732 <      exit(8);
731 >      sprintf( painCave.errMsg,
732 >               "SimSetup error. There has been an error in constructing"
733 >               " the non-complete lattice.\n" );
734 >      painCave.isFatal = 1;
735 >      simError();
736      }
737    }
738    else{
# Line 655 | Line 837 | void SimSetup::makeElement( double x, double y, double
837  
838      current_atom = comp_stamps[current_comp]->getAtom( k );
839      if( !current_atom->havePosition() ){
840 <      std::cerr << "Component " << comp_stamps[current_comp]->getID()
841 <                << ", atom " << current_atom->getType()
842 <                << " does not have a position specified.\n"
843 <                << "The initialization routine is unable to give a start"
844 <                << " position.\n";
845 <      exit(8);
840 >      sprintf( painCave.errMsg,
841 >               "SimSetup:initFromBass error.\n"
842 >               "\tComponent %s, atom %s does not have a position specified.\n"
843 >               "\tThe initialization routine is unable to give a start"
844 >               " position.\n",
845 >               comp_stamps[current_comp]->getID(),
846 >               current_atom->getType() );
847 >      painCave.isFatal = 1;
848 >      simError();
849      }
850  
851      the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines