# | 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 | > | #include <map> |
52 | ||
53 | #include "brains/SimInfo.hpp" | |
54 | < | #define __C |
55 | < | #include "brains/fSimulation.h" |
54 | > | #include "math/Vector3.hpp" |
55 | > | #include "primitives/Molecule.hpp" |
56 | > | #include "UseTheForce/fCutoffPolicy.h" |
57 | > | #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h" |
58 | > | #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h" |
59 | > | #include "UseTheForce/DarkSide/fSwitchingFunctionType.h" |
60 | > | #include "UseTheForce/doForces_interface.h" |
61 | > | #include "UseTheForce/DarkSide/electrostatic_interface.h" |
62 | > | #include "UseTheForce/DarkSide/switcheroo_interface.h" |
63 | > | #include "utils/MemoryUtils.hpp" |
64 | #include "utils/simError.h" | |
65 | + | #include "selection/SelectionManager.hpp" |
66 | + | #include "io/ForceFieldOptions.hpp" |
67 | + | #include "UseTheForce/ForceField.hpp" |
68 | ||
13 | – | #include "UseTheForce/fortranWrappers.hpp" |
14 | – | |
15 | – | #include "math/MatVec3.h" |
16 | – | |
69 | #ifdef IS_MPI | |
70 | < | #include "brains/mpiSimulation.hpp" |
71 | < | #endif |
70 | > | #include "UseTheForce/mpiComponentPlan.h" |
71 | > | #include "UseTheForce/DarkSide/simParallel_interface.h" |
72 | > | #endif |
73 | ||
74 | < | inline double roundMe( double x ){ |
75 | < | return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); |
76 | < | } |
77 | < | |
78 | < | inline double min( double a, double b ){ |
79 | < | return (a < b ) ? a : b; |
80 | < | } |
74 | > | namespace oopse { |
75 | > | std::set<int> getRigidSet(int index, std::map<int, std::set<int> >& container) { |
76 | > | std::map<int, std::set<int> >::iterator i = container.find(index); |
77 | > | std::set<int> result; |
78 | > | if (i != container.end()) { |
79 | > | result = i->second; |
80 | > | } |
81 | ||
82 | < | SimInfo* currentInfo; |
83 | < | |
31 | < | SimInfo::SimInfo(){ |
32 | < | |
33 | < | n_constraints = 0; |
34 | < | 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; |
46 | < | |
47 | < | haveRcut = 0; |
48 | < | haveRsw = 0; |
49 | < | boxIsInit = 0; |
82 | > | return result; |
83 | > | } |
84 | ||
85 | < | resetTime = 1e99; |
85 | > | SimInfo::SimInfo(ForceField* ff, Globals* simParams) : |
86 | > | forceField_(ff), simParams_(simParams), |
87 | > | ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), |
88 | > | nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), |
89 | > | nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
90 | > | nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0), |
91 | > | nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), |
92 | > | sman_(NULL), fortranInitialized_(false), calcBoxDipole_(false) { |
93 | ||
94 | < | orthoRhombic = 0; |
95 | < | orthoTolerance = 1E-6; |
96 | < | useInitXSstate = true; |
94 | > | MoleculeStamp* molStamp; |
95 | > | int nMolWithSameStamp; |
96 | > | int nCutoffAtoms = 0; // number of atoms belong to cutoff groups |
97 | > | int nGroups = 0; //total cutoff groups defined in meta-data file |
98 | > | CutoffGroupStamp* cgStamp; |
99 | > | RigidBodyStamp* rbStamp; |
100 | > | int nRigidAtoms = 0; |
101 | > | std::vector<Component*> components = simParams->getComponents(); |
102 | > | |
103 | > | for (std::vector<Component*>::iterator i = components.begin(); i !=components.end(); ++i) { |
104 | > | molStamp = (*i)->getMoleculeStamp(); |
105 | > | nMolWithSameStamp = (*i)->getNMol(); |
106 | > | |
107 | > | addMoleculeStamp(molStamp, nMolWithSameStamp); |
108 | ||
109 | < | usePBC = 0; |
110 | < | 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; |
109 | > | //calculate atoms in molecules |
110 | > | nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; |
111 | ||
112 | < | haveCutoffGroups = false; |
112 | > | //calculate atoms in cutoff groups |
113 | > | int nAtomsInGroups = 0; |
114 | > | int nCutoffGroupsInStamp = molStamp->getNCutoffGroups(); |
115 | > | |
116 | > | for (int j=0; j < nCutoffGroupsInStamp; j++) { |
117 | > | cgStamp = molStamp->getCutoffGroupStamp(j); |
118 | > | nAtomsInGroups += cgStamp->getNMembers(); |
119 | > | } |
120 | ||
121 | < | excludes = Exclude::Instance(); |
121 | > | nGroups += nCutoffGroupsInStamp * nMolWithSameStamp; |
122 | ||
123 | < | myConfiguration = new SimState(); |
123 | > | nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp; |
124 | ||
125 | < | has_minimizer = false; |
126 | < | the_minimizer =NULL; |
125 | > | //calculate atoms in rigid bodies |
126 | > | int nAtomsInRigidBodies = 0; |
127 | > | int nRigidBodiesInStamp = molStamp->getNRigidBodies(); |
128 | > | |
129 | > | for (int j=0; j < nRigidBodiesInStamp; j++) { |
130 | > | rbStamp = molStamp->getRigidBodyStamp(j); |
131 | > | nAtomsInRigidBodies += rbStamp->getNMembers(); |
132 | > | } |
133 | ||
134 | < | ngroup = 0; |
134 | > | nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp; |
135 | > | nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp; |
136 | > | |
137 | > | } |
138 | ||
139 | < | wrapMeSimInfo( this ); |
140 | < | } |
139 | > | //every free atom (atom does not belong to cutoff groups) is a cutoff |
140 | > | //group therefore the total number of cutoff groups in the system is |
141 | > | //equal to the total number of atoms minus number of atoms belong to |
142 | > | //cutoff group defined in meta-data file plus the number of cutoff |
143 | > | //groups defined in meta-data file |
144 | > | nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; |
145 | ||
146 | < | |
147 | < | SimInfo::~SimInfo(){ |
148 | < | |
149 | < | delete myConfiguration; |
150 | < | |
151 | < | map<string, GenericData*>::iterator i; |
146 | > | //every free atom (atom does not belong to rigid bodies) is an |
147 | > | //integrable object therefore the total number of integrable objects |
148 | > | //in the system is equal to the total number of atoms minus number of |
149 | > | //atoms belong to rigid body defined in meta-data file plus the number |
150 | > | //of rigid bodies defined in meta-data file |
151 | > | nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms |
152 | > | + nGlobalRigidBodies_; |
153 | ||
154 | < | for(i = properties.begin(); i != properties.end(); i++) |
90 | < | delete (*i).second; |
154 | > | nGlobalMols_ = molStampIds_.size(); |
155 | ||
156 | < | } |
156 | > | #ifdef IS_MPI |
157 | > | molToProcMap_.resize(nGlobalMols_); |
158 | > | #endif |
159 | ||
160 | < | void SimInfo::setBox(double newBox[3]) { |
95 | < | |
96 | < | int i, j; |
97 | < | double tempMat[3][3]; |
160 | > | } |
161 | ||
162 | < | for(i=0; i<3; i++) |
163 | < | for (j=0; j<3; j++) tempMat[i][j] = 0.0;; |
162 | > | SimInfo::~SimInfo() { |
163 | > | std::map<int, Molecule*>::iterator i; |
164 | > | for (i = molecules_.begin(); i != molecules_.end(); ++i) { |
165 | > | delete i->second; |
166 | > | } |
167 | > | molecules_.clear(); |
168 | > | |
169 | > | delete sman_; |
170 | > | delete simParams_; |
171 | > | delete forceField_; |
172 | > | } |
173 | ||
174 | < | tempMat[0][0] = newBox[0]; |
175 | < | tempMat[1][1] = newBox[1]; |
176 | < | tempMat[2][2] = newBox[2]; |
174 | > | int SimInfo::getNGlobalConstraints() { |
175 | > | int nGlobalConstraints; |
176 | > | #ifdef IS_MPI |
177 | > | MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM, |
178 | > | MPI_COMM_WORLD); |
179 | > | #else |
180 | > | nGlobalConstraints = nConstraints_; |
181 | > | #endif |
182 | > | return nGlobalConstraints; |
183 | > | } |
184 | ||
185 | < | setBoxM( tempMat ); |
185 | > | bool SimInfo::addMolecule(Molecule* mol) { |
186 | > | MoleculeIterator i; |
187 | ||
188 | < | } |
188 | > | i = molecules_.find(mol->getGlobalIndex()); |
189 | > | if (i == molecules_.end() ) { |
190 | ||
191 | < | void SimInfo::setBoxM( double theBox[3][3] ){ |
192 | < | |
193 | < | int i, j; |
194 | < | double FortranHmat[9]; // to preserve compatibility with Fortran the |
195 | < | // ordering in the array is as follows: |
196 | < | // [ 0 3 6 ] |
197 | < | // [ 1 4 7 ] |
198 | < | // [ 2 5 8 ] |
199 | < | double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
200 | < | |
201 | < | if( !boxIsInit ) boxIsInit = 1; |
202 | < | |
203 | < | for(i=0; i < 3; i++) |
204 | < | for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j]; |
205 | < | |
206 | < | 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]; |
191 | > | molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol)); |
192 | > | |
193 | > | nAtoms_ += mol->getNAtoms(); |
194 | > | nBonds_ += mol->getNBonds(); |
195 | > | nBends_ += mol->getNBends(); |
196 | > | nTorsions_ += mol->getNTorsions(); |
197 | > | nRigidBodies_ += mol->getNRigidBodies(); |
198 | > | nIntegrableObjects_ += mol->getNIntegrableObjects(); |
199 | > | nCutoffGroups_ += mol->getNCutoffGroups(); |
200 | > | nConstraints_ += mol->getNConstraintPairs(); |
201 | > | |
202 | > | addExcludePairs(mol); |
203 | > | |
204 | > | return true; |
205 | > | } else { |
206 | > | return false; |
207 | } | |
208 | } | |
209 | ||
210 | < | setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic); |
211 | < | |
212 | < | } |
138 | < | |
210 | > | bool SimInfo::removeMolecule(Molecule* mol) { |
211 | > | MoleculeIterator i; |
212 | > | i = molecules_.find(mol->getGlobalIndex()); |
213 | ||
214 | < | void SimInfo::getBoxM (double theBox[3][3]) { |
214 | > | if (i != molecules_.end() ) { |
215 | ||
216 | < | int i, j; |
217 | < | for(i=0; i<3; i++) |
218 | < | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]; |
219 | < | } |
216 | > | assert(mol == i->second); |
217 | > | |
218 | > | nAtoms_ -= mol->getNAtoms(); |
219 | > | nBonds_ -= mol->getNBonds(); |
220 | > | nBends_ -= mol->getNBends(); |
221 | > | nTorsions_ -= mol->getNTorsions(); |
222 | > | nRigidBodies_ -= mol->getNRigidBodies(); |
223 | > | nIntegrableObjects_ -= mol->getNIntegrableObjects(); |
224 | > | nCutoffGroups_ -= mol->getNCutoffGroups(); |
225 | > | nConstraints_ -= mol->getNConstraintPairs(); |
226 | ||
227 | + | removeExcludePairs(mol); |
228 | + | molecules_.erase(mol->getGlobalIndex()); |
229 | ||
230 | < | void SimInfo::scaleBox(double scale) { |
231 | < | double theBox[3][3]; |
232 | < | int i, j; |
230 | > | delete mol; |
231 | > | |
232 | > | return true; |
233 | > | } else { |
234 | > | return false; |
235 | > | } |
236 | ||
152 | – | // cerr << "Scaling box by " << scale << "\n"; |
237 | ||
238 | < | for(i=0; i<3; i++) |
155 | < | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale; |
238 | > | } |
239 | ||
240 | < | setBoxM(theBox); |
240 | > | |
241 | > | Molecule* SimInfo::beginMolecule(MoleculeIterator& i) { |
242 | > | i = molecules_.begin(); |
243 | > | return i == molecules_.end() ? NULL : i->second; |
244 | > | } |
245 | ||
246 | < | } |
246 | > | Molecule* SimInfo::nextMolecule(MoleculeIterator& i) { |
247 | > | ++i; |
248 | > | return i == molecules_.end() ? NULL : i->second; |
249 | > | } |
250 | ||
161 | – | void SimInfo::calcHmatInv( void ) { |
162 | – | |
163 | – | int oldOrtho; |
164 | – | int i,j; |
165 | – | double smallDiag; |
166 | – | double tol; |
167 | – | double sanity[3][3]; |
251 | ||
252 | < | invertMat3( Hmat, HmatInv ); |
252 | > | void SimInfo::calcNdf() { |
253 | > | int ndf_local; |
254 | > | MoleculeIterator i; |
255 | > | std::vector<StuntDouble*>::iterator j; |
256 | > | Molecule* mol; |
257 | > | StuntDouble* integrableObject; |
258 | ||
259 | < | // check to see if Hmat is orthorhombic |
260 | < | |
261 | < | oldOrtho = orthoRhombic; |
259 | > | ndf_local = 0; |
260 | > | |
261 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
262 | > | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
263 | > | integrableObject = mol->nextIntegrableObject(j)) { |
264 | ||
265 | < | 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; |
265 | > | ndf_local += 3; |
266 | ||
267 | < | orthoRhombic = 1; |
268 | < | |
269 | < | for (i = 0; i < 3; i++ ) { |
270 | < | for (j = 0 ; j < 3; j++) { |
271 | < | if (i != j) { |
272 | < | if (orthoRhombic) { |
273 | < | if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
274 | < | } |
267 | > | if (integrableObject->isDirectional()) { |
268 | > | if (integrableObject->isLinear()) { |
269 | > | ndf_local += 2; |
270 | > | } else { |
271 | > | ndf_local += 3; |
272 | > | } |
273 | > | } |
274 | > | |
275 | } | |
276 | } | |
190 | – | } |
191 | – | |
192 | – | if( oldOrtho != orthoRhombic ){ |
277 | ||
278 | < | if( orthoRhombic ) { |
279 | < | 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 | < | } |
278 | > | // n_constraints is local, so subtract them on each processor |
279 | > | ndf_local -= nConstraints_; |
280 | ||
281 | < | void SimInfo::calcBoxL( void ){ |
281 | > | #ifdef IS_MPI |
282 | > | MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
283 | > | #else |
284 | > | ndf_ = ndf_local; |
285 | > | #endif |
286 | ||
287 | < | double dx, dy, dz, dsq; |
287 | > | // nZconstraints_ is global, as are the 3 COM translations for the |
288 | > | // entire system: |
289 | > | ndf_ = ndf_ - 3 - nZconstraint_; |
290 | ||
291 | < | // boxVol = Determinant of Hmat |
291 | > | } |
292 | ||
293 | < | boxVol = matDet3( Hmat ); |
293 | > | int SimInfo::getFdf() { |
294 | > | #ifdef IS_MPI |
295 | > | MPI_Allreduce(&fdf_local,&fdf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
296 | > | #else |
297 | > | fdf_ = fdf_local; |
298 | > | #endif |
299 | > | return fdf_; |
300 | > | } |
301 | > | |
302 | > | void SimInfo::calcNdfRaw() { |
303 | > | int ndfRaw_local; |
304 | ||
305 | < | // boxLx |
306 | < | |
307 | < | dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; |
308 | < | dsq = dx*dx + dy*dy + dz*dz; |
232 | < | boxL[0] = sqrt( dsq ); |
233 | < | //maxCutoff = 0.5 * boxL[0]; |
305 | > | MoleculeIterator i; |
306 | > | std::vector<StuntDouble*>::iterator j; |
307 | > | Molecule* mol; |
308 | > | StuntDouble* integrableObject; |
309 | ||
310 | < | // boxLy |
311 | < | |
237 | < | dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; |
238 | < | dsq = dx*dx + dy*dy + dz*dz; |
239 | < | boxL[1] = sqrt( dsq ); |
240 | < | //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
241 | < | |
242 | < | |
243 | < | // boxLz |
244 | < | |
245 | < | dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; |
246 | < | dsq = dx*dx + dy*dy + dz*dz; |
247 | < | boxL[2] = sqrt( dsq ); |
248 | < | //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
249 | < | |
250 | < | //calculate the max cutoff |
251 | < | maxCutoff = calcMaxCutOff(); |
252 | < | |
253 | < | checkCutOffs(); |
254 | < | |
255 | < | } |
256 | < | |
257 | < | |
258 | < | double SimInfo::calcMaxCutOff(){ |
259 | < | |
260 | < | double ri[3], rj[3], rk[3]; |
261 | < | double rij[3], rjk[3], rki[3]; |
262 | < | double minDist; |
263 | < | |
264 | < | ri[0] = Hmat[0][0]; |
265 | < | ri[1] = Hmat[1][0]; |
266 | < | ri[2] = Hmat[2][0]; |
267 | < | |
268 | < | rj[0] = Hmat[0][1]; |
269 | < | rj[1] = Hmat[1][1]; |
270 | < | rj[2] = Hmat[2][1]; |
271 | < | |
272 | < | rk[0] = Hmat[0][2]; |
273 | < | rk[1] = Hmat[1][2]; |
274 | < | rk[2] = Hmat[2][2]; |
310 | > | // Raw degrees of freedom that we have to set |
311 | > | ndfRaw_local = 0; |
312 | ||
313 | < | crossProduct3(ri, rj, rij); |
314 | < | distXY = dotProduct3(rk,rij) / norm3(rij); |
313 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
314 | > | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; |
315 | > | integrableObject = mol->nextIntegrableObject(j)) { |
316 | ||
317 | < | crossProduct3(rj,rk, rjk); |
280 | < | distYZ = dotProduct3(ri,rjk) / norm3(rjk); |
317 | > | ndfRaw_local += 3; |
318 | ||
319 | < | crossProduct3(rk,ri, rki); |
320 | < | distZX = dotProduct3(rj,rki) / norm3(rki); |
321 | < | |
322 | < | minDist = min(min(distXY, distYZ), distZX); |
323 | < | return minDist/2; |
324 | < | |
325 | < | } |
326 | < | |
327 | < | void SimInfo::wrapVector( double thePos[3] ){ |
328 | < | |
292 | < | int i; |
293 | < | double scaled[3]; |
294 | < | |
295 | < | if( !orthoRhombic ){ |
296 | < | // calc the scaled coordinates. |
297 | < | |
298 | < | |
299 | < | matVecMul3(HmatInv, thePos, scaled); |
319 | > | if (integrableObject->isDirectional()) { |
320 | > | if (integrableObject->isLinear()) { |
321 | > | ndfRaw_local += 2; |
322 | > | } else { |
323 | > | ndfRaw_local += 3; |
324 | > | } |
325 | > | } |
326 | > | |
327 | > | } |
328 | > | } |
329 | ||
330 | < | for(i=0; i<3; i++) |
331 | < | scaled[i] -= roundMe(scaled[i]); |
332 | < | |
333 | < | // calc the wrapped real coordinates from the wrapped scaled coordinates |
334 | < | |
306 | < | matVecMul3(Hmat, scaled, thePos); |
307 | < | |
330 | > | #ifdef IS_MPI |
331 | > | MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
332 | > | #else |
333 | > | ndfRaw_ = ndfRaw_local; |
334 | > | #endif |
335 | } | |
309 | – | else{ |
310 | – | // calc the scaled coordinates. |
311 | – | |
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 | – | } |
336 | ||
337 | + | void SimInfo::calcNdfTrans() { |
338 | + | int ndfTrans_local; |
339 | ||
340 | < | int SimInfo::getNDF(){ |
330 | < | int ndf_local; |
340 | > | ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; |
341 | ||
332 | – | ndf_local = 0; |
333 | – | |
334 | – | for(int i = 0; i < integrableObjects.size(); i++){ |
335 | – | ndf_local += 3; |
336 | – | if (integrableObjects[i]->isDirectional()) { |
337 | – | if (integrableObjects[i]->isLinear()) |
338 | – | ndf_local += 2; |
339 | – | else |
340 | – | ndf_local += 3; |
341 | – | } |
342 | – | } |
342 | ||
344 | – | // n_constraints is local, so subtract them on each processor: |
345 | – | |
346 | – | ndf_local -= n_constraints; |
347 | – | |
343 | #ifdef IS_MPI | |
344 | < | MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
344 | > | MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
345 | #else | |
346 | < | ndf = ndf_local; |
346 | > | ndfTrans_ = ndfTrans_local; |
347 | #endif | |
348 | ||
349 | < | // nZconstraints is global, as are the 3 COM translations for the |
350 | < | // entire system: |
349 | > | ndfTrans_ = ndfTrans_ - 3 - nZconstraint_; |
350 | > | |
351 | > | } |
352 | ||
353 | < | ndf = ndf - 3 - nZconstraints; |
353 | > | void SimInfo::addExcludePairs(Molecule* mol) { |
354 | > | std::vector<Bond*>::iterator bondIter; |
355 | > | std::vector<Bend*>::iterator bendIter; |
356 | > | std::vector<Torsion*>::iterator torsionIter; |
357 | > | Bond* bond; |
358 | > | Bend* bend; |
359 | > | Torsion* torsion; |
360 | > | int a; |
361 | > | int b; |
362 | > | int c; |
363 | > | int d; |
364 | ||
365 | < | return ndf; |
360 | < | } |
365 | > | std::map<int, std::set<int> > atomGroups; |
366 | ||
367 | < | int SimInfo::getNDFraw() { |
368 | < | int ndfRaw_local; |
367 | > | Molecule::RigidBodyIterator rbIter; |
368 | > | RigidBody* rb; |
369 | > | Molecule::IntegrableObjectIterator ii; |
370 | > | StuntDouble* integrableObject; |
371 | > | |
372 | > | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
373 | > | integrableObject = mol->nextIntegrableObject(ii)) { |
374 | ||
375 | < | // Raw degrees of freedom that we have to set |
376 | < | ndfRaw_local = 0; |
375 | > | if (integrableObject->isRigidBody()) { |
376 | > | rb = static_cast<RigidBody*>(integrableObject); |
377 | > | std::vector<Atom*> atoms = rb->getAtoms(); |
378 | > | std::set<int> rigidAtoms; |
379 | > | for (int i = 0; i < atoms.size(); ++i) { |
380 | > | rigidAtoms.insert(atoms[i]->getGlobalIndex()); |
381 | > | } |
382 | > | for (int i = 0; i < atoms.size(); ++i) { |
383 | > | atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); |
384 | > | } |
385 | > | } else { |
386 | > | std::set<int> oneAtomSet; |
387 | > | oneAtomSet.insert(integrableObject->getGlobalIndex()); |
388 | > | atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); |
389 | > | } |
390 | > | } |
391 | ||
368 | – | for(int i = 0; i < integrableObjects.size(); i++){ |
369 | – | ndfRaw_local += 3; |
370 | – | if (integrableObjects[i]->isDirectional()) { |
371 | – | if (integrableObjects[i]->isLinear()) |
372 | – | ndfRaw_local += 2; |
373 | – | else |
374 | – | ndfRaw_local += 3; |
375 | – | } |
376 | – | } |
392 | ||
393 | < | #ifdef IS_MPI |
394 | < | MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
395 | < | #else |
396 | < | ndfRaw = ndfRaw_local; |
397 | < | #endif |
393 | > | |
394 | > | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { |
395 | > | a = bond->getAtomA()->getGlobalIndex(); |
396 | > | b = bond->getAtomB()->getGlobalIndex(); |
397 | > | exclude_.addPair(a, b); |
398 | > | } |
399 | ||
400 | < | return ndfRaw; |
401 | < | } |
400 | > | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { |
401 | > | a = bend->getAtomA()->getGlobalIndex(); |
402 | > | b = bend->getAtomB()->getGlobalIndex(); |
403 | > | c = bend->getAtomC()->getGlobalIndex(); |
404 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
405 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
406 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
407 | ||
408 | < | int SimInfo::getNDFtranslational() { |
409 | < | int ndfTrans_local; |
408 | > | exclude_.addPairs(rigidSetA, rigidSetB); |
409 | > | exclude_.addPairs(rigidSetA, rigidSetC); |
410 | > | exclude_.addPairs(rigidSetB, rigidSetC); |
411 | > | |
412 | > | //exclude_.addPair(a, b); |
413 | > | //exclude_.addPair(a, c); |
414 | > | //exclude_.addPair(b, c); |
415 | > | } |
416 | ||
417 | < | ndfTrans_local = 3 * integrableObjects.size() - n_constraints; |
417 | > | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { |
418 | > | a = torsion->getAtomA()->getGlobalIndex(); |
419 | > | b = torsion->getAtomB()->getGlobalIndex(); |
420 | > | c = torsion->getAtomC()->getGlobalIndex(); |
421 | > | d = torsion->getAtomD()->getGlobalIndex(); |
422 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
423 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
424 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
425 | > | std::set<int> rigidSetD = getRigidSet(d, atomGroups); |
426 | ||
427 | + | exclude_.addPairs(rigidSetA, rigidSetB); |
428 | + | exclude_.addPairs(rigidSetA, rigidSetC); |
429 | + | exclude_.addPairs(rigidSetA, rigidSetD); |
430 | + | exclude_.addPairs(rigidSetB, rigidSetC); |
431 | + | exclude_.addPairs(rigidSetB, rigidSetD); |
432 | + | exclude_.addPairs(rigidSetC, rigidSetD); |
433 | ||
434 | < | #ifdef IS_MPI |
435 | < | MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
436 | < | #else |
437 | < | ndfTrans = ndfTrans_local; |
438 | < | #endif |
434 | > | /* |
435 | > | exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetB.begin(), rigidSetB.end()); |
436 | > | exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetC.begin(), rigidSetC.end()); |
437 | > | exclude_.addPairs(rigidSetA.begin(), rigidSetA.end(), rigidSetD.begin(), rigidSetD.end()); |
438 | > | exclude_.addPairs(rigidSetB.begin(), rigidSetB.end(), rigidSetC.begin(), rigidSetC.end()); |
439 | > | exclude_.addPairs(rigidSetB.begin(), rigidSetB.end(), rigidSetD.begin(), rigidSetD.end()); |
440 | > | exclude_.addPairs(rigidSetC.begin(), rigidSetC.end(), rigidSetD.begin(), rigidSetD.end()); |
441 | > | |
442 | > | |
443 | > | exclude_.addPair(a, b); |
444 | > | exclude_.addPair(a, c); |
445 | > | exclude_.addPair(a, d); |
446 | > | exclude_.addPair(b, c); |
447 | > | exclude_.addPair(b, d); |
448 | > | exclude_.addPair(c, d); |
449 | > | */ |
450 | > | } |
451 | ||
452 | < | ndfTrans = ndfTrans - 3 - nZconstraints; |
452 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
453 | > | std::vector<Atom*> atoms = rb->getAtoms(); |
454 | > | for (int i = 0; i < atoms.size() -1 ; ++i) { |
455 | > | for (int j = i + 1; j < atoms.size(); ++j) { |
456 | > | a = atoms[i]->getGlobalIndex(); |
457 | > | b = atoms[j]->getGlobalIndex(); |
458 | > | exclude_.addPair(a, b); |
459 | > | } |
460 | > | } |
461 | > | } |
462 | ||
463 | < | return ndfTrans; |
402 | < | } |
463 | > | } |
464 | ||
465 | < | int SimInfo::getTotIntegrableObjects() { |
466 | < | int nObjs_local; |
467 | < | int nObjs; |
465 | > | void SimInfo::removeExcludePairs(Molecule* mol) { |
466 | > | std::vector<Bond*>::iterator bondIter; |
467 | > | std::vector<Bend*>::iterator bendIter; |
468 | > | std::vector<Torsion*>::iterator torsionIter; |
469 | > | Bond* bond; |
470 | > | Bend* bend; |
471 | > | Torsion* torsion; |
472 | > | int a; |
473 | > | int b; |
474 | > | int c; |
475 | > | int d; |
476 | ||
477 | < | nObjs_local = integrableObjects.size(); |
477 | > | std::map<int, std::set<int> > atomGroups; |
478 | > | |
479 | > | Molecule::RigidBodyIterator rbIter; |
480 | > | RigidBody* rb; |
481 | > | Molecule::IntegrableObjectIterator ii; |
482 | > | StuntDouble* integrableObject; |
483 | > | |
484 | > | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
485 | > | integrableObject = mol->nextIntegrableObject(ii)) { |
486 | ||
487 | + | if (integrableObject->isRigidBody()) { |
488 | + | rb = static_cast<RigidBody*>(integrableObject); |
489 | + | std::vector<Atom*> atoms = rb->getAtoms(); |
490 | + | std::set<int> rigidAtoms; |
491 | + | for (int i = 0; i < atoms.size(); ++i) { |
492 | + | rigidAtoms.insert(atoms[i]->getGlobalIndex()); |
493 | + | } |
494 | + | for (int i = 0; i < atoms.size(); ++i) { |
495 | + | atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms)); |
496 | + | } |
497 | + | } else { |
498 | + | std::set<int> oneAtomSet; |
499 | + | oneAtomSet.insert(integrableObject->getGlobalIndex()); |
500 | + | atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet)); |
501 | + | } |
502 | + | } |
503 | ||
504 | < | #ifdef IS_MPI |
505 | < | MPI_Allreduce(&nObjs_local,&nObjs,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
506 | < | #else |
507 | < | nObjs = nObjs_local; |
508 | < | #endif |
504 | > | |
505 | > | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { |
506 | > | a = bond->getAtomA()->getGlobalIndex(); |
507 | > | b = bond->getAtomB()->getGlobalIndex(); |
508 | > | exclude_.removePair(a, b); |
509 | > | } |
510 | ||
511 | + | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { |
512 | + | a = bend->getAtomA()->getGlobalIndex(); |
513 | + | b = bend->getAtomB()->getGlobalIndex(); |
514 | + | c = bend->getAtomC()->getGlobalIndex(); |
515 | ||
516 | < | return nObjs; |
517 | < | } |
516 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
517 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
518 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
519 | ||
520 | < | void SimInfo::refreshSim(){ |
520 | > | exclude_.removePairs(rigidSetA, rigidSetB); |
521 | > | exclude_.removePairs(rigidSetA, rigidSetC); |
522 | > | exclude_.removePairs(rigidSetB, rigidSetC); |
523 | > | |
524 | > | //exclude_.removePair(a, b); |
525 | > | //exclude_.removePair(a, c); |
526 | > | //exclude_.removePair(b, c); |
527 | > | } |
528 | ||
529 | < | simtype fInfo; |
530 | < | int isError; |
531 | < | int n_global; |
532 | < | int* excl; |
529 | > | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { |
530 | > | a = torsion->getAtomA()->getGlobalIndex(); |
531 | > | b = torsion->getAtomB()->getGlobalIndex(); |
532 | > | c = torsion->getAtomC()->getGlobalIndex(); |
533 | > | d = torsion->getAtomD()->getGlobalIndex(); |
534 | ||
535 | < | fInfo.dielect = 0.0; |
535 | > | std::set<int> rigidSetA = getRigidSet(a, atomGroups); |
536 | > | std::set<int> rigidSetB = getRigidSet(b, atomGroups); |
537 | > | std::set<int> rigidSetC = getRigidSet(c, atomGroups); |
538 | > | std::set<int> rigidSetD = getRigidSet(d, atomGroups); |
539 | ||
540 | < | if( useDipoles ){ |
541 | < | if( useReactionField )fInfo.dielect = dielectric; |
540 | > | exclude_.removePairs(rigidSetA, rigidSetB); |
541 | > | exclude_.removePairs(rigidSetA, rigidSetC); |
542 | > | exclude_.removePairs(rigidSetA, rigidSetD); |
543 | > | exclude_.removePairs(rigidSetB, rigidSetC); |
544 | > | exclude_.removePairs(rigidSetB, rigidSetD); |
545 | > | exclude_.removePairs(rigidSetC, rigidSetD); |
546 | > | |
547 | > | /* |
548 | > | exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetB.begin(), rigidSetB.end()); |
549 | > | exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetC.begin(), rigidSetC.end()); |
550 | > | exclude_.removePairs(rigidSetA.begin(), rigidSetA.end(), rigidSetD.begin(), rigidSetD.end()); |
551 | > | exclude_.removePairs(rigidSetB.begin(), rigidSetB.end(), rigidSetC.begin(), rigidSetC.end()); |
552 | > | exclude_.removePairs(rigidSetB.begin(), rigidSetB.end(), rigidSetD.begin(), rigidSetD.end()); |
553 | > | exclude_.removePairs(rigidSetC.begin(), rigidSetC.end(), rigidSetD.begin(), rigidSetD.end()); |
554 | > | |
555 | > | |
556 | > | exclude_.removePair(a, b); |
557 | > | exclude_.removePair(a, c); |
558 | > | exclude_.removePair(a, d); |
559 | > | exclude_.removePair(b, c); |
560 | > | exclude_.removePair(b, d); |
561 | > | exclude_.removePair(c, d); |
562 | > | */ |
563 | > | } |
564 | > | |
565 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
566 | > | std::vector<Atom*> atoms = rb->getAtoms(); |
567 | > | for (int i = 0; i < atoms.size() -1 ; ++i) { |
568 | > | for (int j = i + 1; j < atoms.size(); ++j) { |
569 | > | a = atoms[i]->getGlobalIndex(); |
570 | > | b = atoms[j]->getGlobalIndex(); |
571 | > | exclude_.removePair(a, b); |
572 | > | } |
573 | > | } |
574 | > | } |
575 | > | |
576 | } | |
577 | ||
434 | – | fInfo.SIM_uses_PBC = usePBC; |
435 | – | //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; |
578 | ||
579 | < | n_exclude = excludes->getSize(); |
580 | < | excl = excludes->getFortranArray(); |
581 | < | |
579 | > | void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) { |
580 | > | int curStampId; |
581 | > | |
582 | > | //index from 0 |
583 | > | curStampId = moleculeStamps_.size(); |
584 | > | |
585 | > | moleculeStamps_.push_back(molStamp); |
586 | > | molStampIds_.insert(molStampIds_.end(), nmol, curStampId); |
587 | > | } |
588 | > | |
589 | > | void SimInfo::update() { |
590 | > | |
591 | > | setupSimType(); |
592 | > | |
593 | #ifdef IS_MPI | |
594 | < | n_global = mpiSim->getNAtomsGlobal(); |
452 | < | #else |
453 | < | n_global = n_atoms; |
594 | > | setupFortranParallel(); |
595 | #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); |
596 | ||
597 | < | if( isError ){ |
597 | > | setupFortranSim(); |
598 | > | |
599 | > | //setup fortran force field |
600 | > | /** @deprecate */ |
601 | > | int isError = 0; |
602 | ||
603 | < | sprintf( painCave.errMsg, |
604 | < | "There was an error setting the simulation information in fortran.\n" ); |
605 | < | painCave.isFatal = 1; |
471 | < | painCave.severity = OOPSE_ERROR; |
472 | < | simError(); |
473 | < | } |
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 | < | } |
603 | > | setupElectrostaticSummationMethod( isError ); |
604 | > | setupSwitchingFunction(); |
605 | > | setupAccumulateBoxDipole(); |
606 | ||
607 | < | void SimInfo::setDefaultRcut( double theRcut ){ |
607 | > | if(isError){ |
608 | > | sprintf( painCave.errMsg, |
609 | > | "ForceField error: There was an error initializing the forceField in fortran.\n" ); |
610 | > | painCave.isFatal = 1; |
611 | > | simError(); |
612 | > | } |
613 | ||
614 | < | haveRcut = 1; |
615 | < | rCut = theRcut; |
490 | < | rList = rCut + 1.0; |
491 | < | |
492 | < | notifyFortranCutOffs( &rCut, &rSw, &rList ); |
493 | < | } |
614 | > | |
615 | > | setupCutoff(); |
616 | ||
617 | < | void SimInfo::setDefaultRcut( double theRcut, double theRsw ){ |
617 | > | calcNdf(); |
618 | > | calcNdfRaw(); |
619 | > | calcNdfTrans(); |
620 | ||
621 | < | rSw = theRsw; |
622 | < | setDefaultRcut( theRcut ); |
499 | < | } |
621 | > | fortranInitialized_ = true; |
622 | > | } |
623 | ||
624 | + | std::set<AtomType*> SimInfo::getUniqueAtomTypes() { |
625 | + | SimInfo::MoleculeIterator mi; |
626 | + | Molecule* mol; |
627 | + | Molecule::AtomIterator ai; |
628 | + | Atom* atom; |
629 | + | std::set<AtomType*> atomTypes; |
630 | ||
631 | < | void SimInfo::checkCutOffs( void ){ |
632 | < | |
633 | < | if( boxIsInit ){ |
634 | < | |
635 | < | //we need to check cutOffs against the box |
636 | < | |
637 | < | if( rCut > maxCutoff ){ |
638 | < | sprintf( painCave.errMsg, |
639 | < | "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; |
523 | < | painCave.isFatal = 1; |
524 | < | simError(); |
525 | < | } |
526 | < | } else { |
527 | < | // initialize this stuff before using it, OK? |
528 | < | sprintf( painCave.errMsg, |
529 | < | "Trying to check cutoffs without a box.\n" |
530 | < | "\tOOPSE should have better programmers than that.\n" ); |
531 | < | painCave.severity = OOPSE_ERROR; |
532 | < | painCave.isFatal = 1; |
533 | < | simError(); |
631 | > | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
632 | > | |
633 | > | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
634 | > | atomTypes.insert(atom->getAtomType()); |
635 | > | } |
636 | > | |
637 | > | } |
638 | > | |
639 | > | return atomTypes; |
640 | } | |
535 | – | |
536 | – | } |
641 | ||
642 | < | void SimInfo::addProperty(GenericData* prop){ |
642 | > | void SimInfo::setupSimType() { |
643 | > | std::set<AtomType*>::iterator i; |
644 | > | std::set<AtomType*> atomTypes; |
645 | > | atomTypes = getUniqueAtomTypes(); |
646 | > | |
647 | > | int useLennardJones = 0; |
648 | > | int useElectrostatic = 0; |
649 | > | int useEAM = 0; |
650 | > | int useSC = 0; |
651 | > | int useCharge = 0; |
652 | > | int useDirectional = 0; |
653 | > | int useDipole = 0; |
654 | > | int useGayBerne = 0; |
655 | > | int useSticky = 0; |
656 | > | int useStickyPower = 0; |
657 | > | int useShape = 0; |
658 | > | int useFLARB = 0; //it is not in AtomType yet |
659 | > | int useDirectionalAtom = 0; |
660 | > | int useElectrostatics = 0; |
661 | > | //usePBC and useRF are from simParams |
662 | > | int usePBC = simParams_->getUsePeriodicBoundaryConditions(); |
663 | > | int useRF; |
664 | > | int useSF; |
665 | > | int useSP; |
666 | > | int useBoxDipole; |
667 | > | std::string myMethod; |
668 | ||
669 | < | map<string, GenericData*>::iterator result; |
670 | < | result = properties.find(prop->getID()); |
671 | < | |
672 | < | //we can't simply use properties[prop->getID()] = prop, |
673 | < | //it will cause memory leak if we already contain a propery which has the same name of prop |
674 | < | |
675 | < | if(result != properties.end()){ |
669 | > | // set the useRF logical |
670 | > | useRF = 0; |
671 | > | useSF = 0; |
672 | > | |
673 | > | |
674 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
675 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
676 | > | toUpper(myMethod); |
677 | > | if (myMethod == "REACTION_FIELD"){ |
678 | > | useRF=1; |
679 | > | } else if (myMethod == "SHIFTED_FORCE"){ |
680 | > | useSF = 1; |
681 | > | } else if (myMethod == "SHIFTED_POTENTIAL"){ |
682 | > | useSP = 1; |
683 | > | } |
684 | > | } |
685 | ||
686 | < | delete (*result).second; |
687 | < | (*result).second = prop; |
686 | > | if (simParams_->haveAccumulateBoxDipole()) |
687 | > | if (simParams_->getAccumulateBoxDipole()) |
688 | > | useBoxDipole = 1; |
689 | > | |
690 | > | //loop over all of the atom types |
691 | > | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
692 | > | useLennardJones |= (*i)->isLennardJones(); |
693 | > | useElectrostatic |= (*i)->isElectrostatic(); |
694 | > | useEAM |= (*i)->isEAM(); |
695 | > | useSC |= (*i)->isSC(); |
696 | > | useCharge |= (*i)->isCharge(); |
697 | > | useDirectional |= (*i)->isDirectional(); |
698 | > | useDipole |= (*i)->isDipole(); |
699 | > | useGayBerne |= (*i)->isGayBerne(); |
700 | > | useSticky |= (*i)->isSticky(); |
701 | > | useStickyPower |= (*i)->isStickyPower(); |
702 | > | useShape |= (*i)->isShape(); |
703 | > | } |
704 | > | |
705 | > | if (useSticky || useStickyPower || useDipole || useGayBerne || useShape) { |
706 | > | useDirectionalAtom = 1; |
707 | > | } |
708 | > | |
709 | > | if (useCharge || useDipole) { |
710 | > | useElectrostatics = 1; |
711 | > | } |
712 | > | |
713 | > | #ifdef IS_MPI |
714 | > | int temp; |
715 | > | |
716 | > | temp = usePBC; |
717 | > | MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
718 | > | |
719 | > | temp = useDirectionalAtom; |
720 | > | MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
721 | > | |
722 | > | temp = useLennardJones; |
723 | > | MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
724 | > | |
725 | > | temp = useElectrostatics; |
726 | > | MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
727 | > | |
728 | > | temp = useCharge; |
729 | > | MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
730 | > | |
731 | > | temp = useDipole; |
732 | > | MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
733 | > | |
734 | > | temp = useSticky; |
735 | > | MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
736 | > | |
737 | > | temp = useStickyPower; |
738 | > | MPI_Allreduce(&temp, &useStickyPower, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
739 | > | |
740 | > | temp = useGayBerne; |
741 | > | MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
742 | > | |
743 | > | temp = useEAM; |
744 | > | MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
745 | > | |
746 | > | temp = useSC; |
747 | > | MPI_Allreduce(&temp, &useSC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
748 | > | |
749 | > | temp = useShape; |
750 | > | MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
751 | > | |
752 | > | temp = useFLARB; |
753 | > | MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
754 | > | |
755 | > | temp = useRF; |
756 | > | MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
757 | > | |
758 | > | temp = useSF; |
759 | > | MPI_Allreduce(&temp, &useSF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
760 | > | |
761 | > | temp = useSP; |
762 | > | MPI_Allreduce(&temp, &useSP, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
763 | > | |
764 | > | temp = useBoxDipole; |
765 | > | MPI_Allreduce(&temp, &useBoxDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
766 | > | |
767 | > | #endif |
768 | > | |
769 | > | fInfo_.SIM_uses_PBC = usePBC; |
770 | > | fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom; |
771 | > | fInfo_.SIM_uses_LennardJones = useLennardJones; |
772 | > | fInfo_.SIM_uses_Electrostatics = useElectrostatics; |
773 | > | fInfo_.SIM_uses_Charges = useCharge; |
774 | > | fInfo_.SIM_uses_Dipoles = useDipole; |
775 | > | fInfo_.SIM_uses_Sticky = useSticky; |
776 | > | fInfo_.SIM_uses_StickyPower = useStickyPower; |
777 | > | fInfo_.SIM_uses_GayBerne = useGayBerne; |
778 | > | fInfo_.SIM_uses_EAM = useEAM; |
779 | > | fInfo_.SIM_uses_SC = useSC; |
780 | > | fInfo_.SIM_uses_Shapes = useShape; |
781 | > | fInfo_.SIM_uses_FLARB = useFLARB; |
782 | > | fInfo_.SIM_uses_RF = useRF; |
783 | > | fInfo_.SIM_uses_SF = useSF; |
784 | > | fInfo_.SIM_uses_SP = useSP; |
785 | > | fInfo_.SIM_uses_BoxDipole = useBoxDipole; |
786 | > | |
787 | > | if( myMethod == "REACTION_FIELD") { |
788 | ||
789 | + | if (simParams_->haveDielectric()) { |
790 | + | fInfo_.dielect = simParams_->getDielectric(); |
791 | + | } else { |
792 | + | sprintf(painCave.errMsg, |
793 | + | "SimSetup Error: No Dielectric constant was set.\n" |
794 | + | "\tYou are trying to use Reaction Field without" |
795 | + | "\tsetting a dielectric constant!\n"); |
796 | + | painCave.isFatal = 1; |
797 | + | simError(); |
798 | + | } |
799 | + | } |
800 | + | |
801 | } | |
552 | – | else{ |
802 | ||
803 | < | properties[prop->getID()] = prop; |
803 | > | void SimInfo::setupFortranSim() { |
804 | > | int isError; |
805 | > | int nExclude; |
806 | > | std::vector<int> fortranGlobalGroupMembership; |
807 | > | |
808 | > | nExclude = exclude_.getSize(); |
809 | > | isError = 0; |
810 | ||
811 | < | } |
811 | > | //globalGroupMembership_ is filled by SimCreator |
812 | > | for (int i = 0; i < nGlobalAtoms_; i++) { |
813 | > | fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); |
814 | > | } |
815 | > | |
816 | > | //calculate mass ratio of cutoff group |
817 | > | std::vector<RealType> mfact; |
818 | > | SimInfo::MoleculeIterator mi; |
819 | > | Molecule* mol; |
820 | > | Molecule::CutoffGroupIterator ci; |
821 | > | CutoffGroup* cg; |
822 | > | Molecule::AtomIterator ai; |
823 | > | Atom* atom; |
824 | > | RealType totalMass; |
825 | > | |
826 | > | //to avoid memory reallocation, reserve enough space for mfact |
827 | > | mfact.reserve(getNCutoffGroups()); |
828 | ||
829 | < | } |
829 | > | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
830 | > | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
831 | ||
832 | < | GenericData* SimInfo::getProperty(const string& propName){ |
833 | < | |
834 | < | map<string, GenericData*>::iterator result; |
835 | < | |
836 | < | //string lowerCaseName = (); |
837 | < | |
838 | < | result = properties.find(propName); |
839 | < | |
568 | < | if(result != properties.end()) |
569 | < | return (*result).second; |
570 | < | else |
571 | < | return NULL; |
572 | < | } |
832 | > | totalMass = cg->getMass(); |
833 | > | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
834 | > | // Check for massless groups - set mfact to 1 if true |
835 | > | if (totalMass != 0) |
836 | > | mfact.push_back(atom->getMass()/totalMass); |
837 | > | else |
838 | > | mfact.push_back( 1.0 ); |
839 | > | } |
840 | ||
841 | + | } |
842 | + | } |
843 | ||
844 | < | void SimInfo::getFortranGroupArrays(SimInfo* info, |
845 | < | 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 | < | |
844 | > | //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) |
845 | > | std::vector<int> identArray; |
846 | ||
847 | < | // Fix the silly fortran indexing problem |
847 | > | //to avoid memory reallocation, reserve enough space identArray |
848 | > | identArray.reserve(getNAtoms()); |
849 | > | |
850 | > | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
851 | > | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
852 | > | identArray.push_back(atom->getIdent()); |
853 | > | } |
854 | > | } |
855 | > | |
856 | > | //fill molMembershipArray |
857 | > | //molMembershipArray is filled by SimCreator |
858 | > | std::vector<int> molMembershipArray(nGlobalAtoms_); |
859 | > | for (int i = 0; i < nGlobalAtoms_; i++) { |
860 | > | molMembershipArray[i] = globalMolMembership_[i] + 1; |
861 | > | } |
862 | > | |
863 | > | //setup fortran simulation |
864 | > | int nGlobalExcludes = 0; |
865 | > | int* globalExcludes = NULL; |
866 | > | int* excludeList = exclude_.getExcludeList(); |
867 | > | setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList , |
868 | > | &nGlobalExcludes, globalExcludes, &molMembershipArray[0], |
869 | > | &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError); |
870 | > | |
871 | > | if( isError ){ |
872 | > | |
873 | > | sprintf( painCave.errMsg, |
874 | > | "There was an error setting the simulation information in fortran.\n" ); |
875 | > | painCave.isFatal = 1; |
876 | > | painCave.severity = OOPSE_ERROR; |
877 | > | simError(); |
878 | > | } |
879 | > | |
880 | #ifdef IS_MPI | |
881 | < | numAtom = mpiSim->getNAtomsGlobal(); |
882 | < | #else |
883 | < | numAtom = n_atoms; |
881 | > | sprintf( checkPointMsg, |
882 | > | "succesfully sent the simulation information to fortran.\n"); |
883 | > | MPIcheckPoint(); |
884 | > | #endif // is_mpi |
885 | > | } |
886 | > | |
887 | > | |
888 | > | #ifdef IS_MPI |
889 | > | void SimInfo::setupFortranParallel() { |
890 | > | |
891 | > | //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex |
892 | > | std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0); |
893 | > | std::vector<int> localToGlobalCutoffGroupIndex; |
894 | > | SimInfo::MoleculeIterator mi; |
895 | > | Molecule::AtomIterator ai; |
896 | > | Molecule::CutoffGroupIterator ci; |
897 | > | Molecule* mol; |
898 | > | Atom* atom; |
899 | > | CutoffGroup* cg; |
900 | > | mpiSimData parallelData; |
901 | > | int isError; |
902 | > | |
903 | > | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
904 | > | |
905 | > | //local index(index in DataStorge) of atom is important |
906 | > | for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
907 | > | localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; |
908 | > | } |
909 | > | |
910 | > | //local index of cutoff group is trivial, it only depends on the order of travesing |
911 | > | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
912 | > | localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); |
913 | > | } |
914 | > | |
915 | > | } |
916 | > | |
917 | > | //fill up mpiSimData struct |
918 | > | parallelData.nMolGlobal = getNGlobalMolecules(); |
919 | > | parallelData.nMolLocal = getNMolecules(); |
920 | > | parallelData.nAtomsGlobal = getNGlobalAtoms(); |
921 | > | parallelData.nAtomsLocal = getNAtoms(); |
922 | > | parallelData.nGroupsGlobal = getNGlobalCutoffGroups(); |
923 | > | parallelData.nGroupsLocal = getNCutoffGroups(); |
924 | > | parallelData.myNode = worldRank; |
925 | > | MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors)); |
926 | > | |
927 | > | //pass mpiSimData struct and index arrays to fortran |
928 | > | setFsimParallel(¶llelData, &(parallelData.nAtomsLocal), |
929 | > | &localToGlobalAtomIndex[0], &(parallelData.nGroupsLocal), |
930 | > | &localToGlobalCutoffGroupIndex[0], &isError); |
931 | > | |
932 | > | if (isError) { |
933 | > | sprintf(painCave.errMsg, |
934 | > | "mpiRefresh errror: fortran didn't like something we gave it.\n"); |
935 | > | painCave.isFatal = 1; |
936 | > | simError(); |
937 | > | } |
938 | > | |
939 | > | sprintf(checkPointMsg, " mpiRefresh successful.\n"); |
940 | > | MPIcheckPoint(); |
941 | > | |
942 | > | |
943 | > | } |
944 | > | |
945 | #endif | |
602 | – | for (int i = 0; i < numAtom; i++) |
603 | – | FglobalGroupMembership.push_back(globalGroupMembership[i] + 1); |
604 | – | |
946 | ||
947 | < | myMols = info->molecules; |
948 | < | numMol = info->n_mol; |
949 | < | 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)){ |
947 | > | void SimInfo::setupCutoff() { |
948 | > | |
949 | > | ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions(); |
950 | ||
951 | < | totalMass = myCutoffGroup->getMass(); |
952 | < | |
953 | < | for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom); |
954 | < | cutoffAtom != NULL; |
955 | < | cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){ |
956 | < | mfact.push_back(cutoffAtom->getMass()/totalMass); |
957 | < | } |
951 | > | // Check the cutoff policy |
952 | > | int cp = TRADITIONAL_CUTOFF_POLICY; // Set to traditional by default |
953 | > | |
954 | > | std::string myPolicy; |
955 | > | if (forceFieldOptions_.haveCutoffPolicy()){ |
956 | > | myPolicy = forceFieldOptions_.getCutoffPolicy(); |
957 | > | }else if (simParams_->haveCutoffPolicy()) { |
958 | > | myPolicy = simParams_->getCutoffPolicy(); |
959 | } | |
960 | + | |
961 | + | if (!myPolicy.empty()){ |
962 | + | toUpper(myPolicy); |
963 | + | if (myPolicy == "MIX") { |
964 | + | cp = MIX_CUTOFF_POLICY; |
965 | + | } else { |
966 | + | if (myPolicy == "MAX") { |
967 | + | cp = MAX_CUTOFF_POLICY; |
968 | + | } else { |
969 | + | if (myPolicy == "TRADITIONAL") { |
970 | + | cp = TRADITIONAL_CUTOFF_POLICY; |
971 | + | } else { |
972 | + | // throw error |
973 | + | sprintf( painCave.errMsg, |
974 | + | "SimInfo error: Unknown cutoffPolicy. (Input file specified %s .)\n\tcutoffPolicy must be one of: \"Mix\", \"Max\", or \"Traditional\".", myPolicy.c_str() ); |
975 | + | painCave.isFatal = 1; |
976 | + | simError(); |
977 | + | } |
978 | + | } |
979 | + | } |
980 | + | } |
981 | + | notifyFortranCutoffPolicy(&cp); |
982 | + | |
983 | + | // Check the Skin Thickness for neighborlists |
984 | + | RealType skin; |
985 | + | if (simParams_->haveSkinThickness()) { |
986 | + | skin = simParams_->getSkinThickness(); |
987 | + | notifyFortranSkinThickness(&skin); |
988 | + | } |
989 | + | |
990 | + | // Check if the cutoff was set explicitly: |
991 | + | if (simParams_->haveCutoffRadius()) { |
992 | + | rcut_ = simParams_->getCutoffRadius(); |
993 | + | if (simParams_->haveSwitchingRadius()) { |
994 | + | rsw_ = simParams_->getSwitchingRadius(); |
995 | + | } else { |
996 | + | if (fInfo_.SIM_uses_Charges | |
997 | + | fInfo_.SIM_uses_Dipoles | |
998 | + | fInfo_.SIM_uses_RF) { |
999 | + | |
1000 | + | rsw_ = 0.85 * rcut_; |
1001 | + | sprintf(painCave.errMsg, |
1002 | + | "SimCreator Warning: No value was set for the switchingRadius.\n" |
1003 | + | "\tOOPSE will use a default value of 85 percent of the cutoffRadius.\n" |
1004 | + | "\tswitchingRadius = %f. for this simulation\n", rsw_); |
1005 | + | painCave.isFatal = 0; |
1006 | + | simError(); |
1007 | + | } else { |
1008 | + | rsw_ = rcut_; |
1009 | + | sprintf(painCave.errMsg, |
1010 | + | "SimCreator Warning: No value was set for the switchingRadius.\n" |
1011 | + | "\tOOPSE will use the same value as the cutoffRadius.\n" |
1012 | + | "\tswitchingRadius = %f. for this simulation\n", rsw_); |
1013 | + | painCave.isFatal = 0; |
1014 | + | simError(); |
1015 | + | } |
1016 | + | } |
1017 | + | |
1018 | + | notifyFortranCutoffs(&rcut_, &rsw_); |
1019 | + | |
1020 | + | } else { |
1021 | + | |
1022 | + | // For electrostatic atoms, we'll assume a large safe value: |
1023 | + | if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { |
1024 | + | sprintf(painCave.errMsg, |
1025 | + | "SimCreator Warning: No value was set for the cutoffRadius.\n" |
1026 | + | "\tOOPSE will use a default value of 15.0 angstroms" |
1027 | + | "\tfor the cutoffRadius.\n"); |
1028 | + | painCave.isFatal = 0; |
1029 | + | simError(); |
1030 | + | rcut_ = 15.0; |
1031 | + | |
1032 | + | if (simParams_->haveElectrostaticSummationMethod()) { |
1033 | + | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
1034 | + | toUpper(myMethod); |
1035 | + | if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") { |
1036 | + | if (simParams_->haveSwitchingRadius()){ |
1037 | + | sprintf(painCave.errMsg, |
1038 | + | "SimInfo Warning: A value was set for the switchingRadius\n" |
1039 | + | "\teven though the electrostaticSummationMethod was\n" |
1040 | + | "\tset to %s\n", myMethod.c_str()); |
1041 | + | painCave.isFatal = 1; |
1042 | + | simError(); |
1043 | + | } |
1044 | + | } |
1045 | + | } |
1046 | + | |
1047 | + | if (simParams_->haveSwitchingRadius()){ |
1048 | + | rsw_ = simParams_->getSwitchingRadius(); |
1049 | + | } else { |
1050 | + | sprintf(painCave.errMsg, |
1051 | + | "SimCreator Warning: No value was set for switchingRadius.\n" |
1052 | + | "\tOOPSE will use a default value of\n" |
1053 | + | "\t0.85 * cutoffRadius for the switchingRadius\n"); |
1054 | + | painCave.isFatal = 0; |
1055 | + | simError(); |
1056 | + | rsw_ = 0.85 * rcut_; |
1057 | + | } |
1058 | + | notifyFortranCutoffs(&rcut_, &rsw_); |
1059 | + | } else { |
1060 | + | // We didn't set rcut explicitly, and we don't have electrostatic atoms, so |
1061 | + | // We'll punt and let fortran figure out the cutoffs later. |
1062 | + | |
1063 | + | notifyFortranYouAreOnYourOwn(); |
1064 | + | |
1065 | + | } |
1066 | + | } |
1067 | } | |
1068 | ||
1069 | < | } |
1069 | > | void SimInfo::setupElectrostaticSummationMethod( int isError ) { |
1070 | > | |
1071 | > | int errorOut; |
1072 | > | int esm = NONE; |
1073 | > | int sm = UNDAMPED; |
1074 | > | RealType alphaVal; |
1075 | > | RealType dielectric; |
1076 | > | |
1077 | > | errorOut = isError; |
1078 | > | alphaVal = simParams_->getDampingAlpha(); |
1079 | > | dielectric = simParams_->getDielectric(); |
1080 | > | |
1081 | > | if (simParams_->haveElectrostaticSummationMethod()) { |
1082 | > | std::string myMethod = simParams_->getElectrostaticSummationMethod(); |
1083 | > | toUpper(myMethod); |
1084 | > | if (myMethod == "NONE") { |
1085 | > | esm = NONE; |
1086 | > | } else { |
1087 | > | if (myMethod == "SWITCHING_FUNCTION") { |
1088 | > | esm = SWITCHING_FUNCTION; |
1089 | > | } else { |
1090 | > | if (myMethod == "SHIFTED_POTENTIAL") { |
1091 | > | esm = SHIFTED_POTENTIAL; |
1092 | > | } else { |
1093 | > | if (myMethod == "SHIFTED_FORCE") { |
1094 | > | esm = SHIFTED_FORCE; |
1095 | > | } else { |
1096 | > | if (myMethod == "REACTION_FIELD") { |
1097 | > | esm = REACTION_FIELD; |
1098 | > | } else { |
1099 | > | // throw error |
1100 | > | sprintf( painCave.errMsg, |
1101 | > | "SimInfo error: Unknown electrostaticSummationMethod.\n" |
1102 | > | "\t(Input file specified %s .)\n" |
1103 | > | "\telectrostaticSummationMethod must be one of: \"none\",\n" |
1104 | > | "\t\"shifted_potential\", \"shifted_force\", or \n" |
1105 | > | "\t\"reaction_field\".\n", myMethod.c_str() ); |
1106 | > | painCave.isFatal = 1; |
1107 | > | simError(); |
1108 | > | } |
1109 | > | } |
1110 | > | } |
1111 | > | } |
1112 | > | } |
1113 | > | } |
1114 | > | |
1115 | > | if (simParams_->haveElectrostaticScreeningMethod()) { |
1116 | > | std::string myScreen = simParams_->getElectrostaticScreeningMethod(); |
1117 | > | toUpper(myScreen); |
1118 | > | if (myScreen == "UNDAMPED") { |
1119 | > | sm = UNDAMPED; |
1120 | > | } else { |
1121 | > | if (myScreen == "DAMPED") { |
1122 | > | sm = DAMPED; |
1123 | > | if (!simParams_->haveDampingAlpha()) { |
1124 | > | //throw error |
1125 | > | sprintf( painCave.errMsg, |
1126 | > | "SimInfo warning: dampingAlpha was not specified in the input file.\n" |
1127 | > | "\tA default value of %f (1/ang) will be used.\n", alphaVal); |
1128 | > | painCave.isFatal = 0; |
1129 | > | simError(); |
1130 | > | } |
1131 | > | } else { |
1132 | > | // throw error |
1133 | > | sprintf( painCave.errMsg, |
1134 | > | "SimInfo error: Unknown electrostaticScreeningMethod.\n" |
1135 | > | "\t(Input file specified %s .)\n" |
1136 | > | "\telectrostaticScreeningMethod must be one of: \"undamped\"\n" |
1137 | > | "or \"damped\".\n", myScreen.c_str() ); |
1138 | > | painCave.isFatal = 1; |
1139 | > | simError(); |
1140 | > | } |
1141 | > | } |
1142 | > | } |
1143 | > | |
1144 | > | // let's pass some summation method variables to fortran |
1145 | > | setElectrostaticSummationMethod( &esm ); |
1146 | > | setFortranElectrostaticMethod( &esm ); |
1147 | > | setScreeningMethod( &sm ); |
1148 | > | setDampingAlpha( &alphaVal ); |
1149 | > | setReactionFieldDielectric( &dielectric ); |
1150 | > | initFortranFF( &errorOut ); |
1151 | > | } |
1152 | > | |
1153 | > | void SimInfo::setupSwitchingFunction() { |
1154 | > | int ft = CUBIC; |
1155 | > | |
1156 | > | if (simParams_->haveSwitchingFunctionType()) { |
1157 | > | std::string funcType = simParams_->getSwitchingFunctionType(); |
1158 | > | toUpper(funcType); |
1159 | > | if (funcType == "CUBIC") { |
1160 | > | ft = CUBIC; |
1161 | > | } else { |
1162 | > | if (funcType == "FIFTH_ORDER_POLYNOMIAL") { |
1163 | > | ft = FIFTH_ORDER_POLY; |
1164 | > | } else { |
1165 | > | // throw error |
1166 | > | sprintf( painCave.errMsg, |
1167 | > | "SimInfo error: Unknown switchingFunctionType. (Input file specified %s .)\n\tswitchingFunctionType must be one of: \"cubic\" or \"fifth_order_polynomial\".", funcType.c_str() ); |
1168 | > | painCave.isFatal = 1; |
1169 | > | simError(); |
1170 | > | } |
1171 | > | } |
1172 | > | } |
1173 | > | |
1174 | > | // send switching function notification to switcheroo |
1175 | > | setFunctionType(&ft); |
1176 | > | |
1177 | > | } |
1178 | > | |
1179 | > | void SimInfo::setupAccumulateBoxDipole() { |
1180 | > | |
1181 | > | // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true |
1182 | > | if ( simParams_->haveAccumulateBoxDipole() ) |
1183 | > | if ( simParams_->getAccumulateBoxDipole() ) { |
1184 | > | setAccumulateBoxDipole(); |
1185 | > | calcBoxDipole_ = true; |
1186 | > | } |
1187 | > | |
1188 | > | } |
1189 | > | |
1190 | > | void SimInfo::addProperty(GenericData* genData) { |
1191 | > | properties_.addProperty(genData); |
1192 | > | } |
1193 | > | |
1194 | > | void SimInfo::removeProperty(const std::string& propName) { |
1195 | > | properties_.removeProperty(propName); |
1196 | > | } |
1197 | > | |
1198 | > | void SimInfo::clearProperties() { |
1199 | > | properties_.clearProperties(); |
1200 | > | } |
1201 | > | |
1202 | > | std::vector<std::string> SimInfo::getPropertyNames() { |
1203 | > | return properties_.getPropertyNames(); |
1204 | > | } |
1205 | > | |
1206 | > | std::vector<GenericData*> SimInfo::getProperties() { |
1207 | > | return properties_.getProperties(); |
1208 | > | } |
1209 | > | |
1210 | > | GenericData* SimInfo::getPropertyByName(const std::string& propName) { |
1211 | > | return properties_.getPropertyByName(propName); |
1212 | > | } |
1213 | > | |
1214 | > | void SimInfo::setSnapshotManager(SnapshotManager* sman) { |
1215 | > | if (sman_ == sman) { |
1216 | > | return; |
1217 | > | } |
1218 | > | delete sman_; |
1219 | > | sman_ = sman; |
1220 | > | |
1221 | > | Molecule* mol; |
1222 | > | RigidBody* rb; |
1223 | > | Atom* atom; |
1224 | > | SimInfo::MoleculeIterator mi; |
1225 | > | Molecule::RigidBodyIterator rbIter; |
1226 | > | Molecule::AtomIterator atomIter;; |
1227 | > | |
1228 | > | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
1229 | > | |
1230 | > | for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) { |
1231 | > | atom->setSnapshotManager(sman_); |
1232 | > | } |
1233 | > | |
1234 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
1235 | > | rb->setSnapshotManager(sman_); |
1236 | > | } |
1237 | > | } |
1238 | > | |
1239 | > | } |
1240 | > | |
1241 | > | Vector3d SimInfo::getComVel(){ |
1242 | > | SimInfo::MoleculeIterator i; |
1243 | > | Molecule* mol; |
1244 | > | |
1245 | > | Vector3d comVel(0.0); |
1246 | > | RealType totalMass = 0.0; |
1247 | > | |
1248 | > | |
1249 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1250 | > | RealType mass = mol->getMass(); |
1251 | > | totalMass += mass; |
1252 | > | comVel += mass * mol->getComVel(); |
1253 | > | } |
1254 | > | |
1255 | > | #ifdef IS_MPI |
1256 | > | RealType tmpMass = totalMass; |
1257 | > | Vector3d tmpComVel(comVel); |
1258 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1259 | > | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1260 | > | #endif |
1261 | > | |
1262 | > | comVel /= totalMass; |
1263 | > | |
1264 | > | return comVel; |
1265 | > | } |
1266 | > | |
1267 | > | Vector3d SimInfo::getCom(){ |
1268 | > | SimInfo::MoleculeIterator i; |
1269 | > | Molecule* mol; |
1270 | > | |
1271 | > | Vector3d com(0.0); |
1272 | > | RealType totalMass = 0.0; |
1273 | > | |
1274 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1275 | > | RealType mass = mol->getMass(); |
1276 | > | totalMass += mass; |
1277 | > | com += mass * mol->getCom(); |
1278 | > | } |
1279 | > | |
1280 | > | #ifdef IS_MPI |
1281 | > | RealType tmpMass = totalMass; |
1282 | > | Vector3d tmpCom(com); |
1283 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1284 | > | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1285 | > | #endif |
1286 | > | |
1287 | > | com /= totalMass; |
1288 | > | |
1289 | > | return com; |
1290 | > | |
1291 | > | } |
1292 | > | |
1293 | > | std::ostream& operator <<(std::ostream& o, SimInfo& info) { |
1294 | > | |
1295 | > | return o; |
1296 | > | } |
1297 | > | |
1298 | > | |
1299 | > | /* |
1300 | > | Returns center of mass and center of mass velocity in one function call. |
1301 | > | */ |
1302 | > | |
1303 | > | void SimInfo::getComAll(Vector3d &com, Vector3d &comVel){ |
1304 | > | SimInfo::MoleculeIterator i; |
1305 | > | Molecule* mol; |
1306 | > | |
1307 | > | |
1308 | > | RealType totalMass = 0.0; |
1309 | > | |
1310 | > | |
1311 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1312 | > | RealType mass = mol->getMass(); |
1313 | > | totalMass += mass; |
1314 | > | com += mass * mol->getCom(); |
1315 | > | comVel += mass * mol->getComVel(); |
1316 | > | } |
1317 | > | |
1318 | > | #ifdef IS_MPI |
1319 | > | RealType tmpMass = totalMass; |
1320 | > | Vector3d tmpCom(com); |
1321 | > | Vector3d tmpComVel(comVel); |
1322 | > | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1323 | > | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1324 | > | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1325 | > | #endif |
1326 | > | |
1327 | > | com /= totalMass; |
1328 | > | comVel /= totalMass; |
1329 | > | } |
1330 | > | |
1331 | > | /* |
1332 | > | Return intertia tensor for entire system and angular momentum Vector. |
1333 | > | |
1334 | > | |
1335 | > | [ Ixx -Ixy -Ixz ] |
1336 | > | J =| -Iyx Iyy -Iyz | |
1337 | > | [ -Izx -Iyz Izz ] |
1338 | > | */ |
1339 | > | |
1340 | > | void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){ |
1341 | > | |
1342 | > | |
1343 | > | RealType xx = 0.0; |
1344 | > | RealType yy = 0.0; |
1345 | > | RealType zz = 0.0; |
1346 | > | RealType xy = 0.0; |
1347 | > | RealType xz = 0.0; |
1348 | > | RealType yz = 0.0; |
1349 | > | Vector3d com(0.0); |
1350 | > | Vector3d comVel(0.0); |
1351 | > | |
1352 | > | getComAll(com, comVel); |
1353 | > | |
1354 | > | SimInfo::MoleculeIterator i; |
1355 | > | Molecule* mol; |
1356 | > | |
1357 | > | Vector3d thisq(0.0); |
1358 | > | Vector3d thisv(0.0); |
1359 | > | |
1360 | > | RealType thisMass = 0.0; |
1361 | > | |
1362 | > | |
1363 | > | |
1364 | > | |
1365 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1366 | > | |
1367 | > | thisq = mol->getCom()-com; |
1368 | > | thisv = mol->getComVel()-comVel; |
1369 | > | thisMass = mol->getMass(); |
1370 | > | // Compute moment of intertia coefficients. |
1371 | > | xx += thisq[0]*thisq[0]*thisMass; |
1372 | > | yy += thisq[1]*thisq[1]*thisMass; |
1373 | > | zz += thisq[2]*thisq[2]*thisMass; |
1374 | > | |
1375 | > | // compute products of intertia |
1376 | > | xy += thisq[0]*thisq[1]*thisMass; |
1377 | > | xz += thisq[0]*thisq[2]*thisMass; |
1378 | > | yz += thisq[1]*thisq[2]*thisMass; |
1379 | > | |
1380 | > | angularMomentum += cross( thisq, thisv ) * thisMass; |
1381 | > | |
1382 | > | } |
1383 | > | |
1384 | > | |
1385 | > | inertiaTensor(0,0) = yy + zz; |
1386 | > | inertiaTensor(0,1) = -xy; |
1387 | > | inertiaTensor(0,2) = -xz; |
1388 | > | inertiaTensor(1,0) = -xy; |
1389 | > | inertiaTensor(1,1) = xx + zz; |
1390 | > | inertiaTensor(1,2) = -yz; |
1391 | > | inertiaTensor(2,0) = -xz; |
1392 | > | inertiaTensor(2,1) = -yz; |
1393 | > | inertiaTensor(2,2) = xx + yy; |
1394 | > | |
1395 | > | #ifdef IS_MPI |
1396 | > | Mat3x3d tmpI(inertiaTensor); |
1397 | > | Vector3d tmpAngMom; |
1398 | > | MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1399 | > | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1400 | > | #endif |
1401 | > | |
1402 | > | return; |
1403 | > | } |
1404 | > | |
1405 | > | //Returns the angular momentum of the system |
1406 | > | Vector3d SimInfo::getAngularMomentum(){ |
1407 | > | |
1408 | > | Vector3d com(0.0); |
1409 | > | Vector3d comVel(0.0); |
1410 | > | Vector3d angularMomentum(0.0); |
1411 | > | |
1412 | > | getComAll(com,comVel); |
1413 | > | |
1414 | > | SimInfo::MoleculeIterator i; |
1415 | > | Molecule* mol; |
1416 | > | |
1417 | > | Vector3d thisr(0.0); |
1418 | > | Vector3d thisp(0.0); |
1419 | > | |
1420 | > | RealType thisMass; |
1421 | > | |
1422 | > | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { |
1423 | > | thisMass = mol->getMass(); |
1424 | > | thisr = mol->getCom()-com; |
1425 | > | thisp = (mol->getComVel()-comVel)*thisMass; |
1426 | > | |
1427 | > | angularMomentum += cross( thisr, thisp ); |
1428 | > | |
1429 | > | } |
1430 | > | |
1431 | > | #ifdef IS_MPI |
1432 | > | Vector3d tmpAngMom; |
1433 | > | MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); |
1434 | > | #endif |
1435 | > | |
1436 | > | return angularMomentum; |
1437 | > | } |
1438 | > | |
1439 | > | |
1440 | > | }//end namespace oopse |
1441 | > |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |