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