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 440 by mmeineke, Tue Apr 1 16:49:17 2003 UTC vs.
Revision 787 by mmeineke, Thu Sep 25 19:27:15 2003 UTC

# Line 13 | Line 13
13  
14   #ifdef IS_MPI
15   #include <mpi.h>
16 #include <mpi++.h>
16   #include "mpiSimulation.hpp"
17   #define TAKE_THIS_TAG_CHAR 0
18   #define TAKE_THIS_TAG_INT 1
# Line 27 | 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 49 | 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 70 | 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
75 >  int i, j;
76 >  
77 > #ifdef IS_MPI
78 >  int done, which_node, which_atom; // loop counter
79 > #endif //is_mpi
80  
81    const int BUFFERSIZE = 2000; // size of the read buffer
82    int n_atoms; // the number of atoms
83    char read_buffer[BUFFERSIZE]; //the line buffer for reading
80 #ifdef IS_MPI
81  char send_buffer[BUFFERSIZE];
82 #endif
84  
85    char *eof_test; // ptr to see when we reach the end of the file
86    char *parseErr;
86  int procIndex;
87  
88 <  entry_plug = the_entry_plug;
88 >  double currTime;
89 >  double boxMat[9];
90 >  double theBoxMat3[3][3];
91  
92 +  simnfo = the_simnfo;
93  
94 +
95   #ifndef IS_MPI
96    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
97    if( eof_test == NULL ){
# Line 100 | Line 104 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
104  
105    n_atoms = atoi( read_buffer );
106  
107 <  Atom **atoms = entry_plug->atoms;
104 <  DirectionalAtom* dAtom;
105 <
106 <  if( n_atoms != entry_plug->n_atoms ){
107 >  if( n_atoms != simnfo->n_atoms ){
108      sprintf( painCave.errMsg,
109               "Initialize from File error. %s n_atoms, %d, "
110               "does not match the BASS file's n_atoms, %d.\n",
111 <             c_in_name, n_atoms, entry_plug->n_atoms );
111 >             c_in_name, n_atoms, simnfo->n_atoms );
112      painCave.isFatal = 1;
113      simError();
114    }
115    
116 <  //read and toss the comment line
116 >  //read the box mat from the comment line
117    
118    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
119    if(eof_test == NULL){
# Line 122 | Line 123 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
123      simError();
124    }
125  
126 +  parseErr = parseBoxLine( read_buffer, boxMat, currTime );
127 +  if( parseErr != NULL ){
128 +    strcpy( painCave.errMsg, parseErr );
129 +    painCave.isFatal = 1;
130 +    simError();
131 +  }
132 +
133 +  for(i=0;i<3;i++)
134 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
135 +
136 +  simnfo->setBoxM( theBoxMat3 );
137 +  simnfo->setTime( currTime );
138 +
139 +
140    for( i=0; i < n_atoms; i++){
141      
142      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
# Line 141 | Line 156 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
156        strcpy( painCave.errMsg, parseErr );
157        painCave.isFatal = 1;
158        simError();
159 <    }    
159 >    }
160    }
161  
162  
# Line 154 | Line 169 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
169    int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
170    int haveError;
171    
172 <  MPI::Status istatus;
172 >  MPI_Status istatus;
173    int *AtomToProcMap = mpiSim->getAtomToProcMap();
174  
175    
# Line 164 | Line 179 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
179      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
180      if( eof_test == NULL ){
181        sprintf( painCave.errMsg,
182 <               "Error reading 1st line of %d \n ",c_in_name);
182 >               "Error reading 1st line of %s \n ",c_in_name);
183        haveError = 1;
184        simError();
185      }
186      
187      n_atoms = atoi( read_buffer );
188      
174    Atom **atoms = entry_plug->atoms;
175    DirectionalAtom* dAtom;
176
189      // Check to see that the number of atoms in the intial configuration file is the
190      // same as declared in simBass.
191      
# Line 181 | Line 193 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
193        sprintf( painCave.errMsg,
194                 "Initialize from File error. %s n_atoms, %d, "
195                 "does not match the BASS file's n_atoms, %d.\n",
196 <               c_in_name, n_atoms, entry_plug->n_atoms );
196 >               c_in_name, n_atoms, simnfo->n_atoms );
197        haveError= 1;
198        simError();
199      }
200      
201 <    //read and toss the comment line
201 >    //read the boxMat from the comment line
202      
203      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
204      if(eof_test == NULL){
205        sprintf( painCave.errMsg,
206                 "error in reading commment in %s\n", c_in_name);
207 <      haveError= 1;
207 >      haveError = 1;
208        simError();
209      }
210 +    
211 +    parseErr = parseBoxLine( read_buffer, boxMat, currTime );
212 +    if( parseErr != NULL ){
213 +      strcpy( painCave.errMsg, parseErr );
214 +      haveError = 1;
215 +      simError();
216 +    }
217 +
218 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD );
219 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD );
220    
221      if(haveError) nodeZeroError();
222  
# Line 228 | Line 250 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
250        else {
251        
252          myStatus = 1;
253 <        MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node,
254 <                             TAKE_THIS_TAG_INT);
255 <        MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
256 <                             TAKE_THIS_TAG_CHAR);
257 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
258 <        MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, istatus);
253 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
254 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
255 >        MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
256 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
257 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
258 >                 MPI_COMM_WORLD);
259 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
260 >                 MPI_COMM_WORLD, &istatus);
261          
262          if(!myStatus) nodeZeroError();
263        }
264      }
265      myStatus = -1;
266      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
267 <      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j,
268 <                            TAKE_THIS_TAG_INT);
267 >      MPI_Send( &myStatus, 1, MPI_INT, j,
268 >                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
269      }
270      
271    } else {
272      
273 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD);
274 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
275 +
276      done = 0;
277      while (!done) {
278  
279 <      MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0,
280 <                           TAKE_THIS_TAG_INT, istatus);
279 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
280 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
281        
282        if(!myStatus) anonymousNodeDie();
283        
284        if(myStatus < 0) break;
285  
286 <      MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
287 <                           TAKE_THIS_TAG_CHAR, istatus);
288 <      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
289 <                           TAKE_THIS_TAG_INT, istatus);
286 >      MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
287 >               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
288 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
289 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
290        
291        myStatus = 1;
292        parseErr = parseDumpLine( read_buffer, which_atom );
# Line 269 | Line 296 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
296          simError();
297        }
298        
299 <      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0,
300 <                            TAKE_THIS_TAG_INT);
299 >      MPI_Send( &myStatus, 1, MPI_INT, 0,
300 >                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
301        
302      }
303    }
304      
305   // last  thing last, enable  fatalities.
306    painCave.isEventLoop = 0;
307 +
308 +  for(i=0;i<3;i++)
309 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
310 +
311 +  simnfo->setBoxM( theBoxMat3 );
312 +  simnfo->setTime( currTime );
313 +
314    
315   #endif
316   }
# Line 285 | Line 319 | char* InitializeFromFile::parseDumpLine(char* readLine
319  
320    char *foo; // the pointer to the current string token
321    
322 <  double rx, ry, rz; // position place holders
323 <  double vx, vy, vz; // velocity placeholders
322 >  double pos[3]; // position place holders
323 >  double vel[3]; // velocity placeholders
324    double q[4]; // the quaternions
325    double jx, jy, jz; // angular velocity placeholders;
326    double qSqr, qLength; // needed to normalize the quaternion vector.
327    
328 <  Atom **atoms = entry_plug->atoms;
328 >  Atom **atoms = simnfo->atoms;
329    DirectionalAtom* dAtom;
330    
331 <  int j, n_atoms, atomIndex;
331 >  int n_atoms, atomIndex;
332  
333   #ifdef IS_MPI
334 +  int j;
335 +
336    n_atoms = mpiSim->getTotAtoms();
337    atomIndex=-1;        
338    for (j=0; j < mpiSim->getMyNlocal(); j++) {
# Line 310 | Line 346 | char* InitializeFromFile::parseDumpLine(char* readLine
346      return strdup( painCave.errMsg );
347    }  
348   #else
349 <  n_atoms = entry_plug->n_atoms;
349 >  n_atoms = simnfo->n_atoms;
350    atomIndex = globalIndex;
351   #endif // is_mpi
352  
# Line 339 | Line 375 | char* InitializeFromFile::parseDumpLine(char* readLine
375               c_in_name, n_atoms, atomIndex );
376      return strdup( painCave.errMsg );
377    }
378 <  rx = atof( foo );
378 >  pos[0] = atof( foo );
379    
380    foo = strtok(NULL, " ,;\t");
381    if(foo == NULL){
# Line 349 | Line 385 | char* InitializeFromFile::parseDumpLine(char* readLine
385               c_in_name, n_atoms, atomIndex );
386      return strdup( painCave.errMsg );
387    }
388 <  ry = atof( foo );
388 >  pos[1] = atof( foo );
389      
390    foo = strtok(NULL, " ,;\t");
391    if(foo == NULL){
# Line 359 | Line 395 | char* InitializeFromFile::parseDumpLine(char* readLine
395               c_in_name, n_atoms, atomIndex );
396      return strdup( painCave.errMsg );
397    }
398 <  rz = atof( foo );    
398 >  pos[2] = atof( foo );    
399  
400  
401    // get the velocities
# Line 372 | Line 408 | char* InitializeFromFile::parseDumpLine(char* readLine
408               c_in_name, n_atoms, atomIndex );
409      return strdup( painCave.errMsg );
410    }
411 <  vx = atof( foo );
411 >  vel[0] = atof( foo );
412      
413    foo = strtok(NULL, " ,;\t");
414    if(foo == NULL){
# Line 382 | Line 418 | char* InitializeFromFile::parseDumpLine(char* readLine
418               c_in_name, n_atoms, atomIndex );
419      return strdup( painCave.errMsg );
420    }
421 <  vy = atof( foo );
421 >  vel[1] = atof( foo );
422      
423    foo = strtok(NULL, " ,;\t");
424    if(foo == NULL){
# Line 392 | Line 428 | char* InitializeFromFile::parseDumpLine(char* readLine
428               c_in_name, n_atoms, atomIndex );
429      return strdup( painCave.errMsg );
430    }
431 <  vz = atof( foo );
431 >  vel[2] = atof( foo );
432      
433      
434    // get the quaternions
# Line 494 | Line 530 | char* InitializeFromFile::parseDumpLine(char* readLine
530      
531    // add the positions and velocities to the atom
532      
533 <  atoms[atomIndex]->setX( rx );
534 <  atoms[atomIndex]->setY( ry );
499 <  atoms[atomIndex]->setZ( rz );
500 <    
501 <  atoms[atomIndex]->set_vx( vx );
502 <  atoms[atomIndex]->set_vy( vy );
503 <  atoms[atomIndex]->set_vz( vz );
533 >  atoms[atomIndex]->setPos( pos );
534 >  atoms[atomIndex]->setVel( vel );
535  
536    return NULL;
537   }
538  
539  
540 + char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9],
541 +                                       double &time ){
542 +
543 +  char *foo; // the pointer to the current string token
544 +
545 +  // set the string tokenizer
546 +  
547 +  foo = strtok(readLine, " ,;\t");
548 +  // set the timeToken.
549 +
550 +  if(foo == NULL){
551 +    sprintf( painCave.errMsg,
552 +             "error in reading Time from %s\n",
553 +             c_in_name );
554 +    return strdup( painCave.errMsg );
555 +  }
556 +  time = atof( foo );
557 +
558 +  // get the Hx vector
559 +
560 +  foo = strtok(NULL, " ,;\t");
561 +  if(foo == NULL){
562 +    sprintf( painCave.errMsg,
563 +             "error in reading Hx[0] from %s\n",
564 +             c_in_name );
565 +    return strdup( painCave.errMsg );
566 +  }
567 +  boxMat[0] = atof( foo );
568 +  
569 +  foo = strtok(NULL, " ,;\t");
570 +  if(foo == NULL){
571 +    sprintf( painCave.errMsg,
572 +             "error in reading Hx[1] from %s\n",
573 +             c_in_name );
574 +    return strdup( painCave.errMsg );
575 +  }
576 +  boxMat[1] = atof( foo );
577 +    
578 +  foo = strtok(NULL, " ,;\t");
579 +  if(foo == NULL){
580 +    sprintf( painCave.errMsg,
581 +             "error in reading Hx[2] from %s\n",
582 +             c_in_name );
583 +    return strdup( painCave.errMsg );
584 +  }
585 +  boxMat[2] = atof( foo );    
586 +
587 +  // get the Hy vector
588 +
589 +  foo = strtok(NULL, " ,;\t");
590 +  if(foo == NULL){
591 +    sprintf( painCave.errMsg,
592 +             "error in reading Hy[0] from %s\n",
593 +             c_in_name );
594 +    return strdup( painCave.errMsg );
595 +  }
596 +  boxMat[3] = atof( foo );
597 +  
598 +  foo = strtok(NULL, " ,;\t");
599 +  if(foo == NULL){
600 +    sprintf( painCave.errMsg,
601 +             "error in reading Hy[1] from %s\n",
602 +             c_in_name );
603 +    return strdup( painCave.errMsg );
604 +  }
605 +  boxMat[4] = atof( foo );
606 +    
607 +  foo = strtok(NULL, " ,;\t");
608 +  if(foo == NULL){
609 +    sprintf( painCave.errMsg,
610 +             "error in reading Hy[2] from %s\n",
611 +             c_in_name );
612 +    return strdup( painCave.errMsg );
613 +  }
614 +  boxMat[5] = atof( foo );    
615 +
616 +  // get the Hz vector
617 +
618 +  foo = strtok(NULL, " ,;\t");
619 +  if(foo == NULL){
620 +    sprintf( painCave.errMsg,
621 +             "error in reading Hz[0] from %s\n",
622 +             c_in_name );
623 +    return strdup( painCave.errMsg );
624 +  }
625 +  boxMat[6] = atof( foo );
626 +  
627 +  foo = strtok(NULL, " ,;\t");
628 +  if(foo == NULL){
629 +    sprintf( painCave.errMsg,
630 +             "error in reading Hz[1] from %s\n",
631 +             c_in_name );
632 +    return strdup( painCave.errMsg );
633 +  }
634 +  boxMat[7] = atof( foo );
635 +    
636 +  foo = strtok(NULL, " ,;\t");
637 +  if(foo == NULL){
638 +    sprintf( painCave.errMsg,
639 +             "error in reading Hz[2] from %s\n",
640 +             c_in_name );
641 +    return strdup( painCave.errMsg );
642 +  }
643 +  boxMat[8] = atof( foo );    
644 +
645 +  return NULL;
646 + }
647 +
648 +
649   #ifdef IS_MPI
650  
651   // a couple of functions to let us escape the read loop
# Line 515 | Line 655 | void initFile::nodeZeroError( void ){
655    
656    myStatus = 0;
657    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
658 <    MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j,
659 <                          TAKE_THIS_TAG_INT);
658 >    MPI_Send( &myStatus, 1, MPI_INT, j,
659 >              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
660    }  
661    
662  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines