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 234 by mmeineke, Fri Jan 10 21:56:06 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  
36 + // declaration of functions needed to wrap the fortran module
37  
38 + extern "C" {
39 +  void forcefactory_( char* forceName,
40 +                      int* status,
41 +                      void (*wrapFunction)( void (*
42 +
43 +
44 +
45   LJ_FF::LJ_FF(){
46  
47    char fileName[200];
# Line 46 | Line 57 | LJ_FF::LJ_FF(){
57    // Init the atomStruct mpi type
58  
59    atomStruct atomProto; // mpiPrototype
60 <  int atomBC[3] = {15,3,1};  // block counts
60 >  int atomBC[3] = {15,3,2};  // block counts
61    MPI_Aint atomDspls[3];           // displacements
62    MPI_Datatype atomMbrTypes[3];    // member mpi types
63  
64    MPI_Address(&atomProto.name, &atomDspls[0]);
65    MPI_Address(&atomProto.mass, &atomDspls[1]);
66 <  MPI_Address(&atomProto.last, &atomDspls[2]);
66 >  MPI_Address(&atomProto.ident, &atomDspls[2]);
67    
68    atomMbrTypes[0] = MPI_CHAR;
69    atomMbrTypes[1] = MPI_DOUBLE;
# Line 151 | Line 162 | void LJ_FF::initializeAtoms( void ){
162        return NULL;
163      }
164      
165 < #ifdef IS_MPI
165 >
166      void add( atomStruct &info ){
167 +    
168 +      // check for duplicates
169 +      
170 +      if( !strcmp( info.name, name ) ){
171 +        sprintf( simError.painCave,
172 +                 "Duplicate LJ atom type \"%s\" found in "
173 +                 "the LJ_FF param file./n",
174 +                 name );
175 +        painCave.isFatal = 1;
176 +        simError();
177 +      }
178 +      
179        if( next != NULL ) next->add(info);
180        else{
181          next = new LinkedType();
# Line 160 | Line 183 | void LJ_FF::initializeAtoms( void ){
183          next->mass     = info.mass;
184          next->epslon   = info.epslon;
185          next->sigma    = info.sigma;
186 +        next->ident    = info.ident;
187        }
188      }
189      
190 +
191 + #ifdef IS_MPI
192 +    
193      void duplicate( atomStruct &info ){
194        strcpy(info.name, name);
195        info.mass     = mass;
196        info.epslon   = epslon;
197        info.sigma    = sigma;
198 +      info.ident    = ident;
199        info.last     = 0;
200      }
201  
# Line 178 | Line 206 | void LJ_FF::initializeAtoms( void ){
206      double mass;
207      double epslon;
208      double sigma;
209 +    int ident;
210      LinkedType* next;
211    };
212    
213    LinkedType* headAtomType;
214    LinkedType* currentAtomType;
186  LinkedType* tempAtomType;
187
188 #ifdef IS_MPI
215    atomStruct info;
216    info.last = 1; // initialize last to have the last set.
217                   // if things go well, last will be set to 0
192 #endif
193  
218  
195  char readLine[500];
196  char* the_token;
197  char* eof_test;
198  int foundAtom = 0;
199  int lineNum = 0;
219    int i;
220 <
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 <
220 >  int identNum;
221    
234
235  //////////////////////////////////////////////////
236
222    Atom** the_atoms;
223    int nAtoms;
224    the_atoms = entry_plug->atoms;
# Line 245 | Line 230 | void LJ_FF::initializeAtoms( void ){
230   #endif
231      
232      // read in the atom types.
233 <    
249 <    rewind( frcFile );
233 >
234      headAtomType = new LinkedType;
251    currentAtomType = headAtomType;
235      
236 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
237 <    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 <    
236 >    fastFoward( "AtomTypes", "initializeAtoms" );
237 >
238      // we are now at the AtomTypes section.
239      
240      eof_test = fgets( readLine, sizeof(readLine), frcFile );
241      lineNum++;
242      
243 +    
244 +    // read a line, and start parseing out the atom types
245 +
246      if( eof_test == NULL ){
247        sprintf( painCave.errMsg,
248                 "Error in reading Atoms from force file at line %d.\n",
# Line 302 | Line 251 | void LJ_FF::initializeAtoms( void ){
251        simError();
252      }
253      
254 +    identNum = 1;
255 +    // stop reading at end of file, or at next section
256      while( readLine[0] != '#' && eof_test != NULL ){
257 <      
257 >
258 >      // toss comment lines
259        if( readLine[0] != '!' ){
260          
261 <        the_token = strtok( readLine, " \n\t,;" );
262 <        if( the_token != NULL ){
263 <          
264 <          strcpy( currentAtomType->name, the_token );
265 <          
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 );
261 >        // the parser returns 0 if the line was blank
262 >        if( parseAtomLJ( readLine, lineNum, info ) ){
263 >          info.ident = identNum;
264 >          headAtomType->add( info );;
265 >          identNum++;
266          }
267        }
342      
343      tempAtomType = new LinkedType;
344      currentAtomType->next = tempAtomType;
345      currentAtomType = tempAtomType;
346      
268        eof_test = fgets( readLine, sizeof(readLine), frcFile );
269        lineNum++;
270      }
# Line 383 | Line 304 | void LJ_FF::initializeAtoms( void ){
304    }
305   #endif // is_mpi
306  
307 <  
307 >  // call new A_types in fortran
308 >
309 >
310    // initialize the atoms
311    
312    Atom* thisAtom;
# Line 402 | Line 325 | void LJ_FF::initializeAtoms( void ){
325      the_atoms[i]->setMass( currentAtomType->mass );
326      the_atoms[i]->setEpslon( currentAtomType->epslon );
327      the_atoms[i]->setSigma( currentAtomType->sigma );
328 +    the_atoms[i]->setIdent( currentAtomType->ident );
329      the_atoms[i]->setLJ();
330    }
331  
# Line 458 | Line 382 | void LJ_FF::initializeTorsions( torsion_set* the_torsi
382   #endif // is_mpi
383  
384   }
385 +
386 +
387 + void LJ_FF::fastForward( char* stopText, char* searchOwner ){
388 +
389 +  int foundText = 0;
390 +  char* the_token;
391 +
392 +  rewind( frcFile );
393 +  lineNum = 0;
394 +
395 +  eof_test = fgets( readLine, sizeof(readLine), frcFile );
396 +  lineNum++;
397 +  if( eof_test == NULL ){
398 +    sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
399 +             " file is empty.\n",
400 +             searchOwner );
401 +    painCave.isFatal = 1;
402 +    simError();
403 +  }
404 +  
405 +  
406 +  while( !foundText ){
407 +    while( eof_test != NULL && readLine[0] != '#' ){
408 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
409 +      lineNum++;
410 +    }
411 +    if( eof_test == NULL ){
412 +      sprintf( painCave.errMsg,
413 +               "Error fast forwarding force file for %s at "
414 +               "line %d: file ended unexpectedly.\n",
415 +               searchOwner,
416 +               lineNum );
417 +      painCave.isFatal = 1;
418 +      simError();
419 +    }
420 +    
421 +    the_token = strtok( readLine, " ,;\t#\n" );
422 +    foundText = !strcmp( stopText, the_token );
423 +    
424 +    if( !foundText ){
425 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
426 +      lineNum++;
427 +      
428 +      if( eof_test == NULL ){
429 +        sprintf( painCave.errMsg,
430 +                 "Error fast forwarding force file for %s at "
431 +                 "line %d: file ended unexpectedly.\n",
432 +                 searchOwner,
433 +                 lineNum );
434 +        painCave.isFatal = 1;
435 +        simError();
436 +      }
437 +    }
438 +  }  
439 + }
440 +
441 +
442 +
443 + int parseAtomLJ( char *lineBuffer, int lineNum,  atomStruct &info ){
444 +
445 +  char* the_token;
446 +  
447 +  the_token = strtok( lineBuffer, " \n\t,;" );
448 +  if( the_token != NULL ){
449 +    
450 +    strcpy( info.name, 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.mass = 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.epslon = atof( the_token );
469 +          
470 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
471 +      sprintf( painCave.errMsg,
472 +               "Error parseing AtomTypes: line %d\n", lineNum );
473 +      painCave.isFatal = 1;
474 +      simError();
475 +    }
476 +        
477 +    info.sigma = atof( the_token );
478 +    
479 +    return 1;
480 +  }
481 +  else return 0;
482 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines