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 660 by tim, Thu Jul 31 19:59:34 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;
# Line 44 | Line 48 | SimInfo::SimInfo(){
48    haveOrigEcr = 0;
49    boxIsInit = 0;
50    
51 +  resetTime = 1e99;
52    
53  
54    usePBC = 0;
# Line 54 | 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 <
67 <  
76 >    
77   }
78  
79   void SimInfo::setBox(double newBox[3]) {
# Line 85 | Line 94 | void SimInfo::setBoxM( double theBox[3][3] ){
94  
95   void SimInfo::setBoxM( double theBox[3][3] ){
96    
97 <  int i, j, status;
89 <  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 ]
# Line 271 | Line 279 | void SimInfo::printMat9(double A[9] ){
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 +
284 +
285 + void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){
286 +
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;
279  int i;
304  
305    // boxVol = Determinant of Hmat
306  
# Line 287 | Line 311 | void SimInfo::calcBoxL( void ){
311    dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0];
312    dsq = dx*dx + dy*dy + dz*dz;
313    boxL[0] = sqrt( dsq );
314 <  maxCutoff = 0.5 * boxL[0];
314 >  //maxCutoff = 0.5 * boxL[0];
315  
316    // boxLy
317    
318    dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1];
319    dsq = dx*dx + dy*dy + dz*dz;
320    boxL[1] = sqrt( dsq );
321 <  if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
321 >  //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
322  
323 +
324    // boxLz
325    
326    dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2];
327    dsq = dx*dx + dy*dy + dz*dz;
328    boxL[2] = sqrt( dsq );
329 <  if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2];
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 ){
# Line 346 | Line 408 | int SimInfo::getNDF(){
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 356 | 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 375 | 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;
# Line 431 | Line 509 | void SimInfo::refreshSim(){
509  
510    this->ndf = this->getNDF();
511    this->ndfRaw = this->getNDFraw();
512 <
512 >  this->ndfTrans = this->getNDFtranslational();
513   }
514  
515  
516   void SimInfo::setRcut( double theRcut ){
517  
440  if( !haveOrigRcut ){
441    haveOrigRcut = 1;
442    origRcut = theRcut;
443  }
444
518    rCut = theRcut;
519    checkCutOffs();
520   }
521  
522 < void SimInfo::setEcr( double theEcr ){
522 > void SimInfo::setDefaultRcut( double theRcut ){
523  
524 <  if( !haveOrigEcr ){
525 <    haveOrigEcr = 1;
526 <    origEcr = theEcr;
527 <  }
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 <
567 >  
568    if( boxIsInit ){
569      
570      //we need to check cutOffs against the box
571 <    
572 <    if( maxCutoff > rCut ){
571 >
572 >    //detect the change of rCut
573 >    if(( maxCutoff > rCut )&&(usePBC)){
574        if( rCut < origRcut ){
575 <        rCut = origRcut;
576 <        if (rCut > maxCutoff) rCut = maxCutoff;
577 <        
578 <        sprintf( painCave.errMsg,
579 <                 "New Box size is setting the long range cutoff radius "
580 <                 "to %lf\n",
581 <                 rCut );
582 <        painCave.isFatal = 0;
583 <        simError();
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 <
489 <    if( maxCutoff > ecr ){
490 <      if( ecr < origEcr ){
491 <        rCut = origEcr;
492 <        if (ecr > maxCutoff) ecr = maxCutoff;
493 <        
494 <        sprintf( painCave.errMsg,
495 <                 "New Box size is setting the electrostaticCutoffRadius "
496 <                 "to %lf\n",
497 <                 ecr );
498 <        painCave.isFatal = 0;
499 <        simError();
500 <      }
501 <    }
502 <
503 <
504 <    if (rCut > maxCutoff) {
588 >    else if ((rCut > maxCutoff)&&(usePBC)) {
589        sprintf( painCave.errMsg,
590                 "New Box size is setting the long range cutoff radius "
591 <               "to %lf\n",
592 <               maxCutoff );
591 >               "to %lf at time %lf\n",
592 >               maxCutoff, currentTime );
593        painCave.isFatal = 0;
594        simError();
595        rCut = maxCutoff;
596      }
597  
598 <    if( ecr > maxCutoff){
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\n",
617 <               maxCutoff  );
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 <  }
526 <  
527 <
528 <  if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1;
529 <
530 <  // rlist is the 1.0 plus max( rcut, ecr )
531 <  
532 <  ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
533 <
534 <  if( cutChanged ){
625 >    // rlist is the 1.0 plus max( rcut, ecr )
626      
627 <    notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
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 <
539 <  oldEcr = ecr;
540 <  oldRcut = rCut;
643 >  
644   }
645  
646   void SimInfo::addProperty(GenericData* prop){
# Line 587 | Line 690 | vector<GenericData*> SimInfo::getProperties(){
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