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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines