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 618 by mmeineke, Tue Jul 15 21:34:56 2003 UTC vs.
Revision 841 by mmeineke, Wed Oct 29 17:55:28 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 44 | 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, j;
# Line 65 | Line 94 | void SimInfo::setBoxM( double theBox[3][3] ){
94  
95   void SimInfo::setBoxM( double theBox[3][3] ){
96    
97 <  int i, j, status;
69 <  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 74 | Line 102 | void SimInfo::setBoxM( double theBox[3][3] ){
102                           // [ 2 5 8 ]
103    double FortranHmatInv[9]; // the inverted Hmat (for Fortran);
104  
105 +  
106 +  if( !boxIsInit ) boxIsInit = 1;
107  
108    for(i=0; i < 3; i++)
109      for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j];
110    
81  //  cerr
82  // << "setting Hmat ->\n"
83  // << "[ " << Hmat[0][0] << ", " << Hmat[0][1] << ", " << Hmat[0][2] << " ]\n"
84  // << "[ " << Hmat[1][0] << ", " << Hmat[1][1] << ", " << Hmat[1][2] << " ]\n"
85  // << "[ " << Hmat[2][0] << ", " << Hmat[2][1] << ", " << Hmat[2][2] << " ]\n";
86
111    calcBoxL();
112    calcHmatInv();
113  
# Line 96 | Line 120 | void SimInfo::setBoxM( double theBox[3][3] ){
120  
121    setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic);
122  
99  smallestBoxL = boxLx;
100  if (boxLy < smallestBoxL) smallestBoxL = boxLy;
101  if (boxLz < smallestBoxL) smallestBoxL = boxLz;
102
103  maxCutoff = smallestBoxL / 2.0;
104
105  if (rList > maxCutoff) {
106    sprintf( painCave.errMsg,
107             "New Box size is forcing neighborlist radius down to %lf\n",
108             maxCutoff );
109    painCave.isFatal = 0;
110    simError();
111
112    rList = maxCutoff;
113
114    sprintf( painCave.errMsg,
115             "New Box size is forcing cutoff radius down to %lf\n",
116             maxCutoff - 1.0 );
117    painCave.isFatal = 0;
118    simError();
119
120    rCut = rList - 1.0;
121
122    // list radius changed so we have to refresh the simulation structure.
123    refreshSim();
124  }
125
126  if( ecr > maxCutoff ){
127
128    sprintf( painCave.errMsg,
129             "New Box size is forcing electrostatic cutoff radius "
130             "down to %lf\n",
131             maxCutoff );
132    painCave.isFatal = 0;
133    simError();
134
135    ecr = maxCutoff;
136    est = 0.05 * ecr;
137
138    refreshSim();
139  }
140    
123   }
124  
125  
# Line 299 | Line 281 | void SimInfo::calcBoxL( void ){
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;
305  int i;
304  
305    // boxVol = Determinant of Hmat
306  
# Line 312 | Line 310 | void SimInfo::calcBoxL( void ){
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[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[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 ){
# Line 369 | 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 379 | 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 398 | 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;
408  
409  fInfo.rrf = 0.0;
410  fInfo.rt = 0.0;
411  fInfo.dielect = 0.0;
463  
464 <  fInfo.rlist = rList;
414 <  fInfo.rcut = rCut;
464 >  fInfo.dielect = 0.0;
465  
466    if( useDipole ){
417    fInfo.rrf = ecr;
418    fInfo.rt = ecr - est;
467      if( useReactionField )fInfo.dielect = dielectric;
468    }
469  
# Line 461 | 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 +
529 + void SimInfo::setEcr( double theEcr ){
530 +
531 +  ecr = theEcr;
532 +  checkCutOffs();
533 + }
534 +
535 + void SimInfo::setDefaultEcr( double theEcr ){
536 +
537 +  haveOrigEcr = 1;
538 +  origEcr = theEcr;
539 +  
540 +  ecr = theEcr;
541 + }
542 +
543 + void SimInfo::setEcr( double theEcr, double theEst ){
544 +
545 +  est = theEst;
546 +  setEcr( theEcr );
547 + }
548 +
549 + void SimInfo::setDefaultEcr( double theEcr, double theEst ){
550 +
551 +  est = theEst;
552 +  setDefaultEcr( theEcr );
553 + }
554 +
555 +
556 + void SimInfo::checkCutOffs( void ){
557 +
558 +  int cutChanged = 0;
559 +  
560 +  if( boxIsInit ){
561 +    
562 +    //we need to check cutOffs against the box
563 +
564 +    //detect the change of rCut
565 +    if(( maxCutoff > rCut )&&(usePBC)){
566 +      if( rCut < origRcut ){
567 +        rCut = origRcut;
568 +        
569 +        if (rCut > maxCutoff)
570 +          rCut = maxCutoff;
571 +  
572 +          sprintf( painCave.errMsg,
573 +                    "New Box size is setting the long range cutoff radius "
574 +                    "to %lf at time %lf\n",
575 +                    rCut, currentTime );
576 +          painCave.isFatal = 0;
577 +          simError();
578 +      }
579 +    }
580 +    else if ((rCut > maxCutoff)&&(usePBC)) {
581 +      sprintf( painCave.errMsg,
582 +               "New Box size is setting the long range cutoff radius "
583 +               "to %lf at time %lf\n",
584 +               maxCutoff, currentTime );
585 +      painCave.isFatal = 0;
586 +      simError();
587 +      rCut = maxCutoff;
588 +    }
589 +
590 +
591 +    //detect the change of ecr
592 +    if( maxCutoff > ecr ){
593 +      if( ecr < origEcr ){
594 +        ecr = origEcr;
595 +        if (ecr > maxCutoff) ecr = maxCutoff;
596 +  
597 +          sprintf( painCave.errMsg,
598 +                    "New Box size is setting the electrostaticCutoffRadius "
599 +                    "to %lf at time %lf\n",
600 +                    ecr, currentTime );
601 +            painCave.isFatal = 0;
602 +            simError();
603 +      }
604 +    }
605 +    else if( ecr > maxCutoff){
606 +      sprintf( painCave.errMsg,
607 +               "New Box size is setting the electrostaticCutoffRadius "
608 +               "to %lf at time %lf\n",
609 +               maxCutoff, currentTime  );
610 +      painCave.isFatal = 0;
611 +      simError();      
612 +      ecr = maxCutoff;
613 +    }
614 +
615 +    if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1;
616 +    
617 +    // rlist is the 1.0 plus max( rcut, ecr )
618 +    
619 +    ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
620 +    
621 +    if( cutChanged ){
622 +      
623 +      notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
624 +    }
625 +    
626 +    oldEcr = ecr;
627 +    oldRcut = rCut;
628 +    
629 +  } else {
630 +    // initialize this stuff before using it, OK?
631 +    sprintf( painCave.errMsg,
632 +             "Trying to check cutoffs without a box. Be smarter.\n" );
633 +    painCave.isFatal = 1;
634 +    simError();      
635 +  }
636 +  
637 + }
638 +
639 + void SimInfo::addProperty(GenericData* prop){
640 +
641 +  map<string, GenericData*>::iterator result;
642 +  result = properties.find(prop->getID());
643 +  
644 +  //we can't simply use  properties[prop->getID()] = prop,
645 +  //it will cause memory leak if we already contain a propery which has the same name of prop
646 +  
647 +  if(result != properties.end()){
648 +    
649 +    delete (*result).second;
650 +    (*result).second = prop;
651 +      
652 +  }
653 +  else{
654 +
655 +    properties[prop->getID()] = prop;
656 +
657 +  }
658 +    
659 + }
660 +
661 + GenericData* SimInfo::getProperty(const string& propName){
662 +
663 +  map<string, GenericData*>::iterator result;
664 +  
665 +  //string lowerCaseName = ();
666 +  
667 +  result = properties.find(propName);
668 +  
669 +  if(result != properties.end())
670 +    return (*result).second;  
671 +  else  
672 +    return NULL;  
673 + }
674 +
675 + vector<GenericData*> SimInfo::getProperties(){
676 +
677 +  vector<GenericData*> result;
678 +  map<string, GenericData*>::iterator i;
679 +  
680 +  for(i = properties.begin(); i != properties.end(); i++)
681 +    result.push_back((*i).second);
682 +    
683 +  return result;
684 + }
685 +
686 + double SimInfo::matTrace3(double m[3][3]){
687 +  double trace;
688 +  trace = m[0][0] + m[1][1] + m[2][2];
689 +
690 +  return trace;
691 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines