| 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") |
| 58 |
|
else{ |
| 59 |
|
sprintf( painCave.errMsg, |
| 60 |
|
"ZConstraint Warning: unknown force substraction policy, " |
| 61 |
< |
"average force substraction policy is used\n"); |
| 61 |
> |
"PolicyByMass is used\n"); |
| 62 |
|
painCave.isFatal = 0; |
| 63 |
|
simError(); |
| 64 |
+ |
forcePolicy = (ForceSubstractionPolicy*) new PolicyByMass(this); |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
} |
| 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(); |
| 579 |
|
//do zconstraint force; |
| 580 |
|
if (haveFixedZMols()) |
| 581 |
|
this->doZconstraintForce(); |
| 582 |
< |
|
| 582 |
> |
|
| 583 |
|
//use harmonical poteintial to move the molecules to the specified positions |
| 584 |
|
if (haveMovingZMols()) |
| 585 |
|
this->doHarmonic(); |
| 613 |
|
#ifdef IS_MPI |
| 614 |
|
} |
| 615 |
|
#endif |
| 615 |
– |
|
| 616 |
|
} |
| 617 |
|
|
| 618 |
|
|
| 802 |
|
double COM[3]; |
| 803 |
|
double force[3]; |
| 804 |
|
|
| 805 |
– |
|
| 806 |
– |
|
| 805 |
|
//constrain the molecules which do not reach the specified positions |
| 806 |
|
|
| 807 |
|
//Zero Out the force of z-contrained molecules |
| 823 |
|
} |
| 824 |
|
totalFZ_local += fz[i]; |
| 825 |
|
|
| 826 |
< |
// cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i] |
| 827 |
< |
// <<"\tcurrent zpos: " << COM[whichDirection] |
| 828 |
< |
// << "\tcurrent fz: " <<fz[i] << endl; |
| 826 |
> |
//cout << "Fixed Molecule\tindex: " << indexOfZConsMols[i] |
| 827 |
> |
// <<"\tcurrent zpos: " << COM[whichDirection] |
| 828 |
> |
// << "\tcurrent fz: " <<fz[i] << endl; |
| 829 |
|
|
| 830 |
+ |
|
| 831 |
|
} |
| 832 |
|
|
| 833 |
|
} |
| 853 |
|
zconsAtoms = zconsMols[i]->getMyAtoms(); |
| 854 |
|
|
| 855 |
|
for(int j =0; j < nAtomOfCurZConsMol; j++) { |
| 856 |
< |
force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol; |
| 857 |
< |
//force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]); |
| 856 |
> |
//force[whichDirection] = -fz[i]/ nAtomOfCurZConsMol; |
| 857 |
> |
force[whichDirection] = - forcePolicy->getZFOfFixedZMols(zconsMols[i], zconsAtoms[j], fz[i]); |
| 858 |
|
zconsAtoms[j]->addFrc(force); |
| 859 |
|
} |
| 860 |
|
|
| 864 |
|
|
| 865 |
|
// cout << "after zero out z-constraint force on fixed z-constraint molecuels " |
| 866 |
|
// << "total force is " << calcTotalForce() << endl; |
| 868 |
– |
|
| 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 |
| 867 |
|
|
| 868 |
|
force[0]= 0; |
| 869 |
|
force[1]= 0; |
| 875 |
|
Atom** unconsAtoms = unconsMols[i]->getMyAtoms(); |
| 876 |
|
|
| 877 |
|
for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){ |
| 878 |
< |
force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
| 879 |
< |
//force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ); |
| 878 |
> |
//force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
| 879 |
> |
force[whichDirection] = forcePolicy->getZFOfMovingMols(unconsAtoms[j],totalFZ); |
| 880 |
|
unconsAtoms[j]->addFrc(force); |
| 881 |
|
} |
| 882 |
|
|
| 889 |
|
Atom** movingZAtoms = zconsMols[i]->getMyAtoms(); |
| 890 |
|
|
| 891 |
|
for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){ |
| 892 |
< |
force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
| 893 |
< |
//force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ); |
| 892 |
> |
//force[whichDirection] = totalFZ / (totNumOfUnconsAtoms + nMovingZAtoms); |
| 893 |
> |
force[whichDirection] = forcePolicy->getZFOfMovingMols(movingZAtoms[j],totalFZ); |
| 894 |
|
movingZAtoms[j]->addFrc(force); |
| 895 |
|
} |
| 896 |
|
} |
| 927 |
|
zconsMols[i]->getCOM(COM); |
| 928 |
|
// cout << "Moving Molecule\tindex: " << indexOfZConsMols[i] |
| 929 |
|
// << "\tcurrent zpos: " << COM[whichDirection] << endl; |
| 930 |
+ |
|
| 931 |
+ |
diff = COM[whichDirection] -zPos[i]; |
| 932 |
|
|
| 948 |
– |
diff = COM[whichDirection] -zPos[i]; |
| 949 |
– |
|
| 933 |
|
harmonicU = 0.5 * kz[i] * diff * diff; |
| 934 |
< |
info->lrPot += harmonicU; |
| 934 |
> |
info->lrPot += harmonicU; |
| 935 |
|
|
| 936 |
|
harmonicF = - kz[i] * diff; |
| 937 |
|
totalFZ_local += harmonicF; |
| 941 |
|
Atom** movingZAtoms = zconsMols[i]->getMyAtoms(); |
| 942 |
|
|
| 943 |
|
for(int j = 0; j < zconsMols[i]->getNAtoms(); j++){ |
| 944 |
< |
force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms(); |
| 945 |
< |
//force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF); |
| 944 |
> |
//force[whichDirection] = harmonicF / zconsMols[i]->getNAtoms(); |
| 945 |
> |
force[whichDirection] = forcePolicy->getHFOfFixedZMols(zconsMols[i], movingZAtoms[j], harmonicF); |
| 946 |
|
movingZAtoms[j]->addFrc(force); |
| 947 |
|
} |
| 948 |
|
} |
| 965 |
|
Atom** unconsAtoms = unconsMols[i]->getMyAtoms(); |
| 966 |
|
|
| 967 |
|
for(int j = 0; j < unconsMols[i]->getNAtoms(); j++){ |
| 968 |
< |
force[whichDirection] = - totalFZ /totNumOfUnconsAtoms; |
| 969 |
< |
//force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ); |
| 968 |
> |
//force[whichDirection] = - totalFZ /totNumOfUnconsAtoms; |
| 969 |
> |
force[whichDirection] = - forcePolicy->getHFOfUnconsMols(unconsAtoms[j], totalFZ); |
| 970 |
|
unconsAtoms[j]->addFrc(force); |
| 971 |
|
} |
| 972 |
|
} |
| 1006 |
|
#else |
| 1007 |
|
MPI_Allreduce(&changed_local, &changed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
| 1008 |
|
#endif |
| 1009 |
< |
|
| 1009 |
> |
|
| 1010 |
|
return (changed > 0); |
| 1011 |
+ |
|
| 1012 |
|
} |
| 1013 |
|
|
| 1014 |
|
template<typename T> bool ZConstraint<T>::haveFixedZMols(){ |
| 1030 |
|
MPI_Allreduce(&havingFixed_local, &havingFixed, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
| 1031 |
|
#endif |
| 1032 |
|
|
| 1033 |
< |
return havingFixed > 0 ? true : false; |
| 1033 |
> |
return (havingFixed > 0); |
| 1034 |
|
} |
| 1035 |
|
|
| 1036 |
|
|
| 1056 |
|
MPI_Allreduce(&havingMoving_local, &havingMoving, 1, MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
| 1057 |
|
#endif |
| 1058 |
|
|
| 1059 |
< |
return havingMoving > 0 ? true : false; |
| 1059 |
> |
return (havingMoving > 0); |
| 1060 |
|
|
| 1061 |
|
} |
| 1062 |
|
|