ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/utils/sysBuild.cpp
(Generate patch)

Comparing trunk/OOPSE/utils/sysBuild.cpp (file contents):
Revision 500 by mmeineke, Mon Apr 14 21:22:54 2003 UTC vs.
Revision 501 by mmeineke, Tue Apr 15 21:20:35 2003 UTC

# Line 1 | Line 1
1   #include <cstdlib>
2   #include <cstdio>
3   #include <cstring>
4 + #include <cmath>
5  
6   #include "simError.h"
7 + #include "parse_me.h"
8 + #include "MakeStamps.hpp"
9 + #include "Globals.hpp"
10 + #include "SimInfo.hpp"
11  
12 + #include "sysBuild.hpp"
13   #include "bilayerSys.hpp"
14  
15 < // quick case asignments
15 > // this routine is defined in BASS_interface.cpp
16 > extern void set_interface_stamps( MakeStamps* ms, Globals* g );
17  
18 +
19 + // case asignments
20   #define BILAYER 1
21  
22  
23   char* program_name;
24 + bassInfo bsInfo;
25   void usage(void);
26  
27  
# Line 23 | Line 33 | int main( int argc, char* argv[]){
33    char current_flag;
34    char* out_prefix;
35    char* in_name;
36 +  char* id;
37    
38 <  sysBuildInfo info;
38 >  includeLinked* headInc;
39 >  includeLinked* prevInc;
40 >  includeLinked* currInc;
41  
42 <  // initialize simError
43 <  initSimError();
42 >  MakeStamps* the_stamps = NULL;
43 >  Globals* the_globals = NULL;
44 >  MoleculeStamp** the_components = NULL;
45 >  LinkedMolStamp* headStamp = NULL;
46 >  LinkedMolStamp* currStamp;
47  
48 +  if(
49 +  
50 +  // initialize all functions and variables
51  
52 <  program_name = argv[0]; /*save the program name in case we need it*/
52 >  initSimError();
53 >  program_name = argv[0];
54    sysType = -1;
55    have_prefix = 0;
56    isRandom = 0;
57    in_name = NULL;
58 +  headInc = NULL;
59 +
60 +  bsInfo.includes = NULL;
61 +  bsInfo.componentsNmol = NULL;
62 +  bsInfo.compStamps = NULL;
63 +  bsInfo.havePressure = 0;
64 +  bsInfo.haveTauBarrostat = 0;
65 +  bsInfo.haveTauThermostat = 0;
66 +  bsInfo.haveQmass = 0;
67 +
68 +  headStamp = new LinkedMolStamp();
69 +  the_stamps = new MakeStamps();
70 +  the_globals = new Globals();
71 +  set_interface_stamps( the_stamps, the_globals );
72 +
73 +  // parse command line arguments
74 +
75    for( i = 1; i < argc; i++){
76      
77      if(argv[i][0] =='-'){
# Line 85 | Line 122 | int main( int argc, char* argv[]){
122              done = 1;
123              break;
124  
125 +          case 'I':
126 +            // -I <include> => the include file.
127 +
128 +            i++;
129 +            if( headInc == NULL ){
130 +              headInc = new includeLinked;
131 +              headInc->next = NULL;
132 +              strcopy( headInc->name, argv[i] );
133 +            }
134 +            else{
135 +              prevInc = headInc;
136 +              currInc = headInc->next;
137 +              while( currInc != NULL ){
138 +                prevInc = currInc;
139 +                currInc = previnc->next;
140 +              }
141 +              currInc = new includeLinked;
142 +              currInc->next = NULL;
143 +              strcopy( currInc->name, argv[i] );
144 +              prevInc->next = currInc;
145 +            }
146 +            
147 +            done = 1;
148 +            break;
149 +
150            case 'h':
151              // -h => give the usage
152              
# Line 149 | Line 211 | int main( int argc, char* argv[]){
211    if( !have_prefix ){
212      out_prefix = strdup( "donkey" );
213    }
152  
153  info.in_name = in_name;
154  info.out_prefix = out_prefix;
155  info.isRandom = isRandom;
214    
215 <  // switch the system type
215 >  // set command line info into the bassInfo struct
216 >  
217 >  bsInfo.outPrefix = out_prefix;
218 >  bsInfo.includes = headInc;
219 >  
220 >
221 >  // open and parse the bass file.
222 >
223 >  set_interface_stamps( the_stamps, the_globals );
224 >  yacc_BASS( info.in_name );  
225 >
226 >  // set the easy ones first
227 >  bsInfo.targetTemp = the_globals->getTargetTemp();
228 >  bsInfo.dt = the_globals->getDt();
229 >  bsInfo.runTime = the_globals->getRunTime();
230 >
231 >  // get the ones we know are there, yet still may need some work.
232 >  bsInfo.nComponents = the_globals->getNComponents();
233 >  strcpy( bsInfo.forceField, the_globals->getForceField() );
234 >
235 >  // get the ensemble:
236 >  strcpy( bsInfo.ensemble, the_globals->getEnsemble() );
237 >  if( !strcasecmp( bsInfo.ensemble, "NPT" ) ) {
238 >    
239 >    if (the_globals->haveTargetPressure()){
240 >      bsInfo.targetPressure = the_globals->getTargetPressure();
241 >      bsInfo.havePressure = 1;
242 >    }
243 >    else {
244 >      sprintf( painCave.errMsg,
245 >               "sysBuild error: If you use the constant pressure\n"
246 >               "    ensemble, you must set targetPressure.\n"
247 >               "    This was found in the BASS file.\n");
248 >      painCave.isFatal = 1;
249 >      simError();
250 >    }
251 >
252 >    if (the_globals->haveTauThermostat()){
253 >      bsInfo.tauThermostat = the_globals->getTauThermostat();
254 >      bsInfo.haveTauThermostat = 1;;
255 >    }
256 >    else if (the_globals->haveQmass()){
257 >      bsinfo.Qmass = the_globals->getQmass();
258 >      bsInfo.haveQmass = 1;
259 >    }
260 >    else {
261 >      sprintf( painCave.errMsg,
262 >               "sysBuild error: If you use one of the constant temperature\n"
263 >               "    ensembles, you must set either tauThermostat or qMass.\n"
264 >               "    Neither of these was found in the BASS file.\n");
265 >      painCave.isFatal = 1;
266 >      simError();
267 >    }
268 >
269 >    if (the_globals->haveTauBarostat()){
270 >      bsInfo.tauBarostat = the_globals->getTauBarostat();
271 >      bsInfo.haveTauBarostat = 1;
272 >    }                                    
273 >    else {
274 >      sprintf( painCave.errMsg,
275 >               "sysBuild error: If you use the constant pressure\n"
276 >               "    ensemble, you must set tauBarostat.\n"
277 >               "    This was found in the BASS file.\n");
278 >      painCave.isFatal = 1;
279 >      simError();
280 >    }
281 >
282 >  }
283 >  else if ( !strcasecmp( bsInfo.ensemble, "NVT") ) {
284 >
285 >    if (the_globals->haveTauThermostat()){
286 >      bsInfo.tauThermostat = the_globals->getTauThermostat();
287 >      bsInfo.haveTauThermostat = 1;
288 >    }
289 >    else if (the_globals->haveQmass()){
290 >      bsInfo.Qmass = the_globals->getQmass();
291 >      bsInfo.haveQmass = 1;
292 >    }
293 >    else {
294 >      sprintf( painCave.errMsg,
295 >               "sysBuild error: If you use one of the constant temperature\n"
296 >               "    ensembles, you must set either tauThermostat or qMass.\n"
297 >               "    Neither of these was found in the BASS file.\n");
298 >      painCave.isFatal = 1;
299 >      simError();
300 >    }
301 >    
302 >  }
303 >  else if ( !strcasecmp( bsInfo.ensemble, "NVE") ) {
304 >    
305 >    // nothing special for now
306 >  }
307 >  else {
308 >    sprintf( painCave.errMsg,
309 >             "sysBuild Warning. Unrecognized Ensemble -> %s, "
310 >             "reverting to NVE for this simulation.\n",
311 >             ensemble );
312 >    painCave.isFatal = 0;
313 >    simError();
314 >    strcpy( bsInfo.ensemble, "NVE" );
315 >  }  
316  
317 +
318 +  // get the components and calculate the tot_nMol and indvidual n_mol
319 +
320 +  the_components = the_globals->getComponents();
321 +  bsInfo.componentsNmol = new int[bsInfo.nComponents];
322 +  bsInfo.compStamps = new MoleculeStamp*[bsInfo.nComponents];  
323 +  bsInfo.totNmol = 0;
324 +  for( i=0; i<bsInfo.nComponents; i++ ){
325 +    
326 +    if( !the_components[i]->haveNMol() ){
327 +      // we have a problem
328 +      sprintf( painCave.errMsg,
329 +               "sysBuild Error. No component NMol"
330 +               " given. Cannot calculate the number of atoms.\n" );
331 +      painCave.isFatal = 1;
332 +      simError();
333 +    }
334 +    
335 +    bsInfo.totNmol += the_components[i]->getNMol();
336 +    bsInfo.componentsNmol[i] = the_components[i]->getNMol();
337 +  }
338 +
339 +  // make an array of molecule stamps that match the components used.
340 +  // also extract the used stamps out into a separate linked list
341 +  
342 +  for( i=0; i<bsInfo.nComponents; i++ ){
343 +
344 +    id = the_components[i]->getType();
345 +    bsInfo.compStamps[i] = NULL;
346 +    
347 +    // check to make sure the component isn't already in the list
348 +
349 +    bsInfo.compStamps[i] = headStamp->match( id );
350 +    if( bsInfo.compStamps[i] == NULL ){
351 +      
352 +      // extract the component from the list;
353 +      
354 +      currStamp = the_stamps->extractMolStamp( id );
355 +      if( currStamp == NULL ){
356 +        sprintf( painCave.errMsg,
357 +                 "sysBuild error: Component \"%s\" was not found in the "
358 +                 "list of declared molecules\n",
359 +                 id );
360 +        painCave.isFatal = 1;
361 +        simError();
362 +      }
363 +      
364 +      headStamp->add( currStamp );
365 +      bsInfo.compStamps[i] = headStamp->match( id );
366 +    }
367 +  }
368 +
369 +  // get and set the boxSize
370 +
371 +  if( the_globals->haveBox() ){
372 +    bsInfo.boxX = the_globals->getBox();
373 +    bsInfo.boxY = the_globals->getBox();
374 +    bsinfo.boxZ = the_globals->getBox();
375 +  }
376 +  else if( the_globals->haveDensity() ){
377 +
378 +    double vol;
379 +    vol = (double)tot_nmol / the_globals->getDensity();
380 +    bsInfo.boxX = pow( vol, ( 1.0 / 3.0 ) );
381 +    bsInfo.boxY = simnfo->box_x;
382 +    bsInfo.boxZ = simnfo->box_x;
383 +  }
384 +  else{
385 +    if( !the_globals->haveBoxX() ){
386 +      sprintf( painCave.errMsg,
387 +               "sysBuild error, no periodic BoxX size given.\n" );
388 +      painCave.isFatal = 1;
389 +      simError();
390 +    }
391 +    bsInfo.boxX = the_globals->getBoxX();
392 +
393 +    if( !the_globals->haveBoxY() ){
394 +      sprintf( painCave.errMsg,
395 +               "sysBuild error, no periodic BoxY size given.\n" );
396 +      painCave.isFatal = 1;
397 +      simError();
398 +    }
399 +    bsInfo.boxY = the_globals->getBoxY();
400 +
401 +    if( !the_globals->haveBoxZ() ){
402 +      sprintf( painCave.errMsg,
403 +               "SimSetup error, no periodic BoxZ size given.\n" );
404 +      painCave.isFatal = 1;
405 +      simError();
406 +    }
407 +    bsInfo.boxZ = the_globals->getBoxZ();
408 +  }
409 +  
410 +
411 +  //************************************************************
412 +  // that should be all we need from bass. now to switch to the
413 +  // appropriate system builder.
414 +  // ***********************************************************
415 +
416 +
417    switch( sysType ){
418      
419    case BILAYER:
420      
421 <    buildBilayer( info );
421 >    buildBilayer( isRandom );
422      break;
423  
424    default:
# Line 170 | Line 428 | int main( int argc, char* argv[]){
428      simError();
429    }
430    
431 +
432 +
433 +  // clean up memory;
434 +
435 +  if( headStamp!= NULL )       delete headStamp;
436 +  if( the_stamps != NULL )     delete the_stamps;
437 +  if( the_globals != NULL )    delete the_globals;
438 +  if( the_components != NULL ) delete[] the_components;
439 +  
440 +  if( bsInfo.componentsNmol != NULL ) delete[] bsInfo.componentsNmol;
441 +  if( bsInfo.compStamps != NULL )     delete[] bsInfo.compStamps;
442 +  if( bsInfo.includes != NULL ){
443 +    prevInc = bsInfo.includes;
444 +    while( prevInc != NULL ){
445 +      currInc = prevInc->next;
446 +      delete prevInc;
447 +      prevInc = currInc;
448 +    }
449 +  }
450 +      
451    return 0;
452   }
453  
# Line 188 | Line 466 | void usage(){
466                  "  ------\n"
467                  "   -h              Display this message\n"
468                  "   -o <prefix>     The output prefix\n"
469 +                "   -I <include>    File name that should be included at the top of the\n"
470 +                "                     output bass file.\n"
471                  "   -r              toggle the random option\n"
472                  "\n"
473                  "  long:\n"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines