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 699 by tim, Fri Aug 15 19:24:13 2003 UTC vs.
Revision 843 by mmeineke, Wed Oct 29 20:41:39 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 48 | Line 48 | SimInfo::SimInfo(){
48    haveOrigEcr = 0;
49    boxIsInit = 0;
50    
51 +  resetTime = 1e99;
52    
53  
54    usePBC = 0;
# Line 93 | Line 94 | void SimInfo::setBoxM( double theBox[3][3] ){
94  
95   void SimInfo::setBoxM( double theBox[3][3] ){
96    
97 <  int i, j, status;
97 <  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 279 | 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;
287  int i;
304  
305    // boxVol = Determinant of Hmat
306  
# Line 295 | 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 356 | 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 372 | Line 424 | int SimInfo::getNDFraw() {
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 385 | 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 441 | 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  
450  if( !haveOrigRcut ){
451    haveOrigRcut = 1;
452    origRcut = theRcut;
453  }
454
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;
464 <  }
524 >  haveOrigRcut = 1;
525 >  origRcut = theRcut;
526 >  rCut = theRcut;
527  
528 +  notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
529 + }
530 +
531 + void SimInfo::setEcr( double theEcr ){
532 +
533    ecr = theEcr;
534    checkCutOffs();
535 + }
536 +
537 + void SimInfo::setDefaultEcr( double theEcr ){
538 +
539 +  haveOrigEcr = 1;
540 +  origEcr = theEcr;
541 +  
542 +  ecr = theEcr;
543 +  notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
544   }
545  
546   void SimInfo::setEcr( double theEcr, double theEst ){
# Line 473 | Line 549 | void SimInfo::setEcr( double theEcr, double theEst ){
549    setEcr( theEcr );
550   }
551  
552 + void SimInfo::setDefaultEcr( double theEcr, double theEst ){
553  
554 < void SimInfo::checkCutOffs( void ){
554 >  est = theEst;
555 >  setDefaultEcr( theEcr );
556 > }
557  
479  int cutChanged = 0;
558  
559 + void SimInfo::checkCutOffs( void ){
560  
561 <
561 >  int cutChanged = 0;
562 >  
563    if( boxIsInit ){
564      
565      //we need to check cutOffs against the box
566 <  
566 >
567 >    //detect the change of rCut
568      if(( maxCutoff > rCut )&&(usePBC)){
569        if( rCut < origRcut ){
570 <        rCut = origRcut;
571 <        if (rCut > maxCutoff) rCut = maxCutoff;
572 <        
573 <        sprintf( painCave.errMsg,
574 <                 "New Box size is setting the long range cutoff radius "
575 <                 "to %lf\n",
576 <                 rCut );
577 <        painCave.isFatal = 0;
578 <        simError();
570 >        rCut = origRcut;
571 >        
572 >        if (rCut > maxCutoff)
573 >          rCut = maxCutoff;
574 >  
575 >          sprintf( painCave.errMsg,
576 >                    "New Box size is setting the long range cutoff radius "
577 >                    "to %lf at time %lf\n",
578 >                    rCut, currentTime );
579 >          painCave.isFatal = 0;
580 >          simError();
581        }
582      }
583 <
501 <    if( maxCutoff > ecr ){
502 <      if( ecr < origEcr ){
503 <        rCut = origEcr;
504 <        if (ecr > maxCutoff) ecr = maxCutoff;
505 <        
506 <        sprintf( painCave.errMsg,
507 <                 "New Box size is setting the electrostaticCutoffRadius "
508 <                 "to %lf\n",
509 <                 ecr );
510 <        painCave.isFatal = 0;
511 <        simError();
512 <      }
513 <    }
514 <
515 <
516 <    if ((rCut > maxCutoff)&&(usePBC)) {
583 >    else if ((rCut > maxCutoff)&&(usePBC)) {
584        sprintf( painCave.errMsg,
585                 "New Box size is setting the long range cutoff radius "
586 <               "to %lf\n",
587 <               maxCutoff );
586 >               "to %lf at time %lf\n",
587 >               maxCutoff, currentTime );
588        painCave.isFatal = 0;
589        simError();
590        rCut = maxCutoff;
591      }
592  
593 <    if( ecr > maxCutoff){
593 >
594 >    //detect the change of ecr
595 >    if( maxCutoff > ecr ){
596 >      if( ecr < origEcr ){
597 >        ecr = origEcr;
598 >        if (ecr > maxCutoff) ecr = maxCutoff;
599 >  
600 >          sprintf( painCave.errMsg,
601 >                    "New Box size is setting the electrostaticCutoffRadius "
602 >                    "to %lf at time %lf\n",
603 >                    ecr, currentTime );
604 >            painCave.isFatal = 0;
605 >            simError();
606 >      }
607 >    }
608 >    else if( ecr > maxCutoff){
609        sprintf( painCave.errMsg,
610                 "New Box size is setting the electrostaticCutoffRadius "
611 <               "to %lf\n",
612 <               maxCutoff  );
611 >               "to %lf at time %lf\n",
612 >               maxCutoff, currentTime  );
613        painCave.isFatal = 0;
614        simError();      
615        ecr = maxCutoff;
616      }
617  
618 +    if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1;
619      
620 <  }
538 <  
539 <
540 <  if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1;
541 <
542 <  // rlist is the 1.0 plus max( rcut, ecr )
543 <  
544 <  ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
545 <
546 <  if( cutChanged ){
620 >    // rlist is the 1.0 plus max( rcut, ecr )
621      
622 <    notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
622 >    ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
623 >    
624 >    if( cutChanged ){
625 >      
626 >      notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
627 >    }
628 >    
629 >    oldEcr = ecr;
630 >    oldRcut = rCut;
631 >    
632 >  } else {
633 >    // initialize this stuff before using it, OK?
634 >    sprintf( painCave.errMsg,
635 >             "Trying to check cutoffs without a box. Be smarter.\n" );
636 >    painCave.isFatal = 1;
637 >    simError();      
638    }
639 <
551 <  oldEcr = ecr;
552 <  oldRcut = rCut;
639 >  
640   }
641  
642   void SimInfo::addProperty(GenericData* prop){
# Line 599 | Line 686 | vector<GenericData*> SimInfo::getProperties(){
686    return result;
687   }
688  
689 + double SimInfo::matTrace3(double m[3][3]){
690 +  double trace;
691 +  trace = m[0][0] + m[1][1] + m[2][2];
692  
693 +  return trace;
694 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines