| 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 "SimInfo.hpp" | 
| 53 | < | #define __C | 
| 54 | < | #include "fSimulation.h" | 
| 55 | < | #include "simError.h" | 
| 52 | > | #include "brains/SimInfo.hpp" | 
| 53 | > | #include "math/Vector3.hpp" | 
| 54 | > | #include "primitives/Molecule.hpp" | 
| 55 | > | #include "UseTheForce/fCutoffPolicy.h" | 
| 56 | > | #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h" | 
| 57 | > | #include "UseTheForce/doForces_interface.h" | 
| 58 | > | #include "UseTheForce/DarkSide/electrostatic_interface.h" | 
| 59 | > | #include "UseTheForce/notifyCutoffs_interface.h" | 
| 60 | > | #include "utils/MemoryUtils.hpp" | 
| 61 | > | #include "utils/simError.h" | 
| 62 | > | #include "selection/SelectionManager.hpp" | 
| 63 |  |  | 
| 13 | – | #include "fortranWrappers.hpp" | 
| 14 | – |  | 
| 15 | – | #include "MatVec3.h" | 
| 16 | – |  | 
| 64 |  | #ifdef IS_MPI | 
| 65 | < | #include "mpiSimulation.hpp" | 
| 66 | < | #endif | 
| 65 | > | #include "UseTheForce/mpiComponentPlan.h" | 
| 66 | > | #include "UseTheForce/DarkSide/simParallel_interface.h" | 
| 67 | > | #endif | 
| 68 |  |  | 
| 69 | < | inline double roundMe( double x ){ | 
| 22 | < | return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); | 
| 23 | < | } | 
| 24 | < |  | 
| 25 | < | inline double min( double a, double b ){ | 
| 26 | < | return (a < b ) ? a : b; | 
| 27 | < | } | 
| 69 | > | namespace oopse { | 
| 70 |  |  | 
| 71 | < | SimInfo* currentInfo; | 
| 71 | > | SimInfo::SimInfo(MakeStamps* stamps, std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs, | 
| 72 | > | ForceField* ff, Globals* simParams) : | 
| 73 | > | stamps_(stamps), forceField_(ff), simParams_(simParams), | 
| 74 | > | ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), | 
| 75 | > | nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), | 
| 76 | > | nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), | 
| 77 | > | nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nRigidBodies_(0), | 
| 78 | > | nIntegrableObjects_(0),  nCutoffGroups_(0), nConstraints_(0), | 
| 79 | > | sman_(NULL), fortranInitialized_(false) { | 
| 80 |  |  | 
| 81 | < | SimInfo::SimInfo(){ | 
| 81 | > |  | 
| 82 | > | std::vector<std::pair<MoleculeStamp*, int> >::iterator i; | 
| 83 | > | MoleculeStamp* molStamp; | 
| 84 | > | int nMolWithSameStamp; | 
| 85 | > | int nCutoffAtoms = 0; // number of atoms belong to cutoff groups | 
| 86 | > | int nGroups = 0;      //total cutoff groups defined in meta-data file | 
| 87 | > | CutoffGroupStamp* cgStamp; | 
| 88 | > | RigidBodyStamp* rbStamp; | 
| 89 | > | int nRigidAtoms = 0; | 
| 90 | > |  | 
| 91 | > | for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) { | 
| 92 | > | molStamp = i->first; | 
| 93 | > | nMolWithSameStamp = i->second; | 
| 94 | > |  | 
| 95 | > | addMoleculeStamp(molStamp, nMolWithSameStamp); | 
| 96 |  |  | 
| 97 | < | n_constraints = 0; | 
| 98 | < | nZconstraints = 0; | 
| 35 | < | n_oriented = 0; | 
| 36 | < | n_dipoles = 0; | 
| 37 | < | ndf = 0; | 
| 38 | < | ndfRaw = 0; | 
| 39 | < | nZconstraints = 0; | 
| 40 | < | the_integrator = NULL; | 
| 41 | < | setTemp = 0; | 
| 42 | < | thermalTime = 0.0; | 
| 43 | < | currentTime = 0.0; | 
| 44 | < | rCut = 0.0; | 
| 45 | < | rSw = 0.0; | 
| 97 | > | //calculate atoms in molecules | 
| 98 | > | nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; | 
| 99 |  |  | 
| 47 | – | haveRcut = 0; | 
| 48 | – | haveRsw = 0; | 
| 49 | – | boxIsInit = 0; | 
| 50 | – |  | 
| 51 | – | resetTime = 1e99; | 
| 100 |  |  | 
| 101 | < | orthoRhombic = 0; | 
| 102 | < | orthoTolerance = 1E-6; | 
| 103 | < | useInitXSstate = true; | 
| 101 | > | //calculate atoms in cutoff groups | 
| 102 | > | int nAtomsInGroups = 0; | 
| 103 | > | int nCutoffGroupsInStamp = molStamp->getNCutoffGroups(); | 
| 104 | > |  | 
| 105 | > | for (int j=0; j < nCutoffGroupsInStamp; j++) { | 
| 106 | > | cgStamp = molStamp->getCutoffGroup(j); | 
| 107 | > | nAtomsInGroups += cgStamp->getNMembers(); | 
| 108 | > | } | 
| 109 |  |  | 
| 110 | < | usePBC = 0; | 
| 58 | < | useLJ = 0; | 
| 59 | < | useSticky = 0; | 
| 60 | < | useCharges = 0; | 
| 61 | < | useDipoles = 0; | 
| 62 | < | useReactionField = 0; | 
| 63 | < | useGB = 0; | 
| 64 | < | useEAM = 0; | 
| 65 | < | useSolidThermInt = 0; | 
| 66 | < | useLiquidThermInt = 0; | 
| 110 | > | nGroups += nCutoffGroupsInStamp * nMolWithSameStamp; | 
| 111 |  |  | 
| 112 | < | haveCutoffGroups = false; | 
| 112 | > | nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp; | 
| 113 |  |  | 
| 114 | < | excludes = Exclude::Instance(); | 
| 114 | > | //calculate atoms in rigid bodies | 
| 115 | > | int nAtomsInRigidBodies = 0; | 
| 116 | > | int nRigidBodiesInStamp = molStamp->getNRigidBodies(); | 
| 117 | > |  | 
| 118 | > | for (int j=0; j < nRigidBodiesInStamp; j++) { | 
| 119 | > | rbStamp = molStamp->getRigidBody(j); | 
| 120 | > | nAtomsInRigidBodies += rbStamp->getNMembers(); | 
| 121 | > | } | 
| 122 |  |  | 
| 123 | < | myConfiguration = new SimState(); | 
| 123 | > | nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp; | 
| 124 | > | nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp; | 
| 125 | > |  | 
| 126 | > | } | 
| 127 |  |  | 
| 128 | < | has_minimizer = false; | 
| 129 | < | the_minimizer =NULL; | 
| 128 | > | //every free atom (atom does not belong to cutoff groups) is a cutoff | 
| 129 | > | //group therefore the total number of cutoff groups in the system is | 
| 130 | > | //equal to the total number of atoms minus number of atoms belong to | 
| 131 | > | //cutoff group defined in meta-data file plus the number of cutoff | 
| 132 | > | //groups defined in meta-data file | 
| 133 | > | nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; | 
| 134 |  |  | 
| 135 | < | ngroup = 0; | 
| 136 | < |  | 
| 137 | < | wrapMeSimInfo( this ); | 
| 138 | < | } | 
| 139 | < |  | 
| 140 | < |  | 
| 141 | < | SimInfo::~SimInfo(){ | 
| 84 | < |  | 
| 85 | < | delete myConfiguration; | 
| 86 | < |  | 
| 87 | < | map<string, GenericData*>::iterator i; | 
| 135 | > | //every free atom (atom does not belong to rigid bodies) is an | 
| 136 | > | //integrable object therefore the total number of integrable objects | 
| 137 | > | //in the system is equal to the total number of atoms minus number of | 
| 138 | > | //atoms belong to rigid body defined in meta-data file plus the number | 
| 139 | > | //of rigid bodies defined in meta-data file | 
| 140 | > | nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms | 
| 141 | > | + nGlobalRigidBodies_; | 
| 142 |  |  | 
| 143 | < | for(i = properties.begin(); i != properties.end(); i++) | 
| 90 | < | delete (*i).second; | 
| 143 | > | nGlobalMols_ = molStampIds_.size(); | 
| 144 |  |  | 
| 145 | < | } | 
| 145 | > | #ifdef IS_MPI | 
| 146 | > | molToProcMap_.resize(nGlobalMols_); | 
| 147 | > | #endif | 
| 148 |  |  | 
| 149 | < | void SimInfo::setBox(double newBox[3]) { | 
| 95 | < |  | 
| 96 | < | int i, j; | 
| 97 | < | double tempMat[3][3]; | 
| 149 | > | } | 
| 150 |  |  | 
| 151 | < | for(i=0; i<3; i++) | 
| 152 | < | for (j=0; j<3; j++) tempMat[i][j] = 0.0;; | 
| 151 | > | SimInfo::~SimInfo() { | 
| 152 | > | std::map<int, Molecule*>::iterator i; | 
| 153 | > | for (i = molecules_.begin(); i != molecules_.end(); ++i) { | 
| 154 | > | delete i->second; | 
| 155 | > | } | 
| 156 | > | molecules_.clear(); | 
| 157 | > |  | 
| 158 | > | delete stamps_; | 
| 159 | > | delete sman_; | 
| 160 | > | delete simParams_; | 
| 161 | > | delete forceField_; | 
| 162 | > | } | 
| 163 |  |  | 
| 164 | < | tempMat[0][0] = newBox[0]; | 
| 165 | < | tempMat[1][1] = newBox[1]; | 
| 166 | < | tempMat[2][2] = newBox[2]; | 
| 164 | > | int SimInfo::getNGlobalConstraints() { | 
| 165 | > | int nGlobalConstraints; | 
| 166 | > | #ifdef IS_MPI | 
| 167 | > | MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM, | 
| 168 | > | MPI_COMM_WORLD); | 
| 169 | > | #else | 
| 170 | > | nGlobalConstraints =  nConstraints_; | 
| 171 | > | #endif | 
| 172 | > | return nGlobalConstraints; | 
| 173 | > | } | 
| 174 |  |  | 
| 175 | < | setBoxM( tempMat ); | 
| 175 | > | bool SimInfo::addMolecule(Molecule* mol) { | 
| 176 | > | MoleculeIterator i; | 
| 177 |  |  | 
| 178 | < | } | 
| 178 | > | i = molecules_.find(mol->getGlobalIndex()); | 
| 179 | > | if (i == molecules_.end() ) { | 
| 180 |  |  | 
| 181 | < | void SimInfo::setBoxM( double theBox[3][3] ){ | 
| 182 | < |  | 
| 183 | < | int i, j; | 
| 184 | < | double FortranHmat[9]; // to preserve compatibility with Fortran the | 
| 185 | < | // ordering in the array is as follows: | 
| 186 | < | // [ 0 3 6 ] | 
| 187 | < | // [ 1 4 7 ] | 
| 188 | < | // [ 2 5 8 ] | 
| 189 | < | double FortranHmatInv[9]; // the inverted Hmat (for Fortran); | 
| 181 | > | molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol)); | 
| 182 | > |  | 
| 183 | > | nAtoms_ += mol->getNAtoms(); | 
| 184 | > | nBonds_ += mol->getNBonds(); | 
| 185 | > | nBends_ += mol->getNBends(); | 
| 186 | > | nTorsions_ += mol->getNTorsions(); | 
| 187 | > | nRigidBodies_ += mol->getNRigidBodies(); | 
| 188 | > | nIntegrableObjects_ += mol->getNIntegrableObjects(); | 
| 189 | > | nCutoffGroups_ += mol->getNCutoffGroups(); | 
| 190 | > | nConstraints_ += mol->getNConstraintPairs(); | 
| 191 |  |  | 
| 192 | < | if( !boxIsInit ) boxIsInit = 1; | 
| 193 | < |  | 
| 194 | < | for(i=0; i < 3; i++) | 
| 195 | < | for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j]; | 
| 196 | < |  | 
| 125 | < | calcBoxL(); | 
| 126 | < | calcHmatInv(); | 
| 127 | < |  | 
| 128 | < | for(i=0; i < 3; i++) { | 
| 129 | < | for (j=0; j < 3; j++) { | 
| 130 | < | FortranHmat[3*j + i] = Hmat[i][j]; | 
| 131 | < | FortranHmatInv[3*j + i] = HmatInv[i][j]; | 
| 192 | > | addExcludePairs(mol); | 
| 193 | > |  | 
| 194 | > | return true; | 
| 195 | > | } else { | 
| 196 | > | return false; | 
| 197 |  | } | 
| 198 |  | } | 
| 199 |  |  | 
| 200 | < | setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic); | 
| 201 | < |  | 
| 202 | < | } | 
| 138 | < |  | 
| 200 | > | bool SimInfo::removeMolecule(Molecule* mol) { | 
| 201 | > | MoleculeIterator i; | 
| 202 | > | i = molecules_.find(mol->getGlobalIndex()); | 
| 203 |  |  | 
| 204 | < | void SimInfo::getBoxM (double theBox[3][3]) { | 
| 204 | > | if (i != molecules_.end() ) { | 
| 205 |  |  | 
| 206 | < | int i, j; | 
| 207 | < | for(i=0; i<3; i++) | 
| 208 | < | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]; | 
| 209 | < | } | 
| 206 | > | assert(mol == i->second); | 
| 207 | > |  | 
| 208 | > | nAtoms_ -= mol->getNAtoms(); | 
| 209 | > | nBonds_ -= mol->getNBonds(); | 
| 210 | > | nBends_ -= mol->getNBends(); | 
| 211 | > | nTorsions_ -= mol->getNTorsions(); | 
| 212 | > | nRigidBodies_ -= mol->getNRigidBodies(); | 
| 213 | > | nIntegrableObjects_ -= mol->getNIntegrableObjects(); | 
| 214 | > | nCutoffGroups_ -= mol->getNCutoffGroups(); | 
| 215 | > | nConstraints_ -= mol->getNConstraintPairs(); | 
| 216 |  |  | 
| 217 | + | removeExcludePairs(mol); | 
| 218 | + | molecules_.erase(mol->getGlobalIndex()); | 
| 219 |  |  | 
| 220 | < | void SimInfo::scaleBox(double scale) { | 
| 221 | < | double theBox[3][3]; | 
| 222 | < | int i, j; | 
| 220 | > | delete mol; | 
| 221 | > |  | 
| 222 | > | return true; | 
| 223 | > | } else { | 
| 224 | > | return false; | 
| 225 | > | } | 
| 226 |  |  | 
| 152 | – | // cerr << "Scaling box by " << scale << "\n"; | 
| 227 |  |  | 
| 228 | < | for(i=0; i<3; i++) | 
| 155 | < | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale; | 
| 228 | > | } | 
| 229 |  |  | 
| 230 | < | setBoxM(theBox); | 
| 230 | > |  | 
| 231 | > | Molecule* SimInfo::beginMolecule(MoleculeIterator& i) { | 
| 232 | > | i = molecules_.begin(); | 
| 233 | > | return i == molecules_.end() ? NULL : i->second; | 
| 234 | > | } | 
| 235 |  |  | 
| 236 | < | } | 
| 236 | > | Molecule* SimInfo::nextMolecule(MoleculeIterator& i) { | 
| 237 | > | ++i; | 
| 238 | > | return i == molecules_.end() ? NULL : i->second; | 
| 239 | > | } | 
| 240 |  |  | 
| 161 | – | void SimInfo::calcHmatInv( void ) { | 
| 162 | – |  | 
| 163 | – | int oldOrtho; | 
| 164 | – | int i,j; | 
| 165 | – | double smallDiag; | 
| 166 | – | double tol; | 
| 167 | – | double sanity[3][3]; | 
| 241 |  |  | 
| 242 | < | invertMat3( Hmat, HmatInv ); | 
| 242 | > | void SimInfo::calcNdf() { | 
| 243 | > | int ndf_local; | 
| 244 | > | MoleculeIterator i; | 
| 245 | > | std::vector<StuntDouble*>::iterator j; | 
| 246 | > | Molecule* mol; | 
| 247 | > | StuntDouble* integrableObject; | 
| 248 |  |  | 
| 249 | < | // check to see if Hmat is orthorhombic | 
| 250 | < |  | 
| 251 | < | oldOrtho = orthoRhombic; | 
| 249 | > | ndf_local = 0; | 
| 250 | > |  | 
| 251 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 252 | > | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; | 
| 253 | > | integrableObject = mol->nextIntegrableObject(j)) { | 
| 254 |  |  | 
| 255 | < | smallDiag = fabs(Hmat[0][0]); | 
| 176 | < | if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); | 
| 177 | < | if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); | 
| 178 | < | tol = smallDiag * orthoTolerance; | 
| 255 | > | ndf_local += 3; | 
| 256 |  |  | 
| 257 | < | orthoRhombic = 1; | 
| 258 | < |  | 
| 259 | < | for (i = 0; i < 3; i++ ) { | 
| 260 | < | for (j = 0 ; j < 3; j++) { | 
| 261 | < | if (i != j) { | 
| 262 | < | if (orthoRhombic) { | 
| 263 | < | if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; | 
| 264 | < | } | 
| 265 | < | } | 
| 266 | < | } | 
| 190 | < | } | 
| 191 | < |  | 
| 192 | < | if( oldOrtho != orthoRhombic ){ | 
| 257 | > | if (integrableObject->isDirectional()) { | 
| 258 | > | if (integrableObject->isLinear()) { | 
| 259 | > | ndf_local += 2; | 
| 260 | > | } else { | 
| 261 | > | ndf_local += 3; | 
| 262 | > | } | 
| 263 | > | } | 
| 264 | > |  | 
| 265 | > | }//end for (integrableObject) | 
| 266 | > | }// end for (mol) | 
| 267 |  |  | 
| 268 | < | if( orthoRhombic ) { | 
| 269 | < | sprintf( painCave.errMsg, | 
| 196 | < | "OOPSE is switching from the default Non-Orthorhombic\n" | 
| 197 | < | "\tto the faster Orthorhombic periodic boundary computations.\n" | 
| 198 | < | "\tThis is usually a good thing, but if you wan't the\n" | 
| 199 | < | "\tNon-Orthorhombic computations, make the orthoBoxTolerance\n" | 
| 200 | < | "\tvariable ( currently set to %G ) smaller.\n", | 
| 201 | < | orthoTolerance); | 
| 202 | < | painCave.severity = OOPSE_INFO; | 
| 203 | < | simError(); | 
| 204 | < | } | 
| 205 | < | else { | 
| 206 | < | sprintf( painCave.errMsg, | 
| 207 | < | "OOPSE is switching from the faster Orthorhombic to the more\n" | 
| 208 | < | "\tflexible Non-Orthorhombic periodic boundary computations.\n" | 
| 209 | < | "\tThis is usually because the box has deformed under\n" | 
| 210 | < | "\tNPTf integration. If you wan't to live on the edge with\n" | 
| 211 | < | "\tthe Orthorhombic computations, make the orthoBoxTolerance\n" | 
| 212 | < | "\tvariable ( currently set to %G ) larger.\n", | 
| 213 | < | orthoTolerance); | 
| 214 | < | painCave.severity = OOPSE_WARNING; | 
| 215 | < | simError(); | 
| 216 | < | } | 
| 217 | < | } | 
| 218 | < | } | 
| 268 | > | // n_constraints is local, so subtract them on each processor | 
| 269 | > | ndf_local -= nConstraints_; | 
| 270 |  |  | 
| 271 | < | void SimInfo::calcBoxL( void ){ | 
| 271 | > | #ifdef IS_MPI | 
| 272 | > | MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 273 | > | #else | 
| 274 | > | ndf_ = ndf_local; | 
| 275 | > | #endif | 
| 276 |  |  | 
| 277 | < | double dx, dy, dz, dsq; | 
| 277 | > | // nZconstraints_ is global, as are the 3 COM translations for the | 
| 278 | > | // entire system: | 
| 279 | > | ndf_ = ndf_ - 3 - nZconstraint_; | 
| 280 |  |  | 
| 281 | < | // boxVol = Determinant of Hmat | 
| 281 | > | } | 
| 282 |  |  | 
| 283 | < | boxVol = matDet3( Hmat ); | 
| 283 | > | void SimInfo::calcNdfRaw() { | 
| 284 | > | int ndfRaw_local; | 
| 285 |  |  | 
| 286 | < | // boxLx | 
| 287 | < |  | 
| 288 | < | dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; | 
| 289 | < | dsq = dx*dx + dy*dy + dz*dz; | 
| 232 | < | boxL[0] = sqrt( dsq ); | 
| 233 | < | //maxCutoff = 0.5 * boxL[0]; | 
| 286 | > | MoleculeIterator i; | 
| 287 | > | std::vector<StuntDouble*>::iterator j; | 
| 288 | > | Molecule* mol; | 
| 289 | > | StuntDouble* integrableObject; | 
| 290 |  |  | 
| 291 | < | // boxLy | 
| 292 | < |  | 
| 293 | < | dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; | 
| 294 | < | dsq = dx*dx + dy*dy + dz*dz; | 
| 295 | < | boxL[1] = sqrt( dsq ); | 
| 296 | < | //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; | 
| 291 | > | // Raw degrees of freedom that we have to set | 
| 292 | > | ndfRaw_local = 0; | 
| 293 | > |  | 
| 294 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 295 | > | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; | 
| 296 | > | integrableObject = mol->nextIntegrableObject(j)) { | 
| 297 |  |  | 
| 298 | + | ndfRaw_local += 3; | 
| 299 |  |  | 
| 300 | < | // boxLz | 
| 301 | < |  | 
| 302 | < | dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; | 
| 303 | < | dsq = dx*dx + dy*dy + dz*dz; | 
| 304 | < | boxL[2] = sqrt( dsq ); | 
| 305 | < | //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; | 
| 300 | > | if (integrableObject->isDirectional()) { | 
| 301 | > | if (integrableObject->isLinear()) { | 
| 302 | > | ndfRaw_local += 2; | 
| 303 | > | } else { | 
| 304 | > | ndfRaw_local += 3; | 
| 305 | > | } | 
| 306 | > | } | 
| 307 | > |  | 
| 308 | > | } | 
| 309 | > | } | 
| 310 | > |  | 
| 311 | > | #ifdef IS_MPI | 
| 312 | > | MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 313 | > | #else | 
| 314 | > | ndfRaw_ = ndfRaw_local; | 
| 315 | > | #endif | 
| 316 | > | } | 
| 317 |  |  | 
| 318 | < | //calculate the max cutoff | 
| 319 | < | maxCutoff =  calcMaxCutOff(); | 
| 252 | < |  | 
| 253 | < | checkCutOffs(); | 
| 318 | > | void SimInfo::calcNdfTrans() { | 
| 319 | > | int ndfTrans_local; | 
| 320 |  |  | 
| 321 | < | } | 
| 321 | > | ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; | 
| 322 |  |  | 
| 323 |  |  | 
| 324 | < | double SimInfo::calcMaxCutOff(){ | 
| 324 | > | #ifdef IS_MPI | 
| 325 | > | MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 326 | > | #else | 
| 327 | > | ndfTrans_ = ndfTrans_local; | 
| 328 | > | #endif | 
| 329 |  |  | 
| 330 | < | double ri[3], rj[3], rk[3]; | 
| 331 | < | double rij[3], rjk[3], rki[3]; | 
| 332 | < | double minDist; | 
| 330 | > | ndfTrans_ = ndfTrans_ - 3 - nZconstraint_; | 
| 331 | > |  | 
| 332 | > | } | 
| 333 |  |  | 
| 334 | < | ri[0] = Hmat[0][0]; | 
| 335 | < | ri[1] = Hmat[1][0]; | 
| 336 | < | ri[2] = Hmat[2][0]; | 
| 337 | < |  | 
| 338 | < | rj[0] = Hmat[0][1]; | 
| 339 | < | rj[1] = Hmat[1][1]; | 
| 340 | < | rj[2] = Hmat[2][1]; | 
| 341 | < |  | 
| 342 | < | rk[0] = Hmat[0][2]; | 
| 343 | < | rk[1] = Hmat[1][2]; | 
| 344 | < | rk[2] = Hmat[2][2]; | 
| 334 | > | void SimInfo::addExcludePairs(Molecule* mol) { | 
| 335 | > | std::vector<Bond*>::iterator bondIter; | 
| 336 | > | std::vector<Bend*>::iterator bendIter; | 
| 337 | > | std::vector<Torsion*>::iterator torsionIter; | 
| 338 | > | Bond* bond; | 
| 339 | > | Bend* bend; | 
| 340 | > | Torsion* torsion; | 
| 341 | > | int a; | 
| 342 | > | int b; | 
| 343 | > | int c; | 
| 344 | > | int d; | 
| 345 |  |  | 
| 346 | < | crossProduct3(ri, rj, rij); | 
| 347 | < | distXY = dotProduct3(rk,rij) / norm3(rij); | 
| 346 | > | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | 
| 347 | > | a = bond->getAtomA()->getGlobalIndex(); | 
| 348 | > | b = bond->getAtomB()->getGlobalIndex(); | 
| 349 | > | exclude_.addPair(a, b); | 
| 350 | > | } | 
| 351 |  |  | 
| 352 | < | crossProduct3(rj,rk, rjk); | 
| 353 | < | distYZ = dotProduct3(ri,rjk) / norm3(rjk); | 
| 352 | > | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | 
| 353 | > | a = bend->getAtomA()->getGlobalIndex(); | 
| 354 | > | b = bend->getAtomB()->getGlobalIndex(); | 
| 355 | > | c = bend->getAtomC()->getGlobalIndex(); | 
| 356 |  |  | 
| 357 | < | crossProduct3(rk,ri, rki); | 
| 358 | < | distZX = dotProduct3(rj,rki) / norm3(rki); | 
| 357 | > | exclude_.addPair(a, b); | 
| 358 | > | exclude_.addPair(a, c); | 
| 359 | > | exclude_.addPair(b, c); | 
| 360 | > | } | 
| 361 |  |  | 
| 362 | < | minDist = min(min(distXY, distYZ), distZX); | 
| 363 | < | return minDist/2; | 
| 364 | < |  | 
| 365 | < | } | 
| 362 | > | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | 
| 363 | > | a = torsion->getAtomA()->getGlobalIndex(); | 
| 364 | > | b = torsion->getAtomB()->getGlobalIndex(); | 
| 365 | > | c = torsion->getAtomC()->getGlobalIndex(); | 
| 366 | > | d = torsion->getAtomD()->getGlobalIndex(); | 
| 367 |  |  | 
| 368 | < | void SimInfo::wrapVector( double thePos[3] ){ | 
| 368 | > | exclude_.addPair(a, b); | 
| 369 | > | exclude_.addPair(a, c); | 
| 370 | > | exclude_.addPair(a, d); | 
| 371 | > | exclude_.addPair(b, c); | 
| 372 | > | exclude_.addPair(b, d); | 
| 373 | > | exclude_.addPair(c, d); | 
| 374 | > | } | 
| 375 |  |  | 
| 376 | < | int i; | 
| 377 | < | double scaled[3]; | 
| 376 | > | Molecule::RigidBodyIterator rbIter; | 
| 377 | > | RigidBody* rb; | 
| 378 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 379 | > | std::vector<Atom*> atoms = rb->getAtoms(); | 
| 380 | > | for (int i = 0; i < atoms.size() -1 ; ++i) { | 
| 381 | > | for (int j = i + 1; j < atoms.size(); ++j) { | 
| 382 | > | a = atoms[i]->getGlobalIndex(); | 
| 383 | > | b = atoms[j]->getGlobalIndex(); | 
| 384 | > | exclude_.addPair(a, b); | 
| 385 | > | } | 
| 386 | > | } | 
| 387 | > | } | 
| 388 |  |  | 
| 389 | < | if( !orthoRhombic ){ | 
| 296 | < | // calc the scaled coordinates. | 
| 297 | < |  | 
| 389 | > | } | 
| 390 |  |  | 
| 391 | < | matVecMul3(HmatInv, thePos, scaled); | 
| 391 | > | void SimInfo::removeExcludePairs(Molecule* mol) { | 
| 392 | > | std::vector<Bond*>::iterator bondIter; | 
| 393 | > | std::vector<Bend*>::iterator bendIter; | 
| 394 | > | std::vector<Torsion*>::iterator torsionIter; | 
| 395 | > | Bond* bond; | 
| 396 | > | Bend* bend; | 
| 397 | > | Torsion* torsion; | 
| 398 | > | int a; | 
| 399 | > | int b; | 
| 400 | > | int c; | 
| 401 | > | int d; | 
| 402 |  |  | 
| 403 | < | for(i=0; i<3; i++) | 
| 404 | < | scaled[i] -= roundMe(scaled[i]); | 
| 405 | < |  | 
| 406 | < | // calc the wrapped real coordinates from the wrapped scaled coordinates | 
| 407 | < |  | 
| 306 | < | matVecMul3(Hmat, scaled, thePos); | 
| 403 | > | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | 
| 404 | > | a = bond->getAtomA()->getGlobalIndex(); | 
| 405 | > | b = bond->getAtomB()->getGlobalIndex(); | 
| 406 | > | exclude_.removePair(a, b); | 
| 407 | > | } | 
| 408 |  |  | 
| 409 | < | } | 
| 410 | < | else{ | 
| 411 | < | // calc the scaled coordinates. | 
| 412 | < |  | 
| 312 | < | for(i=0; i<3; i++) | 
| 313 | < | scaled[i] = thePos[i]*HmatInv[i][i]; | 
| 314 | < |  | 
| 315 | < | // wrap the scaled coordinates | 
| 316 | < |  | 
| 317 | < | for(i=0; i<3; i++) | 
| 318 | < | scaled[i] -= roundMe(scaled[i]); | 
| 319 | < |  | 
| 320 | < | // calc the wrapped real coordinates from the wrapped scaled coordinates | 
| 321 | < |  | 
| 322 | < | for(i=0; i<3; i++) | 
| 323 | < | thePos[i] = scaled[i]*Hmat[i][i]; | 
| 324 | < | } | 
| 325 | < |  | 
| 326 | < | } | 
| 409 | > | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | 
| 410 | > | a = bend->getAtomA()->getGlobalIndex(); | 
| 411 | > | b = bend->getAtomB()->getGlobalIndex(); | 
| 412 | > | c = bend->getAtomC()->getGlobalIndex(); | 
| 413 |  |  | 
| 414 | + | exclude_.removePair(a, b); | 
| 415 | + | exclude_.removePair(a, c); | 
| 416 | + | exclude_.removePair(b, c); | 
| 417 | + | } | 
| 418 |  |  | 
| 419 | < | int SimInfo::getNDF(){ | 
| 420 | < | int ndf_local; | 
| 419 | > | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | 
| 420 | > | a = torsion->getAtomA()->getGlobalIndex(); | 
| 421 | > | b = torsion->getAtomB()->getGlobalIndex(); | 
| 422 | > | c = torsion->getAtomC()->getGlobalIndex(); | 
| 423 | > | d = torsion->getAtomD()->getGlobalIndex(); | 
| 424 |  |  | 
| 425 | < | ndf_local = 0; | 
| 426 | < |  | 
| 427 | < | for(int i = 0; i < integrableObjects.size(); i++){ | 
| 428 | < | ndf_local += 3; | 
| 429 | < | if (integrableObjects[i]->isDirectional()) { | 
| 430 | < | if (integrableObjects[i]->isLinear()) | 
| 338 | < | ndf_local += 2; | 
| 339 | < | else | 
| 340 | < | ndf_local += 3; | 
| 425 | > | exclude_.removePair(a, b); | 
| 426 | > | exclude_.removePair(a, c); | 
| 427 | > | exclude_.removePair(a, d); | 
| 428 | > | exclude_.removePair(b, c); | 
| 429 | > | exclude_.removePair(b, d); | 
| 430 | > | exclude_.removePair(c, d); | 
| 431 |  | } | 
| 432 | + |  | 
| 433 | + | Molecule::RigidBodyIterator rbIter; | 
| 434 | + | RigidBody* rb; | 
| 435 | + | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 436 | + | std::vector<Atom*> atoms = rb->getAtoms(); | 
| 437 | + | for (int i = 0; i < atoms.size() -1 ; ++i) { | 
| 438 | + | for (int j = i + 1; j < atoms.size(); ++j) { | 
| 439 | + | a = atoms[i]->getGlobalIndex(); | 
| 440 | + | b = atoms[j]->getGlobalIndex(); | 
| 441 | + | exclude_.removePair(a, b); | 
| 442 | + | } | 
| 443 | + | } | 
| 444 | + | } | 
| 445 | + |  | 
| 446 |  | } | 
| 447 |  |  | 
| 344 | – | // n_constraints is local, so subtract them on each processor: | 
| 448 |  |  | 
| 449 | < | ndf_local -= n_constraints; | 
| 449 | > | void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) { | 
| 450 | > | int curStampId; | 
| 451 |  |  | 
| 452 | < | #ifdef IS_MPI | 
| 453 | < | MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 350 | < | #else | 
| 351 | < | ndf = ndf_local; | 
| 352 | < | #endif | 
| 452 | > | //index from 0 | 
| 453 | > | curStampId = moleculeStamps_.size(); | 
| 454 |  |  | 
| 455 | < | // nZconstraints is global, as are the 3 COM translations for the | 
| 456 | < | // entire system: | 
| 455 | > | moleculeStamps_.push_back(molStamp); | 
| 456 | > | molStampIds_.insert(molStampIds_.end(), nmol, curStampId); | 
| 457 | > | } | 
| 458 |  |  | 
| 459 | < | ndf = ndf - 3 - nZconstraints; | 
| 459 | > | void SimInfo::update() { | 
| 460 |  |  | 
| 461 | < | return ndf; | 
| 360 | < | } | 
| 461 | > | setupSimType(); | 
| 462 |  |  | 
| 463 | < | int SimInfo::getNDFraw() { | 
| 464 | < | int ndfRaw_local; | 
| 463 | > | #ifdef IS_MPI | 
| 464 | > | setupFortranParallel(); | 
| 465 | > | #endif | 
| 466 |  |  | 
| 467 | < | // Raw degrees of freedom that we have to set | 
| 366 | < | ndfRaw_local = 0; | 
| 467 | > | setupFortranSim(); | 
| 468 |  |  | 
| 469 | < | for(int i = 0; i < integrableObjects.size(); i++){ | 
| 470 | < | ndfRaw_local += 3; | 
| 471 | < | if (integrableObjects[i]->isDirectional()) { | 
| 472 | < | if (integrableObjects[i]->isLinear()) | 
| 473 | < | ndfRaw_local += 2; | 
| 474 | < | else | 
| 475 | < | ndfRaw_local += 3; | 
| 469 | > | //setup fortran force field | 
| 470 | > | /** @deprecate */ | 
| 471 | > | int isError = 0; | 
| 472 | > |  | 
| 473 | > | setupElectrostaticSummationMethod( isError ); | 
| 474 | > |  | 
| 475 | > | if(isError){ | 
| 476 | > | sprintf( painCave.errMsg, | 
| 477 | > | "ForceField error: There was an error initializing the forceField in fortran.\n" ); | 
| 478 | > | painCave.isFatal = 1; | 
| 479 | > | simError(); | 
| 480 |  | } | 
| 481 | < | } | 
| 481 | > |  | 
| 482 |  |  | 
| 483 | < | #ifdef IS_MPI | 
| 379 | < | MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 380 | < | #else | 
| 381 | < | ndfRaw = ndfRaw_local; | 
| 382 | < | #endif | 
| 483 | > | setupCutoff(); | 
| 484 |  |  | 
| 485 | < | return ndfRaw; | 
| 486 | < | } | 
| 485 | > | calcNdf(); | 
| 486 | > | calcNdfRaw(); | 
| 487 | > | calcNdfTrans(); | 
| 488 |  |  | 
| 489 | < | int SimInfo::getNDFtranslational() { | 
| 490 | < | int ndfTrans_local; | 
| 489 | > | fortranInitialized_ = true; | 
| 490 | > | } | 
| 491 |  |  | 
| 492 | < | ndfTrans_local = 3 * integrableObjects.size() - n_constraints; | 
| 492 | > | std::set<AtomType*> SimInfo::getUniqueAtomTypes() { | 
| 493 | > | SimInfo::MoleculeIterator mi; | 
| 494 | > | Molecule* mol; | 
| 495 | > | Molecule::AtomIterator ai; | 
| 496 | > | Atom* atom; | 
| 497 | > | std::set<AtomType*> atomTypes; | 
| 498 |  |  | 
| 499 | + | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 500 |  |  | 
| 501 | < | #ifdef IS_MPI | 
| 502 | < | MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 503 | < | #else | 
| 504 | < | ndfTrans = ndfTrans_local; | 
| 505 | < | #endif | 
| 501 | > | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 502 | > | atomTypes.insert(atom->getAtomType()); | 
| 503 | > | } | 
| 504 | > |  | 
| 505 | > | } | 
| 506 |  |  | 
| 507 | < | ndfTrans = ndfTrans - 3 - nZconstraints; | 
| 507 | > | return atomTypes; | 
| 508 | > | } | 
| 509 |  |  | 
| 510 | < | return ndfTrans; | 
| 511 | < | } | 
| 510 | > | void SimInfo::setupSimType() { | 
| 511 | > | std::set<AtomType*>::iterator i; | 
| 512 | > | std::set<AtomType*> atomTypes; | 
| 513 | > | atomTypes = getUniqueAtomTypes(); | 
| 514 | > |  | 
| 515 | > | int useLennardJones = 0; | 
| 516 | > | int useElectrostatic = 0; | 
| 517 | > | int useEAM = 0; | 
| 518 | > | int useCharge = 0; | 
| 519 | > | int useDirectional = 0; | 
| 520 | > | int useDipole = 0; | 
| 521 | > | int useGayBerne = 0; | 
| 522 | > | int useSticky = 0; | 
| 523 | > | int useStickyPower = 0; | 
| 524 | > | int useShape = 0; | 
| 525 | > | int useFLARB = 0; //it is not in AtomType yet | 
| 526 | > | int useDirectionalAtom = 0; | 
| 527 | > | int useElectrostatics = 0; | 
| 528 | > | //usePBC and useRF are from simParams | 
| 529 | > | int usePBC = simParams_->getUsePeriodicBoundaryConditions(); | 
| 530 | > | int useRF; | 
| 531 | > | int useDW; | 
| 532 | > | std::string myMethod; | 
| 533 |  |  | 
| 534 | < | int SimInfo::getTotIntegrableObjects() { | 
| 535 | < | int nObjs_local; | 
| 536 | < | int nObjs; | 
| 534 | > | // set the useRF logical | 
| 535 | > | useRF = 0; | 
| 536 | > | useDW = 0; | 
| 537 |  |  | 
| 408 | – | nObjs_local =  integrableObjects.size(); | 
| 538 |  |  | 
| 539 | + | if (simParams_->haveElectrostaticSummationMethod()) { | 
| 540 | + | std::string myMethod = simParams_->getElectrostaticSummationMethod(); | 
| 541 | + | toUpper(myMethod); | 
| 542 | + | if (myMethod == "REACTION_FIELD") { | 
| 543 | + | useRF=1; | 
| 544 | + | } else { | 
| 545 | + | if (myMethod == "DAMPED_WOLF") { | 
| 546 | + | useDW = 1; | 
| 547 | + | } | 
| 548 | + | } | 
| 549 | + | } | 
| 550 |  |  | 
| 551 | < | #ifdef IS_MPI | 
| 552 | < | MPI_Allreduce(&nObjs_local,&nObjs,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 553 | < | #else | 
| 554 | < | nObjs = nObjs_local; | 
| 555 | < | #endif | 
| 551 | > | //loop over all of the atom types | 
| 552 | > | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { | 
| 553 | > | useLennardJones |= (*i)->isLennardJones(); | 
| 554 | > | useElectrostatic |= (*i)->isElectrostatic(); | 
| 555 | > | useEAM |= (*i)->isEAM(); | 
| 556 | > | useCharge |= (*i)->isCharge(); | 
| 557 | > | useDirectional |= (*i)->isDirectional(); | 
| 558 | > | useDipole |= (*i)->isDipole(); | 
| 559 | > | useGayBerne |= (*i)->isGayBerne(); | 
| 560 | > | useSticky |= (*i)->isSticky(); | 
| 561 | > | useStickyPower |= (*i)->isStickyPower(); | 
| 562 | > | useShape |= (*i)->isShape(); | 
| 563 | > | } | 
| 564 |  |  | 
| 565 | + | if (useSticky || useStickyPower || useDipole || useGayBerne || useShape) { | 
| 566 | + | useDirectionalAtom = 1; | 
| 567 | + | } | 
| 568 |  |  | 
| 569 | < | return nObjs; | 
| 570 | < | } | 
| 569 | > | if (useCharge || useDipole) { | 
| 570 | > | useElectrostatics = 1; | 
| 571 | > | } | 
| 572 |  |  | 
| 573 | < | void SimInfo::refreshSim(){ | 
| 573 | > | #ifdef IS_MPI | 
| 574 | > | int temp; | 
| 575 |  |  | 
| 576 | < | simtype fInfo; | 
| 577 | < | int isError; | 
| 425 | < | int n_global; | 
| 426 | < | int* excl; | 
| 576 | > | temp = usePBC; | 
| 577 | > | MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 578 |  |  | 
| 579 | < | fInfo.dielect = 0.0; | 
| 579 | > | temp = useDirectionalAtom; | 
| 580 | > | MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 581 | > |  | 
| 582 | > | temp = useLennardJones; | 
| 583 | > | MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 584 | > |  | 
| 585 | > | temp = useElectrostatics; | 
| 586 | > | MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 587 |  |  | 
| 588 | < | if( useDipoles ){ | 
| 589 | < | if( useReactionField )fInfo.dielect = dielectric; | 
| 432 | < | } | 
| 588 | > | temp = useCharge; | 
| 589 | > | MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 590 |  |  | 
| 591 | < | fInfo.SIM_uses_PBC = usePBC; | 
| 592 | < | //fInfo.SIM_uses_LJ = 0; | 
| 436 | < | fInfo.SIM_uses_LJ = useLJ; | 
| 437 | < | fInfo.SIM_uses_sticky = useSticky; | 
| 438 | < | //fInfo.SIM_uses_sticky = 0; | 
| 439 | < | fInfo.SIM_uses_charges = useCharges; | 
| 440 | < | fInfo.SIM_uses_dipoles = useDipoles; | 
| 441 | < | //fInfo.SIM_uses_dipoles = 0; | 
| 442 | < | fInfo.SIM_uses_RF = useReactionField; | 
| 443 | < | //fInfo.SIM_uses_RF = 0; | 
| 444 | < | fInfo.SIM_uses_GB = useGB; | 
| 445 | < | fInfo.SIM_uses_EAM = useEAM; | 
| 591 | > | temp = useDipole; | 
| 592 | > | MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 593 |  |  | 
| 594 | < | n_exclude = excludes->getSize(); | 
| 595 | < | excl = excludes->getFortranArray(); | 
| 449 | < |  | 
| 450 | < | #ifdef IS_MPI | 
| 451 | < | n_global = mpiSim->getNAtomsGlobal(); | 
| 452 | < | #else | 
| 453 | < | n_global = n_atoms; | 
| 454 | < | #endif | 
| 455 | < |  | 
| 456 | < | isError = 0; | 
| 457 | < |  | 
| 458 | < | getFortranGroupArrays(this, FglobalGroupMembership, mfact); | 
| 459 | < | //it may not be a good idea to pass the address of first element in vector | 
| 460 | < | //since c++ standard does not require vector to be stored continuously in meomory | 
| 461 | < | //Most of the compilers will organize the memory of vector continuously | 
| 462 | < | setFsimulation( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl, | 
| 463 | < | &nGlobalExcludes, globalExcludes, molMembershipArray, | 
| 464 | < | &mfact[0], &ngroup, &FglobalGroupMembership[0], &isError); | 
| 594 | > | temp = useSticky; | 
| 595 | > | MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 596 |  |  | 
| 597 | < | if( isError ){ | 
| 597 | > | temp = useStickyPower; | 
| 598 | > | MPI_Allreduce(&temp, &useStickyPower, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 599 |  |  | 
| 600 | < | sprintf( painCave.errMsg, | 
| 601 | < | "There was an error setting the simulation information in fortran.\n" ); | 
| 602 | < | painCave.isFatal = 1; | 
| 603 | < | painCave.severity = OOPSE_ERROR; | 
| 604 | < | simError(); | 
| 600 | > | temp = useGayBerne; | 
| 601 | > | MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 602 | > |  | 
| 603 | > | temp = useEAM; | 
| 604 | > | MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 605 | > |  | 
| 606 | > | temp = useShape; | 
| 607 | > | MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 608 | > |  | 
| 609 | > | temp = useFLARB; | 
| 610 | > | MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 611 | > |  | 
| 612 | > | temp = useRF; | 
| 613 | > | MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 614 | > |  | 
| 615 | > | temp = useDW; | 
| 616 | > | MPI_Allreduce(&temp, &useDW, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 617 | > |  | 
| 618 | > | #endif | 
| 619 | > |  | 
| 620 | > | fInfo_.SIM_uses_PBC = usePBC; | 
| 621 | > | fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom; | 
| 622 | > | fInfo_.SIM_uses_LennardJones = useLennardJones; | 
| 623 | > | fInfo_.SIM_uses_Electrostatics = useElectrostatics; | 
| 624 | > | fInfo_.SIM_uses_Charges = useCharge; | 
| 625 | > | fInfo_.SIM_uses_Dipoles = useDipole; | 
| 626 | > | fInfo_.SIM_uses_Sticky = useSticky; | 
| 627 | > | fInfo_.SIM_uses_StickyPower = useStickyPower; | 
| 628 | > | fInfo_.SIM_uses_GayBerne = useGayBerne; | 
| 629 | > | fInfo_.SIM_uses_EAM = useEAM; | 
| 630 | > | fInfo_.SIM_uses_Shapes = useShape; | 
| 631 | > | fInfo_.SIM_uses_FLARB = useFLARB; | 
| 632 | > | fInfo_.SIM_uses_RF = useRF; | 
| 633 | > | fInfo_.SIM_uses_DampedWolf = useDW; | 
| 634 | > |  | 
| 635 | > | if( myMethod == "REACTION_FIELD") { | 
| 636 | > |  | 
| 637 | > | if (simParams_->haveDielectric()) { | 
| 638 | > | fInfo_.dielect = simParams_->getDielectric(); | 
| 639 | > | } else { | 
| 640 | > | sprintf(painCave.errMsg, | 
| 641 | > | "SimSetup Error: No Dielectric constant was set.\n" | 
| 642 | > | "\tYou are trying to use Reaction Field without" | 
| 643 | > | "\tsetting a dielectric constant!\n"); | 
| 644 | > | painCave.isFatal = 1; | 
| 645 | > | simError(); | 
| 646 | > | } | 
| 647 | > | } | 
| 648 | > |  | 
| 649 |  | } | 
| 474 | – |  | 
| 475 | – | #ifdef IS_MPI | 
| 476 | – | sprintf( checkPointMsg, | 
| 477 | – | "succesfully sent the simulation information to fortran.\n"); | 
| 478 | – | MPIcheckPoint(); | 
| 479 | – | #endif // is_mpi | 
| 480 | – |  | 
| 481 | – | this->ndf = this->getNDF(); | 
| 482 | – | this->ndfRaw = this->getNDFraw(); | 
| 483 | – | this->ndfTrans = this->getNDFtranslational(); | 
| 484 | – | } | 
| 650 |  |  | 
| 651 | < | void SimInfo::setDefaultRcut( double theRcut ){ | 
| 652 | < |  | 
| 653 | < | haveRcut = 1; | 
| 654 | < | rCut = theRcut; | 
| 655 | < | rList = rCut + 1.0; | 
| 656 | < |  | 
| 657 | < | notifyFortranCutOffs( &rCut, &rSw, &rList ); | 
| 493 | < | } | 
| 651 | > | void SimInfo::setupFortranSim() { | 
| 652 | > | int isError; | 
| 653 | > | int nExclude; | 
| 654 | > | std::vector<int> fortranGlobalGroupMembership; | 
| 655 | > |  | 
| 656 | > | nExclude = exclude_.getSize(); | 
| 657 | > | isError = 0; | 
| 658 |  |  | 
| 659 | < | void SimInfo::setDefaultRcut( double theRcut, double theRsw ){ | 
| 659 | > | //globalGroupMembership_ is filled by SimCreator | 
| 660 | > | for (int i = 0; i < nGlobalAtoms_; i++) { | 
| 661 | > | fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); | 
| 662 | > | } | 
| 663 |  |  | 
| 664 | < | rSw = theRsw; | 
| 665 | < | setDefaultRcut( theRcut ); | 
| 666 | < | } | 
| 664 | > | //calculate mass ratio of cutoff group | 
| 665 | > | std::vector<double> mfact; | 
| 666 | > | SimInfo::MoleculeIterator mi; | 
| 667 | > | Molecule* mol; | 
| 668 | > | Molecule::CutoffGroupIterator ci; | 
| 669 | > | CutoffGroup* cg; | 
| 670 | > | Molecule::AtomIterator ai; | 
| 671 | > | Atom* atom; | 
| 672 | > | double totalMass; | 
| 673 |  |  | 
| 674 | + | //to avoid memory reallocation, reserve enough space for mfact | 
| 675 | + | mfact.reserve(getNCutoffGroups()); | 
| 676 | + |  | 
| 677 | + | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 678 | + | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 679 |  |  | 
| 680 | < | void SimInfo::checkCutOffs( void ){ | 
| 681 | < |  | 
| 682 | < | if( boxIsInit ){ | 
| 680 | > | totalMass = cg->getMass(); | 
| 681 | > | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { | 
| 682 | > | // Check for massless groups - set mfact to 1 if true | 
| 683 | > | if (totalMass != 0) | 
| 684 | > | mfact.push_back(atom->getMass()/totalMass); | 
| 685 | > | else | 
| 686 | > | mfact.push_back( 1.0 ); | 
| 687 | > | } | 
| 688 | > |  | 
| 689 | > | } | 
| 690 | > | } | 
| 691 | > |  | 
| 692 | > | //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) | 
| 693 | > | std::vector<int> identArray; | 
| 694 | > |  | 
| 695 | > | //to avoid memory reallocation, reserve enough space identArray | 
| 696 | > | identArray.reserve(getNAtoms()); | 
| 697 |  |  | 
| 698 | < | //we need to check cutOffs against the box | 
| 698 | > | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 699 | > | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 700 | > | identArray.push_back(atom->getIdent()); | 
| 701 | > | } | 
| 702 | > | } | 
| 703 | > |  | 
| 704 | > | //fill molMembershipArray | 
| 705 | > | //molMembershipArray is filled by SimCreator | 
| 706 | > | std::vector<int> molMembershipArray(nGlobalAtoms_); | 
| 707 | > | for (int i = 0; i < nGlobalAtoms_; i++) { | 
| 708 | > | molMembershipArray[i] = globalMolMembership_[i] + 1; | 
| 709 | > | } | 
| 710 |  |  | 
| 711 | < | if( rCut > maxCutoff ){ | 
| 711 | > | //setup fortran simulation | 
| 712 | > | int nGlobalExcludes = 0; | 
| 713 | > | int* globalExcludes = NULL; | 
| 714 | > | int* excludeList = exclude_.getExcludeList(); | 
| 715 | > | setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList , | 
| 716 | > | &nGlobalExcludes, globalExcludes, &molMembershipArray[0], | 
| 717 | > | &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError); | 
| 718 | > |  | 
| 719 | > | if( isError ){ | 
| 720 | > |  | 
| 721 |  | sprintf( painCave.errMsg, | 
| 722 | < | "cutoffRadius is too large for the current periodic box.\n" | 
| 511 | < | "\tCurrent Value of cutoffRadius = %G at time %G\n " | 
| 512 | < | "\tThis is larger than half of at least one of the\n" | 
| 513 | < | "\tperiodic box vectors.  Right now, the Box matrix is:\n" | 
| 514 | < | "\n" | 
| 515 | < | "\t[ %G %G %G ]\n" | 
| 516 | < | "\t[ %G %G %G ]\n" | 
| 517 | < | "\t[ %G %G %G ]\n", | 
| 518 | < | rCut, currentTime, | 
| 519 | < | Hmat[0][0], Hmat[0][1], Hmat[0][2], | 
| 520 | < | Hmat[1][0], Hmat[1][1], Hmat[1][2], | 
| 521 | < | Hmat[2][0], Hmat[2][1], Hmat[2][2]); | 
| 522 | < | painCave.severity = OOPSE_ERROR; | 
| 722 | > | "There was an error setting the simulation information in fortran.\n" ); | 
| 723 |  | painCave.isFatal = 1; | 
| 724 | + | painCave.severity = OOPSE_ERROR; | 
| 725 |  | simError(); | 
| 726 | < | } | 
| 727 | < | } else { | 
| 728 | < | // initialize this stuff before using it, OK? | 
| 729 | < | sprintf( painCave.errMsg, | 
| 730 | < | "Trying to check cutoffs without a box.\n" | 
| 731 | < | "\tOOPSE should have better programmers than that.\n" ); | 
| 732 | < | painCave.severity = OOPSE_ERROR; | 
| 532 | < | painCave.isFatal = 1; | 
| 533 | < | simError(); | 
| 726 | > | } | 
| 727 | > |  | 
| 728 | > | #ifdef IS_MPI | 
| 729 | > | sprintf( checkPointMsg, | 
| 730 | > | "succesfully sent the simulation information to fortran.\n"); | 
| 731 | > | MPIcheckPoint(); | 
| 732 | > | #endif // is_mpi | 
| 733 |  | } | 
| 535 | – |  | 
| 536 | – | } | 
| 734 |  |  | 
| 538 | – | void SimInfo::addProperty(GenericData* prop){ | 
| 735 |  |  | 
| 736 | < | map<string, GenericData*>::iterator result; | 
| 737 | < | result = properties.find(prop->getID()); | 
| 542 | < |  | 
| 543 | < | //we can't simply use  properties[prop->getID()] = prop, | 
| 544 | < | //it will cause memory leak if we already contain a propery which has the same name of prop | 
| 545 | < |  | 
| 546 | < | if(result != properties.end()){ | 
| 736 | > | #ifdef IS_MPI | 
| 737 | > | void SimInfo::setupFortranParallel() { | 
| 738 |  |  | 
| 739 | < | delete (*result).second; | 
| 740 | < | (*result).second = prop; | 
| 741 | < |  | 
| 742 | < | } | 
| 743 | < | else{ | 
| 739 | > | //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex | 
| 740 | > | std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0); | 
| 741 | > | std::vector<int> localToGlobalCutoffGroupIndex; | 
| 742 | > | SimInfo::MoleculeIterator mi; | 
| 743 | > | Molecule::AtomIterator ai; | 
| 744 | > | Molecule::CutoffGroupIterator ci; | 
| 745 | > | Molecule* mol; | 
| 746 | > | Atom* atom; | 
| 747 | > | CutoffGroup* cg; | 
| 748 | > | mpiSimData parallelData; | 
| 749 | > | int isError; | 
| 750 |  |  | 
| 751 | < | properties[prop->getID()] = prop; | 
| 751 | > | for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) { | 
| 752 |  |  | 
| 753 | + | //local index(index in DataStorge) of atom is important | 
| 754 | + | for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 755 | + | localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; | 
| 756 | + | } | 
| 757 | + |  | 
| 758 | + | //local index of cutoff group is trivial, it only depends on the order of travesing | 
| 759 | + | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 760 | + | localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); | 
| 761 | + | } | 
| 762 | + |  | 
| 763 | + | } | 
| 764 | + |  | 
| 765 | + | //fill up mpiSimData struct | 
| 766 | + | parallelData.nMolGlobal = getNGlobalMolecules(); | 
| 767 | + | parallelData.nMolLocal = getNMolecules(); | 
| 768 | + | parallelData.nAtomsGlobal = getNGlobalAtoms(); | 
| 769 | + | parallelData.nAtomsLocal = getNAtoms(); | 
| 770 | + | parallelData.nGroupsGlobal = getNGlobalCutoffGroups(); | 
| 771 | + | parallelData.nGroupsLocal = getNCutoffGroups(); | 
| 772 | + | parallelData.myNode = worldRank; | 
| 773 | + | MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors)); | 
| 774 | + |  | 
| 775 | + | //pass mpiSimData struct and index arrays to fortran | 
| 776 | + | setFsimParallel(¶llelData, &(parallelData.nAtomsLocal), | 
| 777 | + | &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal), | 
| 778 | + | &localToGlobalCutoffGroupIndex[0], &isError); | 
| 779 | + |  | 
| 780 | + | if (isError) { | 
| 781 | + | sprintf(painCave.errMsg, | 
| 782 | + | "mpiRefresh errror: fortran didn't like something we gave it.\n"); | 
| 783 | + | painCave.isFatal = 1; | 
| 784 | + | simError(); | 
| 785 | + | } | 
| 786 | + |  | 
| 787 | + | sprintf(checkPointMsg, " mpiRefresh successful.\n"); | 
| 788 | + | MPIcheckPoint(); | 
| 789 | + |  | 
| 790 | + |  | 
| 791 |  | } | 
| 557 | – |  | 
| 558 | – | } | 
| 792 |  |  | 
| 793 | < | GenericData* SimInfo::getProperty(const string& propName){ | 
| 561 | < |  | 
| 562 | < | map<string, GenericData*>::iterator result; | 
| 563 | < |  | 
| 564 | < | //string lowerCaseName = (); | 
| 565 | < |  | 
| 566 | < | result = properties.find(propName); | 
| 567 | < |  | 
| 568 | < | if(result != properties.end()) | 
| 569 | < | return (*result).second; | 
| 570 | < | else | 
| 571 | < | return NULL; | 
| 572 | < | } | 
| 793 | > | #endif | 
| 794 |  |  | 
| 795 | + | double SimInfo::calcMaxCutoffRadius() { | 
| 796 |  |  | 
| 575 | – | void SimInfo::getFortranGroupArrays(SimInfo* info, | 
| 576 | – | vector<int>& FglobalGroupMembership, | 
| 577 | – | vector<double>& mfact){ | 
| 578 | – |  | 
| 579 | – | Molecule* myMols; | 
| 580 | – | Atom** myAtoms; | 
| 581 | – | int numAtom; | 
| 582 | – | double mtot; | 
| 583 | – | int numMol; | 
| 584 | – | int numCutoffGroups; | 
| 585 | – | CutoffGroup* myCutoffGroup; | 
| 586 | – | vector<CutoffGroup*>::iterator iterCutoff; | 
| 587 | – | Atom* cutoffAtom; | 
| 588 | – | vector<Atom*>::iterator iterAtom; | 
| 589 | – | int atomIndex; | 
| 590 | – | double totalMass; | 
| 591 | – |  | 
| 592 | – | mfact.clear(); | 
| 593 | – | FglobalGroupMembership.clear(); | 
| 594 | – |  | 
| 797 |  |  | 
| 798 | < | // Fix the silly fortran indexing problem | 
| 798 | > | std::set<AtomType*> atomTypes; | 
| 799 | > | std::set<AtomType*>::iterator i; | 
| 800 | > | std::vector<double> cutoffRadius; | 
| 801 | > |  | 
| 802 | > | //get the unique atom types | 
| 803 | > | atomTypes = getUniqueAtomTypes(); | 
| 804 | > |  | 
| 805 | > | //query the max cutoff radius among these atom types | 
| 806 | > | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { | 
| 807 | > | cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i)); | 
| 808 | > | } | 
| 809 | > |  | 
| 810 | > | double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end())); | 
| 811 |  | #ifdef IS_MPI | 
| 812 | < | numAtom = mpiSim->getNAtomsGlobal(); | 
| 599 | < | #else | 
| 600 | < | numAtom = n_atoms; | 
| 812 | > | //pick the max cutoff radius among the processors | 
| 813 |  | #endif | 
| 602 | – | for (int i = 0; i < numAtom; i++) | 
| 603 | – | FglobalGroupMembership.push_back(globalGroupMembership[i] + 1); | 
| 604 | – |  | 
| 814 |  |  | 
| 815 | < | myMols = info->molecules; | 
| 816 | < | numMol = info->n_mol; | 
| 608 | < | for(int i  = 0; i < numMol; i++){ | 
| 609 | < | numCutoffGroups = myMols[i].getNCutoffGroups(); | 
| 610 | < | for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff); | 
| 611 | < | myCutoffGroup != NULL; | 
| 612 | < | myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){ | 
| 815 | > | return maxCutoffRadius; | 
| 816 | > | } | 
| 817 |  |  | 
| 818 | < | totalMass = myCutoffGroup->getMass(); | 
| 819 | < |  | 
| 820 | < | for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom); | 
| 821 | < | cutoffAtom != NULL; | 
| 822 | < | cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){ | 
| 823 | < | mfact.push_back(cutoffAtom->getMass()/totalMass); | 
| 824 | < | } | 
| 818 | > | void SimInfo::getCutoff(double& rcut, double& rsw) { | 
| 819 | > |  | 
| 820 | > | if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { | 
| 821 | > |  | 
| 822 | > | if (!simParams_->haveCutoffRadius()){ | 
| 823 | > | sprintf(painCave.errMsg, | 
| 824 | > | "SimCreator Warning: No value was set for the cutoffRadius.\n" | 
| 825 | > | "\tOOPSE will use a default value of 15.0 angstroms" | 
| 826 | > | "\tfor the cutoffRadius.\n"); | 
| 827 | > | painCave.isFatal = 0; | 
| 828 | > | simError(); | 
| 829 | > | rcut = 15.0; | 
| 830 | > | } else{ | 
| 831 | > | rcut = simParams_->getCutoffRadius(); | 
| 832 | > | } | 
| 833 | > |  | 
| 834 | > | if (!simParams_->haveSwitchingRadius()){ | 
| 835 | > | sprintf(painCave.errMsg, | 
| 836 | > | "SimCreator Warning: No value was set for switchingRadius.\n" | 
| 837 | > | "\tOOPSE will use a default value of\n" | 
| 838 | > | "\t0.85 * cutoffRadius for the switchingRadius\n"); | 
| 839 | > | painCave.isFatal = 0; | 
| 840 | > | simError(); | 
| 841 | > | rsw = 0.85 * rcut; | 
| 842 | > | } else{ | 
| 843 | > | rsw = simParams_->getSwitchingRadius(); | 
| 844 | > | } | 
| 845 | > |  | 
| 846 | > | } else { | 
| 847 | > | // if charge, dipole or reaction field is not used and the cutofff radius is not specified in | 
| 848 | > | //meta-data file, the maximum cutoff radius calculated from forcefiled will be used | 
| 849 | > |  | 
| 850 | > | if (simParams_->haveCutoffRadius()) { | 
| 851 | > | rcut = simParams_->getCutoffRadius(); | 
| 852 | > | } else { | 
| 853 | > | //set cutoff radius to the maximum cutoff radius based on atom types in the whole system | 
| 854 | > | rcut = calcMaxCutoffRadius(); | 
| 855 | > | } | 
| 856 | > |  | 
| 857 | > | if (simParams_->haveSwitchingRadius()) { | 
| 858 | > | rsw  = simParams_->getSwitchingRadius(); | 
| 859 | > | } else { | 
| 860 | > | rsw = rcut; | 
| 861 | > | } | 
| 862 | > |  | 
| 863 |  | } | 
| 864 |  | } | 
| 865 |  |  | 
| 866 | < | } | 
| 866 | > | void SimInfo::setupCutoff() { | 
| 867 | > | getCutoff(rcut_, rsw_); | 
| 868 | > | double rnblist = rcut_ + 1; // skin of neighbor list | 
| 869 | > |  | 
| 870 | > | //Pass these cutoff radius etc. to fortran. This function should be called once and only once | 
| 871 | > |  | 
| 872 | > | int cp =  TRADITIONAL_CUTOFF_POLICY; | 
| 873 | > | if (simParams_->haveCutoffPolicy()) { | 
| 874 | > | std::string myPolicy = simParams_->getCutoffPolicy(); | 
| 875 | > | toUpper(myPolicy); | 
| 876 | > | if (myPolicy == "MIX") { | 
| 877 | > | cp = MIX_CUTOFF_POLICY; | 
| 878 | > | } else { | 
| 879 | > | if (myPolicy == "MAX") { | 
| 880 | > | cp = MAX_CUTOFF_POLICY; | 
| 881 | > | } else { | 
| 882 | > | if (myPolicy == "TRADITIONAL") { | 
| 883 | > | cp = TRADITIONAL_CUTOFF_POLICY; | 
| 884 | > | } else { | 
| 885 | > | // throw error | 
| 886 | > | sprintf( painCave.errMsg, | 
| 887 | > | "SimInfo error: Unknown cutoffPolicy. (Input file specified %s .)\n\tcutoffPolicy must be one of: \"Mix\", \"Max\", or \"Traditional\".", myPolicy.c_str() ); | 
| 888 | > | painCave.isFatal = 1; | 
| 889 | > | simError(); | 
| 890 | > | } | 
| 891 | > | } | 
| 892 | > | } | 
| 893 | > | } | 
| 894 | > |  | 
| 895 | > |  | 
| 896 | > | if (simParams_->haveSkinThickness()) { | 
| 897 | > | double skinThickness = simParams_->getSkinThickness(); | 
| 898 | > | } | 
| 899 | > |  | 
| 900 | > | notifyFortranCutoffs(&rcut_, &rsw_, &rnblist, &cp); | 
| 901 | > | // also send cutoff notification to electrostatics | 
| 902 | > | setElectrostaticCutoffRadius(&rcut_, &rsw_); | 
| 903 | > | } | 
| 904 | > |  | 
| 905 | > | void SimInfo::setupElectrostaticSummationMethod( int isError ) { | 
| 906 | > |  | 
| 907 | > | int errorOut; | 
| 908 | > | int esm =  NONE; | 
| 909 | > | double alphaVal; | 
| 910 | > | double dielectric; | 
| 911 | > |  | 
| 912 | > | errorOut = isError; | 
| 913 | > | alphaVal = simParams_->getDampingAlpha(); | 
| 914 | > | dielectric = simParams_->getDielectric(); | 
| 915 | > |  | 
| 916 | > | if (simParams_->haveElectrostaticSummationMethod()) { | 
| 917 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); | 
| 918 | > | toUpper(myMethod); | 
| 919 | > | if (myMethod == "NONE") { | 
| 920 | > | esm = NONE; | 
| 921 | > | } else { | 
| 922 | > | if (myMethod == "UNDAMPED_WOLF") { | 
| 923 | > | esm = UNDAMPED_WOLF; | 
| 924 | > | } else { | 
| 925 | > | if (myMethod == "DAMPED_WOLF") { | 
| 926 | > | esm = DAMPED_WOLF; | 
| 927 | > | if (!simParams_->haveDampingAlpha()) { | 
| 928 | > | //throw error | 
| 929 | > | sprintf( painCave.errMsg, | 
| 930 | > | "SimInfo warning: dampingAlpha was not specified in the input file. A default value of %f (1/ang) will be used for the Damped Wolf Method.", alphaVal); | 
| 931 | > | painCave.isFatal = 0; | 
| 932 | > | simError(); | 
| 933 | > | } | 
| 934 | > | } else { | 
| 935 | > | if (myMethod == "REACTION_FIELD") { | 
| 936 | > | esm = REACTION_FIELD; | 
| 937 | > | } else { | 
| 938 | > | // throw error | 
| 939 | > | sprintf( painCave.errMsg, | 
| 940 | > | "SimInfo error: Unknown electrostaticSummationMethod. (Input file specified %s .)\n\telectrostaticSummationMethod must be one of: \"none\", \"undamped_wolf\", \"damped_wolf\", or \"reaction_field\".", myMethod.c_str() ); | 
| 941 | > | painCave.isFatal = 1; | 
| 942 | > | simError(); | 
| 943 | > | } | 
| 944 | > | } | 
| 945 | > | } | 
| 946 | > | } | 
| 947 | > | } | 
| 948 | > | // let's pass some summation method variables to fortran | 
| 949 | > | setElectrostaticSummationMethod( &esm ); | 
| 950 | > | setDampedWolfAlpha( &alphaVal ); | 
| 951 | > | setReactionFieldDielectric( &dielectric ); | 
| 952 | > | initFortranFF( &esm, &errorOut ); | 
| 953 | > | } | 
| 954 | > |  | 
| 955 | > | void SimInfo::addProperty(GenericData* genData) { | 
| 956 | > | properties_.addProperty(genData); | 
| 957 | > | } | 
| 958 | > |  | 
| 959 | > | void SimInfo::removeProperty(const std::string& propName) { | 
| 960 | > | properties_.removeProperty(propName); | 
| 961 | > | } | 
| 962 | > |  | 
| 963 | > | void SimInfo::clearProperties() { | 
| 964 | > | properties_.clearProperties(); | 
| 965 | > | } | 
| 966 | > |  | 
| 967 | > | std::vector<std::string> SimInfo::getPropertyNames() { | 
| 968 | > | return properties_.getPropertyNames(); | 
| 969 | > | } | 
| 970 | > |  | 
| 971 | > | std::vector<GenericData*> SimInfo::getProperties() { | 
| 972 | > | return properties_.getProperties(); | 
| 973 | > | } | 
| 974 | > |  | 
| 975 | > | GenericData* SimInfo::getPropertyByName(const std::string& propName) { | 
| 976 | > | return properties_.getPropertyByName(propName); | 
| 977 | > | } | 
| 978 | > |  | 
| 979 | > | void SimInfo::setSnapshotManager(SnapshotManager* sman) { | 
| 980 | > | if (sman_ == sman) { | 
| 981 | > | return; | 
| 982 | > | } | 
| 983 | > | delete sman_; | 
| 984 | > | sman_ = sman; | 
| 985 | > |  | 
| 986 | > | Molecule* mol; | 
| 987 | > | RigidBody* rb; | 
| 988 | > | Atom* atom; | 
| 989 | > | SimInfo::MoleculeIterator mi; | 
| 990 | > | Molecule::RigidBodyIterator rbIter; | 
| 991 | > | Molecule::AtomIterator atomIter;; | 
| 992 | > |  | 
| 993 | > | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 994 | > |  | 
| 995 | > | for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) { | 
| 996 | > | atom->setSnapshotManager(sman_); | 
| 997 | > | } | 
| 998 | > |  | 
| 999 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 1000 | > | rb->setSnapshotManager(sman_); | 
| 1001 | > | } | 
| 1002 | > | } | 
| 1003 | > |  | 
| 1004 | > | } | 
| 1005 | > |  | 
| 1006 | > | Vector3d SimInfo::getComVel(){ | 
| 1007 | > | SimInfo::MoleculeIterator i; | 
| 1008 | > | Molecule* mol; | 
| 1009 | > |  | 
| 1010 | > | Vector3d comVel(0.0); | 
| 1011 | > | double totalMass = 0.0; | 
| 1012 | > |  | 
| 1013 | > |  | 
| 1014 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 1015 | > | double mass = mol->getMass(); | 
| 1016 | > | totalMass += mass; | 
| 1017 | > | comVel += mass * mol->getComVel(); | 
| 1018 | > | } | 
| 1019 | > |  | 
| 1020 | > | #ifdef IS_MPI | 
| 1021 | > | double tmpMass = totalMass; | 
| 1022 | > | Vector3d tmpComVel(comVel); | 
| 1023 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1024 | > | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1025 | > | #endif | 
| 1026 | > |  | 
| 1027 | > | comVel /= totalMass; | 
| 1028 | > |  | 
| 1029 | > | return comVel; | 
| 1030 | > | } | 
| 1031 | > |  | 
| 1032 | > | Vector3d SimInfo::getCom(){ | 
| 1033 | > | SimInfo::MoleculeIterator i; | 
| 1034 | > | Molecule* mol; | 
| 1035 | > |  | 
| 1036 | > | Vector3d com(0.0); | 
| 1037 | > | double totalMass = 0.0; | 
| 1038 | > |  | 
| 1039 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 1040 | > | double mass = mol->getMass(); | 
| 1041 | > | totalMass += mass; | 
| 1042 | > | com += mass * mol->getCom(); | 
| 1043 | > | } | 
| 1044 | > |  | 
| 1045 | > | #ifdef IS_MPI | 
| 1046 | > | double tmpMass = totalMass; | 
| 1047 | > | Vector3d tmpCom(com); | 
| 1048 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1049 | > | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1050 | > | #endif | 
| 1051 | > |  | 
| 1052 | > | com /= totalMass; | 
| 1053 | > |  | 
| 1054 | > | return com; | 
| 1055 | > |  | 
| 1056 | > | } | 
| 1057 | > |  | 
| 1058 | > | std::ostream& operator <<(std::ostream& o, SimInfo& info) { | 
| 1059 | > |  | 
| 1060 | > | return o; | 
| 1061 | > | } | 
| 1062 | > |  | 
| 1063 | > |  | 
| 1064 | > | /* | 
| 1065 | > | Returns center of mass and center of mass velocity in one function call. | 
| 1066 | > | */ | 
| 1067 | > |  | 
| 1068 | > | void SimInfo::getComAll(Vector3d &com, Vector3d &comVel){ | 
| 1069 | > | SimInfo::MoleculeIterator i; | 
| 1070 | > | Molecule* mol; | 
| 1071 | > |  | 
| 1072 | > |  | 
| 1073 | > | double totalMass = 0.0; | 
| 1074 | > |  | 
| 1075 | > |  | 
| 1076 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 1077 | > | double mass = mol->getMass(); | 
| 1078 | > | totalMass += mass; | 
| 1079 | > | com += mass * mol->getCom(); | 
| 1080 | > | comVel += mass * mol->getComVel(); | 
| 1081 | > | } | 
| 1082 | > |  | 
| 1083 | > | #ifdef IS_MPI | 
| 1084 | > | double tmpMass = totalMass; | 
| 1085 | > | Vector3d tmpCom(com); | 
| 1086 | > | Vector3d tmpComVel(comVel); | 
| 1087 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1088 | > | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1089 | > | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1090 | > | #endif | 
| 1091 | > |  | 
| 1092 | > | com /= totalMass; | 
| 1093 | > | comVel /= totalMass; | 
| 1094 | > | } | 
| 1095 | > |  | 
| 1096 | > | /* | 
| 1097 | > | Return intertia tensor for entire system and angular momentum Vector. | 
| 1098 | > |  | 
| 1099 | > |  | 
| 1100 | > | [  Ixx -Ixy  -Ixz ] | 
| 1101 | > | J =| -Iyx  Iyy  -Iyz | | 
| 1102 | > | [ -Izx -Iyz   Izz ] | 
| 1103 | > | */ | 
| 1104 | > |  | 
| 1105 | > | void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){ | 
| 1106 | > |  | 
| 1107 | > |  | 
| 1108 | > | double xx = 0.0; | 
| 1109 | > | double yy = 0.0; | 
| 1110 | > | double zz = 0.0; | 
| 1111 | > | double xy = 0.0; | 
| 1112 | > | double xz = 0.0; | 
| 1113 | > | double yz = 0.0; | 
| 1114 | > | Vector3d com(0.0); | 
| 1115 | > | Vector3d comVel(0.0); | 
| 1116 | > |  | 
| 1117 | > | getComAll(com, comVel); | 
| 1118 | > |  | 
| 1119 | > | SimInfo::MoleculeIterator i; | 
| 1120 | > | Molecule* mol; | 
| 1121 | > |  | 
| 1122 | > | Vector3d thisq(0.0); | 
| 1123 | > | Vector3d thisv(0.0); | 
| 1124 | > |  | 
| 1125 | > | double thisMass = 0.0; | 
| 1126 | > |  | 
| 1127 | > |  | 
| 1128 | > |  | 
| 1129 | > |  | 
| 1130 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 1131 | > |  | 
| 1132 | > | thisq = mol->getCom()-com; | 
| 1133 | > | thisv = mol->getComVel()-comVel; | 
| 1134 | > | thisMass = mol->getMass(); | 
| 1135 | > | // Compute moment of intertia coefficients. | 
| 1136 | > | xx += thisq[0]*thisq[0]*thisMass; | 
| 1137 | > | yy += thisq[1]*thisq[1]*thisMass; | 
| 1138 | > | zz += thisq[2]*thisq[2]*thisMass; | 
| 1139 | > |  | 
| 1140 | > | // compute products of intertia | 
| 1141 | > | xy += thisq[0]*thisq[1]*thisMass; | 
| 1142 | > | xz += thisq[0]*thisq[2]*thisMass; | 
| 1143 | > | yz += thisq[1]*thisq[2]*thisMass; | 
| 1144 | > |  | 
| 1145 | > | angularMomentum += cross( thisq, thisv ) * thisMass; | 
| 1146 | > |  | 
| 1147 | > | } | 
| 1148 | > |  | 
| 1149 | > |  | 
| 1150 | > | inertiaTensor(0,0) = yy + zz; | 
| 1151 | > | inertiaTensor(0,1) = -xy; | 
| 1152 | > | inertiaTensor(0,2) = -xz; | 
| 1153 | > | inertiaTensor(1,0) = -xy; | 
| 1154 | > | inertiaTensor(1,1) = xx + zz; | 
| 1155 | > | inertiaTensor(1,2) = -yz; | 
| 1156 | > | inertiaTensor(2,0) = -xz; | 
| 1157 | > | inertiaTensor(2,1) = -yz; | 
| 1158 | > | inertiaTensor(2,2) = xx + yy; | 
| 1159 | > |  | 
| 1160 | > | #ifdef IS_MPI | 
| 1161 | > | Mat3x3d tmpI(inertiaTensor); | 
| 1162 | > | Vector3d tmpAngMom; | 
| 1163 | > | MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1164 | > | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1165 | > | #endif | 
| 1166 | > |  | 
| 1167 | > | return; | 
| 1168 | > | } | 
| 1169 | > |  | 
| 1170 | > | //Returns the angular momentum of the system | 
| 1171 | > | Vector3d SimInfo::getAngularMomentum(){ | 
| 1172 | > |  | 
| 1173 | > | Vector3d com(0.0); | 
| 1174 | > | Vector3d comVel(0.0); | 
| 1175 | > | Vector3d angularMomentum(0.0); | 
| 1176 | > |  | 
| 1177 | > | getComAll(com,comVel); | 
| 1178 | > |  | 
| 1179 | > | SimInfo::MoleculeIterator i; | 
| 1180 | > | Molecule* mol; | 
| 1181 | > |  | 
| 1182 | > | Vector3d thisr(0.0); | 
| 1183 | > | Vector3d thisp(0.0); | 
| 1184 | > |  | 
| 1185 | > | double thisMass; | 
| 1186 | > |  | 
| 1187 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 1188 | > | thisMass = mol->getMass(); | 
| 1189 | > | thisr = mol->getCom()-com; | 
| 1190 | > | thisp = (mol->getComVel()-comVel)*thisMass; | 
| 1191 | > |  | 
| 1192 | > | angularMomentum += cross( thisr, thisp ); | 
| 1193 | > |  | 
| 1194 | > | } | 
| 1195 | > |  | 
| 1196 | > | #ifdef IS_MPI | 
| 1197 | > | Vector3d tmpAngMom; | 
| 1198 | > | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 1199 | > | #endif | 
| 1200 | > |  | 
| 1201 | > | return angularMomentum; | 
| 1202 | > | } | 
| 1203 | > |  | 
| 1204 | > |  | 
| 1205 | > | }//end namespace oopse | 
| 1206 | > |  |