# | Line 2 | Line 2 | template<typename T> ZConstraint<T>::ZConstraint(SimIn | |
---|---|---|
2 | #include "simError.h" | |
3 | #include <cmath> | |
4 | template<typename T> ZConstraint<T>::ZConstraint(SimInfo* theInfo, ForceFields* the_ff) | |
5 | < | : T(theInfo, the_ff), fz(NULL), curZPos(NULL), |
5 | > | : T(theInfo, the_ff), fz(NULL), curZPos(NULL), fzOut(NULL), |
6 | indexOfZConsMols(NULL), forcePolicy(NULL), curZconsTime(0) | |
7 | { | |
8 | ||
# | Line 27 | Line 27 | template<typename T> ZConstraint<T>::ZConstraint(SimIn | |
27 | double halfOfLargestBox = max(info->boxL[0], max(info->boxL[1], info->boxL[2])) /2; | |
28 | zForceConst = Kb * info->target_temp /(halfOfLargestBox * halfOfLargestBox); | |
29 | ||
30 | < | //creat force substraction policy |
30 | > | //creat force Subtraction policy |
31 | data = info->getProperty(ZCONSFORCEPOLICY_ID); | |
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"); |
34 | > | "ZConstraint Warning: User does not set force Subtraction policy, " |
35 | > | "PolicyByMass is used\n"); |
36 | painCave.isFatal = 0; | |
37 | simError(); | |
38 | ||
39 | < | forcePolicy = (ForceSubstractionPolicy*) new PolicyByNumber(this); |
39 | > | forcePolicy = (ForceSubtractionPolicy*) 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 = (ForceSubtractionPolicy*) new PolicyByMass(this); |
52 | } | |
53 | else{ | |
54 | if(policy->getData() == "BYNUMBER") | |
55 | < | forcePolicy = (ForceSubstractionPolicy*) new PolicyByNumber(this); |
55 | > | forcePolicy = (ForceSubtractionPolicy*) new PolicyByNumber(this); |
56 | else if(policy->getData() == "BYMASS") | |
57 | < | forcePolicy = (ForceSubstractionPolicy*) new PolicyByMass(this); |
57 | > | forcePolicy = (ForceSubtractionPolicy*) new PolicyByMass(this); |
58 | else{ | |
59 | sprintf( painCave.errMsg, | |
60 | < | "ZConstraint Warning: unknown force substraction policy, " |
61 | < | "average force substraction policy is used\n"); |
60 | > | "ZConstraint Warning: unknown force Subtraction policy, " |
61 | > | "PolicyByMass is used\n"); |
62 | painCave.isFatal = 0; | |
63 | simError(); | |
64 | + | forcePolicy = (ForceSubtractionPolicy*) new PolicyByMass(this); |
65 | } | |
66 | } | |
67 | } | |
# | Line 249 | Line 250 | template<typename T> ZConstraint<T>::ZConstraint(SimIn | |
250 | (*parameters)[i].zPos = COM[whichDirection]; | |
251 | ||
252 | sprintf( painCave.errMsg, | |
253 | < | "ZConstraint warningr: Does not specify zpos for z-constraint molecule " |
253 | > | "ZConstraint warning: Does not specify zpos for z-constraint molecule " |
254 | "initial z coornidate will be used \n"); | |
255 | painCave.isFatal = 0; | |
256 | simError(); | |
# | Line 276 | Line 277 | template<typename T> ZConstraint<T>::ZConstraint(SimIn | |
277 | massOfZConsMols.push_back(molecules[i].getTotalMass()); | |
278 | ||
279 | zPos.push_back((*parameters)[searchResult].zPos); | |
280 | < | cout << "index: "<< (*parameters)[searchResult].zconsIndex |
281 | < | <<"\tzPos = " << (*parameters)[searchResult].zPos << endl; |
281 | < | kz.push_back((*parameters)[searchResult]. kRatio * zForceConst); |
280 | > | // cout << "index: "<< (*parameters)[searchResult].zconsIndex |
281 | > | // <<"\tzPos = " << (*parameters)[searchResult].zPos << endl; |
282 | ||
283 | + | kz.push_back((*parameters)[searchResult]. kRatio * zForceConst); |
284 | molecules[i].getCOM(COM); | |
285 | } | |
286 | else | |
# | Line 328 | Line 329 | template<typename T> ZConstraint<T>::ZConstraint(SimIn | |
329 | MPI_Allreduce(&totalMassOfUncons_local, &totalMassOfUncons, 1, | |
330 | MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); | |
331 | #endif | |
331 | – | |
332 | ||
333 | //get total number of unconstrained atoms | |
334 | int nUnconsAtoms_local; | |
# | Line 343 | Line 343 | template<typename T> ZConstraint<T>::ZConstraint(SimIn | |
343 | MPI_INT,MPI_SUM, MPI_COMM_WORLD); | |
344 | #endif | |
345 | ||
346 | – | // creat zconsWriter |
347 | – | fzOut = new ZConsWriter(zconsOutput.c_str(), parameters); |
348 | – | |
349 | – | if(!fzOut){ |
350 | – | sprintf( painCave.errMsg, |
351 | – | "Memory allocation failure in class Zconstraint\n"); |
352 | – | painCave.isFatal = 1; |
353 | – | simError(); |
354 | – | } |
355 | – | |
346 | forcePolicy->update(); | |
347 | } | |
348 | ||
# | Line 404 | Line 394 | template<typename T> void ZConstraint<T>::update() | |
394 | zconsMols.push_back(&molecules[i]); | |
395 | zPos.push_back((*parameters)[index].zPos); | |
396 | kz.push_back((*parameters)[index].kRatio * zForceConst); | |
407 | – | |
397 | massOfZConsMols.push_back(molecules[i].getTotalMass()); | |
398 | ||
399 | molecules[i].getCOM(COM); | |
# | Line 505 | Line 494 | template<typename T> void ZConstraint<T>::integrate(){ | |
494 | } | |
495 | ||
496 | template<typename T> void ZConstraint<T>::integrate(){ | |
497 | + | |
498 | + | // creat zconsWriter |
499 | + | fzOut = new ZConsWriter(zconsOutput.c_str(), parameters); |
500 | ||
501 | + | if(!fzOut){ |
502 | + | sprintf( painCave.errMsg, |
503 | + | "Memory allocation failure in class Zconstraint\n"); |
504 | + | painCave.isFatal = 1; |
505 | + | simError(); |
506 | + | } |
507 | + | |
508 | //zero out the velocities of center of mass of unconstrained molecules | |
509 | //and the velocities of center of mass of every single z-constrained molecueles | |
510 | zeroOutVel(); | |
511 | + | |
512 | + | curZconsTime = zconsTime + info->getTime(); |
513 | ||
514 | T::integrate(); | |
515 | ||
# | Line 529 | Line 530 | template<typename T> void ZConstraint<T>::calcForce(in | |
530 | ||
531 | T::calcForce(calcPot, calcStress); | |
532 | ||
533 | < | if (checkZConsState()){ |
534 | < | zeroOutVel(); |
535 | < | forcePolicy->update(); |
533 | > | if (checkZConsState()){ |
534 | > | zeroOutVel(); |
535 | > | forcePolicy->update(); |
536 | } | |
537 | < | |
537 | > | |
538 | zsys = calcZSys(); | |
539 | zSysCOMVel = calcSysCOMVel(); | |
540 | #ifdef IS_MPI | |
541 | if(worldRank == 0){ | |
542 | #endif | |
543 | < | cout << "---------------------------------------------------------------------" <<endl; |
544 | < | cout << "current time: " << info->getTime() << endl; |
545 | < | cout << "center of mass at z: " << zsys << endl; |
546 | < | cout << "before calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
543 | > | //cout << "---------------------------------------------------------------------" <<endl; |
544 | > | //cout << "current time: " << info->getTime() << endl; |
545 | > | //cout << "center of mass at z: " << zsys << endl; |
546 | > | //cout << "before calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
547 | ||
548 | #ifdef IS_MPI | |
549 | } | |
# | Line 551 | Line 552 | template<typename T> void ZConstraint<T>::calcForce(in | |
552 | //do zconstraint force; | |
553 | if (haveFixedZMols()) | |
554 | this->doZconstraintForce(); | |
555 | < | |
555 | > | |
556 | //use harmonical poteintial to move the molecules to the specified positions | |
557 | if (haveMovingZMols()) | |
558 | this->doHarmonic(); | |
# | Line 581 | Line 582 | template<typename T> void ZConstraint<T>::calcForce(in | |
582 | #ifdef IS_MPI | |
583 | if(worldRank == 0){ | |
584 | #endif | |
585 | < | cout << "after calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
585 | > | //cout << "after calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
586 | #ifdef IS_MPI | |
587 | } | |
588 | #endif | |
588 | – | |
589 | } | |
590 | ||
591 | ||
# | Line 659 | Line 659 | template<typename T> void ZConstraint<T>::zeroOutVel() | |
659 | if (states[i] == zcsFixed){ | |
660 | ||
661 | zconsMols[i]->getCOMvel(COMvel); | |
662 | < | //cout << "before resetting " << indexOfZConsMols[i] <<"'s vz is " << COMvel[whichDirection] << endl; |
662 | > | //cout << "before resetting " << indexOfZConsMols[i] <<"'s vz is " << COMvel[whichDirection] << endl; |
663 | ||
664 | fixedZAtoms = zconsMols[i]->getMyAtoms(); | |
665 | ||
# | Line 681 | Line 681 | template<typename T> void ZConstraint<T>::zeroOutVel() | |
681 | #ifdef IS_MPI | |
682 | if(worldRank == 0){ | |
683 | #endif | |
684 | < | cout << "before resetting the COMVel of sytem is " << zSysCOMVel << endl; |
684 | > | //cout << "before resetting the COMVel of sytem is " << zSysCOMVel << endl; |
685 | #ifdef IS_MPI | |
686 | } | |
687 | #endif | |
# | Line 755 | Line 755 | template<typename T> void ZConstraint<T>::zeroOutVel() | |
755 | #ifdef IS_MPI | |
756 | if(worldRank == 0){ | |
757 | #endif | |
758 | < | cout << "after resetting the COMVel of moving molecules is " << zSysCOMVel << endl; |
758 | > | //cout << "after resetting the COMVel of moving molecules is " << zSysCOMVel << endl; |
759 | #ifdef IS_MPI | |
760 | } | |
761 | #endif | |
# | Line 775 | Line 775 | template<typename T> void ZConstraint<T>::doZconstrain | |
775 | double COM[3]; | |
776 | double force[3]; | |
777 | ||
778 | – | |
779 | – | |
778 | //constrain the molecules which do not reach the specified positions | |
779 | ||
780 | //Zero Out the force of z-contrained molecules | |
781 | totalFZ_local = 0; | |
782 | ||
783 | //calculate the total z-contrained force of fixed z-contrained molecules | |
784 | + | |
785 | + | //cout << "before zero out z-constraint force on fixed z-constraint molecuels " |
786 | + | // << "total force is " << calcTotalForce() << endl; |
787 | ||
788 | for(int i = 0; i < zconsMols.size(); i++){ | |
789 | ||
# | Line 798 | Line 799 | template<typename T> void ZConstraint<T>::doZconstrain | |
799 | } | |
800 | totalFZ_local += fz[i]; | |
801 | ||
802 | < | cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i] |
803 | < | <<"\tcurrent zpos: " << COM[whichDirection] |
804 | < | << "\tcurrent fz: " <<fz[i] << endl; |
802 | > | //cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i] |
803 | > | // <<"\tcurrent zpos: " << COM[whichDirection] |
804 | > | // << "\tcurrent fz: " <<fz[i] << endl; |
805 | ||
806 | + | |
807 | } | |
808 | ||
809 | } | |
# | Line 827 | Line 829 | template<typename T> void ZConstraint<T>::doZconstrain | |
829 | zconsAtoms = zconsMols[i]->getMyAtoms(); | |
830 | ||
831 | for(int j =0; j < nAtomOfCurZConsMol; j++) { | |
832 | < | force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol; |
833 | < | //force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]); |
832 | > | //force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol; |
833 | > | force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]); |
834 | zconsAtoms[j]->addFrc(force); | |
835 | } | |
836 | ||
# | Line 837 | Line 839 | template<typename T> void ZConstraint<T>::doZconstrain | |
839 | } | |
840 | ||
841 | //cout << "after zero out z-constraint force on fixed z-constraint molecuels " | |
842 | < | // << "total force is " << calcTotalForce() << endl; |
842 | > | // << "total force is " << calcTotalForce() << endl; |
843 | > | |
844 | ||
842 | – | //calculate the number of atoms of moving z-constrained molecules |
843 | – | int nMovingZAtoms_local; |
844 | – | int nMovingZAtoms; |
845 | – | |
846 | – | nMovingZAtoms_local = 0; |
847 | – | for(int i = 0; i < zconsMols.size(); i++) |
848 | – | if(states[i] == zcsMoving) |
849 | – | nMovingZAtoms_local += zconsMols[i]->getNAtoms(); |
850 | – | |
851 | – | #ifdef IS_MPI |
852 | – | MPI_Allreduce(&nMovingZAtoms_local, &nMovingZAtoms, 1, |
853 | – | MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); |
854 | – | #else |
855 | – | nMovingZAtoms = nMovingZAtoms_local; |
856 | – | #endif |
857 | – | |
845 | force[0]= 0; | |
846 | force[1]= 0; | |
847 | force[2]= 0; | |
# | Line 865 | Line 852 | template<typename T> void ZConstraint<T>::doZconstrain | |
852 | Atom** unconsAtoms = unconsMols[i]->getMyAtoms(); | |
853 | ||
854 | for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){ | |
855 | < | force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
856 | < | //force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ); |
855 | > | //force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
856 | > | force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ); |
857 | unconsAtoms[j]->addFrc(force); | |
858 | } | |
859 | ||
# | Line 879 | Line 866 | template<typename T> void ZConstraint<T>::doZconstrain | |
866 | Atom** movingZAtoms = zconsMols[i]->getMyAtoms(); | |
867 | ||
868 | for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){ | |
869 | < | force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
870 | < | //force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ); |
869 | > | //force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
870 | > | force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ); |
871 | movingZAtoms[j]->addFrc(force); | |
872 | } | |
873 | } | |
874 | } | |
875 | + | // cout << "after substracting z-constraint force from moving molecuels " |
876 | + | // << "total force is " << calcTotalForce() << endl; |
877 | ||
889 | – | //cout << "after substracting z-constraint force from moving molecuels " |
890 | – | // << "total force is " << calcTotalForce() << endl; |
891 | – | |
878 | } | |
879 | ||
880 | /** | |
# | Line 915 | Line 901 | template<typename T> void ZConstraint<T>::doHarmonic() | |
901 | ||
902 | if (states[i] == zcsMoving){ | |
903 | zconsMols[i]->getCOM(COM); | |
904 | < | cout << "Moving Molecule\tindex: " << indexOfZConsMols[i] <<"\tcurrent zpos: " << COM[whichDirection] << endl; |
904 | > | // cout << "Moving Molecule\tindex: " << indexOfZConsMols[i] |
905 | > | // << "\tcurrent zpos: " << COM[whichDirection] << endl; |
906 | > | |
907 | > | diff = COM[whichDirection] -zPos[i]; |
908 | ||
920 | – | diff = COM[whichDirection] -zPos[i]; |
921 | – | |
909 | harmonicU = 0.5 * kz[i] * diff * diff; | |
910 | < | info->lrPot += harmonicU; |
910 | > | info->lrPot += harmonicU; |
911 | ||
912 | harmonicF = - kz[i] * diff; | |
913 | totalFZ_local += harmonicF; | |
# | Line 930 | Line 917 | template<typename T> void ZConstraint<T>::doHarmonic() | |
917 | Atom** movingZAtoms = zconsMols[i]->getMyAtoms(); | |
918 | ||
919 | for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){ | |
920 | < | force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms(); |
921 | < | //force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF); |
920 | > | //force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms(); |
921 | > | force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF); |
922 | movingZAtoms[j]->addFrc(force); | |
923 | } | |
924 | } | |
# | Line 944 | Line 931 | template<typename T> void ZConstraint<T>::doHarmonic() | |
931 | MPI_Allreduce(&totalFZ_local, &totalFZ, 1, MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | |
932 | #endif | |
933 | ||
934 | + | //cout << "before substracting harmonic force from moving molecuels " |
935 | + | // << "total force is " << calcTotalForce() << endl; |
936 | + | |
937 | force[0]= 0; | |
938 | force[1]= 0; | |
939 | force[2]= 0; | |
# | Line 954 | Line 944 | template<typename T> void ZConstraint<T>::doHarmonic() | |
944 | Atom** unconsAtoms = unconsMols[i]->getMyAtoms(); | |
945 | ||
946 | for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){ | |
947 | < | force[whichDirection] = - totalFZ /totNumOfUnconsAtoms; |
948 | < | //force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ); |
947 | > | //force[whichDirection] = - totalFZ /totNumOfUnconsAtoms; |
948 | > | force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ); |
949 | unconsAtoms[j]->addFrc(force); | |
950 | } | |
951 | } | |
952 | ||
953 | + | //cout << "after substracting harmonic force from moving molecuels " |
954 | + | // << "total force is " << calcTotalForce() << endl; |
955 | + | |
956 | } | |
957 | ||
958 | /** | |
# | Line 996 | Line 989 | template<typename T> bool ZConstraint<T>::checkZConsSt | |
989 | MPI_Allreduce(&changed_local, &changed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); | |
990 | #endif | |
991 | ||
992 | < | return changed > 0 ? true : false; |
992 | > | return (changed > 0); |
993 | > | |
994 | } | |
995 | ||
996 | template<typename T> bool ZConstraint<T>::haveFixedZMols(){ | |
# | Line 1018 | Line 1012 | template<typename T> bool ZConstraint<T>::haveFixedZMo | |
1012 | MPI_Allreduce(&havingFixed_local, &havingFixed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); | |
1013 | #endif | |
1014 | ||
1015 | < | return havingFixed > 0 ? true : false; |
1015 | > | return (havingFixed > 0); |
1016 | } | |
1017 | ||
1018 | ||
# | Line 1044 | Line 1038 | template<typename T> bool ZConstraint<T>::haveMovingZM | |
1038 | MPI_Allreduce(&havingMoving_local, &havingMoving, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); | |
1039 | #endif | |
1040 | ||
1041 | < | return havingMoving > 0 ? true : false; |
1041 | > | return (havingMoving > 0); |
1042 | ||
1043 | } | |
1044 | ||
# | Line 1212 | Line 1206 | template<typename T> void ZConstraint<T>::PolicyByMass | |
1206 | #else | |
1207 | massOfMovingZAtoms = massOfMovingZAtoms_local; | |
1208 | #endif | |
1209 | < | totMassOfMovingAtoms = massOfMovingZAtoms_local + zconsIntegrator->totalMassOfUncons; |
1209 | > | totMassOfMovingAtoms = massOfMovingZAtoms + zconsIntegrator->totalMassOfUncons; |
1210 | } | |
1211 | ||
1212 | template<typename T> double ZConstraint<T>::PolicyByMass::getZFOfFixedZMols(Molecule* mol, Atom* atom, double totalForce){ |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |