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 184 by mmeineke, Thu Nov 21 20:33:06 2002 UTC vs.
Revision 202 by mmeineke, Tue Dec 10 21:41:26 2002 UTC

# Line 73 | Line 73 | 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 119 | 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 129 | Line 131 | void SimSetup::createSim( void ){
131      }
132    }
133    else{
134 <    std::cerr << "NOT A SUPPORTED FEATURE\n";
135 <
136 < //     tot_nmol = the_globals->getNMol();
137 <
138 < //     //we have the total number of molecules, now we check for molfractions
139 < //     for( i=0; i<n_components; i++ ){
140 <
141 < //       if( !the_components[i]->haveMolFraction() ){
142 <
143 < //      if( !the_components[i]->haveNMol() ){
144 < //        //we have a problem
145 < //        std::cerr << "SimSetup error. Neither molFraction nor "
146 < //                  << " nMol was given in component
147 <
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 + #ifdef IS_MPI
159 +  strcpy( checkPointMsg, "Have the number of components" );
160 +  MPIcheckPoint();
161 + #endif // is_mpi
162 +
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 +  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 <    comp_stamps[i] =
177 <      the_stamps->getMolecule( the_components[i]->getType() );
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 + #ifdef IS_MPI
202 +  strcpy( checkPointMsg, "Component stamps successfully extracted\n" );
203 +  MPIcheckPoint();
204 + #endif // is_mpi
205 +  
206  
207  
208 +
209    // caclulate the number of atoms, bonds, bends and torsions
210  
211    tot_atoms = 0;
# Line 162 | 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 176 | 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 <  Atom::createArrays(tot_atoms);
278 <  the_atoms = new Atom*[tot_atoms];
279 <  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 215 | Line 310 | void SimSetup::createSim( void ){
310      makeTorsions();
311    }
312  
218  //  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 250 | 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 279 | 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 + #endif // is_mpi
411 +
412   #ifdef IS_MPI
413 <    if( worldRank == TESTWRITE ){
413 >  strcpy( checkPointMsg, "Successfully read in the initial configuration" );
414 >  MPIcheckPoint();
415   #endif // is_mpi
416 <      
417 <      fprintf( stderr,
418 <               "infile name is \"%s\"\n",
419 <               inFileName );
420 <      
421 <      inFileName = "./butane.bass";
422 <        
423 <      if( the_globals->haveFinalConfig() ){
424 <        strcpy( simnfo->finalName, the_globals->getFinalConfig() );
416 >
417 >
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 <        strcpy( simnfo->finalName, inFileName );
443 <        char* endTest;
303 <        int nameLength = strlen( simnfo->finalName );
304 <        endTest = &(simnfo->finalName[nameLength - 5]);
305 <        if( !strcmp( endTest, ".bass" ) ){
442 >        endTest = &(simnfo->finalName[nameLength - 4]);
443 >        if( !strcmp( endTest, ".bss" ) ){
444            strcpy( endTest, ".eor" );
445          }
446 <        else if( !strcmp( endTest, ".BASS" ) ){
446 >        else if( !strcmp( endTest, ".mdl" ) ){
447            strcpy( endTest, ".eor" );
448          }
449          else{
450 <          endTest = &(simnfo->finalName[nameLength - 4]);
313 <          if( !strcmp( endTest, ".bss" ) ){
314 <            strcpy( endTest, ".eor" );
315 <          }
316 <          else if( !strcmp( endTest, ".mdl" ) ){
317 <            strcpy( endTest, ".eor" );
318 <          }
319 <          else{
320 <            strcat( simnfo->finalName, ".eor" );
321 <          }
450 >          strcat( simnfo->finalName, ".eor" );
451          }
452        }
453 <      
454 <      // make the sample and status out names
455 <      
456 <      strcpy( simnfo->sampleName, inFileName );
457 <      char* endTest;
458 <      int nameLength = strlen( simnfo->sampleName );
459 <      endTest = &(simnfo->sampleName[nameLength - 5]);
460 <      if( !strcmp( endTest, ".bass" ) ){
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, ".BASS" ) ){
472 >      else if( !strcmp( endTest, ".mdl" ) ){
473          strcpy( endTest, ".dump" );
474        }
475        else{
476 <        endTest = &(simnfo->sampleName[nameLength - 4]);
339 <        if( !strcmp( endTest, ".bss" ) ){
340 <          strcpy( endTest, ".dump" );
341 <        }
342 <        else if( !strcmp( endTest, ".mdl" ) ){
343 <          strcpy( endTest, ".dump" );
344 <        }
345 <        else{
346 <          strcat( simnfo->sampleName, ".dump" );
347 <        }
476 >        strcat( simnfo->sampleName, ".dump" );
477        }
478 <      
479 <      strcpy( simnfo->statusName, inFileName );
480 <      nameLength = strlen( simnfo->statusName );
481 <      endTest = &(simnfo->statusName[nameLength - 5]);
482 <      if( !strcmp( endTest, ".bass" ) ){
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, ".BASS" ) ){
494 >      else if( !strcmp( endTest, ".mdl" ) ){
495          strcpy( endTest, ".stat" );
496        }
497        else{
498 <        endTest = &(simnfo->statusName[nameLength - 4]);
361 <        if( !strcmp( endTest, ".bss" ) ){
362 <          strcpy( endTest, ".stat" );
363 <        }
364 <        else if( !strcmp( endTest, ".mdl" ) ){
365 <          strcpy( endTest, ".stat" );
366 <        }
367 <        else{
368 <          strcat( simnfo->statusName, ".stat" );
369 <        }
498 >        strcat( simnfo->statusName, ".stat" );
499        }
371      
372 #ifdef IS_MPI
500      }
501 +    
502 + #ifdef IS_MPI
503 +  }
504   #endif // is_mpi
505 <
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 463 | 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 597 | 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 703 | 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