# | Line 1 | Line 1 | |
---|---|---|
1 | < | #include <cstdlib> |
2 | < | #include <cstring> |
3 | < | #include <cmath> |
1 | > | #include <stdlib.h> |
2 | > | #include <string.h> |
3 | > | #include <math.h> |
4 | ||
5 | #include <iostream> | |
6 | using namespace std; | |
# | Line 20 | Line 20 | inline double roundMe( double x ){ | |
20 | return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 ); | |
21 | } | |
22 | ||
23 | + | inline double min( double a, double b ){ |
24 | + | return (a < b ) ? a : b; |
25 | + | } |
26 | ||
27 | SimInfo* currentInfo; | |
28 | ||
29 | SimInfo::SimInfo(){ | |
30 | excludes = NULL; | |
31 | n_constraints = 0; | |
32 | + | nZconstraints = 0; |
33 | n_oriented = 0; | |
34 | n_dipoles = 0; | |
35 | ndf = 0; | |
36 | ndfRaw = 0; | |
37 | + | nZconstraints = 0; |
38 | the_integrator = NULL; | |
39 | setTemp = 0; | |
40 | thermalTime = 0.0; | |
41 | + | currentTime = 0.0; |
42 | rCut = 0.0; | |
43 | + | ecr = 0.0; |
44 | + | est = 0.0; |
45 | ||
46 | + | haveRcut = 0; |
47 | + | haveEcr = 0; |
48 | + | boxIsInit = 0; |
49 | + | |
50 | + | resetTime = 1e99; |
51 | + | |
52 | + | orthoTolerance = 1E-6; |
53 | + | useInitXSstate = true; |
54 | + | |
55 | usePBC = 0; | |
56 | useLJ = 0; | |
57 | useSticky = 0; | |
# | Line 43 | Line 60 | SimInfo::SimInfo(){ | |
60 | useGB = 0; | |
61 | useEAM = 0; | |
62 | ||
63 | + | myConfiguration = new SimState(); |
64 | + | |
65 | wrapMeSimInfo( this ); | |
66 | } | |
67 | ||
49 | – | void SimInfo::setBox(double newBox[3]) { |
68 | ||
69 | < | double smallestBoxL, maxCutoff; |
52 | < | int status; |
53 | < | int i; |
69 | > | SimInfo::~SimInfo(){ |
70 | ||
71 | < | for(i=0; i<9; i++) Hmat[i] = 0.0;; |
71 | > | delete myConfiguration; |
72 | ||
73 | < | Hmat[0] = newBox[0]; |
74 | < | Hmat[4] = newBox[1]; |
75 | < | Hmat[8] = newBox[2]; |
73 | > | map<string, GenericData*>::iterator i; |
74 | > | |
75 | > | for(i = properties.begin(); i != properties.end(); i++) |
76 | > | delete (*i).second; |
77 | > | |
78 | > | } |
79 | ||
80 | < | calcHmatI(); |
81 | < | calcBoxL(); |
80 | > | void SimInfo::setBox(double newBox[3]) { |
81 | > | |
82 | > | int i, j; |
83 | > | double tempMat[3][3]; |
84 | ||
85 | < | setFortranBoxSize(Hmat, HmatI, &orthoRhombic); |
85 | > | for(i=0; i<3; i++) |
86 | > | for (j=0; j<3; j++) tempMat[i][j] = 0.0;; |
87 | ||
88 | < | smallestBoxL = boxLx; |
89 | < | if (boxLy < smallestBoxL) smallestBoxL = boxLy; |
90 | < | if (boxLz < smallestBoxL) smallestBoxL = boxLz; |
88 | > | tempMat[0][0] = newBox[0]; |
89 | > | tempMat[1][1] = newBox[1]; |
90 | > | tempMat[2][2] = newBox[2]; |
91 | ||
92 | < | maxCutoff = smallestBoxL / 2.0; |
92 | > | setBoxM( tempMat ); |
93 | ||
94 | < | if (rList > maxCutoff) { |
73 | < | sprintf( painCave.errMsg, |
74 | < | "New Box size is forcing neighborlist radius down to %lf\n", |
75 | < | maxCutoff ); |
76 | < | painCave.isFatal = 0; |
77 | < | simError(); |
94 | > | } |
95 | ||
96 | < | rList = maxCutoff; |
96 | > | void SimInfo::setBoxM( double theBox[3][3] ){ |
97 | > | |
98 | > | int i, j; |
99 | > | double FortranHmat[9]; // to preserve compatibility with Fortran the |
100 | > | // ordering in the array is as follows: |
101 | > | // [ 0 3 6 ] |
102 | > | // [ 1 4 7 ] |
103 | > | // [ 2 5 8 ] |
104 | > | double FortranHmatInv[9]; // the inverted Hmat (for Fortran); |
105 | ||
106 | < | sprintf( painCave.errMsg, |
82 | < | "New Box size is forcing cutoff radius down to %lf\n", |
83 | < | maxCutoff - 1.0 ); |
84 | < | painCave.isFatal = 0; |
85 | < | simError(); |
106 | > | if( !boxIsInit ) boxIsInit = 1; |
107 | ||
108 | < | rCut = rList - 1.0; |
108 | > | for(i=0; i < 3; i++) |
109 | > | for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j]; |
110 | > | |
111 | > | calcBoxL(); |
112 | > | calcHmatInv(); |
113 | ||
114 | < | // list radius changed so we have to refresh the simulation structure. |
115 | < | refreshSim(); |
114 | > | for(i=0; i < 3; i++) { |
115 | > | for (j=0; j < 3; j++) { |
116 | > | FortranHmat[3*j + i] = Hmat[i][j]; |
117 | > | FortranHmatInv[3*j + i] = HmatInv[i][j]; |
118 | > | } |
119 | } | |
120 | ||
121 | < | if (rCut > maxCutoff) { |
122 | < | sprintf( painCave.errMsg, |
123 | < | "New Box size is forcing cutoff radius down to %lf\n", |
124 | < | maxCutoff ); |
97 | < | painCave.isFatal = 0; |
98 | < | simError(); |
121 | > | setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic); |
122 | > | |
123 | > | } |
124 | > | |
125 | ||
126 | < | status = 0; |
127 | < | LJ_new_rcut(&rCut, &status); |
128 | < | if (status != 0) { |
129 | < | sprintf( painCave.errMsg, |
130 | < | "Error in recomputing LJ shifts based on new rcut\n"); |
105 | < | painCave.isFatal = 1; |
106 | < | simError(); |
107 | < | } |
108 | < | } |
126 | > | void SimInfo::getBoxM (double theBox[3][3]) { |
127 | > | |
128 | > | int i, j; |
129 | > | for(i=0; i<3; i++) |
130 | > | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]; |
131 | } | |
132 | ||
111 | – | void SimInfo::setBoxM( double theBox[9] ){ |
112 | – | |
113 | – | int i, status; |
114 | – | double smallestBoxL, maxCutoff; |
133 | ||
134 | < | for(i=0; i<9; i++) Hmat[i] = theBox[i]; |
135 | < | calcHmatI(); |
136 | < | calcBoxL(); |
134 | > | void SimInfo::scaleBox(double scale) { |
135 | > | double theBox[3][3]; |
136 | > | int i, j; |
137 | ||
138 | < | setFortranBoxSize(Hmat, HmatI, &orthoRhombic); |
121 | < | |
122 | < | smallestBoxL = boxLx; |
123 | < | if (boxLy < smallestBoxL) smallestBoxL = boxLy; |
124 | < | if (boxLz < smallestBoxL) smallestBoxL = boxLz; |
138 | > | // cerr << "Scaling box by " << scale << "\n"; |
139 | ||
140 | < | maxCutoff = smallestBoxL / 2.0; |
140 | > | for(i=0; i<3; i++) |
141 | > | for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale; |
142 | ||
143 | < | if (rList > maxCutoff) { |
129 | < | sprintf( painCave.errMsg, |
130 | < | "New Box size is forcing neighborlist radius down to %lf\n", |
131 | < | maxCutoff ); |
132 | < | painCave.isFatal = 0; |
133 | < | simError(); |
143 | > | setBoxM(theBox); |
144 | ||
145 | < | rList = maxCutoff; |
145 | > | } |
146 | ||
147 | < | sprintf( painCave.errMsg, |
148 | < | "New Box size is forcing cutoff radius down to %lf\n", |
149 | < | maxCutoff - 1.0 ); |
150 | < | painCave.isFatal = 0; |
151 | < | simError(); |
147 | > | void SimInfo::calcHmatInv( void ) { |
148 | > | |
149 | > | int oldOrtho; |
150 | > | int i,j; |
151 | > | double smallDiag; |
152 | > | double tol; |
153 | > | double sanity[3][3]; |
154 | ||
155 | < | rCut = rList - 1.0; |
155 | > | invertMat3( Hmat, HmatInv ); |
156 | ||
157 | < | // list radius changed so we have to refresh the simulation structure. |
158 | < | refreshSim(); |
159 | < | } |
157 | > | // check to see if Hmat is orthorhombic |
158 | > | |
159 | > | oldOrtho = orthoRhombic; |
160 | ||
161 | < | if (rCut > maxCutoff) { |
162 | < | sprintf( painCave.errMsg, |
163 | < | "New Box size is forcing cutoff radius down to %lf\n", |
164 | < | maxCutoff ); |
153 | < | painCave.isFatal = 0; |
154 | < | simError(); |
161 | > | smallDiag = fabs(Hmat[0][0]); |
162 | > | if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]); |
163 | > | if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]); |
164 | > | tol = smallDiag * orthoTolerance; |
165 | ||
166 | < | status = 0; |
167 | < | LJ_new_rcut(&rCut, &status); |
168 | < | if (status != 0) { |
166 | > | orthoRhombic = 1; |
167 | > | |
168 | > | for (i = 0; i < 3; i++ ) { |
169 | > | for (j = 0 ; j < 3; j++) { |
170 | > | if (i != j) { |
171 | > | if (orthoRhombic) { |
172 | > | if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0; |
173 | > | } |
174 | > | } |
175 | > | } |
176 | > | } |
177 | > | |
178 | > | if( oldOrtho != orthoRhombic ){ |
179 | > | |
180 | > | if( orthoRhombic ){ |
181 | sprintf( painCave.errMsg, | |
182 | < | "Error in recomputing LJ shifts based on new rcut\n"); |
183 | < | painCave.isFatal = 1; |
182 | > | "Hmat is switching from Non-Orthorhombic to OrthoRhombic\n" |
183 | > | " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
184 | > | orthoTolerance); |
185 | simError(); | |
186 | } | |
187 | + | else { |
188 | + | sprintf( painCave.errMsg, |
189 | + | "Hmat is switching from Orthorhombic to Non-OrthoRhombic\n" |
190 | + | " If this is a bad thing, change the orthoBoxTolerance( currently %G ).\n", |
191 | + | orthoTolerance); |
192 | + | simError(); |
193 | + | } |
194 | } | |
195 | } | |
166 | – | |
196 | ||
197 | < | void SimInfo::getBoxM (double theBox[9]) { |
197 | > | double SimInfo::matDet3(double a[3][3]) { |
198 | > | int i, j, k; |
199 | > | double determinant; |
200 | ||
201 | < | int i; |
171 | < | for(i=0; i<9; i++) theBox[i] = Hmat[i]; |
172 | < | } |
201 | > | determinant = 0.0; |
202 | ||
203 | + | for(i = 0; i < 3; i++) { |
204 | + | j = (i+1)%3; |
205 | + | k = (i+2)%3; |
206 | ||
207 | < | void SimInfo::scaleBox(double scale) { |
208 | < | double theBox[9]; |
177 | < | int i; |
207 | > | determinant += a[0][i] * (a[1][j]*a[2][k] - a[1][k]*a[2][j]); |
208 | > | } |
209 | ||
210 | < | for(i=0; i<9; i++) theBox[i] = Hmat[i]*scale; |
180 | < | |
181 | < | setBoxM(theBox); |
182 | < | |
210 | > | return determinant; |
211 | } | |
212 | ||
213 | < | void SimInfo::calcHmatI( void ) { |
186 | < | |
187 | < | double C[3][3]; |
188 | < | double detHmat; |
189 | < | int i, j, k; |
190 | < | double smallDiag; |
191 | < | double tol; |
192 | < | double sanity[3][3]; |
193 | < | |
194 | < | // calculate the adjunct of Hmat; |
195 | < | |
196 | < | C[0][0] = ( Hmat[4]*Hmat[8]) - (Hmat[7]*Hmat[5]); |
197 | < | C[1][0] = -( Hmat[1]*Hmat[8]) + (Hmat[7]*Hmat[2]); |
198 | < | C[2][0] = ( Hmat[1]*Hmat[5]) - (Hmat[4]*Hmat[2]); |
199 | < | |
200 | < | C[0][1] = -( Hmat[3]*Hmat[8]) + (Hmat[6]*Hmat[5]); |
201 | < | C[1][1] = ( Hmat[0]*Hmat[8]) - (Hmat[6]*Hmat[2]); |
202 | < | C[2][1] = -( Hmat[0]*Hmat[5]) + (Hmat[3]*Hmat[2]); |
203 | < | |
204 | < | C[0][2] = ( Hmat[3]*Hmat[7]) - (Hmat[6]*Hmat[4]); |
205 | < | C[1][2] = -( Hmat[0]*Hmat[7]) + (Hmat[6]*Hmat[1]); |
206 | < | C[2][2] = ( Hmat[0]*Hmat[4]) - (Hmat[3]*Hmat[1]); |
207 | < | |
208 | < | // calcutlate the determinant of Hmat |
213 | > | void SimInfo::invertMat3(double a[3][3], double b[3][3]) { |
214 | ||
215 | < | detHmat = 0.0; |
216 | < | for(i=0; i<3; i++) detHmat += Hmat[i] * C[i][0]; |
215 | > | int i, j, k, l, m, n; |
216 | > | double determinant; |
217 | ||
218 | < | |
214 | < | // H^-1 = C^T / det(H) |
215 | < | |
216 | < | i=0; |
217 | < | for(j=0; j<3; j++){ |
218 | < | for(k=0; k<3; k++){ |
218 | > | determinant = matDet3( a ); |
219 | ||
220 | < | HmatI[i] = C[j][k] / detHmat; |
221 | < | i++; |
222 | < | } |
220 | > | if (determinant == 0.0) { |
221 | > | sprintf( painCave.errMsg, |
222 | > | "Can't invert a matrix with a zero determinant!\n"); |
223 | > | painCave.isFatal = 1; |
224 | > | simError(); |
225 | } | |
226 | ||
227 | < | // sanity check |
228 | < | |
229 | < | for(i=0; i<3; i++){ |
230 | < | for(j=0; j<3; j++){ |
227 | > | for (i=0; i < 3; i++) { |
228 | > | j = (i+1)%3; |
229 | > | k = (i+2)%3; |
230 | > | for(l = 0; l < 3; l++) { |
231 | > | m = (l+1)%3; |
232 | > | n = (l+2)%3; |
233 | ||
234 | < | sanity[i][j] = 0.0; |
231 | < | for(k=0; k<3; k++){ |
232 | < | sanity[i][j] += Hmat[3*k+i] * HmatI[3*j+k]; |
233 | < | } |
234 | > | b[l][i] = (a[j][m]*a[k][n] - a[j][n]*a[k][m]) / determinant; |
235 | } | |
236 | } | |
237 | + | } |
238 | ||
239 | < | cerr << "sanity => \n" |
240 | < | << sanity[0][0] << "\t" << sanity[0][1] << "\t" << sanity [0][2] << "\n" |
239 | < | << sanity[1][0] << "\t" << sanity[1][1] << "\t" << sanity [1][2] << "\n" |
240 | < | << sanity[2][0] << "\t" << sanity[2][1] << "\t" << sanity [2][2] |
241 | < | << "\n"; |
242 | < | |
239 | > | void SimInfo::matMul3(double a[3][3], double b[3][3], double c[3][3]) { |
240 | > | double r00, r01, r02, r10, r11, r12, r20, r21, r22; |
241 | ||
242 | < | // check to see if Hmat is orthorhombic |
242 | > | r00 = a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0]; |
243 | > | r01 = a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1]; |
244 | > | r02 = a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2]; |
245 | ||
246 | < | smallDiag = Hmat[0]; |
247 | < | if(smallDiag > Hmat[4]) smallDiag = Hmat[4]; |
248 | < | if(smallDiag > Hmat[8]) smallDiag = Hmat[8]; |
249 | < | tol = smallDiag * 1E-6; |
246 | > | r10 = a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0]; |
247 | > | r11 = a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1]; |
248 | > | r12 = a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2]; |
249 | > | |
250 | > | r20 = a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0]; |
251 | > | r21 = a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1]; |
252 | > | r22 = a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2]; |
253 | > | |
254 | > | c[0][0] = r00; c[0][1] = r01; c[0][2] = r02; |
255 | > | c[1][0] = r10; c[1][1] = r11; c[1][2] = r12; |
256 | > | c[2][0] = r20; c[2][1] = r21; c[2][2] = r22; |
257 | > | } |
258 | ||
259 | < | orthoRhombic = 1; |
260 | < | for(i=0; (i<9) && orthoRhombic; i++){ |
261 | < | |
262 | < | if( (i%4) ){ // ignore the diagonals (0, 4, and 8) |
263 | < | orthoRhombic = (Hmat[i] <= tol); |
259 | > | void SimInfo::matVecMul3(double m[3][3], double inVec[3], double outVec[3]) { |
260 | > | double a0, a1, a2; |
261 | > | |
262 | > | a0 = inVec[0]; a1 = inVec[1]; a2 = inVec[2]; |
263 | > | |
264 | > | outVec[0] = m[0][0]*a0 + m[0][1]*a1 + m[0][2]*a2; |
265 | > | outVec[1] = m[1][0]*a0 + m[1][1]*a1 + m[1][2]*a2; |
266 | > | outVec[2] = m[2][0]*a0 + m[2][1]*a1 + m[2][2]*a2; |
267 | > | } |
268 | > | |
269 | > | void SimInfo::transposeMat3(double in[3][3], double out[3][3]) { |
270 | > | double temp[3][3]; |
271 | > | int i, j; |
272 | > | |
273 | > | for (i = 0; i < 3; i++) { |
274 | > | for (j = 0; j < 3; j++) { |
275 | > | temp[j][i] = in[i][j]; |
276 | } | |
277 | } | |
278 | < | |
278 | > | for (i = 0; i < 3; i++) { |
279 | > | for (j = 0; j < 3; j++) { |
280 | > | out[i][j] = temp[i][j]; |
281 | > | } |
282 | > | } |
283 | } | |
284 | + | |
285 | + | void SimInfo::printMat3(double A[3][3] ){ |
286 | ||
287 | + | std::cerr |
288 | + | << "[ " << A[0][0] << ", " << A[0][1] << ", " << A[0][2] << " ]\n" |
289 | + | << "[ " << A[1][0] << ", " << A[1][1] << ", " << A[1][2] << " ]\n" |
290 | + | << "[ " << A[2][0] << ", " << A[2][1] << ", " << A[2][2] << " ]\n"; |
291 | + | } |
292 | + | |
293 | + | void SimInfo::printMat9(double A[9] ){ |
294 | + | |
295 | + | std::cerr |
296 | + | << "[ " << A[0] << ", " << A[1] << ", " << A[2] << " ]\n" |
297 | + | << "[ " << A[3] << ", " << A[4] << ", " << A[5] << " ]\n" |
298 | + | << "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n"; |
299 | + | } |
300 | + | |
301 | + | |
302 | + | void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){ |
303 | + | |
304 | + | out[0] = a[1] * b[2] - a[2] * b[1]; |
305 | + | out[1] = a[2] * b[0] - a[0] * b[2] ; |
306 | + | out[2] = a[0] * b[1] - a[1] * b[0]; |
307 | + | |
308 | + | } |
309 | + | |
310 | + | double SimInfo::dotProduct3(double a[3], double b[3]){ |
311 | + | return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2]; |
312 | + | } |
313 | + | |
314 | + | double SimInfo::length3(double a[3]){ |
315 | + | return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); |
316 | + | } |
317 | + | |
318 | void SimInfo::calcBoxL( void ){ | |
319 | ||
320 | double dx, dy, dz, dsq; | |
264 | – | int i; |
321 | ||
322 | < | // boxVol = h1 (dot) h2 (cross) h3 |
322 | > | // boxVol = Determinant of Hmat |
323 | ||
324 | < | boxVol = Hmat[0] * ( (Hmat[4]*Hmat[8]) - (Hmat[7]*Hmat[5]) ) |
269 | < | + Hmat[1] * ( (Hmat[5]*Hmat[6]) - (Hmat[8]*Hmat[3]) ) |
270 | < | + Hmat[2] * ( (Hmat[3]*Hmat[7]) - (Hmat[6]*Hmat[4]) ); |
324 | > | boxVol = matDet3( Hmat ); |
325 | ||
272 | – | |
326 | // boxLx | |
327 | ||
328 | < | dx = Hmat[0]; dy = Hmat[1]; dz = Hmat[2]; |
328 | > | dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0]; |
329 | dsq = dx*dx + dy*dy + dz*dz; | |
330 | < | boxLx = sqrt( dsq ); |
330 | > | boxL[0] = sqrt( dsq ); |
331 | > | //maxCutoff = 0.5 * boxL[0]; |
332 | ||
333 | // boxLy | |
334 | ||
335 | < | dx = Hmat[3]; dy = Hmat[4]; dz = Hmat[5]; |
335 | > | dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1]; |
336 | dsq = dx*dx + dy*dy + dz*dz; | |
337 | < | boxLy = sqrt( dsq ); |
337 | > | boxL[1] = sqrt( dsq ); |
338 | > | //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1]; |
339 | ||
340 | + | |
341 | // boxLz | |
342 | ||
343 | < | dx = Hmat[6]; dy = Hmat[7]; dz = Hmat[8]; |
343 | > | dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2]; |
344 | dsq = dx*dx + dy*dy + dz*dz; | |
345 | < | boxLz = sqrt( dsq ); |
345 | > | boxL[2] = sqrt( dsq ); |
346 | > | //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2]; |
347 | > | |
348 | > | //calculate the max cutoff |
349 | > | maxCutoff = calcMaxCutOff(); |
350 | ||
351 | + | checkCutOffs(); |
352 | + | |
353 | } | |
354 | ||
355 | ||
356 | + | double SimInfo::calcMaxCutOff(){ |
357 | + | |
358 | + | double ri[3], rj[3], rk[3]; |
359 | + | double rij[3], rjk[3], rki[3]; |
360 | + | double minDist; |
361 | + | |
362 | + | ri[0] = Hmat[0][0]; |
363 | + | ri[1] = Hmat[1][0]; |
364 | + | ri[2] = Hmat[2][0]; |
365 | + | |
366 | + | rj[0] = Hmat[0][1]; |
367 | + | rj[1] = Hmat[1][1]; |
368 | + | rj[2] = Hmat[2][1]; |
369 | + | |
370 | + | rk[0] = Hmat[0][2]; |
371 | + | rk[1] = Hmat[1][2]; |
372 | + | rk[2] = Hmat[2][2]; |
373 | + | |
374 | + | crossProduct3(ri,rj, rij); |
375 | + | distXY = dotProduct3(rk,rij) / length3(rij); |
376 | + | |
377 | + | crossProduct3(rj,rk, rjk); |
378 | + | distYZ = dotProduct3(ri,rjk) / length3(rjk); |
379 | + | |
380 | + | crossProduct3(rk,ri, rki); |
381 | + | distZX = dotProduct3(rj,rki) / length3(rki); |
382 | + | |
383 | + | minDist = min(min(distXY, distYZ), distZX); |
384 | + | return minDist/2; |
385 | + | |
386 | + | } |
387 | + | |
388 | void SimInfo::wrapVector( double thePos[3] ){ | |
389 | ||
390 | < | int i, j, k; |
390 | > | int i; |
391 | double scaled[3]; | |
392 | ||
393 | if( !orthoRhombic ){ | |
394 | // calc the scaled coordinates. | |
395 | + | |
396 | + | |
397 | + | matVecMul3(HmatInv, thePos, scaled); |
398 | ||
399 | for(i=0; i<3; i++) | |
303 | – | scaled[i] = |
304 | – | thePos[0]*HmatI[i] + thePos[1]*HmatI[i+3] + thePos[3]*HmatI[i+6]; |
305 | – | |
306 | – | // wrap the scaled coordinates |
307 | – | |
308 | – | for(i=0; i<3; i++) |
400 | scaled[i] -= roundMe(scaled[i]); | |
401 | ||
402 | // calc the wrapped real coordinates from the wrapped scaled coordinates | |
403 | ||
404 | < | for(i=0; i<3; i++) |
405 | < | thePos[i] = |
315 | < | scaled[0]*Hmat[i] + scaled[1]*Hmat[i+3] + scaled[2]*Hmat[i+6]; |
404 | > | matVecMul3(Hmat, scaled, thePos); |
405 | > | |
406 | } | |
407 | else{ | |
408 | // calc the scaled coordinates. | |
409 | ||
410 | for(i=0; i<3; i++) | |
411 | < | scaled[i] = thePos[i]*HmatI[i*4]; |
411 | > | scaled[i] = thePos[i]*HmatInv[i][i]; |
412 | ||
413 | // wrap the scaled coordinates | |
414 | ||
# | Line 328 | Line 418 | void SimInfo::wrapVector( double thePos[3] ){ | |
418 | // calc the wrapped real coordinates from the wrapped scaled coordinates | |
419 | ||
420 | for(i=0; i<3; i++) | |
421 | < | thePos[i] = scaled[i]*Hmat[i*4]; |
421 | > | thePos[i] = scaled[i]*Hmat[i][i]; |
422 | } | |
423 | ||
334 | – | |
424 | } | |
425 | ||
426 | ||
427 | int SimInfo::getNDF(){ | |
428 | < | int ndf_local, ndf; |
428 | > | int ndf_local; |
429 | ||
430 | ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints; | |
431 | ||
# | Line 346 | Line 435 | int SimInfo::getNDF(){ | |
435 | ndf = ndf_local; | |
436 | #endif | |
437 | ||
438 | < | ndf = ndf - 3; |
438 | > | ndf = ndf - 3 - nZconstraints; |
439 | ||
440 | return ndf; | |
441 | } | |
442 | ||
443 | int SimInfo::getNDFraw() { | |
444 | < | int ndfRaw_local, ndfRaw; |
444 | > | int ndfRaw_local; |
445 | ||
446 | // Raw degrees of freedom that we have to set | |
447 | ndfRaw_local = 3 * n_atoms + 3 * n_oriented; | |
# | Line 365 | Line 454 | int SimInfo::getNDFraw() { | |
454 | ||
455 | return ndfRaw; | |
456 | } | |
457 | < | |
457 | > | |
458 | > | int SimInfo::getNDFtranslational() { |
459 | > | int ndfTrans_local; |
460 | > | |
461 | > | ndfTrans_local = 3 * n_atoms - n_constraints; |
462 | > | |
463 | > | #ifdef IS_MPI |
464 | > | MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
465 | > | #else |
466 | > | ndfTrans = ndfTrans_local; |
467 | > | #endif |
468 | > | |
469 | > | ndfTrans = ndfTrans - 3 - nZconstraints; |
470 | > | |
471 | > | return ndfTrans; |
472 | > | } |
473 | > | |
474 | void SimInfo::refreshSim(){ | |
475 | ||
476 | simtype fInfo; | |
477 | int isError; | |
478 | int n_global; | |
479 | int* excl; | |
480 | < | |
376 | < | fInfo.rrf = 0.0; |
377 | < | fInfo.rt = 0.0; |
480 | > | |
481 | fInfo.dielect = 0.0; | |
482 | ||
380 | – | fInfo.rlist = rList; |
381 | – | fInfo.rcut = rCut; |
382 | – | |
483 | if( useDipole ){ | |
384 | – | fInfo.rrf = ecr; |
385 | – | fInfo.rt = ecr - est; |
484 | if( useReactionField )fInfo.dielect = dielectric; | |
485 | } | |
486 | ||
# | Line 428 | Line 526 | void SimInfo::refreshSim(){ | |
526 | ||
527 | this->ndf = this->getNDF(); | |
528 | this->ndfRaw = this->getNDFraw(); | |
529 | + | this->ndfTrans = this->getNDFtranslational(); |
530 | + | } |
531 | ||
532 | + | void SimInfo::setDefaultRcut( double theRcut ){ |
533 | + | |
534 | + | haveRcut = 1; |
535 | + | rCut = theRcut; |
536 | + | |
537 | + | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
538 | + | |
539 | + | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
540 | } | |
541 | ||
542 | + | void SimInfo::setDefaultEcr( double theEcr ){ |
543 | + | |
544 | + | haveEcr = 1; |
545 | + | |
546 | + | ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0; |
547 | + | |
548 | + | ecr = theEcr; |
549 | + | |
550 | + | notifyFortranCutOffs( &rCut, &rList, &ecr, &est ); |
551 | + | } |
552 | + | |
553 | + | void SimInfo::setDefaultEcr( double theEcr, double theEst ){ |
554 | + | |
555 | + | est = theEst; |
556 | + | setDefaultEcr( theEcr ); |
557 | + | } |
558 | + | |
559 | + | |
560 | + | void SimInfo::checkCutOffs( void ){ |
561 | + | |
562 | + | if( boxIsInit ){ |
563 | + | |
564 | + | //we need to check cutOffs against the box |
565 | + | |
566 | + | if( rCut > maxCutoff ){ |
567 | + | sprintf( painCave.errMsg, |
568 | + | "Box size is too small for the long range cutoff radius, " |
569 | + | "%lf, at time %lf\n", |
570 | + | rCut, currentTime ); |
571 | + | painCave.isFatal = 1; |
572 | + | simError(); |
573 | + | } |
574 | + | |
575 | + | if( haveEcr ){ |
576 | + | if( ecr > maxCutoff ){ |
577 | + | sprintf( painCave.errMsg, |
578 | + | "Box size is too small for the electrostatic cutoff radius, " |
579 | + | "%lf, at time %lf\n", |
580 | + | ecr, currentTime ); |
581 | + | painCave.isFatal = 1; |
582 | + | simError(); |
583 | + | } |
584 | + | } |
585 | + | } else { |
586 | + | // initialize this stuff before using it, OK? |
587 | + | sprintf( painCave.errMsg, |
588 | + | "Trying to check cutoffs without a box. Be smarter.\n" ); |
589 | + | painCave.isFatal = 1; |
590 | + | simError(); |
591 | + | } |
592 | + | |
593 | + | } |
594 | + | |
595 | + | void SimInfo::addProperty(GenericData* prop){ |
596 | + | |
597 | + | map<string, GenericData*>::iterator result; |
598 | + | result = properties.find(prop->getID()); |
599 | + | |
600 | + | //we can't simply use properties[prop->getID()] = prop, |
601 | + | //it will cause memory leak if we already contain a propery which has the same name of prop |
602 | + | |
603 | + | if(result != properties.end()){ |
604 | + | |
605 | + | delete (*result).second; |
606 | + | (*result).second = prop; |
607 | + | |
608 | + | } |
609 | + | else{ |
610 | + | |
611 | + | properties[prop->getID()] = prop; |
612 | + | |
613 | + | } |
614 | + | |
615 | + | } |
616 | + | |
617 | + | GenericData* SimInfo::getProperty(const string& propName){ |
618 | + | |
619 | + | map<string, GenericData*>::iterator result; |
620 | + | |
621 | + | //string lowerCaseName = (); |
622 | + | |
623 | + | result = properties.find(propName); |
624 | + | |
625 | + | if(result != properties.end()) |
626 | + | return (*result).second; |
627 | + | else |
628 | + | return NULL; |
629 | + | } |
630 | + | |
631 | + | vector<GenericData*> SimInfo::getProperties(){ |
632 | + | |
633 | + | vector<GenericData*> result; |
634 | + | map<string, GenericData*>::iterator i; |
635 | + | |
636 | + | for(i = properties.begin(); i != properties.end(); i++) |
637 | + | result.push_back((*i).second); |
638 | + | |
639 | + | return result; |
640 | + | } |
641 | + | |
642 | + | double SimInfo::matTrace3(double m[3][3]){ |
643 | + | double trace; |
644 | + | trace = m[0][0] + m[1][1] + m[2][2]; |
645 | + | |
646 | + | return trace; |
647 | + | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |