ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/utils/LocalIndexManager.hpp
(Generate patch)

Comparing:
trunk/src/utils/LocalIndexManager.hpp (file contents), Revision 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
branches/development/src/utils/LocalIndexManager.hpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# Line 6 | Line 6
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, 24107 (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   /**
# Line 54 | Line 55
55   #include <list>
56   #include <utility>
57  
58 < namespace oopse {
58 > namespace OpenMD {
59  
60 < /**
61 < * @class IndexListContainer
62 < * @brief
63 < * @todo documentation
64 < */
65 < class IndexListContainer{
66 <    public:
67 <        static const int MAX_INTEGER = 2147483647;
68 <        typedef std::list<std::pair<int, int> >::iterator  IndexListContainerIterator;
60 >  /**
61 >   * @class IndexListContainer
62 >   * @brief
63 >   * @todo documentation
64 >   */
65 >  class IndexListContainer{
66 >  public:
67 >    static const int MAX_INTEGER = 2147483647;
68 >    typedef std::list<std::pair<int, int> >::iterator  IndexListContainerIterator;
69  
70          
71 <        IndexListContainer(int minIndex = 0, int maxIndex = MAX_INTEGER)
72 <                                                 :minIndex_(minIndex), maxIndex_(maxIndex) {
71 >    IndexListContainer(int minIndex = 0, int maxIndex = MAX_INTEGER)
72 >      :minIndex_(minIndex), maxIndex_(maxIndex) {
73              
74 <            indexContainer_.push_back(std::make_pair(minIndex, maxIndex));
75 <        }
74 >        indexContainer_.push_back(std::make_pair(minIndex, maxIndex));
75 >      }
76          
77 <        int pop() {
77 >    int pop() {
78              
79 <            if (indexContainer_.empty()) {
80 <                std::cerr << "" << std::endl;
81 <            }
79 >      if (indexContainer_.empty()) {
80 >        std::cerr << "" << std::endl;
81 >      }
82  
83 <            IndexListContainerIterator i = indexContainer_.begin();
84 <            int result;
83 >      IndexListContainerIterator i = indexContainer_.begin();
84 >      int result;
85              
86 <            result = indexContainer_.front().first;
86 >      result = indexContainer_.front().first;
87              
88 <            if (indexContainer_.front().first  == indexContainer_.front().second) {
89 <                indexContainer_.pop_front();
90 <            } else if (indexContainer_.front().first < indexContainer_.front().second) {
91 <                ++indexContainer_.front().first;
92 <            } else {
93 <                std::cerr << "" << std::endl;
94 <            }
88 >      if (indexContainer_.front().first  == indexContainer_.front().second) {
89 >        indexContainer_.pop_front();
90 >      } else if (indexContainer_.front().first < indexContainer_.front().second) {
91 >        ++indexContainer_.front().first;
92 >      } else {
93 >        std::cerr << "" << std::endl;
94 >      }
95  
96 <            return result;
97 <        }
96 >      return result;
97 >    }
98  
99  
100 <        /**
101 <         *
102 <         */
103 <        void insert(int index) {
104 <            IndexListContainerIterator insertPos = internalInsert(index, index);            
105 <            merge(insertPos);
106 <        }
100 >    /**
101 >     *
102 >     */
103 >    void insert(int index) {
104 >      IndexListContainerIterator insertPos = internalInsert(index, index);            
105 >      merge(insertPos);
106 >    }
107  
108 <        /**
109 <         * Reclaims an index range
110 <         * @param beginIndex
111 <         * @param endIndex
112 <         */
113 <        void insert(int beginIndex, int endIndex) {
114 <             IndexListContainerIterator insertPos = internalInsert(beginIndex, endIndex);
115 <             merge(insertPos);            
116 <        }
108 >    /**
109 >     * Reclaims an index range
110 >     * @param beginIndex
111 >     * @param endIndex
112 >     */
113 >    void insert(int beginIndex, int endIndex) {
114 >      IndexListContainerIterator insertPos = internalInsert(beginIndex, endIndex);
115 >      merge(insertPos);            
116 >    }
117  
118 <        /**
119 <         * Reclaims an index array.
120 <         * @param indices
121 <         */
122 <        void insert(std::vector<int>& indices){
118 >    /**
119 >     * Reclaims an index array.
120 >     * @param indices
121 >     */
122 >    void insert(std::vector<int>& indices){
123  
124 <            if (indices.empty()) {
125 <                return;
126 <            }
124 >      if (indices.empty()) {
125 >        return;
126 >      }
127              
128 <            std::sort(indices.begin(), indices.end());
129 <            std::unique(indices.begin(), indices.end());
128 >      std::sort(indices.begin(), indices.end());
129 >      std::unique(indices.begin(), indices.end());
130  
131 <            std::vector<int>::iterator i;
132 <            IndexListContainerIterator insertPos;
133 <            int beginIndex;
131 >      std::vector<int>::iterator i;
132 >      IndexListContainerIterator insertPos;
133 >      int beginIndex;
134  
135 <            beginIndex = indices[0];
135 >      beginIndex = indices[0];
136          
137 <            for ( i = indices.begin() + 1 ; i != indices.end(); ++i) {
138 <                if (*i != *(i -1) + 1) {
139 <                    insert(beginIndex, *(i-1));
140 <                    beginIndex = *i;
141 <                }
142 <            }
137 >      for ( i = indices.begin() + 1 ; i != indices.end(); ++i) {
138 >        if (*i != *(i -1) + 1) {
139 >          insert(beginIndex, *(i-1));
140 >          beginIndex = *i;
141 >        }
142 >      }
143              
144              
145 <        }
145 >    }
146          
147 <        std::vector<int> getIndicesBefore(int index) {
148 <            std::vector<int> result;
149 <            IndexListContainerIterator i;
147 >    std::vector<int> getIndicesBefore(int index) {
148 >      std::vector<int> result;
149 >      IndexListContainerIterator i;
150  
151 <            for(i = indexContainer_.begin(); i != indexContainer_.end(); ++i) {
152 <                if ((*i).first > index) {
153 <                    //we locate the node whose minimum index is greater that index
154 <                    indexContainer_.erase(indexContainer_.begin(), i);
155 <                    break;
156 <                } else if ((*i).second < index) {
157 <                    //The biggest index current node hold is less than the index we want
158 <                    for (int j = (*i).first; j <= (*i).second; ++j) {
159 <                        result.push_back(j);
160 <                    }
161 <                    continue;
162 <                } else if ((*i).first == (*i).second) {
163 <                    //the index happen to equal to a node which only contains one index
164 <                    result.push_back((*i).first);
165 <                    indexContainer_.erase(indexContainer_.begin(), i);
166 <                    break;
167 <                } else {
151 >      for(i = indexContainer_.begin(); i != indexContainer_.end(); ++i) {
152 >        if ((*i).first > index) {
153 >          //we locate the node whose minimum index is greater that index
154 >          indexContainer_.erase(indexContainer_.begin(), i);
155 >          break;
156 >        } else if ((*i).second < index) {
157 >          //The biggest index current node hold is less than the index we want
158 >          for (int j = (*i).first; j <= (*i).second; ++j) {
159 >            result.push_back(j);
160 >          }
161 >          continue;
162 >        } else if ((*i).first == (*i).second) {
163 >          //the index happen to equal to a node which only contains one index
164 >          result.push_back((*i).first);
165 >          indexContainer_.erase(indexContainer_.begin(), i);
166 >          break;
167 >        } else {
168  
169 <                    for (int j = (*i).first; j < index; ++j) {
170 <                        result.push_back(j);
171 <                    }
169 >          for (int j = (*i).first; j < index; ++j) {
170 >            result.push_back(j);
171 >          }
172                          
173 <                    (*i).first =  index;                  
174 <                    indexContainer_.erase(indexContainer_.begin(), i);
175 <                    break;
176 <                }
173 >          (*i).first =  index;                  
174 >          indexContainer_.erase(indexContainer_.begin(), i);
175 >          break;
176 >        }
177                  
178 <            }
178 >      }
179  
180 <            return result;
180 >      return result;
181  
182 <        }
182 >    }
183          
184 <        int getMaxIndex() {
185 <            return maxIndex_;
186 <        }
184 >    int getMaxIndex() {
185 >      return maxIndex_;
186 >    }
187                  
188 <    private:
188 >  private:
189          
190 <        IndexListContainerIterator internalInsert(int beginIndex, int endIndex) {
190 >    IndexListContainerIterator internalInsert(int beginIndex, int endIndex) {
191  
192 <            if (beginIndex > endIndex) {
193 <                std::swap(beginIndex, endIndex);
194 <                std::cerr << "" << std::endl;
195 <            }
195 <
196 <            if (endIndex > maxIndex_) {
197 <                std::cerr << "" << std::endl;
198 <            }
192 >      if (beginIndex > endIndex) {
193 >        std::swap(beginIndex, endIndex);
194 >        std::cerr << "" << std::endl;
195 >      }
196  
197 +      if (endIndex > maxIndex_) {
198 +        std::cerr << "" << std::endl;
199 +      }
200 +
201                        
202 <            IndexListContainerIterator j;
202 >      IndexListContainerIterator j;
203  
204 <            IndexListContainerIterator i = indexContainer_.begin();  
205 <            for (; i != indexContainer_.end(); ++i) {
206 <                if ((*i).first > endIndex) {
207 <                    indexContainer_.insert(i, std::make_pair(beginIndex, endIndex));
208 <                    return --i;
209 <                } else if ((*i).second < beginIndex) {
210 <                    continue;
211 <                } else {
212 <                    std::cerr << "" << std::endl;
213 <                }
214 <            }
204 >      IndexListContainerIterator i = indexContainer_.begin();  
205 >      for (; i != indexContainer_.end(); ++i) {
206 >        if ((*i).first > endIndex) {
207 >          indexContainer_.insert(i, std::make_pair(beginIndex, endIndex));
208 >          return --i;
209 >        } else if ((*i).second < beginIndex) {
210 >          continue;
211 >        } else {
212 >          std::cerr << "" << std::endl;
213 >        }
214 >      }
215  
216 <            indexContainer_.push_back(std::make_pair(beginIndex, endIndex));
217 <            return --indexContainer_.end();
216 >      indexContainer_.push_back(std::make_pair(beginIndex, endIndex));
217 >      return --indexContainer_.end();
218  
219 <        }
219 >    }
220  
221 <        void merge(IndexListContainerIterator i) {
222 <            IndexListContainerIterator j;
221 >    void merge(IndexListContainerIterator i) {
222 >      IndexListContainerIterator j;
223  
224 <            //check whether current node can be merged with its previous node            
225 <            if ( i != indexContainer_.begin()) {
226 <                j = i;
227 <                --j;
228 <                if (j != indexContainer_.begin() && (*j).second + 1 == (*i).first) {
229 <                    (*i).first = (*j).first;
230 <                    indexContainer_.erase(j);
231 <                }
232 <            }
224 >      //check whether current node can be merged with its previous node            
225 >      if ( i != indexContainer_.begin()) {
226 >        j = i;
227 >        --j;
228 >        if (j != indexContainer_.begin() && (*j).second + 1 == (*i).first) {
229 >          (*i).first = (*j).first;
230 >          indexContainer_.erase(j);
231 >        }
232 >      }
233  
234 <            //check whether current node can be merged with its next node            
235 <            if ( i != indexContainer_.end()) {
236 <                j = i;
237 <                ++j;
234 >      //check whether current node can be merged with its next node            
235 >      if ( i != indexContainer_.end()) {
236 >        j = i;
237 >        ++j;
238  
239 <                if (j != indexContainer_.end() && (*i).second + 1 == (*j).first) {
240 <                    (*i).second = (*j).second;
241 <                    indexContainer_.erase(j);
242 <                }
243 <            }
239 >        if (j != indexContainer_.end() && (*i).second + 1 == (*j).first) {
240 >          (*i).second = (*j).second;
241 >          indexContainer_.erase(j);
242 >        }
243 >      }
244  
245 <        }
246 <        int minIndex_;
247 <        int maxIndex_;        
248 <        std::list<std::pair<int, int> > indexContainer_;
249 < };
245 >    }
246 >    int minIndex_;
247 >    int maxIndex_;        
248 >    std::list<std::pair<int, int> > indexContainer_;
249 >  };
250  
251  
252 < /**
253 < * @class LocalIndexManager LocalIndexManager.hpp "utils/LocalIndexManager.hpp"
254 < * @brief
255 < */
256 < class LocalIndexManager {
257 <    public:
252 >  /**
253 >   * @class LocalIndexManager LocalIndexManager.hpp "utils/LocalIndexManager.hpp"
254 >   * @brief
255 >   */
256 >  class LocalIndexManager {
257 >  public:
258          
259 <        int getNextAtomIndex() {
260 <            return atomIndexContainer_.pop();
261 <        }
259 >    int getNextAtomIndex() {
260 >      return atomIndexContainer_.pop();
261 >    }
262  
263 <        std::vector<int> getAtomIndicesBefore(int index) {
264 <            return atomIndexContainer_.getIndicesBefore(index);
265 <        }
263 >    std::vector<int> getAtomIndicesBefore(int index) {
264 >      return atomIndexContainer_.getIndicesBefore(index);
265 >    }
266          
267 <        void releaseAtomIndex(int index) {
268 <            atomIndexContainer_.insert(index);
269 <        }
267 >    void releaseAtomIndex(int index) {
268 >      atomIndexContainer_.insert(index);
269 >    }
270  
271 <        void releaseAtomIndex(int beginIndex, int endIndex) {
272 <            atomIndexContainer_.insert(beginIndex, endIndex);
273 <        }
271 >    void releaseAtomIndex(int beginIndex, int endIndex) {
272 >      atomIndexContainer_.insert(beginIndex, endIndex);
273 >    }
274  
275 <        void releaseAtomIndex(std::vector<int> indices) {
276 <            atomIndexContainer_.insert(indices);
277 <        }
275 >    void releaseAtomIndex(std::vector<int> indices) {
276 >      atomIndexContainer_.insert(indices);
277 >    }
278  
279 <       int getNextRigidBodyIndex() {
280 <            return rigidBodyIndexContainer_.pop();
281 <        }
279 >    int getNextRigidBodyIndex() {
280 >      return rigidBodyIndexContainer_.pop();
281 >    }
282  
283 <        std::vector<int> getRigidBodyIndicesBefore(int index) {
284 <            return rigidBodyIndexContainer_.getIndicesBefore(index);
285 <        }
283 >    std::vector<int> getRigidBodyIndicesBefore(int index) {
284 >      return rigidBodyIndexContainer_.getIndicesBefore(index);
285 >    }
286          
287 <        void releaseRigidBodyIndex(int index) {
288 <            rigidBodyIndexContainer_.insert(index);
289 <        }
287 >    void releaseRigidBodyIndex(int index) {
288 >      rigidBodyIndexContainer_.insert(index);
289 >    }
290  
291 <        void releaseRigidBodyIndex(int beginIndex, int endIndex) {
292 <            rigidBodyIndexContainer_.insert(beginIndex, endIndex);
293 <        }
291 >    void releaseRigidBodyIndex(int beginIndex, int endIndex) {
292 >      rigidBodyIndexContainer_.insert(beginIndex, endIndex);
293 >    }
294  
295 <        void releaseRigidBodyIndex(std::vector<int> indices) {
296 <            rigidBodyIndexContainer_.insert(indices);
297 <        }
295 >    void releaseRigidBodyIndex(std::vector<int> indices) {
296 >      rigidBodyIndexContainer_.insert(indices);
297 >    }
298 >
299 >    int getNextCutoffGroupIndex() {
300 >      return cutoffGroupIndexContainer_.pop();
301 >    }
302 >
303 >    std::vector<int> getCutoffGroupIndicesBefore(int index) {
304 >      return cutoffGroupIndexContainer_.getIndicesBefore(index);
305 >    }
306 >        
307 >    void releaseCutoffGroupIndex(int index) {
308 >      cutoffGroupIndexContainer_.insert(index);
309 >    }
310 >
311 >    void releaseCutoffGroupIndex(int beginIndex, int endIndex) {
312 >      cutoffGroupIndexContainer_.insert(beginIndex, endIndex);
313 >    }
314 >
315 >    void releaseCutoffGroupIndex(std::vector<int> indices) {
316 >      cutoffGroupIndexContainer_.insert(indices);
317 >    }
318  
319 <    private:
319 >  private:
320  
321 <        IndexListContainer atomIndexContainer_;
322 <        IndexListContainer rigidBodyIndexContainer_;
323 < };
321 >    IndexListContainer atomIndexContainer_;
322 >    IndexListContainer rigidBodyIndexContainer_;
323 >    IndexListContainer cutoffGroupIndexContainer_;
324 >  };
325  
326 < } //end namespace oopse
326 > } //end namespace OpenMD
327   #endif //UTILS_LOCALINDEXMANAGER_HPP

Comparing:
trunk/src/utils/LocalIndexManager.hpp (property svn:keywords), Revision 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
branches/development/src/utils/LocalIndexManager.hpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines