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