ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/SimInfo.cpp
(Generate patch)

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines