| 35 |
|
* |
| 36 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
| 37 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
| 38 |
< |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
| 38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 47 |
|
* @version 1.0 |
| 48 |
|
*/ |
| 49 |
|
|
| 50 |
+ |
#ifdef IS_MPI |
| 51 |
+ |
#include <mpi.h> |
| 52 |
+ |
#endif |
| 53 |
|
#include <algorithm> |
| 54 |
|
#include <set> |
| 55 |
|
#include <map> |
| 64 |
|
#include "io/ForceFieldOptions.hpp" |
| 65 |
|
#include "brains/ForceField.hpp" |
| 66 |
|
#include "nonbonded/SwitchingFunction.hpp" |
| 64 |
– |
#ifdef IS_MPI |
| 65 |
– |
#include <mpi.h> |
| 66 |
– |
#endif |
| 67 |
|
|
| 68 |
|
using namespace std; |
| 69 |
|
namespace OpenMD { |
| 72 |
|
forceField_(ff), simParams_(simParams), |
| 73 |
|
ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), |
| 74 |
|
nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), |
| 75 |
< |
nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), nGlobalFluctuatingCharges_(0), |
| 76 |
< |
nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nInversions_(0), |
| 75 |
> |
nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
| 76 |
> |
nGlobalFluctuatingCharges_(0), nGlobalBonds_(0), nGlobalBends_(0), |
| 77 |
> |
nGlobalTorsions_(0), nGlobalInversions_(0), nGlobalConstraints_(0), |
| 78 |
> |
nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nInversions_(0), |
| 79 |
|
nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0), |
| 80 |
< |
nConstraints_(0), nFluctuatingCharges_(0), sman_(NULL), topologyDone_(false), |
| 81 |
< |
calcBoxDipole_(false), useAtomicVirial_(true) { |
| 80 |
> |
nConstraints_(0), nFluctuatingCharges_(0), sman_(NULL), |
| 81 |
> |
topologyDone_(false), calcBoxDipole_(false), calcBoxQuadrupole_(false), |
| 82 |
> |
useAtomicVirial_(true), hasNGlobalConstraints_(false) { |
| 83 |
|
|
| 84 |
|
MoleculeStamp* molStamp; |
| 85 |
|
int nMolWithSameStamp; |
| 94 |
|
for (vector<Component*>::iterator i = components.begin(); |
| 95 |
|
i !=components.end(); ++i) { |
| 96 |
|
molStamp = (*i)->getMoleculeStamp(); |
| 97 |
+ |
if ( (*i)->haveRegion() ) { |
| 98 |
+ |
molStamp->setRegion( (*i)->getRegion() ); |
| 99 |
+ |
} else { |
| 100 |
+ |
// set the region to a disallowed value: |
| 101 |
+ |
molStamp->setRegion( -1 ); |
| 102 |
+ |
} |
| 103 |
+ |
|
| 104 |
|
nMolWithSameStamp = (*i)->getNMol(); |
| 105 |
|
|
| 106 |
|
addMoleculeStamp(molStamp, nMolWithSameStamp); |
| 107 |
|
|
| 108 |
|
//calculate atoms in molecules |
| 109 |
< |
nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; |
| 109 |
> |
nGlobalAtoms_ += molStamp->getNAtoms() * nMolWithSameStamp; |
| 110 |
> |
nGlobalBonds_ += molStamp->getNBonds() * nMolWithSameStamp; |
| 111 |
> |
nGlobalBends_ += molStamp->getNBends() * nMolWithSameStamp; |
| 112 |
> |
nGlobalTorsions_ += molStamp->getNTorsions() * nMolWithSameStamp; |
| 113 |
> |
nGlobalInversions_ += molStamp->getNInversions() * nMolWithSameStamp; |
| 114 |
|
|
| 115 |
|
//calculate atoms in cutoff groups |
| 116 |
|
int nAtomsInGroups = 0; |
| 282 |
|
ndf_local -= nConstraints_; |
| 283 |
|
|
| 284 |
|
#ifdef IS_MPI |
| 285 |
< |
MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
| 286 |
< |
MPI_Allreduce(&nfq_local,&nGlobalFluctuatingCharges_,1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 285 |
> |
MPI_Allreduce(&ndf_local, &ndf_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 286 |
> |
MPI_Allreduce(&nfq_local, &nGlobalFluctuatingCharges_, 1, |
| 287 |
> |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 288 |
|
#else |
| 289 |
|
ndf_ = ndf_local; |
| 290 |
|
nGlobalFluctuatingCharges_ = nfq_local; |
| 298 |
|
|
| 299 |
|
int SimInfo::getFdf() { |
| 300 |
|
#ifdef IS_MPI |
| 301 |
< |
MPI_Allreduce(&fdf_local,&fdf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
| 301 |
> |
MPI_Allreduce(&fdf_local, &fdf_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 302 |
|
#else |
| 303 |
|
fdf_ = fdf_local; |
| 304 |
|
#endif |
| 354 |
|
} |
| 355 |
|
|
| 356 |
|
#ifdef IS_MPI |
| 357 |
< |
MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
| 357 |
> |
MPI_Allreduce(&ndfRaw_local, &ndfRaw_, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 358 |
|
#else |
| 359 |
|
ndfRaw_ = ndfRaw_local; |
| 360 |
|
#endif |
| 365 |
|
|
| 366 |
|
ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; |
| 367 |
|
|
| 353 |
– |
|
| 368 |
|
#ifdef IS_MPI |
| 369 |
< |
MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); |
| 369 |
> |
MPI_Allreduce(&ndfTrans_local, &ndfTrans_, 1, MPI_INT, MPI_SUM, |
| 370 |
> |
MPI_COMM_WORLD); |
| 371 |
|
#else |
| 372 |
|
ndfTrans_ = ndfTrans_local; |
| 373 |
|
#endif |
| 374 |
|
|
| 375 |
|
ndfTrans_ = ndfTrans_ - 3 - nZconstraint_; |
| 361 |
– |
|
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
void SimInfo::addInteractionPairs(Molecule* mol) { |
| 423 |
|
atomGroups.insert(map<int, set<int> >::value_type(sd->getGlobalIndex(), oneAtomSet)); |
| 424 |
|
} |
| 425 |
|
} |
| 426 |
+ |
|
| 427 |
|
|
| 428 |
|
for (bond= mol->beginBond(bondIter); bond != NULL; |
| 429 |
|
bond = mol->nextBond(bondIter)) { |
| 709 |
|
*/ |
| 710 |
|
void SimInfo::update() { |
| 711 |
|
setupSimVariables(); |
| 712 |
+ |
calcNConstraints(); |
| 713 |
|
calcNdf(); |
| 714 |
|
calcNdfRaw(); |
| 715 |
|
calcNdfTrans(); |
| 749 |
|
// count_local holds the number of found types on this processor |
| 750 |
|
int count_local = foundTypes.size(); |
| 751 |
|
|
| 752 |
< |
int nproc = MPI::COMM_WORLD.Get_size(); |
| 752 |
> |
int nproc; |
| 753 |
> |
MPI_Comm_size( MPI_COMM_WORLD, &nproc); |
| 754 |
|
|
| 755 |
|
// we need arrays to hold the counts and displacement vectors for |
| 756 |
|
// all processors |
| 758 |
|
vector<int> disps(nproc, 0); |
| 759 |
|
|
| 760 |
|
// fill the counts array |
| 761 |
< |
MPI::COMM_WORLD.Allgather(&count_local, 1, MPI::INT, &counts[0], |
| 762 |
< |
1, MPI::INT); |
| 761 |
> |
MPI_Allgather(&count_local, 1, MPI_INT, &counts[0], |
| 762 |
> |
1, MPI_INT, MPI_COMM_WORLD); |
| 763 |
|
|
| 764 |
|
// use the processor counts to compute the displacement array |
| 765 |
|
disps[0] = 0; |
| 773 |
|
vector<int> ftGlobal(totalCount); |
| 774 |
|
|
| 775 |
|
// now spray out the foundTypes to all the other processors: |
| 776 |
< |
MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT, |
| 777 |
< |
&ftGlobal[0], &counts[0], &disps[0], |
| 778 |
< |
MPI::INT); |
| 776 |
> |
MPI_Allgatherv(&foundTypes[0], count_local, MPI_INT, |
| 777 |
> |
&ftGlobal[0], &counts[0], &disps[0], |
| 778 |
> |
MPI_INT, MPI_COMM_WORLD); |
| 779 |
|
|
| 780 |
|
vector<int>::iterator j; |
| 781 |
|
|
| 797 |
|
return atomTypes; |
| 798 |
|
} |
| 799 |
|
|
| 800 |
+ |
|
| 801 |
+ |
int getGlobalCountOfType(AtomType* atype) { |
| 802 |
+ |
/* |
| 803 |
+ |
set<AtomType*> atypes = getSimulatedAtomTypes(); |
| 804 |
+ |
map<AtomType*, int> counts_; |
| 805 |
+ |
|
| 806 |
+ |
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 807 |
+ |
for(atom = mol->beginAtom(ai); atom != NULL; |
| 808 |
+ |
atom = mol->nextAtom(ai)) { |
| 809 |
+ |
atom->getAtomType(); |
| 810 |
+ |
} |
| 811 |
+ |
} |
| 812 |
+ |
*/ |
| 813 |
+ |
return 0; |
| 814 |
+ |
} |
| 815 |
+ |
|
| 816 |
|
void SimInfo::setupSimVariables() { |
| 817 |
|
useAtomicVirial_ = simParams_->getUseAtomicVirial(); |
| 818 |
|
// we only call setAccumulateBoxDipole if the accumulateBoxDipole |
| 822 |
|
if ( simParams_->getAccumulateBoxDipole() ) { |
| 823 |
|
calcBoxDipole_ = true; |
| 824 |
|
} |
| 825 |
+ |
// we only call setAccumulateBoxQuadrupole if the accumulateBoxQuadrupole |
| 826 |
+ |
// parameter is true |
| 827 |
+ |
calcBoxQuadrupole_ = false; |
| 828 |
+ |
if ( simParams_->haveAccumulateBoxQuadrupole() ) |
| 829 |
+ |
if ( simParams_->getAccumulateBoxQuadrupole() ) { |
| 830 |
+ |
calcBoxQuadrupole_ = true; |
| 831 |
+ |
} |
| 832 |
|
|
| 833 |
|
set<AtomType*>::iterator i; |
| 834 |
|
set<AtomType*> atomTypes; |
| 846 |
|
} |
| 847 |
|
|
| 848 |
|
#ifdef IS_MPI |
| 849 |
< |
bool temp; |
| 849 |
> |
int temp; |
| 850 |
> |
|
| 851 |
|
temp = usesDirectional; |
| 852 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesDirectionalAtoms_, 1, MPI::BOOL, |
| 853 |
< |
MPI::LOR); |
| 813 |
< |
|
| 814 |
< |
temp = usesMetallic; |
| 815 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesMetallicAtoms_, 1, MPI::BOOL, |
| 816 |
< |
MPI::LOR); |
| 852 |
> |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 853 |
> |
usesDirectionalAtoms_ = (temp == 0) ? false : true; |
| 854 |
|
|
| 855 |
+ |
temp = usesMetallic; |
| 856 |
+ |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 857 |
+ |
usesMetallicAtoms_ = (temp == 0) ? false : true; |
| 858 |
+ |
|
| 859 |
|
temp = usesElectrostatic; |
| 860 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI::BOOL, |
| 861 |
< |
MPI::LOR); |
| 860 |
> |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 861 |
> |
usesElectrostaticAtoms_ = (temp == 0) ? false : true; |
| 862 |
|
|
| 863 |
|
temp = usesFluctuatingCharges; |
| 864 |
< |
MPI::COMM_WORLD.Allreduce(&temp, &usesFluctuatingCharges_, 1, MPI::BOOL, |
| 865 |
< |
MPI::LOR); |
| 864 |
> |
MPI_Allreduce(MPI_IN_PLACE, &temp, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
| 865 |
> |
usesFluctuatingCharges_ = (temp == 0) ? false : true; |
| 866 |
|
#else |
| 867 |
|
|
| 868 |
|
usesDirectionalAtoms_ = usesDirectional; |
| 918 |
|
|
| 919 |
|
|
| 920 |
|
void SimInfo::prepareTopology() { |
| 880 |
– |
int nExclude, nOneTwo, nOneThree, nOneFour; |
| 921 |
|
|
| 922 |
|
//calculate mass ratio of cutoff group |
| 923 |
|
SimInfo::MoleculeIterator mi; |
| 954 |
|
} |
| 955 |
|
} |
| 956 |
|
|
| 957 |
< |
// Build the identArray_ |
| 957 |
> |
// Build the identArray_ and regions_ |
| 958 |
|
|
| 959 |
|
identArray_.clear(); |
| 960 |
< |
identArray_.reserve(getNAtoms()); |
| 961 |
< |
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 960 |
> |
identArray_.reserve(getNAtoms()); |
| 961 |
> |
regions_.clear(); |
| 962 |
> |
regions_.reserve(getNAtoms()); |
| 963 |
> |
|
| 964 |
> |
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 965 |
> |
int reg = mol->getRegion(); |
| 966 |
|
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 967 |
|
identArray_.push_back(atom->getIdent()); |
| 968 |
+ |
regions_.push_back(reg); |
| 969 |
|
} |
| 970 |
|
} |
| 971 |
< |
|
| 927 |
< |
//scan topology |
| 928 |
< |
|
| 929 |
< |
nExclude = excludedInteractions_.getSize(); |
| 930 |
< |
nOneTwo = oneTwoInteractions_.getSize(); |
| 931 |
< |
nOneThree = oneThreeInteractions_.getSize(); |
| 932 |
< |
nOneFour = oneFourInteractions_.getSize(); |
| 933 |
< |
|
| 934 |
< |
int* excludeList = excludedInteractions_.getPairList(); |
| 935 |
< |
int* oneTwoList = oneTwoInteractions_.getPairList(); |
| 936 |
< |
int* oneThreeList = oneThreeInteractions_.getPairList(); |
| 937 |
< |
int* oneFourList = oneFourInteractions_.getPairList(); |
| 938 |
< |
|
| 971 |
> |
|
| 972 |
|
topologyDone_ = true; |
| 973 |
|
} |
| 974 |
|
|
| 1003 |
|
delete sman_; |
| 1004 |
|
sman_ = sman; |
| 1005 |
|
|
| 973 |
– |
Molecule* mol; |
| 974 |
– |
RigidBody* rb; |
| 975 |
– |
Atom* atom; |
| 976 |
– |
CutoffGroup* cg; |
| 1006 |
|
SimInfo::MoleculeIterator mi; |
| 1007 |
+ |
Molecule::AtomIterator ai; |
| 1008 |
|
Molecule::RigidBodyIterator rbIter; |
| 979 |
– |
Molecule::AtomIterator atomIter; |
| 1009 |
|
Molecule::CutoffGroupIterator cgIter; |
| 1010 |
+ |
Molecule::BondIterator bondIter; |
| 1011 |
+ |
Molecule::BendIterator bendIter; |
| 1012 |
+ |
Molecule::TorsionIterator torsionIter; |
| 1013 |
+ |
Molecule::InversionIterator inversionIter; |
| 1014 |
|
|
| 1015 |
+ |
Molecule* mol; |
| 1016 |
+ |
Atom* atom; |
| 1017 |
+ |
RigidBody* rb; |
| 1018 |
+ |
CutoffGroup* cg; |
| 1019 |
+ |
Bond* bond; |
| 1020 |
+ |
Bend* bend; |
| 1021 |
+ |
Torsion* torsion; |
| 1022 |
+ |
Inversion* inversion; |
| 1023 |
+ |
|
| 1024 |
|
for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
| 1025 |
|
|
| 1026 |
< |
for (atom = mol->beginAtom(atomIter); atom != NULL; |
| 1027 |
< |
atom = mol->nextAtom(atomIter)) { |
| 1026 |
> |
for (atom = mol->beginAtom(ai); atom != NULL; |
| 1027 |
> |
atom = mol->nextAtom(ai)) { |
| 1028 |
|
atom->setSnapshotManager(sman_); |
| 1029 |
< |
} |
| 988 |
< |
|
| 1029 |
> |
} |
| 1030 |
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 1031 |
|
rb = mol->nextRigidBody(rbIter)) { |
| 1032 |
|
rb->setSnapshotManager(sman_); |
| 1033 |
|
} |
| 993 |
– |
|
| 1034 |
|
for (cg = mol->beginCutoffGroup(cgIter); cg != NULL; |
| 1035 |
|
cg = mol->nextCutoffGroup(cgIter)) { |
| 1036 |
|
cg->setSnapshotManager(sman_); |
| 1037 |
|
} |
| 1038 |
< |
} |
| 1039 |
< |
|
| 1038 |
> |
for (bond = mol->beginBond(bondIter); bond != NULL; |
| 1039 |
> |
bond = mol->nextBond(bondIter)) { |
| 1040 |
> |
bond->setSnapshotManager(sman_); |
| 1041 |
> |
} |
| 1042 |
> |
for (bend = mol->beginBend(bendIter); bend != NULL; |
| 1043 |
> |
bend = mol->nextBend(bendIter)) { |
| 1044 |
> |
bend->setSnapshotManager(sman_); |
| 1045 |
> |
} |
| 1046 |
> |
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; |
| 1047 |
> |
torsion = mol->nextTorsion(torsionIter)) { |
| 1048 |
> |
torsion->setSnapshotManager(sman_); |
| 1049 |
> |
} |
| 1050 |
> |
for (inversion = mol->beginInversion(inversionIter); inversion != NULL; |
| 1051 |
> |
inversion = mol->nextInversion(inversionIter)) { |
| 1052 |
> |
inversion->setSnapshotManager(sman_); |
| 1053 |
> |
} |
| 1054 |
> |
} |
| 1055 |
|
} |
| 1056 |
|
|
| 1057 |
|
|
| 1062 |
|
|
| 1063 |
|
|
| 1064 |
|
StuntDouble* SimInfo::getIOIndexToIntegrableObject(int index) { |
| 1065 |
< |
if (index >= IOIndexToIntegrableObject.size()) { |
| 1065 |
> |
if (index >= int(IOIndexToIntegrableObject.size())) { |
| 1066 |
|
sprintf(painCave.errMsg, |
| 1067 |
|
"SimInfo::getIOIndexToIntegrableObject Error: Integrable Object\n" |
| 1068 |
|
"\tindex exceeds number of known objects!\n"); |
| 1077 |
|
IOIndexToIntegrableObject= v; |
| 1078 |
|
} |
| 1079 |
|
|
| 1080 |
< |
int SimInfo::getNGlobalConstraints() { |
| 1026 |
< |
int nGlobalConstraints; |
| 1080 |
> |
void SimInfo::calcNConstraints() { |
| 1081 |
|
#ifdef IS_MPI |
| 1082 |
< |
MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM, |
| 1083 |
< |
MPI_COMM_WORLD); |
| 1082 |
> |
MPI_Allreduce(&nConstraints_, &nGlobalConstraints_, 1, |
| 1083 |
> |
MPI_INT, MPI_SUM, MPI_COMM_WORLD); |
| 1084 |
|
#else |
| 1085 |
< |
nGlobalConstraints = nConstraints_; |
| 1085 |
> |
nGlobalConstraints_ = nConstraints_; |
| 1086 |
|
#endif |
| 1033 |
– |
return nGlobalConstraints; |
| 1087 |
|
} |
| 1088 |
|
|
| 1089 |
|
}//end namespace OpenMD |