ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/selection/DistanceFinder.cpp
(Generate patch)

Comparing trunk/src/selection/DistanceFinder.cpp (file contents):
Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 1938 by gezelter, Thu Oct 31 15:32:17 2013 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
2 > * Copyright (c) 2005, 2010 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
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.
# Line 37 | Line 28
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, 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 + #ifdef IS_MPI
44 + #include <mpi.h>
45 + #endif
46 +
47   #include "selection/DistanceFinder.hpp"
48   #include "primitives/Molecule.hpp"
44 namespace oopse {
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      
# Line 54 | Line 60 | namespace oopse {
60      Atom* atom;
61      Molecule::RigidBodyIterator rbIter;
62      RigidBody* rb;
57
63      
64 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
64 >    
65 >    for (mol = info_->beginMolecule(mi); mol != NULL;
66 >         mol = info_->nextMolecule(mi)) {
67          
68 <      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
68 >      for(atom = mol->beginAtom(ai); atom != NULL;
69 >          atom = mol->nextAtom(ai)) {
70          stuntdoubles_[atom->getGlobalIndex()] = atom;
71        }
72  
73 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
73 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
74 >           rb = mol->nextRigidBody(rbIter)) {
75          stuntdoubles_[rb->getGlobalIndex()] = rb;
76        }
77 <        
69 <    }    
70 <
77 >    }
78    }
79  
80 <  OOPSEBitSet DistanceFinder::find(const OOPSEBitSet& bs, RealType distance) {
80 >  OpenMDBitSet DistanceFinder::find(const OpenMDBitSet& bs, RealType distance) {
81      StuntDouble * center;
82      Vector3d centerPos;
83      Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
84 <    OOPSEBitSet bsResult(nStuntDoubles_);
84 >    OpenMDBitSet bsResult(nStuntDoubles_);  
85      assert(bsResult.size() == bs.size());
86 <    
87 <    for (int i = bs.firstOnBit(); i != -1; i = bs.nextOnBit(i)) {
86 >
87 > #ifdef IS_MPI
88 >    int mol;
89 >    int proc;
90 >    RealType data[3];
91 >    int worldRank = MPI::COMM_WORLD.Get_rank();
92 > #endif
93 >
94 >    for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
95 >      if (stuntdoubles_[j]->isRigidBody()) {
96 >        RigidBody* rb = static_cast<RigidBody*>(stuntdoubles_[j]);
97 >        rb->updateAtoms();
98 >      }
99 >    }
100 >      
101 >    OpenMDBitSet bsTemp(nStuntDoubles_);
102 >    bsTemp = bs;
103 >    bsTemp.parallelReduce();
104 >
105 >    for (int i = bsTemp.firstOnBit(); i != -1; i = bsTemp.nextOnBit(i)) {
106 >
107 >      // Now, if we own stuntdouble i, we can use the position, but in
108 >      // parallel, we'll need to let everyone else know what that
109 >      // position is!
110 >
111 > #ifdef IS_MPI
112 >      mol = info_->getGlobalMolMembership(i);
113 >      proc = info_->getMolToProc(mol);
114 >    
115 >      if (proc == worldRank) {
116 >        center = stuntdoubles_[i];
117 >        centerPos = center->getPos();
118 >        data[0] = centerPos.x();
119 >        data[1] = centerPos.y();
120 >        data[2] = centerPos.z();          
121 >        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc);
122 >      } else {
123 >        MPI::COMM_WORLD.Bcast(data, 3, MPI::REALTYPE, proc);
124 >        centerPos = Vector3d(data);
125 >      }
126 > #else
127        center = stuntdoubles_[i];
128        centerPos = center->getPos();
129 <      for (int j = 0; j < stuntdoubles_.size(); ++j) {
129 > #endif
130 >      
131 >      for (unsigned int j = 0; j < stuntdoubles_.size(); ++j) {
132          Vector3d r =centerPos - stuntdoubles_[j]->getPos();
133          currSnapshot->wrapVector(r);
134          if (r.length() <= distance) {
# Line 88 | Line 136 | namespace oopse {
136          }
137        }
138      }
91
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   }

Comparing trunk/src/selection/DistanceFinder.cpp (property svn:keywords):
Revision 963 by tim, Wed May 17 21:51:42 2006 UTC vs.
Revision 1938 by gezelter, Thu Oct 31 15:32:17 2013 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines