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

Comparing trunk/OOPSE/libmdtools/InitializeFromFile.cpp (file contents):
Revision 447 by mmeineke, Thu Apr 3 20:21:54 2003 UTC vs.
Revision 690 by mmeineke, Tue Aug 12 21:44:06 2003 UTC

# Line 26 | Line 26 | InitializeFromFile :: InitializeFromFile( char *in_nam
26  
27   #endif // is_mpi
28  
29 < InitializeFromFile :: InitializeFromFile( char *in_name ){
29 > InitializeFromFile::InitializeFromFile( char *in_name ){
30 >
31   #ifdef IS_MPI
32    if (worldRank == 0) {
33   #endif
# Line 48 | Line 49 | InitializeFromFile :: ~InitializeFromFile( ){
49    return;  
50   }
51  
52 < InitializeFromFile :: ~InitializeFromFile( ){
52 > InitializeFromFile::~InitializeFromFile( ){
53   #ifdef IS_MPI
54    if (worldRank == 0) {
55   #endif
# Line 69 | Line 70 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
70   }
71  
72  
73 < void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){
73 > void InitializeFromFile :: readInit( SimInfo* the_simnfo ){
74  
75    int i, j, done, which_node, which_atom; // loop counter
76  
# Line 83 | Line 84 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
84    char *eof_test; // ptr to see when we reach the end of the file
85    char *parseErr;
86    int procIndex;
87 +  double currTime;
88 +  double boxMat[9];
89 +  double theBoxMat3[3][3];
90  
91 <  entry_plug = the_entry_plug;
91 >  simnfo = the_simnfo;
92  
93  
94   #ifndef IS_MPI
# Line 99 | Line 103 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
103  
104    n_atoms = atoi( read_buffer );
105  
106 <  Atom **atoms = entry_plug->atoms;
106 >  Atom **atoms = simnfo->atoms;
107    DirectionalAtom* dAtom;
108  
109 <  if( n_atoms != entry_plug->n_atoms ){
109 >  if( n_atoms != simnfo->n_atoms ){
110      sprintf( painCave.errMsg,
111               "Initialize from File error. %s n_atoms, %d, "
112               "does not match the BASS file's n_atoms, %d.\n",
113 <             c_in_name, n_atoms, entry_plug->n_atoms );
113 >             c_in_name, n_atoms, simnfo->n_atoms );
114      painCave.isFatal = 1;
115      simError();
116    }
117    
118 <  //read and toss the comment line
118 >  //read the box mat from the comment line
119    
120    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
121    if(eof_test == NULL){
# Line 121 | Line 125 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
125      simError();
126    }
127  
128 +  parseErr = parseBoxLine( read_buffer, boxMat, currTime );
129 +  if( parseErr != NULL ){
130 +    strcpy( painCave.errMsg, parseErr );
131 +    painCave.isFatal = 1;
132 +    simError();
133 +  }
134 +
135 +  for(i=0;i<3;i++)
136 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
137 +
138 +  simnfo->setBoxM( theBoxMat3 );
139 +  simnfo->setTime( currTime );
140 +
141 +
142    for( i=0; i < n_atoms; i++){
143      
144      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
# Line 140 | Line 158 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
158        strcpy( painCave.errMsg, parseErr );
159        painCave.isFatal = 1;
160        simError();
161 <    }    
161 >    }
162    }
163  
164  
# Line 170 | Line 188 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
188      
189      n_atoms = atoi( read_buffer );
190      
191 <    Atom **atoms = entry_plug->atoms;
191 >    Atom **atoms = simnfo->atoms;
192      DirectionalAtom* dAtom;
193  
194      // Check to see that the number of atoms in the intial configuration file is the
# Line 180 | Line 198 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
198        sprintf( painCave.errMsg,
199                 "Initialize from File error. %s n_atoms, %d, "
200                 "does not match the BASS file's n_atoms, %d.\n",
201 <               c_in_name, n_atoms, entry_plug->n_atoms );
201 >               c_in_name, n_atoms, simnfo->n_atoms );
202        haveError= 1;
203        simError();
204      }
205      
206 <    //read and toss the comment line
206 >    //read the boxMat from the comment line
207      
208      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
209      if(eof_test == NULL){
210        sprintf( painCave.errMsg,
211                 "error in reading commment in %s\n", c_in_name);
212 <      haveError= 1;
212 >      haveError = 1;
213        simError();
214      }
215 +    
216 +    parseErr = parseBoxLine( read_buffer, boxMat, currTime );
217 +    if( parseErr != NULL ){
218 +      strcpy( painCave.errMsg, parseErr );
219 +      haveError = 1;
220 +      simError();
221 +    }
222 +
223 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD );
224 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD );
225    
226      if(haveError) nodeZeroError();
227  
# Line 247 | Line 275 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
275      
276    } else {
277      
278 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD);
279 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
280 +
281      done = 0;
282      while (!done) {
283  
# Line 278 | Line 309 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
309      
310   // last  thing last, enable  fatalities.
311    painCave.isEventLoop = 0;
312 +
313 +  for(i=0;i<3;i++)
314 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
315 +
316 +  simnfo->setBoxM( theBoxMat3 );
317 +  simnfo->setTime( currTime );
318 +
319    
320   #endif
321   }
# Line 286 | Line 324 | char* InitializeFromFile::parseDumpLine(char* readLine
324  
325    char *foo; // the pointer to the current string token
326    
327 <  double rx, ry, rz; // position place holders
328 <  double vx, vy, vz; // velocity placeholders
327 >  double pos[3]; // position place holders
328 >  double vel[3]; // velocity placeholders
329    double q[4]; // the quaternions
330    double jx, jy, jz; // angular velocity placeholders;
331    double qSqr, qLength; // needed to normalize the quaternion vector.
332    
333 <  Atom **atoms = entry_plug->atoms;
333 >  Atom **atoms = simnfo->atoms;
334    DirectionalAtom* dAtom;
335    
336    int j, n_atoms, atomIndex;
# Line 311 | Line 349 | char* InitializeFromFile::parseDumpLine(char* readLine
349      return strdup( painCave.errMsg );
350    }  
351   #else
352 <  n_atoms = entry_plug->n_atoms;
352 >  n_atoms = simnfo->n_atoms;
353    atomIndex = globalIndex;
354   #endif // is_mpi
355  
# Line 340 | Line 378 | char* InitializeFromFile::parseDumpLine(char* readLine
378               c_in_name, n_atoms, atomIndex );
379      return strdup( painCave.errMsg );
380    }
381 <  rx = atof( foo );
381 >  pos[0] = atof( foo );
382    
383    foo = strtok(NULL, " ,;\t");
384    if(foo == NULL){
# Line 350 | Line 388 | char* InitializeFromFile::parseDumpLine(char* readLine
388               c_in_name, n_atoms, atomIndex );
389      return strdup( painCave.errMsg );
390    }
391 <  ry = atof( foo );
391 >  pos[1] = atof( foo );
392      
393    foo = strtok(NULL, " ,;\t");
394    if(foo == NULL){
# Line 360 | Line 398 | char* InitializeFromFile::parseDumpLine(char* readLine
398               c_in_name, n_atoms, atomIndex );
399      return strdup( painCave.errMsg );
400    }
401 <  rz = atof( foo );    
401 >  pos[2] = atof( foo );    
402  
403  
404    // get the velocities
# Line 373 | Line 411 | char* InitializeFromFile::parseDumpLine(char* readLine
411               c_in_name, n_atoms, atomIndex );
412      return strdup( painCave.errMsg );
413    }
414 <  vx = atof( foo );
414 >  vel[0] = atof( foo );
415      
416    foo = strtok(NULL, " ,;\t");
417    if(foo == NULL){
# Line 383 | Line 421 | char* InitializeFromFile::parseDumpLine(char* readLine
421               c_in_name, n_atoms, atomIndex );
422      return strdup( painCave.errMsg );
423    }
424 <  vy = atof( foo );
424 >  vel[1] = atof( foo );
425      
426    foo = strtok(NULL, " ,;\t");
427    if(foo == NULL){
# Line 393 | Line 431 | char* InitializeFromFile::parseDumpLine(char* readLine
431               c_in_name, n_atoms, atomIndex );
432      return strdup( painCave.errMsg );
433    }
434 <  vz = atof( foo );
434 >  vel[2] = atof( foo );
435      
436      
437    // get the quaternions
# Line 495 | Line 533 | char* InitializeFromFile::parseDumpLine(char* readLine
533      
534    // add the positions and velocities to the atom
535      
536 <  atoms[atomIndex]->setX( rx );
537 <  atoms[atomIndex]->setY( ry );
500 <  atoms[atomIndex]->setZ( rz );
501 <    
502 <  atoms[atomIndex]->set_vx( vx );
503 <  atoms[atomIndex]->set_vy( vy );
504 <  atoms[atomIndex]->set_vz( vz );
536 >  atoms[atomIndex]->setPos( pos );
537 >  atoms[atomIndex]->setVel( vel );
538  
539    return NULL;
540   }
541  
542  
543 + char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9],
544 +                                       double &time ){
545 +
546 +  char *foo; // the pointer to the current string token
547 +  int j;
548 +
549 +  // set the string tokenizer
550 +  
551 +  foo = strtok(readLine, " ,;\t");
552 +  // set the timeToken.
553 +
554 +  if(foo == NULL){
555 +    sprintf( painCave.errMsg,
556 +             "error in reading Time from %s\n",
557 +             c_in_name );
558 +    return strdup( painCave.errMsg );
559 +  }
560 +  time = atof( foo );
561 +
562 +  // get the Hx vector
563 +
564 +  foo = strtok(NULL, " ,;\t");
565 +  if(foo == NULL){
566 +    sprintf( painCave.errMsg,
567 +             "error in reading Hx[0] from %s\n",
568 +             c_in_name );
569 +    return strdup( painCave.errMsg );
570 +  }
571 +  boxMat[0] = atof( foo );
572 +  
573 +  foo = strtok(NULL, " ,;\t");
574 +  if(foo == NULL){
575 +    sprintf( painCave.errMsg,
576 +             "error in reading Hx[1] from %s\n",
577 +             c_in_name );
578 +    return strdup( painCave.errMsg );
579 +  }
580 +  boxMat[1] = atof( foo );
581 +    
582 +  foo = strtok(NULL, " ,;\t");
583 +  if(foo == NULL){
584 +    sprintf( painCave.errMsg,
585 +             "error in reading Hx[2] from %s\n",
586 +             c_in_name );
587 +    return strdup( painCave.errMsg );
588 +  }
589 +  boxMat[2] = atof( foo );    
590 +
591 +  // get the Hy vector
592 +
593 +  foo = strtok(NULL, " ,;\t");
594 +  if(foo == NULL){
595 +    sprintf( painCave.errMsg,
596 +             "error in reading Hy[0] from %s\n",
597 +             c_in_name );
598 +    return strdup( painCave.errMsg );
599 +  }
600 +  boxMat[3] = atof( foo );
601 +  
602 +  foo = strtok(NULL, " ,;\t");
603 +  if(foo == NULL){
604 +    sprintf( painCave.errMsg,
605 +             "error in reading Hy[1] from %s\n",
606 +             c_in_name );
607 +    return strdup( painCave.errMsg );
608 +  }
609 +  boxMat[4] = atof( foo );
610 +    
611 +  foo = strtok(NULL, " ,;\t");
612 +  if(foo == NULL){
613 +    sprintf( painCave.errMsg,
614 +             "error in reading Hy[2] from %s\n",
615 +             c_in_name );
616 +    return strdup( painCave.errMsg );
617 +  }
618 +  boxMat[5] = atof( foo );    
619 +
620 +  // get the Hz vector
621 +
622 +  foo = strtok(NULL, " ,;\t");
623 +  if(foo == NULL){
624 +    sprintf( painCave.errMsg,
625 +             "error in reading Hz[0] from %s\n",
626 +             c_in_name );
627 +    return strdup( painCave.errMsg );
628 +  }
629 +  boxMat[6] = atof( foo );
630 +  
631 +  foo = strtok(NULL, " ,;\t");
632 +  if(foo == NULL){
633 +    sprintf( painCave.errMsg,
634 +             "error in reading Hz[1] from %s\n",
635 +             c_in_name );
636 +    return strdup( painCave.errMsg );
637 +  }
638 +  boxMat[7] = atof( foo );
639 +    
640 +  foo = strtok(NULL, " ,;\t");
641 +  if(foo == NULL){
642 +    sprintf( painCave.errMsg,
643 +             "error in reading Hz[2] from %s\n",
644 +             c_in_name );
645 +    return strdup( painCave.errMsg );
646 +  }
647 +  boxMat[8] = atof( foo );    
648 +
649 +  return NULL;
650 + }
651 +
652 +
653   #ifdef IS_MPI
654  
655   // a couple of functions to let us escape the read loop

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines