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