--- trunk/src/io/RestReader.cpp	2005/03/10 15:10:24	417
+++ trunk/src/io/RestReader.cpp	2006/05/17 21:51:42	963
@@ -60,7 +60,6 @@
 
 #ifdef IS_MPI
 #include <mpi.h>
-#include "brains/mpiSimulation.hpp"
 #define TAKE_THIS_TAG_CHAR 0
 #define TAKE_THIS_TAG_INT 1
 #define TAKE_THIS_TAG_DOUBLE 2
@@ -69,7 +68,7 @@ namespace oopse {
 namespace oopse {
   
   RestReader::RestReader( SimInfo* info ) : info_(info){
-        
+    
     idealName = "idealCrystal.in";
     
     isScanned = false;
@@ -93,6 +92,7 @@ namespace oopse {
             "File \"idealCrystal.in\" opened successfully for reading." );
     MPIcheckPoint();
 #endif
+
     return;  
   }
   
@@ -220,13 +220,13 @@ namespace oopse {
     int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
     
     MPI_Status istatus;
-    int localIndex;
     int nCurObj;
     int nitems;
-    
-    nTotObjs = info_->getTotIntegrableObjects();
+    int haveError;
+
+    nTotObjs = info_->getNGlobalIntegrableObjects();
     haveError = 0;
-    
+
     if (worldRank == masterNode) {
       eof_test = fgets(read_buffer, sizeof(read_buffer), inIdealFile);
       if( eof_test == NULL ){
@@ -259,19 +259,19 @@ namespace oopse {
         painCave.isFatal = 1;
         simError();
       }
-      
+
       for (i=0 ; i < info_->getNGlobalMolecules(); i++) {
         int which_node = info_->getMolToProc(i);
         
         if(which_node == masterNode){
           //molecules belong to master node
           
-          localIndex = info_->getMoleculeByGlobalIndex(i);
+          mol = info_->getMoleculeByGlobalIndex(i);
           
-          if(localIndex == NULL) {
-            strcpy(painCave.errMsg, 
-                   "RestReader Error: Molecule not found on node %d!",
-                   worldRank);
+          if(mol == NULL) {
+	    sprintf(painCave.errMsg, 
+		    "RestReader Error: Molecule not found on node %d!\n",
+		    worldRank);
             painCave.isFatal = 1;
             simError();
           }
@@ -291,8 +291,9 @@ namespace oopse {
               painCave.isFatal = 1;
               simError();
             }
-            
-            parseIdealLine(read_buffer, integrableObjects[j]);
+	
+            parseIdealLine(read_buffer, integrableObject);
+	
           }
         } else {
           //molecule belongs to slave nodes
@@ -313,9 +314,7 @@ namespace oopse {
               simError();
             }
             
-            if(haveError) nodeZeroError();
-            
-            MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
+	    MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
                      TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
           }
         }
@@ -328,9 +327,9 @@ namespace oopse {
         if(which_node == worldRank){
           //molecule with global index i belongs to this processor
           
-          localIndex = info_->getMoleculeByGlobalIndex(i);
+          mol = info_->getMoleculeByGlobalIndex(i);
           
-          if(localIndex == NULL) {
+          if(mol == NULL) {
             sprintf(painCave.errMsg, 
                     "RestReader Error: molecule not found on node %d\n", 
                     worldRank);
@@ -338,7 +337,7 @@ namespace oopse {
             simError();
           }
           
-          nCurObj = localIndex->getNIntegrableObjects();
+          nCurObj = mol->getNIntegrableObjects();
           
           MPI_Send(&nCurObj, 1, MPI_INT, masterNode,
                    TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
@@ -367,17 +366,17 @@ namespace oopse {
     
     char *foo; // the pointer to the current string token
     
-    double pos[3];        // position place holders
-    double q[4];          // the quaternions
-    double RfromQ[3][3];  // the rotation matrix 
-    double normalize;     // to normalize the reference unit vector
-    double uX, uY, uZ;    // reference unit vector place holders
-    double uselessToken;
+    RealType pos[3];        // position place holders
+    RealType q[4];          // the quaternions
+    RealType RfromQ[3][3];  // the rotation matrix 
+    RealType normalize;     // to normalize the reference unit vector
+    RealType uX, uY, uZ;    // reference unit vector place holders
+    RealType uselessToken;
     StringTokenizer tokenizer(readLine);
     int nTokens;
     
     nTokens = tokenizer.countTokens();
-    
+
     if (nTokens < 14) {
       sprintf(painCave.errMsg,
               "RestReader Error: Not enough Tokens.\n");
@@ -386,7 +385,7 @@ namespace oopse {
     }
     
     std::string name = tokenizer.nextToken();
-    
+
     if (name != sd->getType()) {
       
       sprintf(painCave.errMsg,
@@ -401,13 +400,13 @@ namespace oopse {
     pos[0] = tokenizer.nextTokenAsDouble();
     pos[1] = tokenizer.nextTokenAsDouble();
     pos[2] = tokenizer.nextTokenAsDouble();
-    
+
     // store the positions in the stuntdouble as generic data doubles
     DoubleGenericData* refPosX = new DoubleGenericData();
     refPosX->setID("refPosX");
     refPosX->setData(pos[0]);
     sd->addProperty(refPosX);
-    
+
     DoubleGenericData* refPosY = new DoubleGenericData();
     refPosY->setID("refPosY");
     refPosY->setData(pos[1]);
@@ -417,7 +416,7 @@ namespace oopse {
     refPosZ->setID("refPosZ");
     refPosZ->setData(pos[2]);
     sd->addProperty(refPosZ);
-    
+
     // we don't need the velocities
     uselessToken = tokenizer.nextTokenAsDouble();
     uselessToken = tokenizer.nextTokenAsDouble();
@@ -493,7 +492,7 @@ namespace oopse {
     char *parseErr;
     
     std::vector<StuntDouble*> vecParticles;
-    std::vector<double> tempZangs;
+    std::vector<RealType> tempZangs;
       
     inAngFileName = info_->getRestFileName();
     
@@ -594,18 +593,19 @@ namespace oopse {
     
     // first thing first, suspend fatalities.
     painCave.isEventLoop = 1;
-    
+
+    int masterNode = 0;
     int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
-    int haveError, index;
-    
-    int *MolToProcMap = mpiSim->getMolToProcMap();
-    int localIndex;
+    int haveError;
+    int index;    
+
     int nCurObj;
-    double angleTranfer;
+    RealType angleTranfer;
     
-    nTotObjs = info_->getTotIntegrableObjects();
+    nTotObjs = info_->getNGlobalIntegrableObjects();
     haveError = 0;
-    if (worldRank == 0) {
+
+    if (worldRank == masterNode) {
       
       eof_test = fgets(read_buffer, sizeof(read_buffer), inAngFile);
       if( eof_test == NULL ){
@@ -636,69 +636,82 @@ namespace oopse {
         simError();
       }
       
-    }
-    // At this point, node 0 has a tempZangs vector completed, and 
-    // everyone else has nada
-    index = 0;
-    
-    for (i=0 ; i < mpiSim->getNMolGlobal(); i++) {
-      // Get the Node number which has this atom
-      which_node = MolToProcMap[i];
+      // At this point, node 0 has a tempZangs vector completed, and 
+      // everyone else has nada
+      index = 0;
       
-      if (worldRank == 0) {
-        if (which_node == 0) {
-          localIndex = mpiSim->getGlobalToLocalMol(i);
-          
-          if(localIndex == -1) {
-            strcpy(painCave.errMsg, "Molecule not found on node 0!");
-            haveError = 1;
+      for (i=0 ; i < info_->getNGlobalMolecules(); i++) {
+	// Get the Node number which has this atom
+	which_node = info_->getMolToProc(i);
+	
+	if (worldRank == masterNode) {
+	  mol = info_->getMoleculeByGlobalIndex(i);
+	  
+	  if(mol == NULL) {
+	    strcpy(painCave.errMsg, "Molecule not found on node 0!");
+	    haveError = 1;
+	    simError();
+	  }
+	  
+	  for (integrableObject = mol->beginIntegrableObject(ii); 
+	       integrableObject != NULL; 
+	       integrableObject = mol->nextIntegrableObject(ii)){
+	    
+	    integrableObject->setZangle(tempZangs[index]);
+	    index++;
+	  }	
+	  
+	} else {
+	  // I am MASTER OF THE UNIVERSE, but I don't own this molecule
+	  
+	  MPI_Recv(&nCurObj, 1, MPI_INT, which_node,
+		   TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
+	  
+	  for(j=0; j < nCurObj; j++){	 	 
+	    angleTransfer = tempZangs[index];
+	    MPI_Send(&angleTransfer, 1, MPI_REALTYPE, which_node, 
+		     TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD);      	  
+	    index++;
+	  }
+	  
+	}
+      }
+    } else {
+      // I am SLAVE TO THE MASTER
+      for (i=0 ; i < info_->getNGlobalMolecules(); i++) {
+        int which_node = info_->getMolToProc(i);
+
+	if (which_node == worldRank) {
+	  
+	  // BUT I OWN THIS MOLECULE!!!
+	  
+	  mol = info_->getMoleculeByGlobalIndex(i);
+
+          if(mol == NULL) {
+            sprintf(painCave.errMsg, 
+                    "RestReader Error: molecule not found on node %d\n", 
+                    worldRank);
+            painCave.isFatal = 1;
             simError();
           }
-          
-          vecParticles = (info_->molecules[localIndex]).getIntegrableObjects();	
-          for(j = 0; j < vecParticles.size(); j++){	  
-            vecParticles[j]->setZangle(tempZangs[index]);
-            index++;
-          }	
-          
-        } else {
-          // I am MASTER OF THE UNIVERSE, but I don't own this molecule
-          
-          MPI_Recv(&nCurObj, 1, MPI_INT, which_node,
-                   TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
-          
-          for(j=0; j < nCurObj; j++){	 	 
-            angleTransfer = tempZangs[index];
-            MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, 
-                     TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD);      	  
-            index++;
-          }
-          
-        }
-        
-      } else {
-        // I am SLAVE TO THE MASTER
-        
-        if (which_node == worldRank) {
-          
-          // BUT I OWN THIS MOLECULE!!!
-          
-          localIndex = mpiSim->getGlobalToLocalMol(i);
-          vecParticles = (info_->molecules[localIndex]).getIntegrableObjects();	
-          nCurObj = vecParticles.size();
-          
-          MPI_Send(&nCurObj, 1, MPI_INT, 0,
-                   TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
-          
-          for(j = 0; j < vecParticles.size(); j++){
-            
-            MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0,
-                     TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus);
-            vecParticles[j]->setZangle(angleTransfer);
-          }	
-        }
+
+          nCurObj = mol->getNIntegrableObjects();
+	
+	  MPI_Send(&nCurObj, 1, MPI_INT, 0,
+		   TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
+	  
+          for (integrableObject = mol->beginIntegrableObject(ii); 
+               integrableObject != NULL; 
+               integrableObject = mol->nextIntegrableObject(ii)){
+	    
+	    MPI_Recv(&angleTransfer, 1, MPI_REALTYPE, 0,
+		     TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus);
+
+	    integrableObject->setZangle(angleTransfer);
+	  }	
+	}
       }
-    }
+    } 
 #endif
   }
   
@@ -732,69 +745,84 @@ namespace oopse {
     // first thing first, suspend fatalities.
     painCave.isEventLoop = 1;
     
+    int masterNode = 0;
     int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
-    int haveError, index;
+    int haveError;
     int which_node;
     
     MPI_Status istatus;
-    int *MolToProcMap = mpiSim->getMolToProcMap();
-    int localIndex;
+    
     int nCurObj;
-    double angleTranfer;
+    RealType angleTranfer;
     
-    nTotObjs = info_->getTotIntegrableObjects();
+    nTotObjs = info_->getNGlobalIntegrableObjects();
     haveError = 0;
-    
-    for (i=0 ; i < mpiSim->getNMolGlobal(); i++) {
-      // Get the Node number which has this atom
-      which_node = MolToProcMap[i];
-      
-      // let's let node 0 pass out constant values to all the processors
-      if (worldRank == 0) {
-        if (which_node == 0) {
-          localIndex = mpiSim->getGlobalToLocalMol(i);
-          
-          if(localIndex == -1) {
-            strcpy(painCave.errMsg, "Molecule not found on node 0!");
-            haveError = 1;
-            simError();
-          }
-          
-          vecParticles = (info_->molecules[localIndex]).getIntegrableObjects();	
-          for(j = 0; j < vecParticles.size(); j++){	  
-            vecParticles[j]->setZangle( 0.0 );
-          }	
-          
-        } else {
-          // I am MASTER OF THE UNIVERSE, but I don't own this molecule
-          
-          MPI_Recv(&nCurObj, 1, MPI_INT, which_node,
-                   TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
-          
-          for(j=0; j < nCurObj; j++){	 	 
-            angleTransfer = 0.0;
-            MPI_Send(&angleTransfer, 1, MPI_DOUBLE, which_node, 
-                     TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD);      	  
-            index++;
-          }
-        }
-      } else {
-        // I am SLAVE TO THE MASTER
-        
-        if (which_node == worldRank) {
-          
-          // BUT I OWN THIS MOLECULE!!!
-          
-          localIndex = mpiSim->getGlobalToLocalMol(i);
-          vecParticles = (info_->molecules[localIndex]).getIntegrableObjects();	
-          nCurObj = vecParticles.size();
-          
-          MPI_Send(&nCurObj, 1, MPI_INT, 0,
-                   TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
-          
-          for(j = 0; j < vecParticles.size(); j++){
-            
-            MPI_Recv(&angleTransfer, 1, MPI_DOUBLE, 0,
+    if (worldRank == masterNode) {
+
+      for (i=0 ; i < info_->getNGlobalMolecules(); i++) {
+	// Get the Node number which has this atom
+	which_node = info_->getMolToProc(i);
+	
+	// let's let node 0 pass out constant values to all the processors
+	if (worldRank == masterNode) {
+	  mol = info_->getMoleculeByGlobalIndex(i);
+	  
+	  if(mol == NULL) {
+	    strcpy(painCave.errMsg, "Molecule not found on node 0!");
+	    haveError = 1;
+	    simError();
+	  }
+	  
+	  for (integrableObject = mol->beginIntegrableObject(ii); 
+	       integrableObject != NULL; 
+	       integrableObject = mol->nextIntegrableObject(ii)){
+	    
+	    integrableObject->setZangle( 0.0 );
+	    
+	  }
+	  
+	} else {
+	  // I am MASTER OF THE UNIVERSE, but I don't own this molecule
+	  
+	  MPI_Recv(&nCurObj, 1, MPI_INT, which_node,
+		   TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
+	  
+	  for(j=0; j < nCurObj; j++){	 	 
+	    angleTransfer = 0.0;
+	    MPI_Send(&angleTransfer, 1, MPI_REALTYPE, which_node, 
+		     TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD);      	  
+	    
+	  }
+	}
+      }
+    } else {
+      // I am SLAVE TO THE MASTER
+      for (i=0 ; i < info_->getNGlobalMolecules(); i++) {
+	int which_node = info_->getMolToProc(i);
+	
+	if (which_node == worldRank) {
+	  
+	  // BUT I OWN THIS MOLECULE!!!
+	  mol = info_->getMoleculeByGlobalIndex(i);
+	  
+	  if(mol == NULL) {
+	    sprintf(painCave.errMsg, 
+		    "RestReader Error: molecule not found on node %d\n", 
+		    worldRank);
+	    painCave.isFatal = 1;
+	    simError();
+	  }
+	  
+	  nCurObj = mol->getNIntegrableObjects();
+	  
+	  MPI_Send(&nCurObj, 1, MPI_INT, 0,
+		   TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
+	  
+	  for (integrableObject = mol->beginIntegrableObject(ii); 
+               integrableObject != NULL; 
+               integrableObject = mol->nextIntegrableObject(ii)){
+	    
+            MPI_Recv(&angleTransfer, 1, MPI_REALTYPE, 0,
                      TAKE_THIS_TAG_DOUBLE, MPI_COMM_WORLD, &istatus);
             vecParticles[j]->setZangle(angleTransfer);
           }