ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/brains/SimInfo.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/brains/SimInfo.cpp (file contents):
Revision 1617 by chuckv, Wed Oct 20 20:46:20 2004 UTC vs.
Revision 2082 by tim, Mon Mar 7 22:39:33 2005 UTC

# Line 1 | Line 1
1 < #include <stdlib.h>
2 < #include <string.h>
3 < #include <math.h>
1 > /*
2 > * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 > *
4 > * The University of Notre Dame grants you ("Licensee") a
5 > * non-exclusive, royalty free, license to use, modify and
6 > * redistribute this software in source and binary code form, provided
7 > * that the following conditions are met:
8 > *
9 > * 1. Acknowledgement of the program authors must be made in any
10 > *    publication of scientific results based in part on use of the
11 > *    program.  An acceptable form of acknowledgement is citation of
12 > *    the article in which the program was described (Matthew
13 > *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 > *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 > *    Parallel Simulation Engine for Molecular Dynamics,"
16 > *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 > *
18 > * 2. Redistributions of source code must retain the above copyright
19 > *    notice, this list of conditions and the following disclaimer.
20 > *
21 > * 3. Redistributions in binary form must reproduce the above copyright
22 > *    notice, this list of conditions and the following disclaimer in the
23 > *    documentation and/or other materials provided with the
24 > *    distribution.
25 > *
26 > * This software is provided "AS IS," without a warranty of any
27 > * kind. All express or implied conditions, representations and
28 > * warranties, including any implied warranty of merchantability,
29 > * fitness for a particular purpose or non-infringement, are hereby
30 > * excluded.  The University of Notre Dame and its licensors shall not
31 > * be liable for any damages suffered by licensee as a result of
32 > * using, modifying or distributing the software or its
33 > * derivatives. In no event will the University of Notre Dame or its
34 > * licensors be liable for any lost revenue, profit or data, or for
35 > * direct, indirect, special, consequential, incidental or punitive
36 > * damages, however caused and regardless of the theory of liability,
37 > * arising out of the use of or inability to use software, even if the
38 > * University of Notre Dame has been advised of the possibility of
39 > * such damages.
40 > */
41 >
42 > /**
43 > * @file SimInfo.cpp
44 > * @author    tlin
45 > * @date  11/02/2004
46 > * @version 1.0
47 > */
48  
49 < #include <iostream>
50 < using namespace std;
49 > #include <algorithm>
50 > #include <set>
51  
52   #include "brains/SimInfo.hpp"
53 < #define __C
54 < #include "brains/fSimulation.h"
55 < #include "utils/simError.h"
12 < #include "UseTheForce/DarkSide/simulation_interface.h"
53 > #include "math/Vector3.hpp"
54 > #include "primitives/Molecule.hpp"
55 > #include "UseTheForce/doForces_interface.h"
56   #include "UseTheForce/notifyCutoffs_interface.h"
57 + #include "utils/MemoryUtils.hpp"
58 + #include "utils/simError.h"
59 + #include "selection/SelectionManager.hpp"
60  
61 < //#include "UseTheForce/fortranWrappers.hpp"
61 > #ifdef IS_MPI
62 > #include "UseTheForce/mpiComponentPlan.h"
63 > #include "UseTheForce/DarkSide/simParallel_interface.h"
64 > #endif
65  
66 < #include "math/MatVec3.h"
66 > namespace oopse {
67  
68 < #ifdef IS_MPI
69 < #include "brains/mpiSimulation.hpp"
70 < #endif
68 > SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
69 >                                ForceField* ff, Globals* simParams) :
70 >                                forceField_(ff), simParams_(simParams),
71 >                                ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
72 >                                nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
73 >                                nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
74 >                                nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nRigidBodies_(0),
75 >                                nIntegrableObjects_(0),  nCutoffGroups_(0), nConstraints_(0),
76 >                                sman_(NULL), fortranInitialized_(false), selectMan_(NULL) {
77  
78 < inline double roundMe( double x ){
79 <  return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 );
80 < }
81 <          
82 < inline double min( double a, double b ){
83 <  return (a < b ) ? a : b;
84 < }
78 >            
79 >    std::vector<std::pair<MoleculeStamp*, int> >::iterator i;
80 >    MoleculeStamp* molStamp;
81 >    int nMolWithSameStamp;
82 >    int nCutoffAtoms = 0; // number of atoms belong to cutoff groups
83 >    int nGroups = 0;          //total cutoff groups defined in meta-data file
84 >    CutoffGroupStamp* cgStamp;    
85 >    RigidBodyStamp* rbStamp;
86 >    int nRigidAtoms = 0;
87 >    
88 >    for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) {
89 >        molStamp = i->first;
90 >        nMolWithSameStamp = i->second;
91 >        
92 >        addMoleculeStamp(molStamp, nMolWithSameStamp);
93  
94 < SimInfo* currentInfo;
94 >        //calculate atoms in molecules
95 >        nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;  
96  
33 SimInfo::SimInfo(){
97  
98 <  n_constraints = 0;
99 <  nZconstraints = 0;
100 <  n_oriented = 0;
101 <  n_dipoles = 0;
102 <  ndf = 0;
103 <  ndfRaw = 0;
104 <  nZconstraints = 0;
105 <  the_integrator = NULL;
43 <  setTemp = 0;
44 <  thermalTime = 0.0;
45 <  currentTime = 0.0;
46 <  rCut = 0.0;
47 <  rSw = 0.0;
98 >        //calculate atoms in cutoff groups
99 >        int nAtomsInGroups = 0;
100 >        int nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
101 >        
102 >        for (int j=0; j < nCutoffGroupsInStamp; j++) {
103 >            cgStamp = molStamp->getCutoffGroup(j);
104 >            nAtomsInGroups += cgStamp->getNMembers();
105 >        }
106  
107 <  haveRcut = 0;
108 <  haveRsw = 0;
51 <  boxIsInit = 0;
52 <  
53 <  resetTime = 1e99;
107 >        nGroups += nCutoffGroupsInStamp * nMolWithSameStamp;
108 >        nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp;            
109  
110 <  orthoRhombic = 0;
111 <  orthoTolerance = 1E-6;
112 <  useInitXSstate = true;
110 >        //calculate atoms in rigid bodies
111 >        int nAtomsInRigidBodies = 0;
112 >        int nRigidBodiesInStamp = molStamp->getNRigidBodies();
113 >        
114 >        for (int j=0; j < nRigidBodiesInStamp; j++) {
115 >            rbStamp = molStamp->getRigidBody(j);
116 >            nAtomsInRigidBodies += rbStamp->getNMembers();
117 >        }
118  
119 <  usePBC = 0;
120 <  useLJ = 0;
121 <  useSticky = 0;
122 <  useCharges = 0;
63 <  useDipoles = 0;
64 <  useReactionField = 0;
65 <  useGB = 0;
66 <  useEAM = 0;
67 <  useSolidThermInt = 0;
68 <  useLiquidThermInt = 0;
119 >        nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp;
120 >        nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp;            
121 >        
122 >    }
123  
124 <  haveCutoffGroups = false;
124 >    //every free atom (atom does not belong to cutoff groups) is a cutoff group
125 >    //therefore the total number of cutoff groups in the system is equal to
126 >    //the total number of atoms minus number of atoms belong to cutoff group defined in meta-data
127 >    //file plus the number of cutoff groups defined in meta-data file
128 >    nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
129  
130 <  excludes = Exclude::Instance();
130 >    //every free atom (atom does not belong to rigid bodies) is an integrable object
131 >    //therefore the total number of  integrable objects in the system is equal to
132 >    //the total number of atoms minus number of atoms belong to  rigid body defined in meta-data
133 >    //file plus the number of  rigid bodies defined in meta-data file
134 >    nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nGlobalRigidBodies_;
135  
136 <  myConfiguration = new SimState();
136 >    nGlobalMols_ = molStampIds_.size();
137  
138 <  has_minimizer = false;
139 <  the_minimizer =NULL;
138 > #ifdef IS_MPI    
139 >    molToProcMap_.resize(nGlobalMols_);
140 > #endif
141  
142 <  ngroup = 0;
142 >    selectMan_ = new SelectionManager(this);
143 >    selectMan_->selectAll();
144 > }
145  
146 + SimInfo::~SimInfo() {
147 +    std::map<int, Molecule*>::iterator i;
148 +    for (i = molecules_.begin(); i != molecules_.end(); ++i) {
149 +        delete i->second;
150 +    }
151 +    molecules_.clear();
152 +    
153 +    MemoryUtils::deletePointers(moleculeStamps_);
154 +    
155 +    delete sman_;
156 +    delete simParams_;
157 +    delete forceField_;
158 +    delete selectMan_;
159   }
160  
161 + int SimInfo::getNGlobalConstraints() {
162 +    int nGlobalConstraints;
163 + #ifdef IS_MPI
164 +    MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM,
165 +                  MPI_COMM_WORLD);    
166 + #else
167 +    nGlobalConstraints =  nConstraints_;
168 + #endif
169 +    return nGlobalConstraints;
170 + }
171  
172 < SimInfo::~SimInfo(){
172 > bool SimInfo::addMolecule(Molecule* mol) {
173 >    MoleculeIterator i;
174  
175 <  delete myConfiguration;
175 >    i = molecules_.find(mol->getGlobalIndex());
176 >    if (i == molecules_.end() ) {
177  
178 <  map<string, GenericData*>::iterator i;
179 <  
180 <  for(i = properties.begin(); i != properties.end(); i++)
181 <    delete (*i).second;
178 >        molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol));
179 >        
180 >        nAtoms_ += mol->getNAtoms();
181 >        nBonds_ += mol->getNBonds();
182 >        nBends_ += mol->getNBends();
183 >        nTorsions_ += mol->getNTorsions();
184 >        nRigidBodies_ += mol->getNRigidBodies();
185 >        nIntegrableObjects_ += mol->getNIntegrableObjects();
186 >        nCutoffGroups_ += mol->getNCutoffGroups();
187 >        nConstraints_ += mol->getNConstraintPairs();
188  
189 +        addExcludePairs(mol);
190 +        
191 +        return true;
192 +    } else {
193 +        return false;
194 +    }
195   }
196  
197 < void SimInfo::setBox(double newBox[3]) {
198 <  
199 <  int i, j;
98 <  double tempMat[3][3];
197 > bool SimInfo::removeMolecule(Molecule* mol) {
198 >    MoleculeIterator i;
199 >    i = molecules_.find(mol->getGlobalIndex());
200  
201 <  for(i=0; i<3; i++)
101 <    for (j=0; j<3; j++) tempMat[i][j] = 0.0;;
201 >    if (i != molecules_.end() ) {
202  
203 <  tempMat[0][0] = newBox[0];
204 <  tempMat[1][1] = newBox[1];
205 <  tempMat[2][2] = newBox[2];
203 >        assert(mol == i->second);
204 >        
205 >        nAtoms_ -= mol->getNAtoms();
206 >        nBonds_ -= mol->getNBonds();
207 >        nBends_ -= mol->getNBends();
208 >        nTorsions_ -= mol->getNTorsions();
209 >        nRigidBodies_ -= mol->getNRigidBodies();
210 >        nIntegrableObjects_ -= mol->getNIntegrableObjects();
211 >        nCutoffGroups_ -= mol->getNCutoffGroups();
212 >        nConstraints_ -= mol->getNConstraintPairs();
213  
214 <  setBoxM( tempMat );
214 >        removeExcludePairs(mol);
215 >        molecules_.erase(mol->getGlobalIndex());
216  
217 < }
217 >        delete mol;
218 >        
219 >        return true;
220 >    } else {
221 >        return false;
222 >    }
223  
111 void SimInfo::setBoxM( double theBox[3][3] ){
112  
113  int i, j;
114  double FortranHmat[9]; // to preserve compatibility with Fortran the
115                         // ordering in the array is as follows:
116                         // [ 0 3 6 ]
117                         // [ 1 4 7 ]
118                         // [ 2 5 8 ]
119  double FortranHmatInv[9]; // the inverted Hmat (for Fortran);
224  
225 <  if( !boxIsInit ) boxIsInit = 1;
225 > }    
226  
227 <  for(i=0; i < 3; i++)
228 <    for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j];
229 <  
230 <  calcBoxL();
231 <  calcHmatInv();
227 >        
228 > Molecule* SimInfo::beginMolecule(MoleculeIterator& i) {
229 >    i = molecules_.begin();
230 >    return i == molecules_.end() ? NULL : i->second;
231 > }    
232  
233 <  for(i=0; i < 3; i++) {
234 <    for (j=0; j < 3; j++) {
235 <      FortranHmat[3*j + i] = Hmat[i][j];
132 <      FortranHmatInv[3*j + i] = HmatInv[i][j];
133 <    }
134 <  }
135 <
136 <  setFortranBox(FortranHmat, FortranHmatInv, &orthoRhombic);
137 <
233 > Molecule* SimInfo::nextMolecule(MoleculeIterator& i) {
234 >    ++i;
235 >    return i == molecules_.end() ? NULL : i->second;    
236   }
139
237  
141 void SimInfo::getBoxM (double theBox[3][3]) {
238  
239 <  int i, j;
240 <  for(i=0; i<3; i++)
241 <    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j];
242 < }
239 > void SimInfo::calcNdf() {
240 >    int ndf_local;
241 >    MoleculeIterator i;
242 >    std::vector<StuntDouble*>::iterator j;
243 >    Molecule* mol;
244 >    StuntDouble* integrableObject;
245  
246 +    ndf_local = 0;
247 +    
248 +    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
249 +        for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
250 +               integrableObject = mol->nextIntegrableObject(j)) {
251  
252 < void SimInfo::scaleBox(double scale) {
150 <  double theBox[3][3];
151 <  int i, j;
252 >            ndf_local += 3;
253  
254 <  // cerr << "Scaling box by " << scale << "\n";
254 >            if (integrableObject->isDirectional()) {
255 >                if (integrableObject->isLinear()) {
256 >                    ndf_local += 2;
257 >                } else {
258 >                    ndf_local += 3;
259 >                }
260 >            }
261 >            
262 >        }//end for (integrableObject)
263 >    }// end for (mol)
264 >    
265 >    // n_constraints is local, so subtract them on each processor
266 >    ndf_local -= nConstraints_;
267  
268 <  for(i=0; i<3; i++)
269 <    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale;
268 > #ifdef IS_MPI
269 >    MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
270 > #else
271 >    ndf_ = ndf_local;
272 > #endif
273  
274 <  setBoxM(theBox);
274 >    // nZconstraints_ is global, as are the 3 COM translations for the
275 >    // entire system:
276 >    ndf_ = ndf_ - 3 - nZconstraint_;
277  
278   }
279  
280 < void SimInfo::calcHmatInv( void ) {
281 <  
164 <  int oldOrtho;
165 <  int i,j;
166 <  double smallDiag;
167 <  double tol;
168 <  double sanity[3][3];
280 > void SimInfo::calcNdfRaw() {
281 >    int ndfRaw_local;
282  
283 <  invertMat3( Hmat, HmatInv );
283 >    MoleculeIterator i;
284 >    std::vector<StuntDouble*>::iterator j;
285 >    Molecule* mol;
286 >    StuntDouble* integrableObject;
287  
288 <  // check to see if Hmat is orthorhombic
289 <  
290 <  oldOrtho = orthoRhombic;
288 >    // Raw degrees of freedom that we have to set
289 >    ndfRaw_local = 0;
290 >    
291 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
292 >        for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
293 >               integrableObject = mol->nextIntegrableObject(j)) {
294  
295 <  smallDiag = fabs(Hmat[0][0]);
177 <  if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]);
178 <  if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]);
179 <  tol = smallDiag * orthoTolerance;
295 >            ndfRaw_local += 3;
296  
297 <  orthoRhombic = 1;
298 <  
299 <  for (i = 0; i < 3; i++ ) {
300 <    for (j = 0 ; j < 3; j++) {
301 <      if (i != j) {
302 <        if (orthoRhombic) {
303 <          if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0;
304 <        }        
305 <      }
297 >            if (integrableObject->isDirectional()) {
298 >                if (integrableObject->isLinear()) {
299 >                    ndfRaw_local += 2;
300 >                } else {
301 >                    ndfRaw_local += 3;
302 >                }
303 >            }
304 >            
305 >        }
306      }
191  }
192
193  if( oldOrtho != orthoRhombic ){
307      
308 <    if( orthoRhombic ) {
309 <      sprintf( painCave.errMsg,
310 <               "OOPSE is switching from the default Non-Orthorhombic\n"
311 <               "\tto the faster Orthorhombic periodic boundary computations.\n"
312 <               "\tThis is usually a good thing, but if you wan't the\n"
200 <               "\tNon-Orthorhombic computations, make the orthoBoxTolerance\n"
201 <               "\tvariable ( currently set to %G ) smaller.\n",
202 <               orthoTolerance);
203 <      painCave.severity = OOPSE_INFO;
204 <      simError();
205 <    }
206 <    else {
207 <      sprintf( painCave.errMsg,
208 <               "OOPSE is switching from the faster Orthorhombic to the more\n"
209 <               "\tflexible Non-Orthorhombic periodic boundary computations.\n"
210 <               "\tThis is usually because the box has deformed under\n"
211 <               "\tNPTf integration. If you wan't to live on the edge with\n"
212 <               "\tthe Orthorhombic computations, make the orthoBoxTolerance\n"
213 <               "\tvariable ( currently set to %G ) larger.\n",
214 <               orthoTolerance);
215 <      painCave.severity = OOPSE_WARNING;
216 <      simError();
217 <    }
218 <  }
308 > #ifdef IS_MPI
309 >    MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
310 > #else
311 >    ndfRaw_ = ndfRaw_local;
312 > #endif
313   }
314  
315 < void SimInfo::calcBoxL( void ){
315 > void SimInfo::calcNdfTrans() {
316 >    int ndfTrans_local;
317  
318 <  double dx, dy, dz, dsq;
318 >    ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
319  
225  // boxVol = Determinant of Hmat
320  
321 <  boxVol = matDet3( Hmat );
321 > #ifdef IS_MPI
322 >    MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
323 > #else
324 >    ndfTrans_ = ndfTrans_local;
325 > #endif
326  
327 <  // boxLx
328 <  
329 <  dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0];
232 <  dsq = dx*dx + dy*dy + dz*dz;
233 <  boxL[0] = sqrt( dsq );
234 <  //maxCutoff = 0.5 * boxL[0];
327 >    ndfTrans_ = ndfTrans_ - 3 - nZconstraint_;
328 >
329 > }
330  
331 <  // boxLy
332 <  
333 <  dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1];
334 <  dsq = dx*dx + dy*dy + dz*dz;
335 <  boxL[1] = sqrt( dsq );
336 <  //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
331 > void SimInfo::addExcludePairs(Molecule* mol) {
332 >    std::vector<Bond*>::iterator bondIter;
333 >    std::vector<Bend*>::iterator bendIter;
334 >    std::vector<Torsion*>::iterator torsionIter;
335 >    Bond* bond;
336 >    Bend* bend;
337 >    Torsion* torsion;
338 >    int a;
339 >    int b;
340 >    int c;
341 >    int d;
342 >    
343 >    for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
344 >        a = bond->getAtomA()->getGlobalIndex();
345 >        b = bond->getAtomB()->getGlobalIndex();        
346 >        exclude_.addPair(a, b);
347 >    }
348  
349 +    for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
350 +        a = bend->getAtomA()->getGlobalIndex();
351 +        b = bend->getAtomB()->getGlobalIndex();        
352 +        c = bend->getAtomC()->getGlobalIndex();
353  
354 <  // boxLz
355 <  
356 <  dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2];
357 <  dsq = dx*dx + dy*dy + dz*dz;
248 <  boxL[2] = sqrt( dsq );
249 <  //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2];
354 >        exclude_.addPair(a, b);
355 >        exclude_.addPair(a, c);
356 >        exclude_.addPair(b, c);        
357 >    }
358  
359 <  //calculate the max cutoff
360 <  maxCutoff =  calcMaxCutOff();
361 <  
362 <  checkCutOffs();
359 >    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
360 >        a = torsion->getAtomA()->getGlobalIndex();
361 >        b = torsion->getAtomB()->getGlobalIndex();        
362 >        c = torsion->getAtomC()->getGlobalIndex();        
363 >        d = torsion->getAtomD()->getGlobalIndex();        
364  
365 +        exclude_.addPair(a, b);
366 +        exclude_.addPair(a, c);
367 +        exclude_.addPair(a, d);
368 +        exclude_.addPair(b, c);
369 +        exclude_.addPair(b, d);
370 +        exclude_.addPair(c, d);        
371 +    }
372 +
373 +    
374   }
375  
376 + void SimInfo::removeExcludePairs(Molecule* mol) {
377 +    std::vector<Bond*>::iterator bondIter;
378 +    std::vector<Bend*>::iterator bendIter;
379 +    std::vector<Torsion*>::iterator torsionIter;
380 +    Bond* bond;
381 +    Bend* bend;
382 +    Torsion* torsion;
383 +    int a;
384 +    int b;
385 +    int c;
386 +    int d;
387 +    
388 +    for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
389 +        a = bond->getAtomA()->getGlobalIndex();
390 +        b = bond->getAtomB()->getGlobalIndex();        
391 +        exclude_.removePair(a, b);
392 +    }
393  
394 < double SimInfo::calcMaxCutOff(){
394 >    for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
395 >        a = bend->getAtomA()->getGlobalIndex();
396 >        b = bend->getAtomB()->getGlobalIndex();        
397 >        c = bend->getAtomC()->getGlobalIndex();
398  
399 <  double ri[3], rj[3], rk[3];
400 <  double rij[3], rjk[3], rki[3];
401 <  double minDist;
399 >        exclude_.removePair(a, b);
400 >        exclude_.removePair(a, c);
401 >        exclude_.removePair(b, c);        
402 >    }
403  
404 <  ri[0] = Hmat[0][0];
405 <  ri[1] = Hmat[1][0];
406 <  ri[2] = Hmat[2][0];
404 >    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
405 >        a = torsion->getAtomA()->getGlobalIndex();
406 >        b = torsion->getAtomB()->getGlobalIndex();        
407 >        c = torsion->getAtomC()->getGlobalIndex();        
408 >        d = torsion->getAtomD()->getGlobalIndex();        
409  
410 <  rj[0] = Hmat[0][1];
411 <  rj[1] = Hmat[1][1];
412 <  rj[2] = Hmat[2][1];
410 >        exclude_.removePair(a, b);
411 >        exclude_.removePair(a, c);
412 >        exclude_.removePair(a, d);
413 >        exclude_.removePair(b, c);
414 >        exclude_.removePair(b, d);
415 >        exclude_.removePair(c, d);        
416 >    }
417  
418 <  rk[0] = Hmat[0][2];
274 <  rk[1] = Hmat[1][2];
275 <  rk[2] = Hmat[2][2];
276 <    
277 <  crossProduct3(ri, rj, rij);
278 <  distXY = dotProduct3(rk,rij) / norm3(rij);
418 > }
419  
280  crossProduct3(rj,rk, rjk);
281  distYZ = dotProduct3(ri,rjk) / norm3(rjk);
420  
421 <  crossProduct3(rk,ri, rki);
422 <  distZX = dotProduct3(rj,rki) / norm3(rki);
421 > void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) {
422 >    int curStampId;
423  
424 <  minDist = min(min(distXY, distYZ), distZX);
425 <  return minDist/2;
426 <  
424 >    //index from 0
425 >    curStampId = moleculeStamps_.size();
426 >
427 >    moleculeStamps_.push_back(molStamp);
428 >    molStampIds_.insert(molStampIds_.end(), nmol, curStampId);
429   }
430  
431 < void SimInfo::wrapVector( double thePos[3] ){
431 > void SimInfo::update() {
432  
433 <  int i;
294 <  double scaled[3];
433 >    setupSimType();
434  
435 <  if( !orthoRhombic ){
436 <    // calc the scaled coordinates.
437 <  
435 > #ifdef IS_MPI
436 >    setupFortranParallel();
437 > #endif
438  
439 <    matVecMul3(HmatInv, thePos, scaled);
301 <    
302 <    for(i=0; i<3; i++)
303 <      scaled[i] -= roundMe(scaled[i]);
304 <    
305 <    // calc the wrapped real coordinates from the wrapped scaled coordinates
306 <    
307 <    matVecMul3(Hmat, scaled, thePos);
439 >    setupFortranSim();
440  
441 <  }
442 <  else{
443 <    // calc the scaled coordinates.
441 >    //setup fortran force field
442 >    /** @deprecate */    
443 >    int isError = 0;
444 >    initFortranFF( &fInfo_.SIM_uses_RF , &isError );
445 >    if(isError){
446 >        sprintf( painCave.errMsg,
447 >         "ForceField error: There was an error initializing the forceField in fortran.\n" );
448 >        painCave.isFatal = 1;
449 >        simError();
450 >    }
451 >  
452      
453 <    for(i=0; i<3; i++)
454 <      scaled[i] = thePos[i]*HmatInv[i][i];
455 <    
456 <    // wrap the scaled coordinates
457 <    
458 <    for(i=0; i<3; i++)
459 <      scaled[i] -= roundMe(scaled[i]);
320 <    
321 <    // calc the wrapped real coordinates from the wrapped scaled coordinates
322 <    
323 <    for(i=0; i<3; i++)
324 <      thePos[i] = scaled[i]*Hmat[i][i];
325 <  }
326 <    
453 >    setupCutoff();
454 >
455 >    calcNdf();
456 >    calcNdfRaw();
457 >    calcNdfTrans();
458 >
459 >    fortranInitialized_ = true;
460   }
461  
462 + std::set<AtomType*> SimInfo::getUniqueAtomTypes() {
463 +    SimInfo::MoleculeIterator mi;
464 +    Molecule* mol;
465 +    Molecule::AtomIterator ai;
466 +    Atom* atom;
467 +    std::set<AtomType*> atomTypes;
468  
469 < int SimInfo::getNDF(){
331 <  int ndf_local;
469 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
470  
471 <  ndf_local = 0;
472 <  
473 <  for(int i = 0; i < integrableObjects.size(); i++){
474 <    ndf_local += 3;
337 <    if (integrableObjects[i]->isDirectional()) {
338 <      if (integrableObjects[i]->isLinear())
339 <        ndf_local += 2;
340 <      else
341 <        ndf_local += 3;
471 >        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
472 >            atomTypes.insert(atom->getAtomType());
473 >        }
474 >        
475      }
343  }
476  
477 <  // n_constraints is local, so subtract them on each processor:
477 >    return atomTypes;        
478 > }
479  
480 <  ndf_local -= n_constraints;
480 > void SimInfo::setupSimType() {
481 >    std::set<AtomType*>::iterator i;
482 >    std::set<AtomType*> atomTypes;
483 >    atomTypes = getUniqueAtomTypes();
484 >    
485 >    int useLennardJones = 0;
486 >    int useElectrostatic = 0;
487 >    int useEAM = 0;
488 >    int useCharge = 0;
489 >    int useDirectional = 0;
490 >    int useDipole = 0;
491 >    int useGayBerne = 0;
492 >    int useSticky = 0;
493 >    int useShape = 0;
494 >    int useFLARB = 0; //it is not in AtomType yet
495 >    int useDirectionalAtom = 0;    
496 >    int useElectrostatics = 0;
497 >    //usePBC and useRF are from simParams
498 >    int usePBC = simParams_->getPBC();
499 >    int useRF = simParams_->getUseRF();
500  
501 < #ifdef IS_MPI
502 <  MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
503 < #else
504 <  ndf = ndf_local;
501 >    //loop over all of the atom types
502 >    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
503 >        useLennardJones |= (*i)->isLennardJones();
504 >        useElectrostatic |= (*i)->isElectrostatic();
505 >        useEAM |= (*i)->isEAM();
506 >        useCharge |= (*i)->isCharge();
507 >        useDirectional |= (*i)->isDirectional();
508 >        useDipole |= (*i)->isDipole();
509 >        useGayBerne |= (*i)->isGayBerne();
510 >        useSticky |= (*i)->isSticky();
511 >        useShape |= (*i)->isShape();
512 >    }
513 >
514 >    if (useSticky || useDipole || useGayBerne || useShape) {
515 >        useDirectionalAtom = 1;
516 >    }
517 >
518 >    if (useCharge || useDipole) {
519 >        useElectrostatics = 1;
520 >    }
521 >
522 > #ifdef IS_MPI    
523 >    int temp;
524 >
525 >    temp = usePBC;
526 >    MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
527 >
528 >    temp = useDirectionalAtom;
529 >    MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
530 >
531 >    temp = useLennardJones;
532 >    MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
533 >
534 >    temp = useElectrostatics;
535 >    MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
536 >
537 >    temp = useCharge;
538 >    MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
539 >
540 >    temp = useDipole;
541 >    MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
542 >
543 >    temp = useSticky;
544 >    MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
545 >
546 >    temp = useGayBerne;
547 >    MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
548 >
549 >    temp = useEAM;
550 >    MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
551 >
552 >    temp = useShape;
553 >    MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);  
554 >
555 >    temp = useFLARB;
556 >    MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
557 >
558 >    temp = useRF;
559 >    MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
560 >    
561   #endif
562  
563 <  // nZconstraints is global, as are the 3 COM translations for the
564 <  // entire system:
563 >    fInfo_.SIM_uses_PBC = usePBC;    
564 >    fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom;
565 >    fInfo_.SIM_uses_LennardJones = useLennardJones;
566 >    fInfo_.SIM_uses_Electrostatics = useElectrostatics;    
567 >    fInfo_.SIM_uses_Charges = useCharge;
568 >    fInfo_.SIM_uses_Dipoles = useDipole;
569 >    fInfo_.SIM_uses_Sticky = useSticky;
570 >    fInfo_.SIM_uses_GayBerne = useGayBerne;
571 >    fInfo_.SIM_uses_EAM = useEAM;
572 >    fInfo_.SIM_uses_Shapes = useShape;
573 >    fInfo_.SIM_uses_FLARB = useFLARB;
574 >    fInfo_.SIM_uses_RF = useRF;
575  
576 <  ndf = ndf - 3 - nZconstraints;
576 >    if( fInfo_.SIM_uses_Dipoles && fInfo_.SIM_uses_RF) {
577  
578 <  return ndf;
578 >        if (simParams_->haveDielectric()) {
579 >            fInfo_.dielect = simParams_->getDielectric();
580 >        } else {
581 >            sprintf(painCave.errMsg,
582 >                    "SimSetup Error: No Dielectric constant was set.\n"
583 >                    "\tYou are trying to use Reaction Field without"
584 >                    "\tsetting a dielectric constant!\n");
585 >            painCave.isFatal = 1;
586 >            simError();
587 >        }
588 >        
589 >    } else {
590 >        fInfo_.dielect = 0.0;
591 >    }
592 >
593   }
594  
595 < int SimInfo::getNDFraw() {
596 <  int ndfRaw_local;
595 > void SimInfo::setupFortranSim() {
596 >    int isError;
597 >    int nExclude;
598 >    std::vector<int> fortranGlobalGroupMembership;
599 >    
600 >    nExclude = exclude_.getSize();
601 >    isError = 0;
602  
603 <  // Raw degrees of freedom that we have to set
604 <  ndfRaw_local = 0;
603 >    //globalGroupMembership_ is filled by SimCreator    
604 >    for (int i = 0; i < nGlobalAtoms_; i++) {
605 >        fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
606 >    }
607  
608 <  for(int i = 0; i < integrableObjects.size(); i++){
609 <    ndfRaw_local += 3;
610 <    if (integrableObjects[i]->isDirectional()) {
611 <       if (integrableObjects[i]->isLinear())
612 <        ndfRaw_local += 2;
613 <      else
614 <        ndfRaw_local += 3;
608 >    //calculate mass ratio of cutoff group
609 >    std::vector<double> mfact;
610 >    SimInfo::MoleculeIterator mi;
611 >    Molecule* mol;
612 >    Molecule::CutoffGroupIterator ci;
613 >    CutoffGroup* cg;
614 >    Molecule::AtomIterator ai;
615 >    Atom* atom;
616 >    double totalMass;
617 >
618 >    //to avoid memory reallocation, reserve enough space for mfact
619 >    mfact.reserve(getNCutoffGroups());
620 >    
621 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
622 >        for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
623 >
624 >            totalMass = cg->getMass();
625 >            for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
626 >                        mfact.push_back(atom->getMass()/totalMass);
627 >            }
628 >
629 >        }      
630      }
631 <  }
631 >
632 >    //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!)
633 >    std::vector<int> identArray;
634 >
635 >    //to avoid memory reallocation, reserve enough space identArray
636 >    identArray.reserve(getNAtoms());
637      
638 < #ifdef IS_MPI
639 <  MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
640 < #else
641 <  ndfRaw = ndfRaw_local;
642 < #endif
638 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
639 >        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
640 >            identArray.push_back(atom->getIdent());
641 >        }
642 >    }    
643  
644 <  return ndfRaw;
645 < }
644 >    //fill molMembershipArray
645 >    //molMembershipArray is filled by SimCreator    
646 >    std::vector<int> molMembershipArray(nGlobalAtoms_);
647 >    for (int i = 0; i < nGlobalAtoms_; i++) {
648 >        molMembershipArray[i] = globalMolMembership_[i] + 1;
649 >    }
650 >    
651 >    //setup fortran simulation
652 >    //gloalExcludes and molMembershipArray should go away (They are never used)
653 >    //why the hell fortran need to know molecule?
654 >    //OOPSE = Object-Obfuscated Parallel Simulation Engine
655 >    int nGlobalExcludes = 0;
656 >    int* globalExcludes = NULL;
657 >    int* excludeList = exclude_.getExcludeList();
658 >    setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList ,
659 >                  &nGlobalExcludes, globalExcludes, &molMembershipArray[0],
660 >                  &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError);
661  
662 < int SimInfo::getNDFtranslational() {
389 <  int ndfTrans_local;
662 >    if( isError ){
663  
664 <  ndfTrans_local = 3 * integrableObjects.size() - n_constraints;
664 >        sprintf( painCave.errMsg,
665 >                 "There was an error setting the simulation information in fortran.\n" );
666 >        painCave.isFatal = 1;
667 >        painCave.severity = OOPSE_ERROR;
668 >        simError();
669 >    }
670  
671 + #ifdef IS_MPI
672 +    sprintf( checkPointMsg,
673 +       "succesfully sent the simulation information to fortran.\n");
674 +    MPIcheckPoint();
675 + #endif // is_mpi
676 + }
677  
678 +
679   #ifdef IS_MPI
680 <  MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
681 < #else
682 <  ndfTrans = ndfTrans_local;
683 < #endif
680 > void SimInfo::setupFortranParallel() {
681 >    
682 >    //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex
683 >    std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0);
684 >    std::vector<int> localToGlobalCutoffGroupIndex;
685 >    SimInfo::MoleculeIterator mi;
686 >    Molecule::AtomIterator ai;
687 >    Molecule::CutoffGroupIterator ci;
688 >    Molecule* mol;
689 >    Atom* atom;
690 >    CutoffGroup* cg;
691 >    mpiSimData parallelData;
692 >    int isError;
693  
694 <  ndfTrans = ndfTrans - 3 - nZconstraints;
694 >    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
695  
696 <  return ndfTrans;
697 < }
696 >        //local index(index in DataStorge) of atom is important
697 >        for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
698 >            localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1;
699 >        }
700  
701 < int SimInfo::getTotIntegrableObjects() {
702 <  int nObjs_local;
703 <  int nObjs;
701 >        //local index of cutoff group is trivial, it only depends on the order of travesing
702 >        for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
703 >            localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1);
704 >        }        
705 >        
706 >    }
707  
708 <  nObjs_local =  integrableObjects.size();
708 >    //fill up mpiSimData struct
709 >    parallelData.nMolGlobal = getNGlobalMolecules();
710 >    parallelData.nMolLocal = getNMolecules();
711 >    parallelData.nAtomsGlobal = getNGlobalAtoms();
712 >    parallelData.nAtomsLocal = getNAtoms();
713 >    parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
714 >    parallelData.nGroupsLocal = getNCutoffGroups();
715 >    parallelData.myNode = worldRank;
716 >    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
717  
718 +    //pass mpiSimData struct and index arrays to fortran
719 +    setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
720 +                    &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal),
721 +                    &localToGlobalCutoffGroupIndex[0], &isError);
722  
723 < #ifdef IS_MPI
724 <  MPI_Allreduce(&nObjs_local,&nObjs,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
725 < #else
726 <  nObjs = nObjs_local;
727 < #endif
723 >    if (isError) {
724 >        sprintf(painCave.errMsg,
725 >                "mpiRefresh errror: fortran didn't like something we gave it.\n");
726 >        painCave.isFatal = 1;
727 >        simError();
728 >    }
729  
730 +    sprintf(checkPointMsg, " mpiRefresh successful.\n");
731 +    MPIcheckPoint();
732  
733 <  return nObjs;
733 >
734   }
735  
736 < void SimInfo::refreshSim(){
736 > #endif
737  
738 <  simtype fInfo;
425 <  int isError;
426 <  int n_global;
427 <  int* excl;
738 > double SimInfo::calcMaxCutoffRadius() {
739  
429  fInfo.dielect = 0.0;
740  
741 <  if( useDipoles ){
742 <    if( useReactionField )fInfo.dielect = dielectric;
743 <  }
741 >    std::set<AtomType*> atomTypes;
742 >    std::set<AtomType*>::iterator i;
743 >    std::vector<double> cutoffRadius;
744  
745 <  fInfo.SIM_uses_PBC = usePBC;
746 <  //fInfo.SIM_uses_LJ = 0;
437 <  fInfo.SIM_uses_LJ = useLJ;
438 <  fInfo.SIM_uses_sticky = useSticky;
439 <  //fInfo.SIM_uses_sticky = 0;
440 <  fInfo.SIM_uses_charges = useCharges;
441 <  fInfo.SIM_uses_dipoles = useDipoles;
442 <  //fInfo.SIM_uses_dipoles = 0;
443 <  fInfo.SIM_uses_RF = useReactionField;
444 <  //fInfo.SIM_uses_RF = 0;
445 <  fInfo.SIM_uses_GB = useGB;
446 <  fInfo.SIM_uses_EAM = useEAM;
745 >    //get the unique atom types
746 >    atomTypes = getUniqueAtomTypes();
747  
748 <  n_exclude = excludes->getSize();
749 <  excl = excludes->getFortranArray();
750 <  
748 >    //query the max cutoff radius among these atom types
749 >    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
750 >        cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i));
751 >    }
752 >
753 >    double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end()));
754   #ifdef IS_MPI
755 <  n_global = mpiSim->getNAtomsGlobal();
453 < #else
454 <  n_global = n_atoms;
755 >    //pick the max cutoff radius among the processors
756   #endif
456  
457  isError = 0;
458  
459  getFortranGroupArrays(this, FglobalGroupMembership, mfact);
460  //it may not be a good idea to pass the address of first element in vector
461  //since c++ standard does not require vector to be stored continuously in meomory
462  //Most of the compilers will organize the memory of vector continuously
463  setFortranSim( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl,
464                  &nGlobalExcludes, globalExcludes, molMembershipArray,
465                  &mfact[0], &ngroup, &FglobalGroupMembership[0], &isError);
757  
758 <  if( isError ){
468 <    
469 <    sprintf( painCave.errMsg,
470 <             "There was an error setting the simulation information in fortran.\n" );
471 <    painCave.isFatal = 1;
472 <    painCave.severity = OOPSE_ERROR;
473 <    simError();
474 <  }
475 <  
476 < #ifdef IS_MPI
477 <  sprintf( checkPointMsg,
478 <           "succesfully sent the simulation information to fortran.\n");
479 <  MPIcheckPoint();
480 < #endif // is_mpi
481 <  
482 <  this->ndf = this->getNDF();
483 <  this->ndfRaw = this->getNDFraw();
484 <  this->ndfTrans = this->getNDFtranslational();
758 >    return maxCutoffRadius;
759   }
760  
761 < void SimInfo::setDefaultRcut( double theRcut ){
762 <  
763 <  haveRcut = 1;
764 <  rCut = theRcut;
765 <  rList = rCut + 1.0;
766 <  
767 <  notifyFortranCutoffs( &rCut, &rSw, &rList );
761 > void SimInfo::getCutoff(double& rcut, double& rsw) {
762 >    
763 >    if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
764 >        
765 >        if (!simParams_->haveRcut()){
766 >            sprintf(painCave.errMsg,
767 >                "SimCreator Warning: No value was set for the cutoffRadius.\n"
768 >                "\tOOPSE will use a default value of 15.0 angstroms"
769 >                "\tfor the cutoffRadius.\n");
770 >            painCave.isFatal = 0;
771 >            simError();
772 >            rcut = 15.0;
773 >        } else{
774 >            rcut = simParams_->getRcut();
775 >        }
776 >
777 >        if (!simParams_->haveRsw()){
778 >            sprintf(painCave.errMsg,
779 >                "SimCreator Warning: No value was set for switchingRadius.\n"
780 >                "\tOOPSE will use a default value of\n"
781 >                "\t0.95 * cutoffRadius for the switchingRadius\n");
782 >            painCave.isFatal = 0;
783 >            simError();
784 >            rsw = 0.95 * rcut;
785 >        } else{
786 >            rsw = simParams_->getRsw();
787 >        }
788 >
789 >    } else {
790 >        // if charge, dipole or reaction field is not used and the cutofff radius is not specified in
791 >        //meta-data file, the maximum cutoff radius calculated from forcefiled will be used
792 >        
793 >        if (simParams_->haveRcut()) {
794 >            rcut = simParams_->getRcut();
795 >        } else {
796 >            //set cutoff radius to the maximum cutoff radius based on atom types in the whole system
797 >            rcut = calcMaxCutoffRadius();
798 >        }
799 >
800 >        if (simParams_->haveRsw()) {
801 >            rsw  = simParams_->getRsw();
802 >        } else {
803 >            rsw = rcut;
804 >        }
805 >    
806 >    }
807   }
808  
809 < void SimInfo::setDefaultRcut( double theRcut, double theRsw ){
809 > void SimInfo::setupCutoff() {
810 >    getCutoff(rcut_, rsw_);    
811 >    double rnblist = rcut_ + 1; // skin of neighbor list
812  
813 <  rSw = theRsw;
814 <  setDefaultRcut( theRcut );
813 >    //Pass these cutoff radius etc. to fortran. This function should be called once and only once
814 >    notifyFortranCutoffs(&rcut_, &rsw_, &rnblist);
815   }
816  
817 + void SimInfo::addProperty(GenericData* genData) {
818 +    properties_.addProperty(genData);  
819 + }
820  
821 < void SimInfo::checkCutOffs( void ){
822 <  
505 <  if( boxIsInit ){
506 <    
507 <    //we need to check cutOffs against the box
508 <    
509 <    if( rCut > maxCutoff ){
510 <      sprintf( painCave.errMsg,
511 <               "cutoffRadius is too large for the current periodic box.\n"
512 <               "\tCurrent Value of cutoffRadius = %G at time %G\n "
513 <               "\tThis is larger than half of at least one of the\n"
514 <               "\tperiodic box vectors.  Right now, the Box matrix is:\n"
515 <               "\n"
516 <               "\t[ %G %G %G ]\n"
517 <               "\t[ %G %G %G ]\n"
518 <               "\t[ %G %G %G ]\n",
519 <               rCut, currentTime,
520 <               Hmat[0][0], Hmat[0][1], Hmat[0][2],
521 <               Hmat[1][0], Hmat[1][1], Hmat[1][2],
522 <               Hmat[2][0], Hmat[2][1], Hmat[2][2]);
523 <      painCave.severity = OOPSE_ERROR;
524 <      painCave.isFatal = 1;
525 <      simError();
526 <    }    
527 <  } else {
528 <    // initialize this stuff before using it, OK?
529 <    sprintf( painCave.errMsg,
530 <             "Trying to check cutoffs without a box.\n"
531 <             "\tOOPSE should have better programmers than that.\n" );
532 <    painCave.severity = OOPSE_ERROR;
533 <    painCave.isFatal = 1;
534 <    simError();      
535 <  }
536 <  
821 > void SimInfo::removeProperty(const std::string& propName) {
822 >    properties_.removeProperty(propName);  
823   }
824  
825 < void SimInfo::addProperty(GenericData* prop){
825 > void SimInfo::clearProperties() {
826 >    properties_.clearProperties();
827 > }
828  
829 <  map<string, GenericData*>::iterator result;
830 <  result = properties.find(prop->getID());
831 <  
544 <  //we can't simply use  properties[prop->getID()] = prop,
545 <  //it will cause memory leak if we already contain a propery which has the same name of prop
546 <  
547 <  if(result != properties.end()){
548 <    
549 <    delete (*result).second;
550 <    (*result).second = prop;
829 > std::vector<std::string> SimInfo::getPropertyNames() {
830 >    return properties_.getPropertyNames();  
831 > }
832        
833 <  }
834 <  else{
833 > std::vector<GenericData*> SimInfo::getProperties() {
834 >    return properties_.getProperties();
835 > }
836  
837 <    properties[prop->getID()] = prop;
837 > GenericData* SimInfo::getPropertyByName(const std::string& propName) {
838 >    return properties_.getPropertyByName(propName);
839 > }
840  
841 <  }
841 > void SimInfo::setSnapshotManager(SnapshotManager* sman) {
842 >    //if (sman_ == sman_) {
843 >    //    return;
844 >    //}
845      
846 +    //delete sman_;
847 +    sman_ = sman;
848 +
849 +    Molecule* mol;
850 +    RigidBody* rb;
851 +    Atom* atom;
852 +    SimInfo::MoleculeIterator mi;
853 +    Molecule::RigidBodyIterator rbIter;
854 +    Molecule::AtomIterator atomIter;;
855 +
856 +    for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
857 +        
858 +        for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) {
859 +            atom->setSnapshotManager(sman_);
860 +        }
861 +        
862 +        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
863 +            rb->setSnapshotManager(sman_);
864 +        }
865 +    }    
866 +    
867   }
868  
869 < GenericData* SimInfo::getProperty(const string& propName){
869 > Vector3d SimInfo::getComVel(){
870 >    SimInfo::MoleculeIterator i;
871 >    Molecule* mol;
872 >
873 >    Vector3d comVel(0.0);
874 >    double totalMass = 0.0;
875 >    
876  
877 <  map<string, GenericData*>::iterator result;
878 <  
879 <  //string lowerCaseName = ();
880 <  
881 <  result = properties.find(propName);
882 <  
883 <  if(result != properties.end())
884 <    return (*result).second;  
885 <  else  
886 <    return NULL;  
877 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
878 >        double mass = mol->getMass();
879 >        totalMass += mass;
880 >        comVel += mass * mol->getComVel();
881 >    }  
882 >
883 > #ifdef IS_MPI
884 >    double tmpMass = totalMass;
885 >    Vector3d tmpComVel(comVel);    
886 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
887 >    MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
888 > #endif
889 >
890 >    comVel /= totalMass;
891 >
892 >    return comVel;
893   }
894  
895 + Vector3d SimInfo::getCom(){
896 +    SimInfo::MoleculeIterator i;
897 +    Molecule* mol;
898  
899 < void SimInfo::getFortranGroupArrays(SimInfo* info,
900 <                                    vector<int>& FglobalGroupMembership,
901 <                                    vector<double>& mfact){
902 <  
903 <  Molecule* myMols;
904 <  Atom** myAtoms;
905 <  int numAtom;
906 <  double mtot;
584 <  int numMol;
585 <  int numCutoffGroups;
586 <  CutoffGroup* myCutoffGroup;
587 <  vector<CutoffGroup*>::iterator iterCutoff;
588 <  Atom* cutoffAtom;
589 <  vector<Atom*>::iterator iterAtom;
590 <  int atomIndex;
591 <  double totalMass;
592 <  
593 <  mfact.clear();
594 <  FglobalGroupMembership.clear();
595 <  
899 >    Vector3d com(0.0);
900 >    double totalMass = 0.0;
901 >    
902 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
903 >        double mass = mol->getMass();
904 >        totalMass += mass;
905 >        com += mass * mol->getCom();
906 >    }  
907  
597  // Fix the silly fortran indexing problem
908   #ifdef IS_MPI
909 <  numAtom = mpiSim->getNAtomsGlobal();
910 < #else
911 <  numAtom = n_atoms;
909 >    double tmpMass = totalMass;
910 >    Vector3d tmpCom(com);    
911 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
912 >    MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
913   #endif
603  for (int i = 0; i < numAtom; i++)
604    FglobalGroupMembership.push_back(globalGroupMembership[i] + 1);
605  
914  
915 <  myMols = info->molecules;
608 <  numMol = info->n_mol;
609 <  for(int i  = 0; i < numMol; i++){
610 <    numCutoffGroups = myMols[i].getNCutoffGroups();
611 <    for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff);
612 <        myCutoffGroup != NULL;
613 <        myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){
915 >    com /= totalMass;
916  
917 <      totalMass = myCutoffGroup->getMass();
616 <      
617 <      for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom);
618 <          cutoffAtom != NULL;
619 <          cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){
620 <        mfact.push_back(cutoffAtom->getMass()/totalMass);
621 <      }  
622 <    }
623 <  }
917 >    return com;
918  
919 + }        
920 +
921 + std::ostream& operator <<(std::ostream& o, SimInfo& info) {
922 +
923 +    return o;
924   }
925 +
926 + }//end namespace oopse
927 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines