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

Comparing trunk/mdtools/interface_implementation/LJ_FF.cpp (file contents):
Revision 215 by chuckv, Thu Dec 19 21:59:51 2002 UTC vs.
Revision 230 by chuckv, Thu Jan 9 19:40:38 2003 UTC

# Line 10 | Line 10 | using namespace std;
10   #include "simError.h"
11  
12  
13 < #ifdef IS_MPI
13 > // Declare the structures that will be passed by the parser and  MPI
14  
15 #include "mpiForceField.h"
16
17
18 // Declare the structures that will be passed by MPI
19
15   typedef struct{
16    char name[15];
17    double mass;
18    double epslon;
19    double sigma;
20 +  int ident;
21    int last;      //  0  -> default
22 <                 //  1  -> tells nodes to stop listening
22 >                 //  1  -> in MPI: tells nodes to stop listening
23   } atomStruct;
24 +
25 + int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info );
26 +
27 + #ifdef IS_MPI
28 +
29 + #include "mpiForceField.h"
30 +
31   MPI_Datatype mpiAtomStructType;
32  
33   #endif
34  
35  
33
36   LJ_FF::LJ_FF(){
37  
38    char fileName[200];
# Line 46 | Line 48 | LJ_FF::LJ_FF(){
48    // Init the atomStruct mpi type
49  
50    atomStruct atomProto; // mpiPrototype
51 <  int atomBC[3] = {15,3,1};  // block counts
51 >  int atomBC[3] = {15,3,2};  // block counts
52    MPI_Aint atomDspls[3];           // displacements
53    MPI_Datatype atomMbrTypes[3];    // member mpi types
54  
55    MPI_Address(&atomProto.name, &atomDspls[0]);
56    MPI_Address(&atomProto.mass, &atomDspls[1]);
57 <  MPI_Address(&atomProto.last, &atomDspls[2]);
57 >  MPI_Address(&atomProto.ident, &atomDspls[2]);
58    
59    atomMbrTypes[0] = MPI_CHAR;
60    atomMbrTypes[1] = MPI_DOUBLE;
# Line 151 | Line 153 | void LJ_FF::initializeAtoms( void ){
153        return NULL;
154      }
155      
156 < #ifdef IS_MPI
156 >
157      void add( atomStruct &info ){
158 +    
159 +      // check for duplicates
160 +      
161 +      if( !strcmp( info.name, name ) ){
162 +        sprintf( simError.painCave,
163 +                 "Duplicate LJ atom type \"%s\" found in "
164 +                 "the LJ_FF param file./n",
165 +                 name );
166 +        painCave.isFatal = 1;
167 +        simError();
168 +      }
169 +      
170        if( next != NULL ) next->add(info);
171        else{
172          next = new LinkedType();
# Line 160 | Line 174 | void LJ_FF::initializeAtoms( void ){
174          next->mass     = info.mass;
175          next->epslon   = info.epslon;
176          next->sigma    = info.sigma;
177 +        next->ident    = info.ident;
178        }
179      }
180      
181 +
182 + #ifdef IS_MPI
183 +    
184      void duplicate( atomStruct &info ){
185        strcpy(info.name, name);
186        info.mass     = mass;
187        info.epslon   = epslon;
188        info.sigma    = sigma;
189 +      info.ident    = ident;
190        info.last     = 0;
191      }
192  
# Line 178 | Line 197 | void LJ_FF::initializeAtoms( void ){
197      double mass;
198      double epslon;
199      double sigma;
200 +    int ident;
201      LinkedType* next;
202    };
203    
204    LinkedType* headAtomType;
205    LinkedType* currentAtomType;
186  LinkedType* tempAtomType;
187
188 #ifdef IS_MPI
206    atomStruct info;
207    info.last = 1; // initialize last to have the last set.
208                   // if things go well, last will be set to 0
192 #endif
193  
209  
195  char readLine[500];
196  char* the_token;
197  char* eof_test;
198  int foundAtom = 0;
199  int lineNum = 0;
210    int i;
211 <
202 <  
203 <  //////////////////////////////////////////////////
204 <  // a quick water fix
205 <
206 <  double waterI[3][3];
207 <  waterI[0][0] = 1.76958347772500;
208 <  waterI[0][1] = 0.0;
209 <  waterI[0][2] = 0.0;
210 <
211 <  waterI[1][0] = 0.0;
212 <  waterI[1][1] = 0.614537057924513;
213 <  waterI[1][2] = 0.0;
214 <
215 <  waterI[2][0] = 0.0;
216 <  waterI[2][1] = 0.0;
217 <  waterI[2][2] = 1.15504641980049;
218 <
219 <
220 <  double headI[3][3];
221 <  headI[0][0] = 1125;
222 <  headI[0][1] = 0.0;
223 <  headI[0][2] = 0.0;
224 <
225 <  headI[1][0] = 0.0;
226 <  headI[1][1] = 1125;
227 <  headI[1][2] = 0.0;
228 <
229 <  headI[2][0] = 0.0;
230 <  headI[2][1] = 0.0;
231 <  headI[2][2] = 250;
232 <
211 >  int identNum;
212    
234
235  //////////////////////////////////////////////////
236
213    Atom** the_atoms;
214    int nAtoms;
215    the_atoms = entry_plug->atoms;
# Line 245 | Line 221 | void LJ_FF::initializeAtoms( void ){
221   #endif
222      
223      // read in the atom types.
224 <    
249 <    rewind( frcFile );
224 >
225      headAtomType = new LinkedType;
251    currentAtomType = headAtomType;
226      
227 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
228 <    lineNum++;
255 <    if( eof_test == NULL ){
256 <      sprintf( painCave.errMsg, "Error in reading Atoms from force file.\n" );
257 <      painCave.isFatal = 1;
258 <      simError();
259 <    }
260 <    
261 <    
262 <    while( !foundAtom ){
263 <      while( eof_test != NULL && readLine[0] != '#' ){
264 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
265 <        lineNum++;
266 <      }
267 <      if( eof_test == NULL ){
268 <        sprintf( painCave.errMsg,
269 <                 "Error in reading Atoms from force file at line %d.\n",
270 <                 lineNum );
271 <        painCave.isFatal = 1;
272 <        simError();
273 <      }
274 <      
275 <      the_token = strtok( readLine, " ,;\t#\n" );
276 <      foundAtom = !strcmp( "AtomTypes", the_token );
277 <      
278 <      if( !foundAtom ){
279 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
280 <        lineNum++;
281 <        
282 <        if( eof_test == NULL ){
283 <          sprintf( painCave.errMsg,
284 <                   "Error in reading Atoms from force file at line %d.\n",
285 <                   lineNum );
286 <          painCave.isFatal = 1;
287 <          simError();
288 <        }
289 <      }
290 <    }
291 <    
227 >    fastFoward( "AtomTypes", "initializeAtoms" );
228 >
229      // we are now at the AtomTypes section.
230      
231      eof_test = fgets( readLine, sizeof(readLine), frcFile );
232      lineNum++;
233      
234 +    
235 +    // read a line, and start parseing out the atom types
236 +
237      if( eof_test == NULL ){
238        sprintf( painCave.errMsg,
239                 "Error in reading Atoms from force file at line %d.\n",
# Line 302 | Line 242 | void LJ_FF::initializeAtoms( void ){
242        simError();
243      }
244      
245 +    identNum = 1;
246 +    // stop reading at end of file, or at next section
247      while( readLine[0] != '#' && eof_test != NULL ){
248 <      
248 >
249 >      // toss comment lines
250        if( readLine[0] != '!' ){
251          
252 <        the_token = strtok( readLine, " \n\t,;" );
253 <        if( the_token != NULL ){
254 <          
255 <          strcpy( currentAtomType->name, the_token );
256 <          
314 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
315 <            sprintf( painCave.errMsg,
316 <                     "Error parseing AtomTypes: line %d\n", lineNum );
317 <            painCave.isFatal = 1;
318 <            simError();
319 <          }
320 <          
321 <          sscanf( the_token, "%lf", &currentAtomType->mass );
322 <          
323 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
324 <            sprintf( painCave.errMsg,
325 <                     "Error parseing AtomTypes: line %d\n", lineNum );
326 <            painCave.isFatal = 1;
327 <            simError();
328 <          }
329 <          
330 <          sscanf( the_token, "%lf", &currentAtomType->epslon );
331 <          
332 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
333 <            sprintf( painCave.errMsg,
334 <                     "Error parseing AtomTypes: line %d\n", lineNum );
335 <            painCave.isFatal = 1;
336 <            simError();
337 <          }
338 <          
339 <          sscanf( the_token, "%lf", &currentAtomType->sigma );
252 >        // the parser returns 0 if the line was blank
253 >        if( parseAtomLJ( readLine, lineNum, info ) ){
254 >          info.ident = identNum;
255 >          headAtomType->add( info );;
256 >          identNum++;
257          }
258        }
342      
343      tempAtomType = new LinkedType;
344      currentAtomType->next = tempAtomType;
345      currentAtomType = tempAtomType;
346      
259        eof_test = fgets( readLine, sizeof(readLine), frcFile );
260        lineNum++;
261      }
# Line 383 | Line 295 | void LJ_FF::initializeAtoms( void ){
295    }
296   #endif // is_mpi
297  
298 <  
298 >  // call new A_types in fortran
299 >
300 >
301    // initialize the atoms
302    
303    Atom* thisAtom;
# Line 402 | Line 316 | void LJ_FF::initializeAtoms( void ){
316      the_atoms[i]->setMass( currentAtomType->mass );
317      the_atoms[i]->setEpslon( currentAtomType->epslon );
318      the_atoms[i]->setSigma( currentAtomType->sigma );
319 +    the_atoms[i]->setIdent( currentAtomType->ident );
320      the_atoms[i]->setLJ();
321    }
322  
# Line 458 | Line 373 | void LJ_FF::initializeTorsions( torsion_set* the_torsi
373   #endif // is_mpi
374  
375   }
376 +
377 +
378 + void LJ_FF::fastForward( char* stopText, char* searchOwner ){
379 +
380 +  int foundText = 0;
381 +  char* the_token;
382 +
383 +  rewind( frcFile );
384 +  lineNum = 0;
385 +
386 +  eof_test = fgets( readLine, sizeof(readLine), frcFile );
387 +  lineNum++;
388 +  if( eof_test == NULL ){
389 +    sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
390 +             " file is empty.\n",
391 +             searchOwner );
392 +    painCave.isFatal = 1;
393 +    simError();
394 +  }
395 +  
396 +  
397 +  while( !foundText ){
398 +    while( eof_test != NULL && readLine[0] != '#' ){
399 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
400 +      lineNum++;
401 +    }
402 +    if( eof_test == NULL ){
403 +      sprintf( painCave.errMsg,
404 +               "Error fast forwarding force file for %s at "
405 +               "line %d: file ended unexpectedly.\n",
406 +               searchOwner,
407 +               lineNum );
408 +      painCave.isFatal = 1;
409 +      simError();
410 +    }
411 +    
412 +    the_token = strtok( readLine, " ,;\t#\n" );
413 +    foundText = !strcmp( stopText, the_token );
414 +    
415 +    if( !foundText ){
416 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
417 +      lineNum++;
418 +      
419 +      if( eof_test == NULL ){
420 +        sprintf( painCave.errMsg,
421 +                 "Error fast forwarding force file for %s at "
422 +                 "line %d: file ended unexpectedly.\n",
423 +                 searchOwner,
424 +                 lineNum );
425 +        painCave.isFatal = 1;
426 +        simError();
427 +      }
428 +    }
429 +  }  
430 + }
431 +
432 +
433 +
434 + int parseAtomLJ( char *lineBuffer, int lineNum,  atomStruct &info ){
435 +
436 +  char* the_token;
437 +  
438 +  the_token = strtok( lineBuffer, " \n\t,;" );
439 +  if( the_token != NULL ){
440 +    
441 +    strcpy( info.name, the_token );
442 +          
443 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
444 +      sprintf( painCave.errMsg,
445 +               "Error parseing AtomTypes: line %d\n", lineNum );
446 +      painCave.isFatal = 1;
447 +      simError();
448 +    }
449 +    
450 +    info.mass = atof( the_token );
451 +    
452 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
453 +      sprintf( painCave.errMsg,
454 +               "Error parseing AtomTypes: line %d\n", lineNum );
455 +      painCave.isFatal = 1;
456 +      simError();
457 +    }
458 +        
459 +    info.epslon = atof( the_token );
460 +          
461 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
462 +      sprintf( painCave.errMsg,
463 +               "Error parseing AtomTypes: line %d\n", lineNum );
464 +      painCave.isFatal = 1;
465 +      simError();
466 +    }
467 +        
468 +    info.sigma = atof( the_token );
469 +    
470 +    return 1;
471 +  }
472 +  else return 0;
473 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines