| 6 |
|
* redistribute this software in source and binary code form, provided |
| 7 |
|
* that the following conditions are met: |
| 8 |
|
* |
| 9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
| 10 |
< |
* publication of scientific results based in part on use of the |
| 11 |
< |
* program. An acceptable form of acknowledgement is citation of |
| 12 |
< |
* the article in which the program was described (Matthew |
| 13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
| 14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
| 15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
| 16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
| 17 |
< |
* |
| 18 |
< |
* 2. Redistributions of source code must retain the above copyright |
| 9 |
> |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
|
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
* |
| 12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
| 12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
|
* notice, this list of conditions and the following disclaimer in the |
| 14 |
|
* documentation and/or other materials provided with the |
| 15 |
|
* distribution. |
| 28 |
|
* arising out of the use of or inability to use software, even if the |
| 29 |
|
* University of Notre Dame has been advised of the possibility of |
| 30 |
|
* such damages. |
| 31 |
+ |
* |
| 32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
| 33 |
+ |
* research, please cite the appropriate papers when you publish your |
| 34 |
+ |
* work. Good starting points are: |
| 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). |
| 39 |
+ |
* [4] Vardeman & Gezelter, in progress (2009). |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
|
/** |
| 49 |
|
|
| 50 |
|
#include "brains/ForceManager.hpp" |
| 51 |
|
#include "primitives/Molecule.hpp" |
| 52 |
< |
#include "UseTheForce/doForces_interface.h" |
| 53 |
< |
#define __C |
| 54 |
< |
#include "UseTheForce/DarkSide/fInteractionMap.h" |
| 52 |
> |
#define __OPENMD_C |
| 53 |
|
#include "utils/simError.h" |
| 54 |
+ |
#include "primitives/Bond.hpp" |
| 55 |
|
#include "primitives/Bend.hpp" |
| 56 |
< |
#include "primitives/Bend.hpp" |
| 57 |
< |
namespace oopse { |
| 56 |
> |
#include "primitives/Torsion.hpp" |
| 57 |
> |
#include "primitives/Inversion.hpp" |
| 58 |
> |
#include "nonbonded/NonBondedInteraction.hpp" |
| 59 |
> |
#include "parallel/ForceMatrixDecomposition.hpp" |
| 60 |
|
|
| 61 |
< |
/* |
| 62 |
< |
struct BendOrderStruct { |
| 63 |
< |
Bend* bend; |
| 64 |
< |
BendDataSet dataSet; |
| 64 |
< |
}; |
| 65 |
< |
struct TorsionOrderStruct { |
| 66 |
< |
Torsion* torsion; |
| 67 |
< |
TorsionDataSet dataSet; |
| 68 |
< |
}; |
| 61 |
> |
using namespace std; |
| 62 |
> |
namespace OpenMD { |
| 63 |
> |
|
| 64 |
> |
ForceManager::ForceManager(SimInfo * info) : info_(info) { |
| 65 |
|
|
| 66 |
< |
bool BendSortFunctor(const BendOrderStruct& b1, const BendOrderStruct& b2) { |
| 67 |
< |
return b1.dataSet.deltaV < b2.dataSet.deltaV; |
| 66 |
> |
#ifdef IS_MPI |
| 67 |
> |
fDecomp_ = new ForceMatrixDecomposition(info_); |
| 68 |
> |
#else |
| 69 |
> |
// fDecomp_ = new ForceSerialDecomposition(info); |
| 70 |
> |
#endif |
| 71 |
|
} |
| 72 |
< |
|
| 73 |
< |
bool TorsionSortFunctor(const TorsionOrderStruct& t1, const TorsionOrderStruct& t2) { |
| 74 |
< |
return t1.dataSet.deltaV < t2.dataSet.deltaV; |
| 76 |
< |
} |
| 77 |
< |
*/ |
| 78 |
< |
void ForceManager::calcForces(bool needPotential, bool needStress) { |
| 79 |
< |
|
| 72 |
> |
|
| 73 |
> |
void ForceManager::calcForces() { |
| 74 |
> |
|
| 75 |
|
if (!info_->isFortranInitialized()) { |
| 76 |
|
info_->update(); |
| 77 |
+ |
interactionMan_->setSimInfo(info_); |
| 78 |
+ |
interactionMan_->initialize(); |
| 79 |
+ |
swfun_ = interactionMan_->getSwitchingFunction(); |
| 80 |
+ |
fDecomp_->distributeInitialData(); |
| 81 |
+ |
info_->setupFortran(); |
| 82 |
|
} |
| 83 |
– |
|
| 84 |
– |
preCalculation(); |
| 83 |
|
|
| 84 |
< |
calcShortRangeInteraction(); |
| 85 |
< |
|
| 86 |
< |
calcLongRangeInteraction(needPotential, needStress); |
| 89 |
< |
|
| 84 |
> |
preCalculation(); |
| 85 |
> |
shortRangeInteractions(); |
| 86 |
> |
longRangeInteractions(); |
| 87 |
|
postCalculation(); |
| 91 |
– |
|
| 92 |
– |
/* |
| 93 |
– |
std::vector<BendOrderStruct> bendOrderStruct; |
| 94 |
– |
for(std::map<Bend*, BendDataSet>::iterator i = bendDataSets.begin(); i != bendDataSets.end(); ++i) { |
| 95 |
– |
BendOrderStruct tmp; |
| 96 |
– |
tmp.bend= const_cast<Bend*>(i->first); |
| 97 |
– |
tmp.dataSet = i->second; |
| 98 |
– |
bendOrderStruct.push_back(tmp); |
| 99 |
– |
} |
| 100 |
– |
|
| 101 |
– |
std::vector<TorsionOrderStruct> torsionOrderStruct; |
| 102 |
– |
for(std::map<Torsion*, TorsionDataSet>::iterator j = torsionDataSets.begin(); j != torsionDataSets.end(); ++j) { |
| 103 |
– |
TorsionOrderStruct tmp; |
| 104 |
– |
tmp.torsion = const_cast<Torsion*>(j->first); |
| 105 |
– |
tmp.dataSet = j->second; |
| 106 |
– |
torsionOrderStruct.push_back(tmp); |
| 107 |
– |
} |
| 88 |
|
|
| 109 |
– |
std::sort(bendOrderStruct.begin(), bendOrderStruct.end(), std::ptr_fun(BendSortFunctor)); |
| 110 |
– |
std::sort(torsionOrderStruct.begin(), torsionOrderStruct.end(), std::ptr_fun(TorsionSortFunctor)); |
| 111 |
– |
for (std::vector<BendOrderStruct>::iterator k = bendOrderStruct.begin(); k != bendOrderStruct.end(); ++k) { |
| 112 |
– |
Bend* bend = k->bend; |
| 113 |
– |
std::cout << "Bend: atom1=" <<bend->getAtomA()->getGlobalIndex() << ",atom2 = "<< bend->getAtomB()->getGlobalIndex() << ",atom3="<<bend->getAtomC()->getGlobalIndex() << " "; |
| 114 |
– |
std::cout << "deltaV=" << k->dataSet.deltaV << ",p_theta=" << k->dataSet.prev.angle <<",p_pot=" << k->dataSet.prev.potential<< ",c_theta=" << k->dataSet.curr.angle << ", c_pot = " << k->dataSet.curr.potential <<std::endl; |
| 115 |
– |
} |
| 116 |
– |
for (std::vector<TorsionOrderStruct>::iterator l = torsionOrderStruct.begin(); l != torsionOrderStruct.end(); ++l) { |
| 117 |
– |
Torsion* torsion = l->torsion; |
| 118 |
– |
std::cout << "Torsion: atom1=" <<torsion->getAtomA()->getGlobalIndex() << ",atom2 = "<< torsion->getAtomB()->getGlobalIndex() << ",atom3="<<torsion->getAtomC()->getGlobalIndex() << ",atom4="<<torsion->getAtomD()->getGlobalIndex()<< " "; |
| 119 |
– |
std::cout << "deltaV=" << l->dataSet.deltaV << ",p_theta=" << l->dataSet.prev.angle <<",p_pot=" << l->dataSet.prev.potential<< ",c_theta=" << l->dataSet.curr.angle << ", c_pot = " << l->dataSet.curr.potential <<std::endl; |
| 120 |
– |
} |
| 121 |
– |
*/ |
| 89 |
|
} |
| 90 |
< |
|
| 90 |
> |
|
| 91 |
|
void ForceManager::preCalculation() { |
| 92 |
|
SimInfo::MoleculeIterator mi; |
| 93 |
|
Molecule* mol; |
| 95 |
|
Atom* atom; |
| 96 |
|
Molecule::RigidBodyIterator rbIter; |
| 97 |
|
RigidBody* rb; |
| 98 |
+ |
Molecule::CutoffGroupIterator ci; |
| 99 |
+ |
CutoffGroup* cg; |
| 100 |
|
|
| 101 |
|
// forces are zeroed here, before any are accumulated. |
| 102 |
< |
// NOTE: do not rezero the forces in Fortran. |
| 103 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 102 |
> |
|
| 103 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 104 |
> |
mol = info_->nextMolecule(mi)) { |
| 105 |
|
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
| 106 |
|
atom->zeroForcesAndTorques(); |
| 107 |
|
} |
| 108 |
< |
|
| 108 |
> |
|
| 109 |
|
//change the positions of atoms which belong to the rigidbodies |
| 110 |
< |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 110 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 111 |
> |
rb = mol->nextRigidBody(rbIter)) { |
| 112 |
|
rb->zeroForcesAndTorques(); |
| 113 |
|
} |
| 114 |
+ |
|
| 115 |
+ |
if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){ |
| 116 |
+ |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; |
| 117 |
+ |
cg = mol->nextCutoffGroup(ci)) { |
| 118 |
+ |
//calculate the center of mass of cutoff group |
| 119 |
+ |
cg->updateCOM(); |
| 120 |
+ |
} |
| 121 |
+ |
} |
| 122 |
|
} |
| 123 |
+ |
|
| 124 |
+ |
// Zero out the stress tensor |
| 125 |
+ |
tau *= 0.0; |
| 126 |
|
|
| 127 |
|
} |
| 128 |
< |
|
| 129 |
< |
void ForceManager::calcShortRangeInteraction() { |
| 128 |
> |
|
| 129 |
> |
void ForceManager::shortRangeInteractions() { |
| 130 |
|
Molecule* mol; |
| 131 |
|
RigidBody* rb; |
| 132 |
|
Bond* bond; |
| 133 |
|
Bend* bend; |
| 134 |
|
Torsion* torsion; |
| 135 |
+ |
Inversion* inversion; |
| 136 |
|
SimInfo::MoleculeIterator mi; |
| 137 |
|
Molecule::RigidBodyIterator rbIter; |
| 138 |
|
Molecule::BondIterator bondIter;; |
| 139 |
|
Molecule::BendIterator bendIter; |
| 140 |
|
Molecule::TorsionIterator torsionIter; |
| 141 |
+ |
Molecule::InversionIterator inversionIter; |
| 142 |
|
RealType bondPotential = 0.0; |
| 143 |
|
RealType bendPotential = 0.0; |
| 144 |
|
RealType torsionPotential = 0.0; |
| 145 |
+ |
RealType inversionPotential = 0.0; |
| 146 |
|
|
| 147 |
|
//calculate short range interactions |
| 148 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 148 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 149 |
> |
mol = info_->nextMolecule(mi)) { |
| 150 |
|
|
| 151 |
|
//change the positions of atoms which belong to the rigidbodies |
| 152 |
< |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 153 |
< |
rb->updateAtoms(); |
| 152 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 153 |
> |
rb = mol->nextRigidBody(rbIter)) { |
| 154 |
> |
rb->updateAtoms(); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
< |
for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { |
| 157 |
> |
for (bond = mol->beginBond(bondIter); bond != NULL; |
| 158 |
> |
bond = mol->nextBond(bondIter)) { |
| 159 |
|
bond->calcForce(); |
| 160 |
|
bondPotential += bond->getPotential(); |
| 161 |
|
} |
| 162 |
|
|
| 163 |
< |
|
| 164 |
< |
for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { |
| 165 |
< |
|
| 166 |
< |
RealType angle; |
| 167 |
< |
bend->calcForce(angle); |
| 168 |
< |
RealType currBendPot = bend->getPotential(); |
| 169 |
< |
bendPotential += bend->getPotential(); |
| 170 |
< |
std::map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend); |
| 171 |
< |
if (i == bendDataSets.end()) { |
| 172 |
< |
BendDataSet dataSet; |
| 173 |
< |
dataSet.prev.angle = dataSet.curr.angle = angle; |
| 174 |
< |
dataSet.prev.potential = dataSet.curr.potential = currBendPot; |
| 175 |
< |
dataSet.deltaV = 0.0; |
| 176 |
< |
bendDataSets.insert(std::map<Bend*, BendDataSet>::value_type(bend, dataSet)); |
| 177 |
< |
}else { |
| 178 |
< |
i->second.prev.angle = i->second.curr.angle; |
| 179 |
< |
i->second.prev.potential = i->second.curr.potential; |
| 180 |
< |
i->second.curr.angle = angle; |
| 181 |
< |
i->second.curr.potential = currBendPot; |
| 182 |
< |
i->second.deltaV = fabs(i->second.curr.potential - i->second.prev.potential); |
| 183 |
< |
} |
| 163 |
> |
for (bend = mol->beginBend(bendIter); bend != NULL; |
| 164 |
> |
bend = mol->nextBend(bendIter)) { |
| 165 |
> |
|
| 166 |
> |
RealType angle; |
| 167 |
> |
bend->calcForce(angle); |
| 168 |
> |
RealType currBendPot = bend->getPotential(); |
| 169 |
> |
|
| 170 |
> |
bendPotential += bend->getPotential(); |
| 171 |
> |
map<Bend*, BendDataSet>::iterator i = bendDataSets.find(bend); |
| 172 |
> |
if (i == bendDataSets.end()) { |
| 173 |
> |
BendDataSet dataSet; |
| 174 |
> |
dataSet.prev.angle = dataSet.curr.angle = angle; |
| 175 |
> |
dataSet.prev.potential = dataSet.curr.potential = currBendPot; |
| 176 |
> |
dataSet.deltaV = 0.0; |
| 177 |
> |
bendDataSets.insert(map<Bend*, BendDataSet>::value_type(bend, dataSet)); |
| 178 |
> |
}else { |
| 179 |
> |
i->second.prev.angle = i->second.curr.angle; |
| 180 |
> |
i->second.prev.potential = i->second.curr.potential; |
| 181 |
> |
i->second.curr.angle = angle; |
| 182 |
> |
i->second.curr.potential = currBendPot; |
| 183 |
> |
i->second.deltaV = fabs(i->second.curr.potential - |
| 184 |
> |
i->second.prev.potential); |
| 185 |
> |
} |
| 186 |
|
} |
| 187 |
< |
|
| 188 |
< |
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { |
| 187 |
> |
|
| 188 |
> |
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; |
| 189 |
> |
torsion = mol->nextTorsion(torsionIter)) { |
| 190 |
|
RealType angle; |
| 191 |
< |
torsion->calcForce(angle); |
| 191 |
> |
torsion->calcForce(angle); |
| 192 |
|
RealType currTorsionPot = torsion->getPotential(); |
| 193 |
< |
torsionPotential += torsion->getPotential(); |
| 194 |
< |
std::map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); |
| 195 |
< |
if (i == torsionDataSets.end()) { |
| 196 |
< |
TorsionDataSet dataSet; |
| 197 |
< |
dataSet.prev.angle = dataSet.curr.angle = angle; |
| 198 |
< |
dataSet.prev.potential = dataSet.curr.potential = currTorsionPot; |
| 199 |
< |
dataSet.deltaV = 0.0; |
| 200 |
< |
torsionDataSets.insert(std::map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet)); |
| 201 |
< |
}else { |
| 202 |
< |
i->second.prev.angle = i->second.curr.angle; |
| 203 |
< |
i->second.prev.potential = i->second.curr.potential; |
| 204 |
< |
i->second.curr.angle = angle; |
| 205 |
< |
i->second.curr.potential = currTorsionPot; |
| 206 |
< |
i->second.deltaV = fabs(i->second.curr.potential - i->second.prev.potential); |
| 207 |
< |
} |
| 208 |
< |
} |
| 209 |
< |
|
| 193 |
> |
torsionPotential += torsion->getPotential(); |
| 194 |
> |
map<Torsion*, TorsionDataSet>::iterator i = torsionDataSets.find(torsion); |
| 195 |
> |
if (i == torsionDataSets.end()) { |
| 196 |
> |
TorsionDataSet dataSet; |
| 197 |
> |
dataSet.prev.angle = dataSet.curr.angle = angle; |
| 198 |
> |
dataSet.prev.potential = dataSet.curr.potential = currTorsionPot; |
| 199 |
> |
dataSet.deltaV = 0.0; |
| 200 |
> |
torsionDataSets.insert(map<Torsion*, TorsionDataSet>::value_type(torsion, dataSet)); |
| 201 |
> |
}else { |
| 202 |
> |
i->second.prev.angle = i->second.curr.angle; |
| 203 |
> |
i->second.prev.potential = i->second.curr.potential; |
| 204 |
> |
i->second.curr.angle = angle; |
| 205 |
> |
i->second.curr.potential = currTorsionPot; |
| 206 |
> |
i->second.deltaV = fabs(i->second.curr.potential - |
| 207 |
> |
i->second.prev.potential); |
| 208 |
> |
} |
| 209 |
> |
} |
| 210 |
> |
|
| 211 |
> |
for (inversion = mol->beginInversion(inversionIter); |
| 212 |
> |
inversion != NULL; |
| 213 |
> |
inversion = mol->nextInversion(inversionIter)) { |
| 214 |
> |
RealType angle; |
| 215 |
> |
inversion->calcForce(angle); |
| 216 |
> |
RealType currInversionPot = inversion->getPotential(); |
| 217 |
> |
inversionPotential += inversion->getPotential(); |
| 218 |
> |
map<Inversion*, InversionDataSet>::iterator i = inversionDataSets.find(inversion); |
| 219 |
> |
if (i == inversionDataSets.end()) { |
| 220 |
> |
InversionDataSet dataSet; |
| 221 |
> |
dataSet.prev.angle = dataSet.curr.angle = angle; |
| 222 |
> |
dataSet.prev.potential = dataSet.curr.potential = currInversionPot; |
| 223 |
> |
dataSet.deltaV = 0.0; |
| 224 |
> |
inversionDataSets.insert(map<Inversion*, InversionDataSet>::value_type(inversion, dataSet)); |
| 225 |
> |
}else { |
| 226 |
> |
i->second.prev.angle = i->second.curr.angle; |
| 227 |
> |
i->second.prev.potential = i->second.curr.potential; |
| 228 |
> |
i->second.curr.angle = angle; |
| 229 |
> |
i->second.curr.potential = currInversionPot; |
| 230 |
> |
i->second.deltaV = fabs(i->second.curr.potential - |
| 231 |
> |
i->second.prev.potential); |
| 232 |
> |
} |
| 233 |
> |
} |
| 234 |
|
} |
| 235 |
|
|
| 236 |
< |
RealType shortRangePotential = bondPotential + bendPotential + torsionPotential; |
| 236 |
> |
RealType shortRangePotential = bondPotential + bendPotential + |
| 237 |
> |
torsionPotential + inversionPotential; |
| 238 |
|
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 239 |
|
curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential; |
| 240 |
|
curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential; |
| 241 |
|
curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential; |
| 242 |
|
curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential; |
| 243 |
< |
|
| 243 |
> |
curSnapshot->statData[Stats::INVERSION_POTENTIAL] = inversionPotential; |
| 244 |
|
} |
| 245 |
+ |
|
| 246 |
+ |
void ForceManager::longRangeInteractions() { |
| 247 |
|
|
| 248 |
< |
void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) { |
| 249 |
< |
Snapshot* curSnapshot; |
| 250 |
< |
DataStorage* config; |
| 251 |
< |
RealType* frc; |
| 252 |
< |
RealType* pos; |
| 253 |
< |
RealType* trq; |
| 254 |
< |
RealType* A; |
| 255 |
< |
RealType* electroFrame; |
| 256 |
< |
RealType* rc; |
| 257 |
< |
|
| 258 |
< |
//get current snapshot from SimInfo |
| 241 |
< |
curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 242 |
< |
|
| 243 |
< |
//get array pointers |
| 244 |
< |
config = &(curSnapshot->atomData); |
| 245 |
< |
frc = config->getArrayPointer(DataStorage::dslForce); |
| 246 |
< |
pos = config->getArrayPointer(DataStorage::dslPosition); |
| 247 |
< |
trq = config->getArrayPointer(DataStorage::dslTorque); |
| 248 |
< |
A = config->getArrayPointer(DataStorage::dslAmat); |
| 249 |
< |
electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); |
| 248 |
> |
// some of this initial stuff will go away: |
| 249 |
> |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 250 |
> |
DataStorage* config = &(curSnapshot->atomData); |
| 251 |
> |
DataStorage* cgConfig = &(curSnapshot->cgData); |
| 252 |
> |
RealType* frc = config->getArrayPointer(DataStorage::dslForce); |
| 253 |
> |
RealType* pos = config->getArrayPointer(DataStorage::dslPosition); |
| 254 |
> |
RealType* trq = config->getArrayPointer(DataStorage::dslTorque); |
| 255 |
> |
RealType* A = config->getArrayPointer(DataStorage::dslAmat); |
| 256 |
> |
RealType* electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); |
| 257 |
> |
RealType* particlePot = config->getArrayPointer(DataStorage::dslParticlePot); |
| 258 |
> |
RealType* rc; |
| 259 |
|
|
| 260 |
< |
//calculate the center of mass of cutoff group |
| 261 |
< |
SimInfo::MoleculeIterator mi; |
| 253 |
< |
Molecule* mol; |
| 254 |
< |
Molecule::CutoffGroupIterator ci; |
| 255 |
< |
CutoffGroup* cg; |
| 256 |
< |
Vector3d com; |
| 257 |
< |
std::vector<Vector3d> rcGroup; |
| 258 |
< |
|
| 259 |
< |
if(info_->getNCutoffGroups() > 0){ |
| 260 |
< |
|
| 261 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 262 |
< |
for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
| 263 |
< |
cg->getCOM(com); |
| 264 |
< |
rcGroup.push_back(com); |
| 265 |
< |
} |
| 266 |
< |
}// end for (mol) |
| 267 |
< |
|
| 268 |
< |
rc = rcGroup[0].getArrayPointer(); |
| 260 |
> |
if(info_->getNGlobalCutoffGroups() != info_->getNGlobalAtoms()){ |
| 261 |
> |
rc = cgConfig->getArrayPointer(DataStorage::dslPosition); |
| 262 |
|
} else { |
| 263 |
< |
// center of mass of the group is the same as position of the atom if cutoff group does not exist |
| 263 |
> |
// center of mass of the group is the same as position of the atom |
| 264 |
> |
// if cutoff group does not exist |
| 265 |
|
rc = pos; |
| 266 |
|
} |
| 267 |
< |
|
| 267 |
> |
|
| 268 |
|
//initialize data before passing to fortran |
| 269 |
< |
RealType longRangePotential[LR_POT_TYPES]; |
| 269 |
> |
RealType longRangePotential[N_INTERACTION_FAMILIES]; |
| 270 |
|
RealType lrPot = 0.0; |
| 277 |
– |
|
| 278 |
– |
Mat3x3d tau; |
| 279 |
– |
short int passedCalcPot = needPotential; |
| 280 |
– |
short int passedCalcStress = needStress; |
| 271 |
|
int isError = 0; |
| 272 |
|
|
| 273 |
< |
for (int i=0; i<LR_POT_TYPES;i++){ |
| 273 |
> |
// dangerous to iterate over enums, but we'll live on the edge: |
| 274 |
> |
for (int i = NO_FAMILY; i != N_INTERACTION_FAMILIES; ++i){ |
| 275 |
|
longRangePotential[i]=0.0; //Initialize array |
| 276 |
|
} |
| 277 |
|
|
| 278 |
< |
doForceLoop( pos, |
| 288 |
< |
rc, |
| 289 |
< |
A, |
| 290 |
< |
electroFrame, |
| 291 |
< |
frc, |
| 292 |
< |
trq, |
| 293 |
< |
tau.getArrayPointer(), |
| 294 |
< |
longRangePotential, |
| 295 |
< |
&passedCalcPot, |
| 296 |
< |
&passedCalcStress, |
| 297 |
< |
&isError ); |
| 278 |
> |
// new stuff starts here: |
| 279 |
|
|
| 280 |
< |
if( isError ){ |
| 281 |
< |
sprintf( painCave.errMsg, |
| 282 |
< |
"Error returned from the fortran force calculation.\n" ); |
| 283 |
< |
painCave.isFatal = 1; |
| 284 |
< |
simError(); |
| 280 |
> |
fDecomp_->distributeData(); |
| 281 |
> |
|
| 282 |
> |
int cg1, cg2, atom1, atom2; |
| 283 |
> |
Vector3d d_grp, dag; |
| 284 |
> |
RealType rgrpsq, rgrp; |
| 285 |
> |
RealType vij; |
| 286 |
> |
Vector3d fij, fg; |
| 287 |
> |
pair<int, int> gtypes; |
| 288 |
> |
RealType rCutSq; |
| 289 |
> |
bool in_switching_region; |
| 290 |
> |
RealType sw, dswdr, swderiv; |
| 291 |
> |
vector<int> atomListColumn, atomListRow, atomListLocal; |
| 292 |
> |
InteractionData idat; |
| 293 |
> |
SelfData sdat; |
| 294 |
> |
RealType mf; |
| 295 |
> |
|
| 296 |
> |
int loopStart, loopEnd; |
| 297 |
> |
|
| 298 |
> |
loopEnd = PAIR_LOOP; |
| 299 |
> |
if (info_->requiresPrepair() ) { |
| 300 |
> |
loopStart = PREPAIR_LOOP; |
| 301 |
> |
} else { |
| 302 |
> |
loopStart = PAIR_LOOP; |
| 303 |
|
} |
| 304 |
< |
for (int i=0; i<LR_POT_TYPES;i++){ |
| 305 |
< |
lrPot += longRangePotential[i]; //Quick hack |
| 304 |
> |
|
| 305 |
> |
for (int iLoop = loopStart; iLoop < loopEnd; iLoop++) { |
| 306 |
> |
|
| 307 |
> |
if (iLoop == loopStart) { |
| 308 |
> |
bool update_nlist = fDecomp_->checkNeighborList(); |
| 309 |
> |
if (update_nlist) |
| 310 |
> |
neighborList = fDecomp_->buildNeighborList(); |
| 311 |
> |
} |
| 312 |
> |
|
| 313 |
> |
for (vector<pair<int, int> >::iterator it = neighborList.begin(); |
| 314 |
> |
it != neighborList.end(); ++it) { |
| 315 |
> |
|
| 316 |
> |
cg1 = (*it).first; |
| 317 |
> |
cg2 = (*it).second; |
| 318 |
> |
|
| 319 |
> |
gtypes = fDecomp_->getGroupTypes(cg1, cg2); |
| 320 |
> |
d_grp = fDecomp_->getIntergroupVector(cg1, cg2); |
| 321 |
> |
curSnapshot->wrapVector(d_grp); |
| 322 |
> |
rgrpsq = d_grp.lengthSquare(); |
| 323 |
> |
rCutSq = groupCutoffMap[gtypes].first; |
| 324 |
> |
|
| 325 |
> |
if (rgrpsq < rCutSq) { |
| 326 |
> |
*(idat.rcut) = groupCutoffMap[gtypes].second; |
| 327 |
> |
if (iLoop == PAIR_LOOP) { |
| 328 |
> |
vij *= 0.0; |
| 329 |
> |
fij = V3Zero; |
| 330 |
> |
} |
| 331 |
> |
|
| 332 |
> |
in_switching_region = swfun_->getSwitch(rgrpsq, *(idat.sw), dswdr, |
| 333 |
> |
rgrp); |
| 334 |
> |
atomListRow = fDecomp_->getAtomsInGroupRow(cg1); |
| 335 |
> |
atomListColumn = fDecomp_->getAtomsInGroupColumn(cg2); |
| 336 |
> |
|
| 337 |
> |
for (vector<int>::iterator ia = atomListRow.begin(); |
| 338 |
> |
ia != atomListRow.end(); ++ia) { |
| 339 |
> |
atom1 = (*ia); |
| 340 |
> |
|
| 341 |
> |
for (vector<int>::iterator jb = atomListColumn.begin(); |
| 342 |
> |
jb != atomListColumn.end(); ++jb) { |
| 343 |
> |
atom2 = (*jb); |
| 344 |
> |
|
| 345 |
> |
if (!fDecomp_->skipAtomPair(atom1, atom2)) { |
| 346 |
> |
|
| 347 |
> |
idat = fDecomp_->fillInteractionData(atom1, atom2); |
| 348 |
> |
|
| 349 |
> |
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
| 350 |
> |
*(idat.d) = d_grp; |
| 351 |
> |
*(idat.r2) = rgrpsq; |
| 352 |
> |
} else { |
| 353 |
> |
*(idat.d) = fDecomp_->getInteratomicVector(atom1, atom2); |
| 354 |
> |
curSnapshot->wrapVector( *(idat.d) ); |
| 355 |
> |
*(idat.r2) = idat.d->lengthSquare(); |
| 356 |
> |
} |
| 357 |
> |
|
| 358 |
> |
*(idat.rij) = sqrt( *(idat.r2) ); |
| 359 |
> |
|
| 360 |
> |
if (iLoop == PREPAIR_LOOP) { |
| 361 |
> |
interactionMan_->doPrePair(idat); |
| 362 |
> |
} else { |
| 363 |
> |
interactionMan_->doPair(idat); |
| 364 |
> |
vij += *(idat.vpair); |
| 365 |
> |
fij += *(idat.f1); |
| 366 |
> |
tau -= outProduct( *(idat.d), *(idat.f1)); |
| 367 |
> |
} |
| 368 |
> |
} |
| 369 |
> |
} |
| 370 |
> |
} |
| 371 |
> |
|
| 372 |
> |
if (iLoop == PAIR_LOOP) { |
| 373 |
> |
if (in_switching_region) { |
| 374 |
> |
swderiv = vij * dswdr / rgrp; |
| 375 |
> |
fg = swderiv * d_grp; |
| 376 |
> |
|
| 377 |
> |
fij += fg; |
| 378 |
> |
|
| 379 |
> |
if (atomListRow.size() == 1 && atomListColumn.size() == 1) { |
| 380 |
> |
tau -= outProduct( *(idat.d), fg); |
| 381 |
> |
} |
| 382 |
> |
|
| 383 |
> |
for (vector<int>::iterator ia = atomListRow.begin(); |
| 384 |
> |
ia != atomListRow.end(); ++ia) { |
| 385 |
> |
atom1 = (*ia); |
| 386 |
> |
mf = fDecomp_->getMfactRow(atom1); |
| 387 |
> |
// fg is the force on atom ia due to cutoff group's |
| 388 |
> |
// presence in switching region |
| 389 |
> |
fg = swderiv * d_grp * mf; |
| 390 |
> |
fDecomp_->addForceToAtomRow(atom1, fg); |
| 391 |
> |
|
| 392 |
> |
if (atomListRow.size() > 1) { |
| 393 |
> |
if (info_->usesAtomicVirial()) { |
| 394 |
> |
// find the distance between the atom |
| 395 |
> |
// and the center of the cutoff group: |
| 396 |
> |
dag = fDecomp_->getAtomToGroupVectorRow(atom1, cg1); |
| 397 |
> |
tau -= outProduct(dag, fg); |
| 398 |
> |
} |
| 399 |
> |
} |
| 400 |
> |
} |
| 401 |
> |
for (vector<int>::iterator jb = atomListColumn.begin(); |
| 402 |
> |
jb != atomListColumn.end(); ++jb) { |
| 403 |
> |
atom2 = (*jb); |
| 404 |
> |
mf = fDecomp_->getMfactColumn(atom2); |
| 405 |
> |
// fg is the force on atom jb due to cutoff group's |
| 406 |
> |
// presence in switching region |
| 407 |
> |
fg = -swderiv * d_grp * mf; |
| 408 |
> |
fDecomp_->addForceToAtomColumn(atom2, fg); |
| 409 |
> |
|
| 410 |
> |
if (atomListColumn.size() > 1) { |
| 411 |
> |
if (info_->usesAtomicVirial()) { |
| 412 |
> |
// find the distance between the atom |
| 413 |
> |
// and the center of the cutoff group: |
| 414 |
> |
dag = fDecomp_->getAtomToGroupVectorColumn(atom2, cg2); |
| 415 |
> |
tau -= outProduct(dag, fg); |
| 416 |
> |
} |
| 417 |
> |
} |
| 418 |
> |
} |
| 419 |
> |
} |
| 420 |
> |
//if (!SIM_uses_AtomicVirial) { |
| 421 |
> |
// tau -= outProduct(d_grp, fij); |
| 422 |
> |
//} |
| 423 |
> |
} |
| 424 |
> |
} |
| 425 |
> |
} |
| 426 |
> |
|
| 427 |
> |
if (iLoop == PREPAIR_LOOP) { |
| 428 |
> |
if (info_->requiresPrepair()) { |
| 429 |
> |
fDecomp_->collectIntermediateData(); |
| 430 |
> |
atomListLocal = fDecomp_->getAtomList(); |
| 431 |
> |
for (vector<int>::iterator ia = atomListLocal.begin(); |
| 432 |
> |
ia != atomListLocal.end(); ++ia) { |
| 433 |
> |
atom1 = (*ia); |
| 434 |
> |
sdat = fDecomp_->fillSelfData(atom1); |
| 435 |
> |
interactionMan_->doPreForce(sdat); |
| 436 |
> |
} |
| 437 |
> |
fDecomp_->distributeIntermediateData(); |
| 438 |
> |
} |
| 439 |
> |
} |
| 440 |
> |
|
| 441 |
|
} |
| 442 |
+ |
|
| 443 |
+ |
fDecomp_->collectData(); |
| 444 |
+ |
|
| 445 |
+ |
if (info_->requiresSkipCorrection() || info_->requiresSelfCorrection()) { |
| 446 |
+ |
atomListLocal = fDecomp_->getAtomList(); |
| 447 |
+ |
for (vector<int>::iterator ia = atomListLocal.begin(); |
| 448 |
+ |
ia != atomListLocal.end(); ++ia) { |
| 449 |
+ |
atom1 = (*ia); |
| 450 |
|
|
| 451 |
+ |
if (info_->requiresSkipCorrection()) { |
| 452 |
+ |
vector<int> skipList = fDecomp_->getSkipsForAtom(atom1); |
| 453 |
+ |
for (vector<int>::iterator jb = skipList.begin(); |
| 454 |
+ |
jb != skipList.end(); ++jb) { |
| 455 |
+ |
atom2 = (*jb); |
| 456 |
+ |
idat = fDecomp_->fillSkipData(atom1, atom2); |
| 457 |
+ |
interactionMan_->doSkipCorrection(idat); |
| 458 |
+ |
} |
| 459 |
+ |
} |
| 460 |
+ |
|
| 461 |
+ |
if (info_->requiresSelfCorrection()) { |
| 462 |
+ |
sdat = fDecomp_->fillSelfData(atom1); |
| 463 |
+ |
interactionMan_->doSelfCorrection(sdat); |
| 464 |
+ |
} |
| 465 |
+ |
} |
| 466 |
+ |
} |
| 467 |
+ |
|
| 468 |
+ |
// dangerous to iterate over enums, but we'll live on the edge: |
| 469 |
+ |
for (int i = NO_FAMILY; i != N_INTERACTION_FAMILIES; ++i){ |
| 470 |
+ |
lrPot += longRangePotential[i]; //Quick hack |
| 471 |
+ |
} |
| 472 |
+ |
|
| 473 |
|
//store the tau and long range potential |
| 474 |
|
curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot; |
| 475 |
< |
curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT]; |
| 476 |
< |
curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT]; |
| 313 |
< |
|
| 314 |
< |
curSnapshot->statData.setTau(tau); |
| 475 |
> |
curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VANDERWAALS_FAMILY]; |
| 476 |
> |
curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_FAMILY]; |
| 477 |
|
} |
| 478 |
|
|
| 479 |
< |
|
| 479 |
> |
|
| 480 |
|
void ForceManager::postCalculation() { |
| 481 |
|
SimInfo::MoleculeIterator mi; |
| 482 |
|
Molecule* mol; |
| 483 |
|
Molecule::RigidBodyIterator rbIter; |
| 484 |
|
RigidBody* rb; |
| 485 |
+ |
Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 486 |
|
|
| 487 |
|
// collect the atomic forces onto rigid bodies |
| 488 |
< |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 489 |
< |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 490 |
< |
rb->calcForcesAndTorques(); |
| 488 |
> |
|
| 489 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 490 |
> |
mol = info_->nextMolecule(mi)) { |
| 491 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 492 |
> |
rb = mol->nextRigidBody(rbIter)) { |
| 493 |
> |
Mat3x3d rbTau = rb->calcForcesAndTorquesAndVirial(); |
| 494 |
> |
tau += rbTau; |
| 495 |
|
} |
| 496 |
|
} |
| 497 |
< |
|
| 497 |
> |
|
| 498 |
> |
#ifdef IS_MPI |
| 499 |
> |
Mat3x3d tmpTau(tau); |
| 500 |
> |
MPI_Allreduce(tmpTau.getArrayPointer(), tau.getArrayPointer(), |
| 501 |
> |
9, MPI_REALTYPE, MPI_SUM, MPI_COMM_WORLD); |
| 502 |
> |
#endif |
| 503 |
> |
curSnapshot->statData.setTau(tau); |
| 504 |
|
} |
| 505 |
|
|
| 506 |
< |
} //end namespace oopse |
| 506 |
> |
} //end namespace OpenMD |