--- trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2004/04/12 20:32:20 1097 +++ trunk/OOPSE/libmdtools/InitializeFromFile.cpp 2004/04/14 15:37:41 1108 @@ -85,12 +85,15 @@ void InitializeFromFile :: readInit( SimInfo* the_simn #endif //is_mpi const int BUFFERSIZE = 2000; // size of the read buffer - int n_atoms; // the number of atoms + int nTotObjs; // the number of atoms char read_buffer[BUFFERSIZE]; //the line buffer for reading char *eof_test; // ptr to see when we reach the end of the file char *parseErr; + vector integrableObjects; + vector::iterator iter; + simnfo = the_simnfo; @@ -104,13 +107,13 @@ void InitializeFromFile :: readInit( SimInfo* the_simn simError(); } - n_atoms = atoi( read_buffer ); + nTotObjs = atoi( read_buffer ); - if( n_atoms != simnfo->n_atoms ){ + if( nTotObjs != simnfo->getTotIntegrableObjects() ){ sprintf( painCave.errMsg, "Initialize from File error. %s n_atoms, %d, " "does not match the BASS file's n_atoms, %d.\n", - c_in_name, n_atoms, simnfo->n_atoms ); + c_in_name, nTotObjs, simnfo->getTotIntegrableObjects()); painCave.isFatal = 1; simError(); } @@ -125,8 +128,6 @@ void InitializeFromFile :: readInit( SimInfo* the_simn simError(); } - - parseErr = parseCommentLine( read_buffer, simnfo); if( parseErr != NULL ){ strcpy( painCave.errMsg, parseErr ); @@ -136,26 +137,29 @@ void InitializeFromFile :: readInit( SimInfo* the_simn //parse dump lines - for( i=0; i < n_atoms; i++){ + for( i=0; i < simnfo->n_mol; i++){ - eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); - if(eof_test == NULL){ - sprintf(painCave.errMsg, - "error in reading file %s\n" - "natoms = %d; index = %d\n" - "error reading the line from the file.\n", - c_in_name, n_atoms, i ); - painCave.isFatal = 1; - simError(); - } + integrableObjects = (simnfo->molecules[i]).getIntegrableObjects(); + for(iter = integrableObjects.begin(); iter!= integrableObjects.end(); iter++) - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - painCave.isFatal = 1; - simError(); - } + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + if(eof_test == NULL){ + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + c_in_name, nTotObjs, i ); + painCave.isFatal = 1; + simError(); + } + + parseErr = parseDumpLine( read_buffer, *iter); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + painCave.isFatal = 1; + simError(); + } } @@ -169,9 +173,10 @@ void InitializeFromFile :: readInit( SimInfo* the_simn int haveError; MPI_Status istatus; - int *AtomToProcMap = mpiSim->getAtomToProcMap(); + int *MolToProcMap = mpiSim->getMolToProcMap(); + int localIndex; + int nCurObj; - haveError = 0; if (worldRank == 0) { @@ -183,16 +188,16 @@ void InitializeFromFile :: readInit( SimInfo* the_simn simError(); } - n_atoms = atoi( read_buffer ); + nTotObjs = atoi( read_buffer ); - // Check to see that the number of atoms in the intial configuration file is the + // Check to see that the number of integrable objects in the intial configuration file is the // same as declared in simBass. - if( n_atoms != mpiSim->getTotAtoms() ){ + if( nTotObjs != simnfo->getTotIntegrableObjects()){ sprintf( painCave.errMsg, "Initialize from File error. %s n_atoms, %d, " "does not match the BASS file's n_atoms, %d.\n", - c_in_name, n_atoms, simnfo->n_atoms ); + c_in_name, nTotObjs, simnfo->getTotIntegrableObjects()); haveError= 1; simError(); } @@ -222,105 +227,118 @@ void InitializeFromFile :: readInit( SimInfo* the_simn simError(); } - for (i=0 ; i < mpiSim->getTotAtoms(); i++) { + for (i=0 ; i < mpiSim->getTotNmol(); i++) { + which_node = MolToProcMap[i]; + if(which_node == 0){ + //molecules belong to master node - eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); - if(eof_test == NULL){ - sprintf(painCave.errMsg, - "error in reading file %s\n" - "natoms = %d; index = %d\n" - "error reading the line from the file.\n", - c_in_name, n_atoms, i ); - haveError= 1; - simError(); + localIndex = mpiSim->getGlobalToLocalMol(i); + + if(localIndex == -1) { + strcpy(painCave.errMsg, "Molecule not found on node 0!"); + haveError = 1; + simError(); } - if(haveError) nodeZeroError(); + integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); + for(j=0; j < integrableObjects.size(); j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + if(eof_test == NULL){ + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + c_in_name, nTotObjs, i ); + haveError= 1; + simError(); + } + + if(haveError) nodeZeroError(); - // Get the Node number which wants this atom: - which_node = AtomToProcMap[i]; - if (which_node == 0) { - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - haveError = 1; - simError(); - } - if(haveError) nodeZeroError(); + parseDumpLine(read_buffer, integrableObjects[i]); + + } + + } + else{ + //molecule belongs to slave nodes - else { + MPI_Recv(&nCurObj, 1, MPI_INT, 0, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + + for(j=0; j < integrableObjects.size(); j++){ + + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + if(eof_test == NULL){ + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + c_in_name, nTotObjs, i ); + haveError= 1; + simError(); + } + + if(haveError) nodeZeroError(); - myStatus = 1; - MPI_Send(&myStatus, 1, MPI_INT, which_node, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); - MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, - MPI_COMM_WORLD); - MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, - MPI_COMM_WORLD, &istatus); + MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, + TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); + + } - if(!myStatus) nodeZeroError(); } + } - myStatus = -1; - for (j = 1; j < mpiSim->getNumberProcessors(); j++) { - MPI_Send( &myStatus, 1, MPI_INT, j, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - } + + } + else{ + //actions taken at slave nodes + for (i=0 ; i < mpiSim->getTotNmol(); i++) { + which_node = MolToProcMap[i]; + + if(which_node == worldRank){ + //molecule with global index i belongs to this processor + + localIndex = mpiSim->getGlobalToLocalMol(i); - } else { + if(localIndex == -1) { + sprintf(painCave.errMsg, "Molecule not found on node %d\n", worldRank); + haveError = 1; + simError(); + } - MPI_Bcast(read_buffer, BUFFERSIZE, MPI_CHAR, 0, MPI_COMM_WORLD); + integrableObjects = (simnfo->molecules[localIndex]).getIntegrableObjects(); - parseErr = parseCommentLine( read_buffer, simnfo); - - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - haveError = 1; - simError(); - } + nCurObj = integrableObjects.size(); + + MPI_Recv(&nCurObj, 1, MPI_INT, 0, + TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + for(j = 0; j < integrableObjects.size(); j++){ - done = 0; - while (!done) { + MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, + TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); - MPI_Recv(&myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); + parseErr = parseDumpLine(read_buffer, integrableObjects[j]); - if(!myStatus) anonymousNodeDie(); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + simError(); + } - if(myStatus < 0) break; - - MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, - TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); - MPI_Recv(&which_atom, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); - - myStatus = 1; - parseErr = parseDumpLine( read_buffer, which_atom ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - myStatus = 0;; - simError(); + } + } - - MPI_Send( &myStatus, 1, MPI_INT, 0, - TAKE_THIS_TAG_INT, MPI_COMM_WORLD); - + } - } - // last thing last, enable fatalities. - painCave.isEventLoop = 0; - - - + } #endif } -char* InitializeFromFile::parseDumpLine(char* readLine, int globalIndex){ +char* InitializeFromFile::parseDumpLine(char* readLine, StuntDouble* sd){ char *foo; // the pointer to the current string token @@ -330,43 +348,18 @@ char* InitializeFromFile::parseDumpLine(char* readLine double ji[3]; // angular velocity placeholders; double qSqr, qLength; // needed to normalize the quaternion vector. - Atom **atoms = simnfo->atoms; - DirectionalAtom* dAtom; - int n_atoms, atomIndex; - -#ifdef IS_MPI - int j; - - n_atoms = mpiSim->getTotAtoms(); - atomIndex=-1; - for (j=0; j < mpiSim->getMyNlocal(); j++) { - if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j; - } - if (atomIndex == -1) { - sprintf( painCave.errMsg, - "Initialize from file error. Atom at index %d " - "in file %s does not exist on processor %d .\n", - globalIndex, c_in_name, mpiSim->getMyNode() ); - return strdup( painCave.errMsg ); - } -#else - n_atoms = simnfo->n_atoms; - atomIndex = globalIndex; -#endif // is_mpi - // set the string tokenizer foo = strtok(readLine, " ,;\t"); // check the atom name to the current atom - if( strcmp( foo, atoms[atomIndex]->getType() ) ){ + if( strcmp( foo, sd->getType() ) ){ sprintf( painCave.errMsg, - "Initialize from file error. Atom %s at index %d " - "in file %s does not" + "Initialize from file error. Does not" " match the BASS atom %s.\n", - foo, atomIndex, c_in_name, atoms[atomIndex]->getType() ); + sd->getType() ); return strdup( painCave.errMsg ); } @@ -375,9 +368,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading postition x from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading postition x from %s\n", + c_in_name); return strdup( painCave.errMsg ); } pos[0] = atof( foo ); @@ -385,9 +377,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading postition y from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading postition y from %s\n", + c_in_name); return strdup( painCave.errMsg ); } pos[1] = atof( foo ); @@ -395,9 +386,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading postition z from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading postition z from %s\n", + c_in_name); return strdup( painCave.errMsg ); } pos[2] = atof( foo ); @@ -408,9 +398,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading velocity x from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } vel[0] = atof( foo ); @@ -418,9 +407,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading velocity y from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } vel[1] = atof( foo ); @@ -428,24 +416,30 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading velocity z from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } vel[2] = atof( foo ); + // add the positions and velocities to the atom + + sd->setPos( pos ); + sd->setVel( vel ); + + if (!sd->isDirectional()) + return NULL; + // get the quaternions - if( atoms[atomIndex]->isDirectional() ){ + if( sd->isDirectional() ){ foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - sprintf(painCave.errMsg, - "error in reading quaternion 0 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + sprintf( painCave.errMsg, + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } q[0] = atof( foo ); @@ -453,9 +447,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading quaternion 1 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } q[1] = atof( foo ); @@ -463,9 +456,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading quaternion 2 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } q[2] = atof( foo ); @@ -473,9 +465,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading quaternion 3 from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } q[3] = atof( foo ); @@ -485,9 +476,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading angular momentum jx from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } ji[0] = atof( foo ); @@ -495,9 +485,8 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading angular momentum jy from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } ji[1] = atof(foo ); @@ -505,14 +494,12 @@ char* InitializeFromFile::parseDumpLine(char* readLine foo = strtok(NULL, " ,;\t"); if(foo == NULL){ sprintf( painCave.errMsg, - "error in reading angular momentum jz from %s\n" - "natoms = %d, index = %d\n", - c_in_name, n_atoms, atomIndex ); + "error in reading velocity x from %s\n", + c_in_name ); return strdup( painCave.errMsg ); } ji[2] = atof( foo ); - dAtom = ( DirectionalAtom* )atoms[atomIndex]; // check that the quaternion vector is normalized @@ -524,17 +511,13 @@ char* InitializeFromFile::parseDumpLine(char* readLine q[2] = q[2] / qLength; q[3] = q[3] / qLength; - dAtom->setQ( q ); + // add quaternion and angular velocities - // add the angular velocities - - dAtom->setJ( ji ); + sd->setQ( q ); + sd->setJ( ji ); } - // add the positions and velocities to the atom - atoms[atomIndex]->setPos( pos ); - atoms[atomIndex]->setVel( vel ); return NULL; }