| 1 | 
gezelter | 
1930 | 
 /* | 
| 2 | 
  | 
  | 
 * 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 | 
  | 
  | 
 /** | 
| 43 | 
  | 
  | 
  * @file ForceManager.cpp | 
| 44 | 
  | 
  | 
  * @author tlin | 
| 45 | 
  | 
  | 
  * @date 11/09/2004 | 
| 46 | 
  | 
  | 
  * @time 10:39am | 
| 47 | 
  | 
  | 
  * @version 1.0 | 
| 48 | 
  | 
  | 
  */ | 
| 49 | 
  | 
  | 
 | 
| 50 | 
  | 
  | 
#include "brains/ForceManager.hpp" | 
| 51 | 
  | 
  | 
#include "primitives/Molecule.hpp" | 
| 52 | 
  | 
  | 
#include "UseTheForce/doForces_interface.h" | 
| 53 | 
  | 
  | 
#include "utils/simError.h" | 
| 54 | 
  | 
  | 
namespace oopse { | 
| 55 | 
  | 
  | 
 | 
| 56 | 
  | 
  | 
void ForceManager::calcForces(bool needPotential, bool needStress) { | 
| 57 | 
  | 
  | 
 | 
| 58 | 
  | 
  | 
    if (!info_->isFortranInitialized()) { | 
| 59 | 
  | 
  | 
        info_->update(); | 
| 60 | 
  | 
  | 
    } | 
| 61 | 
  | 
  | 
 | 
| 62 | 
  | 
  | 
    preCalculation(); | 
| 63 | 
  | 
  | 
     | 
| 64 | 
  | 
  | 
    calcShortRangeInteraction(); | 
| 65 | 
  | 
  | 
 | 
| 66 | 
  | 
  | 
    calcLongRangeInteraction(needPotential, needStress); | 
| 67 | 
  | 
  | 
 | 
| 68 | 
  | 
  | 
    postCalculation(); | 
| 69 | 
  | 
  | 
         | 
| 70 | 
  | 
  | 
} | 
| 71 | 
  | 
  | 
 | 
| 72 | 
  | 
  | 
void ForceManager::preCalculation() { | 
| 73 | 
  | 
  | 
    SimInfo::MoleculeIterator mi; | 
| 74 | 
  | 
  | 
    Molecule* mol; | 
| 75 | 
  | 
  | 
    Molecule::AtomIterator ai; | 
| 76 | 
  | 
  | 
    Atom* atom; | 
| 77 | 
  | 
  | 
    Molecule::RigidBodyIterator rbIter; | 
| 78 | 
  | 
  | 
    RigidBody* rb; | 
| 79 | 
  | 
  | 
     | 
| 80 | 
  | 
  | 
    // forces are zeroed here, before any are accumulated. | 
| 81 | 
  | 
  | 
    // NOTE: do not rezero the forces in Fortran. | 
| 82 | 
  | 
  | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 83 | 
  | 
  | 
        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 84 | 
  | 
  | 
            atom->zeroForcesAndTorques(); | 
| 85 | 
  | 
  | 
        } | 
| 86 | 
  | 
  | 
         | 
| 87 | 
  | 
  | 
        //change the positions of atoms which belong to the rigidbodies | 
| 88 | 
  | 
  | 
        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 89 | 
  | 
  | 
            rb->zeroForcesAndTorques(); | 
| 90 | 
  | 
  | 
        }         | 
| 91 | 
  | 
  | 
    } | 
| 92 | 
  | 
  | 
     | 
| 93 | 
  | 
  | 
} | 
| 94 | 
  | 
  | 
 | 
| 95 | 
  | 
  | 
void ForceManager::calcShortRangeInteraction() { | 
| 96 | 
  | 
  | 
    Molecule* mol; | 
| 97 | 
  | 
  | 
    RigidBody* rb; | 
| 98 | 
  | 
  | 
    Bond* bond; | 
| 99 | 
  | 
  | 
    Bend* bend; | 
| 100 | 
  | 
  | 
    Torsion* torsion; | 
| 101 | 
  | 
  | 
    SimInfo::MoleculeIterator mi; | 
| 102 | 
  | 
  | 
    Molecule::RigidBodyIterator rbIter; | 
| 103 | 
  | 
  | 
    Molecule::BondIterator bondIter;; | 
| 104 | 
  | 
  | 
    Molecule::BendIterator  bendIter; | 
| 105 | 
  | 
  | 
    Molecule::TorsionIterator  torsionIter; | 
| 106 | 
  | 
  | 
 | 
| 107 | 
  | 
  | 
    //calculate short range interactions     | 
| 108 | 
  | 
  | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 109 | 
  | 
  | 
 | 
| 110 | 
  | 
  | 
        //change the positions of atoms which belong to the rigidbodies | 
| 111 | 
  | 
  | 
        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 112 | 
  | 
  | 
            rb->updateAtoms(); | 
| 113 | 
  | 
  | 
        } | 
| 114 | 
  | 
  | 
 | 
| 115 | 
  | 
  | 
        for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | 
| 116 | 
  | 
  | 
            bond->calcForce(); | 
| 117 | 
  | 
  | 
        } | 
| 118 | 
  | 
  | 
 | 
| 119 | 
  | 
  | 
        for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | 
| 120 | 
  | 
  | 
            bend->calcForce(); | 
| 121 | 
  | 
  | 
        } | 
| 122 | 
  | 
  | 
 | 
| 123 | 
  | 
  | 
        for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | 
| 124 | 
  | 
  | 
            torsion->calcForce(); | 
| 125 | 
  | 
  | 
        } | 
| 126 | 
  | 
  | 
 | 
| 127 | 
  | 
  | 
    } | 
| 128 | 
  | 
  | 
     | 
| 129 | 
  | 
  | 
    double  shortRangePotential = 0.0; | 
| 130 | 
  | 
  | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 131 | 
  | 
  | 
        shortRangePotential += mol->getPotential(); | 
| 132 | 
  | 
  | 
    } | 
| 133 | 
  | 
  | 
 | 
| 134 | 
  | 
  | 
    Snapshot* curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 135 | 
  | 
  | 
    curSnapshot->statData[Stats::SHORT_RANGE_POTENTIAL] = shortRangePotential; | 
| 136 | 
  | 
  | 
} | 
| 137 | 
  | 
  | 
 | 
| 138 | 
  | 
  | 
void ForceManager::calcLongRangeInteraction(bool needPotential, bool needStress) { | 
| 139 | 
  | 
  | 
    Snapshot* curSnapshot; | 
| 140 | 
  | 
  | 
    DataStorage* config; | 
| 141 | 
  | 
  | 
    double* frc; | 
| 142 | 
  | 
  | 
    double* pos; | 
| 143 | 
  | 
  | 
    double* trq; | 
| 144 | 
  | 
  | 
    double* A; | 
| 145 | 
  | 
  | 
    double* electroFrame; | 
| 146 | 
  | 
  | 
    double* rc; | 
| 147 | 
  | 
  | 
     | 
| 148 | 
  | 
  | 
    //get current snapshot from SimInfo | 
| 149 | 
  | 
  | 
    curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 150 | 
  | 
  | 
 | 
| 151 | 
  | 
  | 
    //get array pointers | 
| 152 | 
  | 
  | 
    config = &(curSnapshot->atomData); | 
| 153 | 
  | 
  | 
    frc = config->getArrayPointer(DataStorage::dslForce); | 
| 154 | 
  | 
  | 
    pos = config->getArrayPointer(DataStorage::dslPosition); | 
| 155 | 
  | 
  | 
    trq = config->getArrayPointer(DataStorage::dslTorque); | 
| 156 | 
  | 
  | 
    A   = config->getArrayPointer(DataStorage::dslAmat); | 
| 157 | 
  | 
  | 
    electroFrame = config->getArrayPointer(DataStorage::dslElectroFrame); | 
| 158 | 
  | 
  | 
 | 
| 159 | 
  | 
  | 
    //calculate the center of mass of cutoff group | 
| 160 | 
  | 
  | 
    SimInfo::MoleculeIterator mi; | 
| 161 | 
  | 
  | 
    Molecule* mol; | 
| 162 | 
  | 
  | 
    Molecule::CutoffGroupIterator ci; | 
| 163 | 
  | 
  | 
    CutoffGroup* cg; | 
| 164 | 
  | 
  | 
    Vector3d com; | 
| 165 | 
  | 
  | 
    std::vector<Vector3d> rcGroup; | 
| 166 | 
  | 
  | 
     | 
| 167 | 
  | 
  | 
    if(info_->getNCutoffGroups() > 0){ | 
| 168 | 
  | 
  | 
 | 
| 169 | 
  | 
  | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 170 | 
  | 
  | 
        for(cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 171 | 
  | 
  | 
            cg->getCOM(com); | 
| 172 | 
  | 
  | 
            rcGroup.push_back(com); | 
| 173 | 
  | 
  | 
        } | 
| 174 | 
  | 
  | 
    }// end for (mol) | 
| 175 | 
  | 
  | 
        | 
| 176 | 
  | 
  | 
        rc = rcGroup[0].getArrayPointer(); | 
| 177 | 
  | 
  | 
    } else { | 
| 178 | 
  | 
  | 
        // center of mass of the group is the same as position of the atom  if cutoff group does not exist | 
| 179 | 
  | 
  | 
        rc = pos; | 
| 180 | 
  | 
  | 
    } | 
| 181 | 
  | 
  | 
   | 
| 182 | 
  | 
  | 
    //initialize data before passing to fortran | 
| 183 | 
  | 
  | 
    double longRangePotential = 0.0; | 
| 184 | 
  | 
  | 
    Mat3x3d tau; | 
| 185 | 
  | 
  | 
    short int passedCalcPot = needPotential; | 
| 186 | 
  | 
  | 
    short int passedCalcStress = needStress; | 
| 187 | 
  | 
  | 
    int isError = 0; | 
| 188 | 
  | 
  | 
 | 
| 189 | 
  | 
  | 
    doForceLoop( pos, | 
| 190 | 
  | 
  | 
            rc, | 
| 191 | 
  | 
  | 
            A, | 
| 192 | 
  | 
  | 
            electroFrame, | 
| 193 | 
  | 
  | 
            frc, | 
| 194 | 
  | 
  | 
            trq, | 
| 195 | 
  | 
  | 
            tau.getArrayPointer(), | 
| 196 | 
  | 
  | 
            &longRangePotential,  | 
| 197 | 
  | 
  | 
            &passedCalcPot, | 
| 198 | 
  | 
  | 
            &passedCalcStress, | 
| 199 | 
  | 
  | 
            &isError ); | 
| 200 | 
  | 
  | 
 | 
| 201 | 
  | 
  | 
    if( isError ){ | 
| 202 | 
  | 
  | 
        sprintf( painCave.errMsg, | 
| 203 | 
  | 
  | 
             "Error returned from the fortran force calculation.\n" ); | 
| 204 | 
  | 
  | 
        painCave.isFatal = 1; | 
| 205 | 
  | 
  | 
        simError(); | 
| 206 | 
  | 
  | 
    } | 
| 207 | 
  | 
  | 
 | 
| 208 | 
  | 
  | 
    //store the tau and long range potential     | 
| 209 | 
  | 
  | 
    curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = longRangePotential; | 
| 210 | 
  | 
  | 
    curSnapshot->statData.setTau(tau); | 
| 211 | 
  | 
  | 
} | 
| 212 | 
  | 
  | 
 | 
| 213 | 
  | 
  | 
 | 
| 214 | 
  | 
  | 
void ForceManager::postCalculation() { | 
| 215 | 
  | 
  | 
    SimInfo::MoleculeIterator mi; | 
| 216 | 
  | 
  | 
    Molecule* mol; | 
| 217 | 
  | 
  | 
    Molecule::RigidBodyIterator rbIter; | 
| 218 | 
  | 
  | 
    RigidBody* rb; | 
| 219 | 
  | 
  | 
     | 
| 220 | 
  | 
  | 
    // collect the atomic forces onto rigid bodies | 
| 221 | 
  | 
  | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 222 | 
  | 
  | 
        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 223 | 
  | 
  | 
            rb->calcForcesAndTorques(); | 
| 224 | 
  | 
  | 
        } | 
| 225 | 
  | 
  | 
    } | 
| 226 | 
  | 
  | 
 | 
| 227 | 
  | 
  | 
} | 
| 228 | 
  | 
  | 
 | 
| 229 | 
  | 
  | 
} //end namespace oopse |