ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/ZConstraint.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/ZConstraint.cpp (file contents):
Revision 723 by mmeineke, Tue Aug 26 20:12:51 2003 UTC vs.
Revision 733 by tim, Wed Aug 27 19:23:29 2003 UTC

# Line 32 | Line 32 | template<typename T> ZConstraint<T>::ZConstraint(SimIn
32    if(!data){
33      sprintf( painCave.errMsg,
34                 "ZConstraint Warning: User does not set force substraction policy, "
35 <               "average force substraction policy is used\n");
35 >               "PolicyByMass is used\n");
36      painCave.isFatal = 0;
37      simError();      
38  
39 <    forcePolicy = (ForceSubstractionPolicy*) new PolicyByNumber(this);
39 >    forcePolicy = (ForceSubstractionPolicy*) new PolicyByMass(this);
40    }
41    else{
42      policy = dynamic_cast<StringData*>(data);
# Line 44 | Line 44 | template<typename T> ZConstraint<T>::ZConstraint(SimIn
44      if(!policy){
45        sprintf( painCave.errMsg,
46                   "ZConstraint Error: Convertion from GenericData to StringData failure, "
47 <                 "average force substraction policy is used\n");
47 >                 "PolicyByMass is used\n");
48        painCave.isFatal = 0;
49        simError();      
50  
51 <      forcePolicy = (ForceSubstractionPolicy*) new PolicyByNumber(this);
51 >      forcePolicy = (ForceSubstractionPolicy*) new PolicyByMass(this);
52      }
53      else{
54        if(policy->getData() == "BYNUMBER")
# Line 578 | Line 578 | template<typename T> void ZConstraint<T>::calcForce(in
578    //do zconstraint force;
579    if (haveFixedZMols())
580      this->doZconstraintForce();
581 <    
581 >
582    //use harmonical poteintial to move the molecules to the specified positions
583    if (haveMovingZMols())
584      this->doHarmonic();
# Line 612 | Line 612 | template<typename T> void ZConstraint<T>::calcForce(in
612   #ifdef IS_MPI
613    }
614   #endif
615
615   }
616  
617  
# Line 802 | Line 801 | template<typename T> void ZConstraint<T>::doZconstrain
801    double COM[3];
802    double force[3];
803  
805
806
804    //constrain the molecules which do not reach the specified positions  
805      
806    //Zero Out the force of z-contrained molecules    
# Line 825 | Line 822 | template<typename T> void ZConstraint<T>::doZconstrain
822        }
823        totalFZ_local += fz[i];
824  
825 < //       cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i]
826 < //              <<"\tcurrent zpos: " << COM[whichDirection]
827 < //              << "\tcurrent fz: " <<fz[i] << endl;
825 >      //cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i]
826 >      //      <<"\tcurrent zpos: " << COM[whichDirection]
827 >      //       << "\tcurrent fz: " <<fz[i] << endl;
828  
829 +
830      }
831      
832    }
# Line 854 | Line 852 | template<typename T> void ZConstraint<T>::doZconstrain
852        zconsAtoms = zconsMols[i]->getMyAtoms();  
853      
854        for(int j =0; j < nAtomOfCurZConsMol; j++) {
855 <      force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol;
856 <        //force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]);
855 >        //force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol;
856 >        force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]);
857          zconsAtoms[j]->addFrc(force);
858        }
859      
# Line 866 | Line 864 | template<typename T> void ZConstraint<T>::doZconstrain
864   //   cout << "after zero out z-constraint force on fixed z-constraint molecuels "
865   //        << "total force is " << calcTotalForce() << endl;
866  
869  //calculate the number of atoms of moving z-constrained molecules
870  int nMovingZAtoms_local;
871  int nMovingZAtoms;
872  
873  nMovingZAtoms_local = 0;
874  for(int i = 0; i < zconsMols.size(); i++)
875    if(states[i] == zcsMoving)
876     nMovingZAtoms_local += zconsMols[i]->getNAtoms();
877  
878 #ifdef IS_MPI
879  MPI_Allreduce(&nMovingZAtoms_local, &nMovingZAtoms, 1,
880                      MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
881 #else
882  nMovingZAtoms = nMovingZAtoms_local;
883 #endif
884
867    force[0]= 0;
868    force[1]= 0;
869    force[2]= 0;
# Line 892 | Line 874 | template<typename T> void ZConstraint<T>::doZconstrain
874       Atom** unconsAtoms = unconsMols[i]->getMyAtoms();
875      
876       for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){          
877 <       force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms);
878 <       //force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ);
877 >       //force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms);
878 >       force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ);
879         unconsAtoms[j]->addFrc(force);
880       }
881      
# Line 906 | Line 888 | template<typename T> void ZConstraint<T>::doZconstrain
888        Atom** movingZAtoms = zconsMols[i]->getMyAtoms();    
889  
890        for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){
891 <        force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms);
892 <        //force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ);
891 >        //force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms);
892 >        force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ);
893          movingZAtoms[j]->addFrc(force);
894        }
895      }
# Line 944 | Line 926 | template<typename T> void ZConstraint<T>::doHarmonic()
926        zconsMols[i]->getCOM(COM);
927   //       cout << "Moving Molecule\tindex: " << indexOfZConsMols[i]
928   //         << "\tcurrent zpos: " << COM[whichDirection] << endl;
929 +
930 +      diff = COM[whichDirection] -zPos[i];
931      
948    diff = COM[whichDirection] -zPos[i];
949    
932        harmonicU = 0.5 * kz[i] * diff * diff;  
933 <    info->lrPot += harmonicU;
933 >      info->lrPot += harmonicU;
934  
935        harmonicF =  - kz[i] * diff;
936        totalFZ_local += harmonicF;
# Line 958 | Line 940 | template<typename T> void ZConstraint<T>::doHarmonic()
940        Atom** movingZAtoms = zconsMols[i]->getMyAtoms();    
941  
942         for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){          
943 <        force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms();
944 <         //force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF);
943 >        //force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms();
944 >        force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF);
945           movingZAtoms[j]->addFrc(force);
946         }
947      }
# Line 982 | Line 964 | template<typename T> void ZConstraint<T>::doHarmonic()
964       Atom** unconsAtoms = unconsMols[i]->getMyAtoms();
965      
966       for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){          
967 <       force[whichDirection] = - totalFZ /totNumOfUnconsAtoms;
968 <       //force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ);
967 >       //force[whichDirection] = - totalFZ /totNumOfUnconsAtoms;
968 >       force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ);
969         unconsAtoms[j]->addFrc(force);    
970       }
971    }  
# Line 1023 | Line 1005 | template<typename T> bool ZConstraint<T>::checkZConsSt
1005   #else
1006    MPI_Allreduce(&changed_local, &changed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD);
1007   #endif
1008 <  
1008 >
1009    return (changed > 0);
1010 +
1011   }
1012  
1013   template<typename T> bool ZConstraint<T>::haveFixedZMols(){
# Line 1046 | Line 1029 | template<typename T> bool ZConstraint<T>::haveFixedZMo
1029    MPI_Allreduce(&havingFixed_local, &havingFixed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD);
1030   #endif
1031  
1032 <  return havingFixed > 0 ? true : false;
1032 >  return (havingFixed > 0);
1033   }
1034  
1035  
# Line 1072 | Line 1055 | template<typename T> bool ZConstraint<T>::haveMovingZM
1055    MPI_Allreduce(&havingMoving_local, &havingMoving, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD);
1056   #endif
1057  
1058 <  return havingMoving > 0 ? true : false;
1058 >  return (havingMoving > 0);
1059    
1060   }
1061  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines