| 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 | 
  | 
 */ | 
| 42 | 
  | 
 | 
| 43 | 
– | 
#include "selection/DistanceFinder.hpp" | 
| 44 | 
– | 
#include "primitives/Molecule.hpp" | 
| 43 | 
  | 
#ifdef IS_MPI | 
| 44 | 
  | 
#include <mpi.h> | 
| 45 | 
  | 
#endif | 
| 46 | 
  | 
 | 
| 47 | 
< | 
namespace OpenMD { | 
| 47 | 
> | 
#include "selection/DistanceFinder.hpp" | 
| 48 | 
> | 
#include "primitives/Molecule.hpp" | 
| 49 | 
  | 
 | 
| 50 | 
+ | 
namespace OpenMD { | 
| 51 | 
+ | 
   | 
| 52 | 
  | 
  DistanceFinder::DistanceFinder(SimInfo* info) : info_(info) { | 
| 53 | 
< | 
 | 
| 53 | 
> | 
     | 
| 54 | 
  | 
    nStuntDoubles_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(); | 
| 55 | 
  | 
    stuntdoubles_.resize(nStuntDoubles_); | 
| 56 | 
  | 
     | 
| 60 | 
  | 
    Atom* atom; | 
| 61 | 
  | 
    Molecule::RigidBodyIterator rbIter; | 
| 62 | 
  | 
    RigidBody* rb; | 
| 62 | 
– | 
 | 
| 63 | 
  | 
     | 
| 64 | 
+ | 
     | 
| 65 | 
  | 
    for (mol = info_->beginMolecule(mi); mol != NULL;  | 
| 66 | 
  | 
         mol = info_->nextMolecule(mi)) { | 
| 67 | 
  | 
         | 
| 136 | 
  | 
        } | 
| 137 | 
  | 
      } | 
| 138 | 
  | 
    } | 
| 138 | 
– | 
 | 
| 139 | 
  | 
    return bsResult; | 
| 140 | 
  | 
  } | 
| 141 | 
  | 
 | 
| 142 | 
+ | 
 | 
| 143 | 
+ | 
OpenMDBitSet DistanceFinder::find(const OpenMDBitSet& bs, RealType distance, int frame ) { | 
| 144 | 
+ | 
    StuntDouble * center; | 
| 145 | 
+ | 
    Vector3d centerPos; | 
| 146 | 
+ | 
    Snapshot* currSnapshot = info_->getSnapshotManager()->getSnapshot(frame); | 
| 147 | 
+ | 
    OpenMDBitSet bsResult(nStuntDoubles_);    | 
| 148 | 
+ | 
    assert(bsResult.size() == bs.size()); | 
| 149 | 
+ | 
 | 
| 150 | 
+ | 
#ifdef IS_MPI | 
| 151 | 
+ | 
    int mol; | 
| 152 | 
+ | 
    int proc; | 
| 153 | 
+ | 
    RealType data[3]; | 
| 154 | 
+ | 
    int worldRank = MPI::COMM_WORLD.Get_rank(); | 
| 155 | 
+ | 
#endif | 
| 156 | 
+ | 
  | 
| 157 | 
+ | 
    for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) { | 
| 158 | 
+ | 
      if (stuntdoubles_[j]->isRigidBody()) { | 
| 159 | 
+ | 
        RigidBody* rb = static_cast<RigidBody*>(stuntdoubles_[j]); | 
| 160 | 
+ | 
        rb->updateAtoms(frame); | 
| 161 | 
+ | 
      } | 
| 162 | 
+ | 
    } | 
| 163 | 
+ | 
        | 
| 164 | 
+ | 
    OpenMDBitSet bsTemp(nStuntDoubles_); | 
| 165 | 
+ | 
    bsTemp = bs; | 
| 166 | 
+ | 
    bsTemp.parallelReduce(); | 
| 167 | 
+ | 
 | 
| 168 | 
+ | 
    for (int i = bsTemp.firstOnBit(); i != -1; i = bsTemp.nextOnBit(i)) { | 
| 169 | 
+ | 
 | 
| 170 | 
+ | 
      // Now, if we own stuntdouble i, we can use the position, but in | 
| 171 | 
+ | 
      // parallel, we'll need to let everyone else know what that | 
| 172 | 
+ | 
      // position is! | 
| 173 | 
+ | 
 | 
| 174 | 
+ | 
#ifdef IS_MPI | 
| 175 | 
+ | 
      mol = info_->getGlobalMolMembership(i); | 
| 176 | 
+ | 
      proc = info_->getMolToProc(mol); | 
| 177 | 
+ | 
      | 
| 178 | 
+ | 
      if (proc == worldRank) { | 
| 179 | 
+ | 
        center = stuntdoubles_[i]; | 
| 180 | 
+ | 
        centerPos = center->getPos(frame); | 
| 181 | 
+ | 
        data[0] = centerPos.x(); | 
| 182 | 
+ | 
        data[1] = centerPos.y(); | 
| 183 | 
+ | 
        data[2] = centerPos.z();           | 
| 184 | 
+ | 
        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc); | 
| 185 | 
+ | 
      } else { | 
| 186 | 
+ | 
        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc); | 
| 187 | 
+ | 
        centerPos = Vector3d(data); | 
| 188 | 
+ | 
      } | 
| 189 | 
+ | 
#else | 
| 190 | 
+ | 
      center = stuntdoubles_[i]; | 
| 191 | 
+ | 
      centerPos = center->getPos(frame); | 
| 192 | 
+ | 
#endif | 
| 193 | 
+ | 
       | 
| 194 | 
+ | 
      for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) { | 
| 195 | 
+ | 
        Vector3d r =centerPos - stuntdoubles_[j]->getPos(frame); | 
| 196 | 
+ | 
        currSnapshot->wrapVector(r); | 
| 197 | 
+ | 
        if (r.length() <= distance) { | 
| 198 | 
+ | 
          bsResult.setBitOn(j); | 
| 199 | 
+ | 
        } | 
| 200 | 
+ | 
      } | 
| 201 | 
+ | 
    } | 
| 202 | 
+ | 
    return bsResult; | 
| 203 | 
+ | 
  } | 
| 204 | 
  | 
} |