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