# | 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 276 | Line 276 | template<typename T> ZConstraint<T>::ZConstraint(SimIn | |
276 | massOfZConsMols.push_back(molecules[i].getTotalMass()); | |
277 | ||
278 | zPos.push_back((*parameters)[searchResult].zPos); | |
279 | < | cout << "index: "<< (*parameters)[searchResult].zconsIndex |
280 | < | <<"\tzPos = " << (*parameters)[searchResult].zPos << endl; |
279 | > | // cout << "index: "<< (*parameters)[searchResult].zconsIndex |
280 | > | // <<"\tzPos = " << (*parameters)[searchResult].zPos << endl; |
281 | kz.push_back((*parameters)[searchResult]. kRatio * zForceConst); | |
282 | ||
283 | molecules[i].getCOM(COM); | |
# | Line 509 | Line 509 | template<typename T> void ZConstraint<T>::integrate(){ | |
509 | //zero out the velocities of center of mass of unconstrained molecules | |
510 | //and the velocities of center of mass of every single z-constrained molecueles | |
511 | zeroOutVel(); | |
512 | + | |
513 | + | curZconsTime = zconsTime + info->getTime(); |
514 | ||
515 | T::integrate(); | |
516 | ||
# | Line 530 | Line 532 | template<typename T> void ZConstraint<T>::calcForce(in | |
532 | T::calcForce(calcPot, calcStress); | |
533 | ||
534 | if (checkZConsState()){ | |
535 | + | |
536 | + | #ifdef IS_MPI |
537 | + | if(worldRank == 0){ |
538 | + | #endif |
539 | + | // std::cerr << "\n" |
540 | + | // << "*******************************************\n" |
541 | + | // << " about to call zeroOutVel()\n" |
542 | + | // << "*******************************************\n" |
543 | + | // << "\n"; |
544 | + | #ifdef IS_MPI |
545 | + | } |
546 | + | #endif |
547 | zeroOutVel(); | |
534 | – | forcePolicy->update(); |
535 | – | } |
548 | ||
549 | + | #ifdef IS_MPI |
550 | + | if(worldRank == 0){ |
551 | + | #endif |
552 | + | // std::cerr << "\n" |
553 | + | // << "*******************************************\n" |
554 | + | // << " finished zeroOutVel()\n" |
555 | + | // << "*******************************************\n" |
556 | + | // << "\n"; |
557 | + | #ifdef IS_MPI |
558 | + | } |
559 | + | #endif |
560 | + | |
561 | + | forcePolicy->update(); |
562 | + | } |
563 | + | |
564 | zsys = calcZSys(); | |
565 | zSysCOMVel = calcSysCOMVel(); | |
566 | #ifdef IS_MPI | |
567 | if(worldRank == 0){ | |
568 | #endif | |
569 | < | cout << "---------------------------------------------------------------------" <<endl; |
570 | < | cout << "current time: " << info->getTime() << endl; |
571 | < | cout << "center of mass at z: " << zsys << endl; |
572 | < | cout << "before calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
569 | > | // cout << "---------------------------------------------------------------------" <<endl; |
570 | > | // cout << "current time: " << info->getTime() << endl; |
571 | > | // cout << "center of mass at z: " << zsys << endl; |
572 | > | // cout << "before calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
573 | ||
574 | #ifdef IS_MPI | |
575 | } | |
# | Line 581 | Line 608 | template<typename T> void ZConstraint<T>::calcForce(in | |
608 | #ifdef IS_MPI | |
609 | if(worldRank == 0){ | |
610 | #endif | |
611 | < | cout << "after calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
611 | > | // cout << "after calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
612 | #ifdef IS_MPI | |
613 | } | |
614 | #endif | |
# | Line 681 | Line 708 | template<typename T> void ZConstraint<T>::zeroOutVel() | |
708 | #ifdef IS_MPI | |
709 | if(worldRank == 0){ | |
710 | #endif | |
711 | < | cout << "before resetting the COMVel of sytem is " << zSysCOMVel << endl; |
711 | > | // cout << "before resetting the COMVel of sytem is " << zSysCOMVel << endl; |
712 | #ifdef IS_MPI | |
713 | } | |
714 | #endif | |
# | Line 755 | Line 782 | template<typename T> void ZConstraint<T>::zeroOutVel() | |
782 | #ifdef IS_MPI | |
783 | if(worldRank == 0){ | |
784 | #endif | |
785 | < | cout << "after resetting the COMVel of moving molecules is " << zSysCOMVel << endl; |
785 | > | // cout << "after resetting the COMVel of moving molecules is " << zSysCOMVel << endl; |
786 | #ifdef IS_MPI | |
787 | } | |
788 | #endif | |
# | Line 798 | Line 825 | template<typename T> void ZConstraint<T>::doZconstrain | |
825 | } | |
826 | totalFZ_local += fz[i]; | |
827 | ||
828 | < | cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i] |
829 | < | <<"\tcurrent zpos: " << COM[whichDirection] |
830 | < | << "\tcurrent fz: " <<fz[i] << endl; |
828 | > | //cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i] |
829 | > | // <<"\tcurrent zpos: " << COM[whichDirection] |
830 | > | // << "\tcurrent fz: " <<fz[i] << endl; |
831 | ||
832 | + | |
833 | } | |
834 | ||
835 | } | |
# | Line 827 | Line 855 | template<typename T> void ZConstraint<T>::doZconstrain | |
855 | zconsAtoms = zconsMols[i]->getMyAtoms(); | |
856 | ||
857 | for(int j =0; j < nAtomOfCurZConsMol; j++) { | |
858 | < | force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol; |
859 | < | //force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]); |
858 | > | //force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol; |
859 | > | force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]); |
860 | zconsAtoms[j]->addFrc(force); | |
861 | } | |
862 | ||
# | Line 836 | Line 864 | template<typename T> void ZConstraint<T>::doZconstrain | |
864 | ||
865 | } | |
866 | ||
867 | < | //cout << "after zero out z-constraint force on fixed z-constraint molecuels " |
868 | < | // << "total force is " << calcTotalForce() << endl; |
867 | > | // cout << "after zero out z-constraint force on fixed z-constraint molecuels " |
868 | > | // << "total force is " << calcTotalForce() << endl; |
869 | ||
870 | //calculate the number of atoms of moving z-constrained molecules | |
871 | int nMovingZAtoms_local; | |
# | Line 865 | Line 893 | template<typename T> void ZConstraint<T>::doZconstrain | |
893 | Atom** unconsAtoms = unconsMols[i]->getMyAtoms(); | |
894 | ||
895 | for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){ | |
896 | < | force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
897 | < | //force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ); |
896 | > | //force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
897 | > | force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ); |
898 | unconsAtoms[j]->addFrc(force); | |
899 | } | |
900 | ||
# | Line 879 | Line 907 | template<typename T> void ZConstraint<T>::doZconstrain | |
907 | Atom** movingZAtoms = zconsMols[i]->getMyAtoms(); | |
908 | ||
909 | for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){ | |
910 | < | force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
911 | < | //force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ); |
910 | > | //force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
911 | > | force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ); |
912 | movingZAtoms[j]->addFrc(force); | |
913 | } | |
914 | } | |
# | Line 915 | Line 943 | template<typename T> void ZConstraint<T>::doHarmonic() | |
943 | ||
944 | if (states[i] == zcsMoving){ | |
945 | zconsMols[i]->getCOM(COM); | |
946 | < | cout << "Moving Molecule\tindex: " << indexOfZConsMols[i] <<"\tcurrent zpos: " << COM[whichDirection] << endl; |
946 | > | // cout << "Moving Molecule\tindex: " << indexOfZConsMols[i] |
947 | > | // << "\tcurrent zpos: " << COM[whichDirection] << endl; |
948 | > | |
949 | > | diff = COM[whichDirection] -zPos[i]; |
950 | ||
920 | – | diff = COM[whichDirection] -zPos[i]; |
921 | – | |
951 | harmonicU = 0.5 * kz[i] * diff * diff; | |
952 | < | info->lrPot += harmonicU; |
952 | > | info->lrPot += harmonicU; |
953 | ||
954 | harmonicF = - kz[i] * diff; | |
955 | totalFZ_local += harmonicF; | |
# | Line 930 | Line 959 | template<typename T> void ZConstraint<T>::doHarmonic() | |
959 | Atom** movingZAtoms = zconsMols[i]->getMyAtoms(); | |
960 | ||
961 | for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){ | |
962 | < | force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms(); |
963 | < | //force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF); |
962 | > | //force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms(); |
963 | > | force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF); |
964 | movingZAtoms[j]->addFrc(force); | |
965 | } | |
966 | } | |
# | Line 954 | Line 983 | template<typename T> void ZConstraint<T>::doHarmonic() | |
983 | Atom** unconsAtoms = unconsMols[i]->getMyAtoms(); | |
984 | ||
985 | for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){ | |
986 | < | force[whichDirection] = - totalFZ /totNumOfUnconsAtoms; |
987 | < | //force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ); |
986 | > | //force[whichDirection] = - totalFZ /totNumOfUnconsAtoms; |
987 | > | force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ); |
988 | unconsAtoms[j]->addFrc(force); | |
989 | } | |
990 | } | |
# | Line 996 | Line 1025 | template<typename T> bool ZConstraint<T>::checkZConsSt | |
1025 | MPI_Allreduce(&changed_local, &changed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); | |
1026 | #endif | |
1027 | ||
1028 | < | return changed > 0 ? true : false; |
1028 | > | return (changed > 0); |
1029 | > | |
1030 | } | |
1031 | ||
1032 | template<typename T> bool ZConstraint<T>::haveFixedZMols(){ | |
# | Line 1018 | Line 1048 | template<typename T> bool ZConstraint<T>::haveFixedZMo | |
1048 | MPI_Allreduce(&havingFixed_local, &havingFixed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); | |
1049 | #endif | |
1050 | ||
1051 | < | return havingFixed > 0 ? true : false; |
1051 | > | return (havingFixed > 0); |
1052 | } | |
1053 | ||
1054 | ||
# | Line 1044 | Line 1074 | template<typename T> bool ZConstraint<T>::haveMovingZM | |
1074 | MPI_Allreduce(&havingMoving_local, &havingMoving, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); | |
1075 | #endif | |
1076 | ||
1077 | < | return havingMoving > 0 ? true : false; |
1077 | > | return (havingMoving > 0); |
1078 | ||
1079 | } | |
1080 | ||
# | Line 1175 | Line 1205 | template<typename T> void ZConstraint<T>::PolicyByNumb | |
1205 | nMovingZAtoms = nMovingZAtoms_local; | |
1206 | #endif | |
1207 | totNumOfMovingAtoms = nMovingZAtoms + zconsIntegrator->totNumOfUnconsAtoms; | |
1208 | + | |
1209 | + | #ifdef IS_MPI |
1210 | + | if(worldRank == 0){ |
1211 | + | #endif |
1212 | + | // std::cerr << "\n" |
1213 | + | // << "*******************************************\n" |
1214 | + | // << " fiished Policy by numbr()\n" |
1215 | + | // << "*******************************************\n" |
1216 | + | // << "\n"; |
1217 | + | #ifdef IS_MPI |
1218 | + | } |
1219 | + | #endif |
1220 | } | |
1221 | ||
1222 | template<typename T>double ZConstraint<T>::PolicyByNumber::getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce){ |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |