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 568 by mmeineke, Mon Jun 30 22:04:01 2003 UTC vs.
Revision 574 by gezelter, Tue Jul 8 20:56:10 2003 UTC

# Line 2 | Line 2
2   #include <cstring>
3   #include <cmath>
4  
5 + #include <iostream>
6 + using namespace std;
7  
8   #include "SimInfo.hpp"
9   #define __C
# Line 14 | Line 16 | SimInfo* currentInfo;
16   #include "mpiSimulation.hpp"
17   #endif
18  
19 + inline double roundMe( double x ){
20 +  return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 );
21 + }
22 +          
23 +
24   SimInfo* currentInfo;
25  
26   SimInfo::SimInfo(){
# Line 54 | Line 61 | void SimInfo::setBox(double newBox[3]) {
61    calcHmatI();
62    calcBoxL();
63  
64 <  setFortranBoxSize(Hmat);
64 >  setFortranBoxSize(Hmat, HmatI, &orthoRhombic);
65  
66    smallestBoxL = boxLx;
67    if (boxLy < smallestBoxL) smallestBoxL = boxLy;
# Line 110 | Line 117 | void SimInfo::setBoxM( double theBox[9] ){
117    calcHmatI();
118    calcBoxL();
119  
120 <  setFortranBoxSize(Hmat);
120 >  setFortranBoxSize(Hmat, HmatI, &orthoRhombic);
121  
122    smallestBoxL = boxLx;
123    if (boxLy < smallestBoxL) smallestBoxL = boxLy;
# Line 158 | Line 165 | void SimInfo::getBox(double theBox[9]) {
165   }
166  
167  
168 < void SimInfo::getBox(double theBox[9]) {
168 > void SimInfo::getBoxM (double theBox[9]) {
169  
170    int i;
171    for(i=0; i<9; i++) theBox[i] = Hmat[i];
172   }
166
173  
174 +
175 + void SimInfo::scaleBox(double scale) {
176 +  double theBox[9];
177 +  int i;
178 +
179 +  for(i=0; i<9; i++) theBox[i] = Hmat[i]*scale;
180 +
181 +  setBoxM(theBox);
182 +
183 + }
184 +
185   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  
# Line 199 | Line 219 | void SimInfo::calcHmatI( void ) {
219  
220        HmatI[i] = C[j][k] / detHmat;
221        i++;
222 +    }
223 +  }
224 +
225 +  // sanity check
226 +
227 +  for(i=0; i<3; i++){
228 +    for(j=0; j<3; j++){
229 +      
230 +      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 +    }
235 +  }
236 +
237 +  cerr << "sanity => \n"
238 +       << 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 +    
243 +
244 +  // check to see if Hmat is orthorhombic
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;
250 +
251 +  orthoRhombic = 1;
252 +  for(i=0; (i<9) && orthoRhombic; i++){
253 +    
254 +    if( (i%4) ){ // ignore the diagonals (0, 4, and 8)
255 +      orthoRhombic = (Hmat[i] <= tol);
256      }
257    }
258 +    
259   }
260  
261   void SimInfo::calcBoxL( void ){
# Line 241 | Line 296 | void SimInfo::wrapVector( double thePos[3] ){
296    int i, j, k;
297    double scaled[3];
298  
299 <  // calc the scaled coordinates.
300 <  
301 <  for(i=0; i<3; i++)
302 <    scaled[i] = thePos[0]*Hmat[i] + thePos[1]*Hat[i+3] + thePos[3]*Hmat[i+6];
303 <
304 <  // wrap the scaled coordinates
305 <
306 <  for(i=0; i<3; i++)
307 <    scaled[i] -= (copysign(1,scaled[i]) * (int)(fabs(scaled[i]) + 0.5));
308 <  
309 <
299 >  if( !orthoRhombic ){
300 >    // calc the scaled coordinates.
301 >    
302 >    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++)
309 >      scaled[i] -= roundMe(scaled[i]);
310 >    
311 >    // calc the wrapped real coordinates from the wrapped scaled coordinates
312 >    
313 >    for(i=0; i<3; i++)
314 >      thePos[i] =
315 >        scaled[0]*Hmat[i] + scaled[1]*Hmat[i+3] + scaled[2]*Hmat[i+6];
316 >  }
317 >  else{
318 >    // calc the scaled coordinates.
319 >    
320 >    for(i=0; i<3; i++)
321 >      scaled[i] = thePos[i]*HmatI[i*4];
322 >    
323 >    // wrap the scaled coordinates
324 >    
325 >    for(i=0; i<3; i++)
326 >      scaled[i] -= roundMe(scaled[i]);
327 >    
328 >    // calc the wrapped real coordinates from the wrapped scaled coordinates
329 >    
330 >    for(i=0; i<3; i++)
331 >      thePos[i] = scaled[i]*Hmat[i*4];
332 >  }
333 >    
334 >    
335   }
336  
337  
# Line 297 | Line 377 | void SimInfo::refreshSim(){
377    fInfo.rt = 0.0;
378    fInfo.dielect = 0.0;
379  
300  fInfo.box[0] = box_x;
301  fInfo.box[1] = box_y;
302  fInfo.box[2] = box_z;
303
380    fInfo.rlist = rList;
381    fInfo.rcut = rCut;
382  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines