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") |
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(); |
612 |
|
#ifdef IS_MPI |
613 |
|
} |
614 |
|
#endif |
615 |
– |
|
615 |
|
} |
616 |
|
|
617 |
|
|
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 |
|
} |
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]; |
931 |
|
|
948 |
– |
diff = COM[whichDirection] -zPos[i]; |
949 |
– |
|
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 |
|
|