| 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); |
| 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 |
|
|
| 527 |
|
double zsys; |
| 528 |
|
double COM[3]; |
| 529 |
|
double force[3]; |
| 530 |
+ |
double zSysCOMVel; |
| 531 |
|
|
| 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(); |
| 548 |
< |
forcePolicy->update(); |
| 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 |
< |
cout << "---------------------------------------------------------------------" <<endl; |
| 566 |
< |
cout << "current time: " << info->getTime() << endl; |
| 567 |
< |
cout << "center of mass at z: " << zsys << endl; |
| 568 |
< |
//cout << "before calcForce, the COMVel of moving molecules is " << calcMovingMolsCOMVel() <<endl; |
| 569 |
< |
cout << "before calcForce, the COMVel of system is " << calcSysCOMVel() <<endl; |
| 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; |
| 573 |
|
|
| 574 |
< |
//cout << "before doZConstraintForce, totalForce is " << calcTotalForce() << endl; |
| 574 |
> |
#ifdef IS_MPI |
| 575 |
> |
} |
| 576 |
> |
#endif |
| 577 |
|
|
| 578 |
|
//do zconstraint force; |
| 579 |
|
if (haveFixedZMols()) |
| 583 |
|
if (haveMovingZMols()) |
| 584 |
|
this->doHarmonic(); |
| 585 |
|
|
| 552 |
– |
//cout << "after doHarmonic, totalForce is " << calcTotalForce() << endl; |
| 553 |
– |
|
| 586 |
|
//write out forces and current positions of z-constraint molecules |
| 587 |
|
if(info->getTime() >= curZconsTime){ |
| 588 |
|
for(int i = 0; i < zconsMols.size(); i++){ |
| 603 |
|
fzOut->writeFZ(info->getTime(), zconsMols.size(), indexOfZConsMols, fz, curZPos); |
| 604 |
|
curZconsTime += zconsTime; |
| 605 |
|
} |
| 606 |
< |
|
| 607 |
< |
//cout << "after calcForce, the COMVel of moving molecules is " << calcMovingMolsCOMVel() <<endl; |
| 608 |
< |
cout << "after calcForce, the COMVel of system is " << calcSysCOMVel() <<endl; |
| 606 |
> |
|
| 607 |
> |
zSysCOMVel = calcSysCOMVel(); |
| 608 |
> |
#ifdef IS_MPI |
| 609 |
> |
if(worldRank == 0){ |
| 610 |
> |
#endif |
| 611 |
> |
// cout << "after calcForce, the COMVel of system is " << zSysCOMVel <<endl; |
| 612 |
> |
#ifdef IS_MPI |
| 613 |
> |
} |
| 614 |
> |
#endif |
| 615 |
> |
|
| 616 |
|
} |
| 617 |
|
|
| 618 |
|
|
| 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 |
| 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 |
| 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 |
|
} |
| 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 |
|
|
| 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; |
| 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 |
|
|
| 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 |
|
} |
| 943 |
|
|
| 944 |
|
if (states[i] == zcsMoving){ |
| 945 |
|
zconsMols[i]->getCOM(COM); |
| 946 |
< |
cout << "Moving Molecule --\tindex: " << indexOfZConsMols[i] <<"\tcurrent zpos: " << COM[whichDirection] << endl; |
| 947 |
< |
|
| 948 |
< |
diff = COM[whichDirection] -zPos[i]; |
| 946 |
> |
// cout << "Moving Molecule\tindex: " << indexOfZConsMols[i] |
| 947 |
> |
// << "\tcurrent zpos: " << COM[whichDirection] << endl; |
| 948 |
> |
|
| 949 |
> |
diff = COM[whichDirection] -zPos[i]; |
| 950 |
|
|
| 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; |
| 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 |
|
} |
| 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 |
|
} |
| 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(){ |
| 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 |
|
|
| 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 |
|
|
| 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){ |