| 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); |
| 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") |
| 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); |
| 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"; |
| 539 |
> |
// std::cerr << "\n" |
| 540 |
> |
// << "*******************************************\n" |
| 541 |
> |
// << " about to call zeroOutVel()\n" |
| 542 |
> |
// << "*******************************************\n" |
| 543 |
> |
// << "\n"; |
| 544 |
|
#ifdef IS_MPI |
| 545 |
|
} |
| 546 |
|
#endif |
| 549 |
|
#ifdef IS_MPI |
| 550 |
|
if(worldRank == 0){ |
| 551 |
|
#endif |
| 552 |
< |
std::cerr << "\n" |
| 553 |
< |
<< "*******************************************\n" |
| 554 |
< |
<< " finished zeroOutVel()\n" |
| 555 |
< |
<< "*******************************************\n" |
| 556 |
< |
<< "\n"; |
| 552 |
> |
// std::cerr << "\n" |
| 553 |
> |
// << "*******************************************\n" |
| 554 |
> |
// << " finished zeroOutVel()\n" |
| 555 |
> |
// << "*******************************************\n" |
| 556 |
> |
// << "\n"; |
| 557 |
|
#ifdef IS_MPI |
| 558 |
|
} |
| 559 |
|
#endif |
| 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 |
|
} |
| 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(); |
| 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 |
| 615 |
– |
|
| 615 |
|
} |
| 616 |
|
|
| 617 |
|
|
| 707 |
|
#ifdef IS_MPI |
| 708 |
|
if(worldRank == 0){ |
| 709 |
|
#endif |
| 710 |
< |
cout << "before resetting the COMVel of sytem is " << zSysCOMVel << endl; |
| 710 |
> |
// cout << "before resetting the COMVel of sytem is " << zSysCOMVel << endl; |
| 711 |
|
#ifdef IS_MPI |
| 712 |
|
} |
| 713 |
|
#endif |
| 781 |
|
#ifdef IS_MPI |
| 782 |
|
if(worldRank == 0){ |
| 783 |
|
#endif |
| 784 |
< |
cout << "after resetting the COMVel of moving molecules is " << zSysCOMVel << endl; |
| 784 |
> |
// cout << "after resetting the COMVel of moving molecules is " << zSysCOMVel << endl; |
| 785 |
|
#ifdef IS_MPI |
| 786 |
|
} |
| 787 |
|
#endif |
| 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 |
| 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 |
|
} |
| 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 |
|
|
| 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; |
| 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 |
|
|
| 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 |
|
} |
| 924 |
|
|
| 925 |
|
if (states[i] == zcsMoving){ |
| 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]; |
| 927 |
> |
// cout << "Moving Molecule\tindex: " << indexOfZConsMols[i] |
| 928 |
> |
// << "\tcurrent zpos: " << COM[whichDirection] << endl; |
| 929 |
> |
|
| 930 |
> |
diff = COM[whichDirection] -zPos[i]; |
| 931 |
|
|
| 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; |
| 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 |
|
} |
| 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 |
|
} |
| 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(){ |
| 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 |
|
|
| 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 |
|
|
| 1190 |
|
#ifdef IS_MPI |
| 1191 |
|
if(worldRank == 0){ |
| 1192 |
|
#endif |
| 1193 |
< |
std::cerr << "\n" |
| 1194 |
< |
<< "*******************************************\n" |
| 1195 |
< |
<< " fiished Policy by numbr()\n" |
| 1196 |
< |
<< "*******************************************\n" |
| 1197 |
< |
<< "\n"; |
| 1193 |
> |
// std::cerr << "\n" |
| 1194 |
> |
// << "*******************************************\n" |
| 1195 |
> |
// << " fiished Policy by numbr()\n" |
| 1196 |
> |
// << "*******************************************\n" |
| 1197 |
> |
// << "\n"; |
| 1198 |
|
#ifdef IS_MPI |
| 1199 |
|
} |
| 1200 |
|
#endif |