| 1 | gezelter | 507 | /* | 
| 2 | gezelter | 246 | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 |  |  | * | 
| 4 |  |  | * The University of Notre Dame grants you ("Licensee") a | 
| 5 |  |  | * non-exclusive, royalty free, license to use, modify and | 
| 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 | 
| 19 |  |  | *    notice, this list of conditions and the following disclaimer. | 
| 20 |  |  | * | 
| 21 |  |  | * 3. Redistributions in binary form must reproduce the above copyright | 
| 22 |  |  | *    notice, this list of conditions and the following disclaimer in the | 
| 23 |  |  | *    documentation and/or other materials provided with the | 
| 24 |  |  | *    distribution. | 
| 25 |  |  | * | 
| 26 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 27 |  |  | * kind. All express or implied conditions, representations and | 
| 28 |  |  | * warranties, including any implied warranty of merchantability, | 
| 29 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 30 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 31 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 32 |  |  | * using, modifying or distributing the software or its | 
| 33 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 34 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 35 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 36 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 37 |  |  | * arising out of the use of or inability to use software, even if the | 
| 38 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 39 |  |  | * such damages. | 
| 40 |  |  | */ | 
| 41 |  |  |  | 
| 42 | gezelter | 507 | /** | 
| 43 |  |  | * @file ForceManager.cpp | 
| 44 |  |  | * @author tlin | 
| 45 |  |  | * @date 11/09/2004 | 
| 46 |  |  | * @time 10:39am | 
| 47 |  |  | * @version 1.0 | 
| 48 |  |  | */ | 
| 49 | gezelter | 246 |  | 
| 50 |  |  | #include "brains/ForceManager.hpp" | 
| 51 |  |  | #include "primitives/Molecule.hpp" | 
| 52 |  |  | #include "UseTheForce/doForces_interface.h" | 
| 53 | chuckv | 664 | #define __C | 
| 54 |  |  | #include "UseTheForce/DarkSide/fInteractionMap.h" | 
| 55 | gezelter | 246 | #include "utils/simError.h" | 
| 56 |  |  | namespace oopse { | 
| 57 |  |  |  | 
| 58 | gezelter | 507 | void ForceManager::calcForces(bool needPotential, bool needStress) { | 
| 59 | gezelter | 246 |  | 
| 60 |  |  | if (!info_->isFortranInitialized()) { | 
| 61 | gezelter | 507 | info_->update(); | 
| 62 | gezelter | 246 | } | 
| 63 |  |  |  | 
| 64 |  |  | preCalculation(); | 
| 65 |  |  |  | 
| 66 |  |  | calcShortRangeInteraction(); | 
| 67 |  |  |  | 
| 68 |  |  | calcLongRangeInteraction(needPotential, needStress); | 
| 69 |  |  |  | 
| 70 |  |  | postCalculation(); | 
| 71 |  |  |  | 
| 72 | gezelter | 507 | } | 
| 73 | gezelter | 246 |  | 
| 74 | gezelter | 507 | void ForceManager::preCalculation() { | 
| 75 | gezelter | 246 | SimInfo::MoleculeIterator mi; | 
| 76 |  |  | Molecule* mol; | 
| 77 |  |  | Molecule::AtomIterator ai; | 
| 78 |  |  | Atom* atom; | 
| 79 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 80 |  |  | RigidBody* rb; | 
| 81 |  |  |  | 
| 82 |  |  | // forces are zeroed here, before any are accumulated. | 
| 83 |  |  | // NOTE: do not rezero the forces in Fortran. | 
| 84 |  |  | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 85 | gezelter | 507 | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 86 |  |  | atom->zeroForcesAndTorques(); | 
| 87 |  |  | } | 
| 88 | gezelter | 246 |  | 
| 89 | gezelter | 507 | //change the positions of atoms which belong to the rigidbodies | 
| 90 |  |  | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 91 |  |  | rb->zeroForcesAndTorques(); | 
| 92 |  |  | } | 
| 93 | gezelter | 246 | } | 
| 94 |  |  |  | 
| 95 | gezelter | 507 | } | 
| 96 | gezelter | 246 |  | 
| 97 | gezelter | 507 | void ForceManager::calcShortRangeInteraction() { | 
| 98 | gezelter | 246 | Molecule* mol; | 
| 99 |  |  | RigidBody* rb; | 
| 100 |  |  | Bond* bond; | 
| 101 |  |  | Bend* bend; | 
| 102 |  |  | Torsion* torsion; | 
| 103 |  |  | SimInfo::MoleculeIterator mi; | 
| 104 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 105 |  |  | Molecule::BondIterator bondIter;; | 
| 106 |  |  | Molecule::BendIterator  bendIter; | 
| 107 |  |  | Molecule::TorsionIterator  torsionIter; | 
| 108 |  |  |  | 
| 109 |  |  | //calculate short range interactions | 
| 110 |  |  | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 111 |  |  |  | 
| 112 | gezelter | 507 | //change the positions of atoms which belong to the rigidbodies | 
| 113 |  |  | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 114 |  |  | rb->updateAtoms(); | 
| 115 |  |  | } | 
| 116 | gezelter | 246 |  | 
| 117 | gezelter | 507 | for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | 
| 118 |  |  | bond->calcForce(); | 
| 119 |  |  | } | 
| 120 | gezelter | 246 |  | 
| 121 | gezelter | 507 | for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | 
| 122 |  |  | bend->calcForce(); | 
| 123 |  |  | } | 
| 124 | gezelter | 246 |  | 
| 125 | gezelter | 507 | for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | 
| 126 |  |  | torsion->calcForce(); | 
| 127 |  |  | } | 
| 128 | gezelter | 246 |  | 
| 129 |  |  | } | 
| 130 |  |  |  | 
| 131 | tim | 665 |  | 
| 132 |  |  | double bondPotential = 0.0; | 
| 133 |  |  | double bendPotential = 0.0; | 
| 134 |  |  | double torsionPotential = 0.0; | 
| 135 |  |  |  | 
| 136 | gezelter | 246 | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 137 |  |  |  | 
| 138 | tim | 665 | for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | 
| 139 |  |  | bondPotential += bond->getPotential(); | 
| 140 |  |  | } | 
| 141 |  |  |  | 
| 142 |  |  | for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | 
| 143 |  |  | bendPotential += bend->getPotential(); | 
| 144 |  |  | } | 
| 145 |  |  |  | 
| 146 |  |  | for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | 
| 147 |  |  | torsionPotential += torsion->getPotential(); | 
| 148 |  |  | } | 
| 149 |  |  |  | 
| 150 |  |  | } | 
| 151 |  |  |  | 
| 152 |  |  | double  shortRangePotential = bondPotential + bendPotential + torsionPotential; | 
| 153 | gezelter | 246 | Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 154 |  |  | curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential; | 
| 155 | tim | 665 | curSnapshot->statData[Stats::BOND_POTENTIAL] = bondPotential; | 
| 156 |  |  | curSnapshot->statData[Stats::BEND_POTENTIAL] = bendPotential; | 
| 157 |  |  | curSnapshot->statData[Stats::DIHEDRAL_POTENTIAL] = torsionPotential; | 
| 158 |  |  |  | 
| 159 | gezelter | 507 | } | 
| 160 | gezelter | 246 |  | 
| 161 | gezelter | 507 | void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) { | 
| 162 | gezelter | 246 | Snapshot* curSnapshot; | 
| 163 |  |  | DataStorage* config; | 
| 164 |  |  | double* frc; | 
| 165 |  |  | double* pos; | 
| 166 |  |  | double* trq; | 
| 167 |  |  | double* A; | 
| 168 |  |  | double* electroFrame; | 
| 169 |  |  | double* rc; | 
| 170 |  |  |  | 
| 171 |  |  | //get current snapshot from SimInfo | 
| 172 |  |  | curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 173 |  |  |  | 
| 174 |  |  | //get array pointers | 
| 175 |  |  | config = &(curSnapshot->atomData); | 
| 176 |  |  | frc = config->getArrayPointer(DataStorage::dslForce); | 
| 177 |  |  | pos = config->getArrayPointer(DataStorage::dslPosition); | 
| 178 |  |  | trq = config->getArrayPointer(DataStorage::dslTorque); | 
| 179 |  |  | A   = config->getArrayPointer(DataStorage::dslAmat); | 
| 180 |  |  | electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); | 
| 181 |  |  |  | 
| 182 |  |  | //calculate the center of mass of cutoff group | 
| 183 |  |  | SimInfo::MoleculeIterator mi; | 
| 184 |  |  | Molecule* mol; | 
| 185 |  |  | Molecule::CutoffGroupIterator ci; | 
| 186 |  |  | CutoffGroup* cg; | 
| 187 |  |  | Vector3d com; | 
| 188 |  |  | std::vector<Vector3d> rcGroup; | 
| 189 | chrisfen | 645 |  | 
| 190 | gezelter | 246 | if(info_->getNCutoffGroups() > 0){ | 
| 191 | chrisfen | 645 |  | 
| 192 | gezelter | 507 | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 193 | gezelter | 246 | for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 194 | gezelter | 507 | cg->getCOM(com); | 
| 195 |  |  | rcGroup.push_back(com); | 
| 196 | gezelter | 246 | } | 
| 197 | gezelter | 507 | }// end for (mol) | 
| 198 | gezelter | 246 |  | 
| 199 | gezelter | 507 | rc = rcGroup[0].getArrayPointer(); | 
| 200 | gezelter | 246 | } else { | 
| 201 | gezelter | 507 | // center of mass of the group is the same as position of the atom  if cutoff group does not exist | 
| 202 |  |  | rc = pos; | 
| 203 | gezelter | 246 | } | 
| 204 |  |  |  | 
| 205 |  |  | //initialize data before passing to fortran | 
| 206 | chuckv | 664 | double longRangePotential[LR_POT_TYPES]; | 
| 207 |  |  | double lrPot = 0.0; | 
| 208 |  |  |  | 
| 209 | gezelter | 246 | Mat3x3d tau; | 
| 210 |  |  | short int passedCalcPot = needPotential; | 
| 211 |  |  | short int passedCalcStress = needStress; | 
| 212 |  |  | int isError = 0; | 
| 213 |  |  |  | 
| 214 | chuckv | 664 | for (int i=0; i<LR_POT_TYPES;i++){ | 
| 215 |  |  | longRangePotential[i]=0.0; //Initialize array | 
| 216 |  |  | } | 
| 217 |  |  |  | 
| 218 |  |  |  | 
| 219 |  |  |  | 
| 220 | gezelter | 246 | doForceLoop( pos, | 
| 221 | gezelter | 507 | rc, | 
| 222 |  |  | A, | 
| 223 |  |  | electroFrame, | 
| 224 |  |  | frc, | 
| 225 |  |  | trq, | 
| 226 |  |  | tau.getArrayPointer(), | 
| 227 | chuckv | 664 | longRangePotential, | 
| 228 | gezelter | 507 | &passedCalcPot, | 
| 229 |  |  | &passedCalcStress, | 
| 230 |  |  | &isError ); | 
| 231 | gezelter | 246 |  | 
| 232 |  |  | if( isError ){ | 
| 233 | gezelter | 507 | sprintf( painCave.errMsg, | 
| 234 |  |  | "Error returned from the fortran force calculation.\n" ); | 
| 235 |  |  | painCave.isFatal = 1; | 
| 236 |  |  | simError(); | 
| 237 | gezelter | 246 | } | 
| 238 | chuckv | 664 | for (int i=0; i<LR_POT_TYPES;i++){ | 
| 239 |  |  | lrPot += longRangePotential[i]; //Quick hack | 
| 240 |  |  | } | 
| 241 | gezelter | 246 |  | 
| 242 |  |  | //store the tau and long range potential | 
| 243 | chuckv | 664 | curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot; | 
| 244 |  |  | //  curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential; | 
| 245 | tim | 688 | curSnapshot->statData[Stats::VANDERWAALS_POTENTIAL] = longRangePotential[VDW_POT]; | 
| 246 | tim | 681 | curSnapshot->statData[Stats::ELECTROSTATIC_POTENTIAL] = longRangePotential[ELECTROSTATIC_POT]; | 
| 247 |  |  |  | 
| 248 | gezelter | 246 | curSnapshot->statData.setTau(tau); | 
| 249 | gezelter | 507 | } | 
| 250 | gezelter | 246 |  | 
| 251 |  |  |  | 
| 252 | gezelter | 507 | void ForceManager::postCalculation() { | 
| 253 | gezelter | 246 | SimInfo::MoleculeIterator mi; | 
| 254 |  |  | Molecule* mol; | 
| 255 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 256 |  |  | RigidBody* rb; | 
| 257 |  |  |  | 
| 258 |  |  | // collect the atomic forces onto rigid bodies | 
| 259 |  |  | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 260 | gezelter | 507 | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 261 |  |  | rb->calcForcesAndTorques(); | 
| 262 |  |  | } | 
| 263 | gezelter | 246 | } | 
| 264 |  |  |  | 
| 265 | gezelter | 507 | } | 
| 266 | gezelter | 246 |  | 
| 267 |  |  | } //end namespace oopse |