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 626 by mmeineke, Wed Jul 16 21:30:56 2003 UTC vs.
Revision 781 by tim, Mon Sep 22 23:07:57 2003 UTC

# 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 43 | Line 48 | SimInfo::SimInfo(){
48    haveOrigEcr = 0;
49    boxIsInit = 0;
50    
51 +  resetTime = 1e99;
52    
53  
54    usePBC = 0;
# Line 53 | 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 260 | Line 280 | void SimInfo::printMat9(double A[9] ){
280              << "[ " << A[0] << ", " << A[1] << ", " << A[2] << " ]\n"
281              << "[ " << A[3] << ", " << A[4] << ", " << A[5] << " ]\n"
282              << "[ " << A[6] << ", " << A[7] << ", " << A[8] << " ]\n";
283 + }
284 +
285 +
286 + void SimInfo::crossProduct3(double a[3],double b[3], double out[3]){
287 +
288 +      out[0] = a[1] * b[2] - a[2] * b[1];
289 +      out[1] = a[2] * b[0] - a[0] * b[2] ;
290 +      out[2] = a[0] * b[1] - a[1] * b[0];
291 +      
292 + }
293 +
294 + double SimInfo::dotProduct3(double a[3], double b[3]){
295 +  return a[0]*b[0] + a[1]*b[1]+ a[2]*b[2];
296 + }
297 +
298 + double SimInfo::length3(double a[3]){
299 +  return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
300   }
301  
302   void SimInfo::calcBoxL( void ){
# Line 276 | Line 313 | void SimInfo::calcBoxL( void ){
313    dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0];
314    dsq = dx*dx + dy*dy + dz*dz;
315    boxL[0] = sqrt( dsq );
316 <  maxCutoff = 0.5 * boxL[0];
316 >  //maxCutoff = 0.5 * boxL[0];
317  
318    // boxLy
319    
320    dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1];
321    dsq = dx*dx + dy*dy + dz*dz;
322    boxL[1] = sqrt( dsq );
323 <  if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
323 >  //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
324  
325 +
326    // boxLz
327    
328    dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2];
329    dsq = dx*dx + dy*dy + dz*dz;
330    boxL[2] = sqrt( dsq );
331 <  if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2];
331 >  //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2];
332  
333 +  //calculate the max cutoff
334 +  maxCutoff =  calcMaxCutOff();
335 +  
336 +  checkCutOffs();
337 +
338   }
339  
340  
341 + double SimInfo::calcMaxCutOff(){
342 +
343 +  double ri[3], rj[3], rk[3];
344 +  double rij[3], rjk[3], rki[3];
345 +  double minDist;
346 +
347 +  ri[0] = Hmat[0][0];
348 +  ri[1] = Hmat[1][0];
349 +  ri[2] = Hmat[2][0];
350 +
351 +  rj[0] = Hmat[0][1];
352 +  rj[1] = Hmat[1][1];
353 +  rj[2] = Hmat[2][1];
354 +
355 +  rk[0] = Hmat[0][2];
356 +  rk[1] = Hmat[1][2];
357 +  rk[2] = Hmat[2][2];
358 +  
359 +  crossProduct3(ri,rj, rij);
360 +  distXY = dotProduct3(rk,rij) / length3(rij);
361 +
362 +  crossProduct3(rj,rk, rjk);
363 +  distYZ = dotProduct3(ri,rjk) / length3(rjk);
364 +
365 +  crossProduct3(rk,ri, rki);
366 +  distZX = dotProduct3(rj,rki) / length3(rki);
367 +
368 +  minDist = min(min(distXY, distYZ), distZX);
369 +  return minDist/2;
370 +  
371 + }
372 +
373   void SimInfo::wrapVector( double thePos[3] ){
374  
375    int i, j, k;
# Line 345 | Line 420 | int SimInfo::getNDF(){
420    ndf = ndf_local;
421   #endif
422  
423 <  ndf = ndf - 3;
423 >  ndf = ndf - 3 - nZconstraints;
424  
425    return ndf;
426   }
# Line 364 | Line 439 | int SimInfo::getNDFraw() {
439  
440    return ndfRaw;
441   }
442 <
442 >
443 > int SimInfo::getNDFtranslational() {
444 >  int ndfTrans_local, ndfTrans;
445 >
446 >  ndfTrans_local = 3 * n_atoms - n_constraints;
447 >
448 > #ifdef IS_MPI
449 >  MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
450 > #else
451 >  ndfTrans = ndfTrans_local;
452 > #endif
453 >
454 >  ndfTrans = ndfTrans - 3 - nZconstraints;
455 >
456 >  return ndfTrans;
457 > }
458 >
459   void SimInfo::refreshSim(){
460  
461    simtype fInfo;
# Line 420 | Line 511 | void SimInfo::refreshSim(){
511  
512    this->ndf = this->getNDF();
513    this->ndfRaw = this->getNDFraw();
514 <
514 >  this->ndfTrans = this->getNDFtranslational();
515   }
516  
517  
# Line 456 | Line 547 | void SimInfo::checkCutOffs( void ){
547   void SimInfo::checkCutOffs( void ){
548  
549    int cutChanged = 0;
550 <
550 >  
551    if( boxIsInit ){
552      
553      //we need to check cutOffs against the box
463    
464    if( maxCutoff > rCut ){
465      if( rCut < origRcut ){
466        rCut = origRcut;
467        if (rCut > maxCutoff) rCut = maxCutoff;
468        
469        sprintf( painCave.errMsg,
470                 "New Box size is setting the long range cutoff radius "
471                 "to %lf\n",
472                 rCut );
473        painCave.isFatal = 0;
474        simError();
475      }
476    }
554  
555 <    if( maxCutoff > ecr ){
556 <      if( ecr < origEcr ){
557 <        rCut = origEcr;
558 <        if (ecr > maxCutoff) ecr = maxCutoff;
559 <        
560 <        sprintf( painCave.errMsg,
561 <                 "New Box size is setting the electrostaticCutoffRadius "
562 <                 "to %lf\n",
563 <                 ecr );
564 <        painCave.isFatal = 0;
565 <        simError();
555 >    //detect the change of rCut
556 >    if(( maxCutoff > rCut )&&(usePBC)){
557 >      if( rCut < origRcut ){
558 >        rCut = origRcut;
559 >        
560 >        if (rCut > maxCutoff)
561 >          rCut = maxCutoff;
562 >  
563 >          sprintf( painCave.errMsg,
564 >                    "New Box size is setting the long range cutoff radius "
565 >                    "to %lf at time %lf\n",
566 >                    rCut, currentTime );
567 >          painCave.isFatal = 0;
568 >          simError();
569        }
570      }
571 <
492 <
493 <    if (rCut > maxCutoff) {
571 >    else if ((rCut > maxCutoff)&&(usePBC)) {
572        sprintf( painCave.errMsg,
573                 "New Box size is setting the long range cutoff radius "
574 <               "to %lf\n",
575 <               maxCutoff );
574 >               "to %lf at time %lf\n",
575 >               maxCutoff, currentTime );
576        painCave.isFatal = 0;
577        simError();
578        rCut = maxCutoff;
579      }
580  
581 <    if( ecr > maxCutoff){
581 >
582 >    //detect the change of ecr
583 >    if( maxCutoff > ecr ){
584 >      if( ecr < origEcr ){
585 >        ecr = origEcr;
586 >        if (ecr > maxCutoff) ecr = maxCutoff;
587 >  
588 >          sprintf( painCave.errMsg,
589 >                    "New Box size is setting the electrostaticCutoffRadius "
590 >                    "to %lf at time %lf\n",
591 >                    ecr, currentTime );
592 >            painCave.isFatal = 0;
593 >            simError();
594 >      }
595 >    }
596 >    else if( ecr > maxCutoff){
597        sprintf( painCave.errMsg,
598                 "New Box size is setting the electrostaticCutoffRadius "
599 <               "to %lf\n",
600 <               maxCutoff  );
599 >               "to %lf at time %lf\n",
600 >               maxCutoff, currentTime  );
601        painCave.isFatal = 0;
602        simError();      
603        ecr = maxCutoff;
604      }
605  
606 +    if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1;
607      
608 +    // rlist is the 1.0 plus max( rcut, ecr )
609 +    
610 +    ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
611 +    
612 +    if( cutChanged ){
613 +      
614 +      notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
615 +    }
616 +    
617 +    oldEcr = ecr;
618 +    oldRcut = rCut;
619 +    
620 +  } else {
621 +    // initialize this stuff before using it, OK?
622 +    sprintf( painCave.errMsg,
623 +             "Trying to check cutoffs without a box. Be smarter.\n" );
624 +    painCave.isFatal = 1;
625 +    simError();      
626    }
627 <  
627 >  
628 > }
629  
630 <  if( (oldEcr != ecr) || ( oldRcut != rCut ) ) cutChanged = 1;
630 > void SimInfo::addProperty(GenericData* prop){
631  
632 <  // rlist is the 1.0 plus max( rcut, ecr )
632 >  map<string, GenericData*>::iterator result;
633 >  result = properties.find(prop->getID());
634    
635 <  ( rCut > ecr )? rList = rCut + 1.0: rList = ecr + 1.0;
636 <
637 <  if( cutChanged ){
635 >  //we can't simply use  properties[prop->getID()] = prop,
636 >  //it will cause memory leak if we already contain a propery which has the same name of prop
637 >  
638 >  if(result != properties.end()){
639      
640 <    notifyFortranCutOffs( &rCut, &rList, &ecr, &est );
640 >    delete (*result).second;
641 >    (*result).second = prop;
642 >      
643    }
644 +  else{
645  
646 <  oldEcr = ecr;
647 <  oldRcut = rCut;
646 >    properties[prop->getID()] = prop;
647 >
648 >  }
649 >    
650   }
651 +
652 + GenericData* SimInfo::getProperty(const string& propName){
653 +
654 +  map<string, GenericData*>::iterator result;
655 +  
656 +  //string lowerCaseName = ();
657 +  
658 +  result = properties.find(propName);
659 +  
660 +  if(result != properties.end())
661 +    return (*result).second;  
662 +  else  
663 +    return NULL;  
664 + }
665 +
666 + vector<GenericData*> SimInfo::getProperties(){
667 +
668 +  vector<GenericData*> result;
669 +  map<string, GenericData*>::iterator i;
670 +  
671 +  for(i = properties.begin(); i != properties.end(); i++)
672 +    result.push_back((*i).second);
673 +    
674 +  return result;
675 + }
676 +
677 + double SimInfo::matTrace3(double m[3][3]){
678 +  double trace;
679 +  trace = m[0][0] + m[1][1] + m[2][2];
680 +
681 +  return trace;
682 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines