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 689 by tim, Tue Aug 12 19:56:49 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 >  std::cerr << "Hello from Initialize from file.\n";
32 >
33   #ifdef IS_MPI
34    if (worldRank == 0) {
35   #endif
# Line 49 | Line 51 | InitializeFromFile :: ~InitializeFromFile( ){
51    return;  
52   }
53  
54 < InitializeFromFile :: ~InitializeFromFile( ){
54 > InitializeFromFile::~InitializeFromFile( ){
55   #ifdef IS_MPI
56    if (worldRank == 0) {
57   #endif
# Line 70 | Line 72 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
72   }
73  
74  
75 < void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){
75 > void InitializeFromFile :: readInit( SimInfo* the_simnfo ){
76  
77    int i, j, done, which_node, which_atom; // loop counter
78  
# Line 84 | Line 86 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
86    char *eof_test; // ptr to see when we reach the end of the file
87    char *parseErr;
88    int procIndex;
89 +  double currTime;
90 +  double boxMat[9];
91 +  double theBoxMat3[3][3];
92  
93 <  entry_plug = the_entry_plug;
93 >  simnfo = the_simnfo;
94  
95  
96   #ifndef IS_MPI
# Line 100 | Line 105 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
105  
106    n_atoms = atoi( read_buffer );
107  
108 <  Atom **atoms = entry_plug->atoms;
108 >  Atom **atoms = simnfo->atoms;
109    DirectionalAtom* dAtom;
110  
111 <  if( n_atoms != entry_plug->n_atoms ){
111 >  if( n_atoms != simnfo->n_atoms ){
112      sprintf( painCave.errMsg,
113               "Initialize from File error. %s n_atoms, %d, "
114               "does not match the BASS file's n_atoms, %d.\n",
115 <             c_in_name, n_atoms, entry_plug->n_atoms );
115 >             c_in_name, n_atoms, simnfo->n_atoms );
116      painCave.isFatal = 1;
117      simError();
118    }
119    
120 <  //read and toss the comment line
120 >  //read the box mat from the comment line
121    
122    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
123    if(eof_test == NULL){
# Line 122 | Line 127 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
127      simError();
128    }
129  
130 +  parseErr = parseBoxLine( read_buffer, boxMat, currTime );
131 +  if( parseErr != NULL ){
132 +    strcpy( painCave.errMsg, parseErr );
133 +    painCave.isFatal = 1;
134 +    simError();
135 +  }
136 +
137 +  for(i=0;i<3;i++)
138 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
139 +
140 +  simnfo->setBoxM( theBoxMat3 );
141 +  simnfo->setTime( currTime );
142 +
143 +
144    for( i=0; i < n_atoms; i++){
145      
146      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
# Line 141 | Line 160 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
160        strcpy( painCave.errMsg, parseErr );
161        painCave.isFatal = 1;
162        simError();
163 <    }    
163 >    }
164    }
165  
166  
# Line 154 | Line 173 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
173    int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
174    int haveError;
175    
176 <  MPI::Status istatus;
176 >  MPI_Status istatus;
177    int *AtomToProcMap = mpiSim->getAtomToProcMap();
178  
179    
# Line 171 | Line 190 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
190      
191      n_atoms = atoi( read_buffer );
192      
193 <    Atom **atoms = entry_plug->atoms;
193 >    Atom **atoms = simnfo->atoms;
194      DirectionalAtom* dAtom;
195  
196      // Check to see that the number of atoms in the intial configuration file is the
# Line 181 | Line 200 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
200        sprintf( painCave.errMsg,
201                 "Initialize from File error. %s n_atoms, %d, "
202                 "does not match the BASS file's n_atoms, %d.\n",
203 <               c_in_name, n_atoms, entry_plug->n_atoms );
203 >               c_in_name, n_atoms, simnfo->n_atoms );
204        haveError= 1;
205        simError();
206      }
207      
208 <    //read and toss the comment line
208 >    //read the boxMat from the comment line
209      
210      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
211      if(eof_test == NULL){
212        sprintf( painCave.errMsg,
213                 "error in reading commment in %s\n", c_in_name);
214 <      haveError= 1;
214 >      haveError = 1;
215        simError();
216      }
217 +    
218 +    parseErr = parseBoxLine( read_buffer, boxMat, currTime );
219 +    if( parseErr != NULL ){
220 +      strcpy( painCave.errMsg, parseErr );
221 +      haveError = 1;
222 +      simError();
223 +    }
224 +
225 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD );
226 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD );
227    
228      if(haveError) nodeZeroError();
229  
# Line 228 | Line 257 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
257        else {
258        
259          myStatus = 1;
260 <        MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node,
261 <                             TAKE_THIS_TAG_INT);
262 <        MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
263 <                             TAKE_THIS_TAG_CHAR);
264 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
265 <        MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, istatus);
260 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
261 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
262 >        MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
263 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
264 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
265 >                 MPI_COMM_WORLD);
266 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
267 >                 MPI_COMM_WORLD, &istatus);
268          
269          if(!myStatus) nodeZeroError();
270        }
271      }
272      myStatus = -1;
273      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
274 <      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j,
275 <                            TAKE_THIS_TAG_INT);
274 >      MPI_Send( &myStatus, 1, MPI_INT, j,
275 >                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
276      }
277      
278    } else {
279      
280 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD);
281 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
282 +
283      done = 0;
284      while (!done) {
285  
286 <      MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0,
287 <                           TAKE_THIS_TAG_INT, istatus);
286 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
287 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
288        
289        if(!myStatus) anonymousNodeDie();
290        
291        if(myStatus < 0) break;
292  
293 <      MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
294 <                           TAKE_THIS_TAG_CHAR, istatus);
295 <      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
296 <                           TAKE_THIS_TAG_INT, istatus);
293 >      MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
294 >               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
295 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
296 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
297        
298        myStatus = 1;
299        parseErr = parseDumpLine( read_buffer, which_atom );
# Line 269 | Line 303 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
303          simError();
304        }
305        
306 <      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0,
307 <                            TAKE_THIS_TAG_INT);
306 >      MPI_Send( &myStatus, 1, MPI_INT, 0,
307 >                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
308        
309      }
310    }
311      
312   // last  thing last, enable  fatalities.
313    painCave.isEventLoop = 0;
314 +
315 +  for(i=0;i<3;i++)
316 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
317 +
318 +  simnfo->setBoxM( theBoxMat3 );
319 +  simnfo->setTime( currTime );
320 +
321    
322   #endif
323   }
# Line 285 | Line 326 | char* InitializeFromFile::parseDumpLine(char* readLine
326  
327    char *foo; // the pointer to the current string token
328    
329 <  double rx, ry, rz; // position place holders
330 <  double vx, vy, vz; // velocity placeholders
329 >  double pos[3]; // position place holders
330 >  double vel[3]; // velocity placeholders
331    double q[4]; // the quaternions
332    double jx, jy, jz; // angular velocity placeholders;
333    double qSqr, qLength; // needed to normalize the quaternion vector.
334    
335 <  Atom **atoms = entry_plug->atoms;
335 >  Atom **atoms = simnfo->atoms;
336    DirectionalAtom* dAtom;
337    
338    int j, n_atoms, atomIndex;
# Line 310 | Line 351 | char* InitializeFromFile::parseDumpLine(char* readLine
351      return strdup( painCave.errMsg );
352    }  
353   #else
354 <  n_atoms = entry_plug->n_atoms;
354 >  n_atoms = simnfo->n_atoms;
355    atomIndex = globalIndex;
356   #endif // is_mpi
357  
# Line 339 | Line 380 | char* InitializeFromFile::parseDumpLine(char* readLine
380               c_in_name, n_atoms, atomIndex );
381      return strdup( painCave.errMsg );
382    }
383 <  rx = atof( foo );
383 >  pos[0] = atof( foo );
384    
385    foo = strtok(NULL, " ,;\t");
386    if(foo == NULL){
# Line 349 | Line 390 | char* InitializeFromFile::parseDumpLine(char* readLine
390               c_in_name, n_atoms, atomIndex );
391      return strdup( painCave.errMsg );
392    }
393 <  ry = atof( foo );
393 >  pos[1] = atof( foo );
394      
395    foo = strtok(NULL, " ,;\t");
396    if(foo == NULL){
# Line 359 | Line 400 | char* InitializeFromFile::parseDumpLine(char* readLine
400               c_in_name, n_atoms, atomIndex );
401      return strdup( painCave.errMsg );
402    }
403 <  rz = atof( foo );    
403 >  pos[2] = atof( foo );    
404  
405  
406    // get the velocities
# Line 372 | Line 413 | char* InitializeFromFile::parseDumpLine(char* readLine
413               c_in_name, n_atoms, atomIndex );
414      return strdup( painCave.errMsg );
415    }
416 <  vx = atof( foo );
416 >  vel[0] = atof( foo );
417      
418    foo = strtok(NULL, " ,;\t");
419    if(foo == NULL){
# Line 382 | Line 423 | char* InitializeFromFile::parseDumpLine(char* readLine
423               c_in_name, n_atoms, atomIndex );
424      return strdup( painCave.errMsg );
425    }
426 <  vy = atof( foo );
426 >  vel[1] = atof( foo );
427      
428    foo = strtok(NULL, " ,;\t");
429    if(foo == NULL){
# Line 392 | Line 433 | char* InitializeFromFile::parseDumpLine(char* readLine
433               c_in_name, n_atoms, atomIndex );
434      return strdup( painCave.errMsg );
435    }
436 <  vz = atof( foo );
436 >  vel[2] = atof( foo );
437      
438      
439    // get the quaternions
# Line 494 | Line 535 | char* InitializeFromFile::parseDumpLine(char* readLine
535      
536    // add the positions and velocities to the atom
537      
538 <  atoms[atomIndex]->setX( rx );
539 <  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 );
538 >  atoms[atomIndex]->setPos( pos );
539 >  atoms[atomIndex]->setVel( vel );
540  
541    return NULL;
542   }
543  
544  
545 + char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9],
546 +                                       double &time ){
547 +
548 +  char *foo; // the pointer to the current string token
549 +  int j;
550 +
551 +  // set the string tokenizer
552 +  
553 +  foo = strtok(readLine, " ,;\t");
554 +  // set the timeToken.
555 +
556 +  if(foo == NULL){
557 +    sprintf( painCave.errMsg,
558 +             "error in reading Time from %s\n",
559 +             c_in_name );
560 +    return strdup( painCave.errMsg );
561 +  }
562 +  time = atof( foo );
563 +
564 +  // get the Hx vector
565 +
566 +  foo = strtok(NULL, " ,;\t");
567 +  if(foo == NULL){
568 +    sprintf( painCave.errMsg,
569 +             "error in reading Hx[0] from %s\n",
570 +             c_in_name );
571 +    return strdup( painCave.errMsg );
572 +  }
573 +  boxMat[0] = atof( foo );
574 +  
575 +  foo = strtok(NULL, " ,;\t");
576 +  if(foo == NULL){
577 +    sprintf( painCave.errMsg,
578 +             "error in reading Hx[1] from %s\n",
579 +             c_in_name );
580 +    return strdup( painCave.errMsg );
581 +  }
582 +  boxMat[1] = atof( foo );
583 +    
584 +  foo = strtok(NULL, " ,;\t");
585 +  if(foo == NULL){
586 +    sprintf( painCave.errMsg,
587 +             "error in reading Hx[2] from %s\n",
588 +             c_in_name );
589 +    return strdup( painCave.errMsg );
590 +  }
591 +  boxMat[2] = atof( foo );    
592 +
593 +  // get the Hy vector
594 +
595 +  foo = strtok(NULL, " ,;\t");
596 +  if(foo == NULL){
597 +    sprintf( painCave.errMsg,
598 +             "error in reading Hy[0] from %s\n",
599 +             c_in_name );
600 +    return strdup( painCave.errMsg );
601 +  }
602 +  boxMat[3] = atof( foo );
603 +  
604 +  foo = strtok(NULL, " ,;\t");
605 +  if(foo == NULL){
606 +    sprintf( painCave.errMsg,
607 +             "error in reading Hy[1] from %s\n",
608 +             c_in_name );
609 +    return strdup( painCave.errMsg );
610 +  }
611 +  boxMat[4] = atof( foo );
612 +    
613 +  foo = strtok(NULL, " ,;\t");
614 +  if(foo == NULL){
615 +    sprintf( painCave.errMsg,
616 +             "error in reading Hy[2] from %s\n",
617 +             c_in_name );
618 +    return strdup( painCave.errMsg );
619 +  }
620 +  boxMat[5] = atof( foo );    
621 +
622 +  // get the Hz vector
623 +
624 +  foo = strtok(NULL, " ,;\t");
625 +  if(foo == NULL){
626 +    sprintf( painCave.errMsg,
627 +             "error in reading Hz[0] from %s\n",
628 +             c_in_name );
629 +    return strdup( painCave.errMsg );
630 +  }
631 +  boxMat[6] = atof( foo );
632 +  
633 +  foo = strtok(NULL, " ,;\t");
634 +  if(foo == NULL){
635 +    sprintf( painCave.errMsg,
636 +             "error in reading Hz[1] from %s\n",
637 +             c_in_name );
638 +    return strdup( painCave.errMsg );
639 +  }
640 +  boxMat[7] = atof( foo );
641 +    
642 +  foo = strtok(NULL, " ,;\t");
643 +  if(foo == NULL){
644 +    sprintf( painCave.errMsg,
645 +             "error in reading Hz[2] from %s\n",
646 +             c_in_name );
647 +    return strdup( painCave.errMsg );
648 +  }
649 +  boxMat[8] = atof( foo );    
650 +
651 +  return NULL;
652 + }
653 +
654 +
655   #ifdef IS_MPI
656  
657   // a couple of functions to let us escape the read loop
# Line 515 | Line 661 | void initFile::nodeZeroError( void ){
661    
662    myStatus = 0;
663    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
664 <    MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j,
665 <                          TAKE_THIS_TAG_INT);
664 >    MPI_Send( &myStatus, 1, MPI_INT, j,
665 >              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
666    }  
667    
668  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines