ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimInfo.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/SimInfo.cpp (file contents):
Revision 574 by gezelter, Tue Jul 8 20:56:10 2003 UTC vs.
Revision 999 by chrisfen, Fri Jan 30 15:01:09 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines