--- trunk/src/utils/LocalIndexManager.hpp 2005/01/12 22:41:40 246 +++ trunk/src/utils/LocalIndexManager.hpp 2009/11/25 20:02:06 1390 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,6 +28,15 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Vardeman & Gezelter, in progress (2009). */ /** @@ -54,252 +54,252 @@ #include #include -namespace oopse { +namespace OpenMD { -/** - * @class IndexListContainer - * @brief - * @todo documentation - */ -class IndexListContainer{ - public: - static const int MAX_INTEGER = 2147483647; - typedef std::list >::iterator IndexListContainerIterator; + /** + * @class IndexListContainer + * @brief + * @todo documentation + */ + class IndexListContainer{ + public: + static const int MAX_INTEGER = 2147483647; + typedef std::list >::iterator IndexListContainerIterator; - IndexListContainer(int minIndex = 0, int maxIndex = MAX_INTEGER) - :minIndex_(minIndex), maxIndex_(maxIndex) { + IndexListContainer(int minIndex = 0, int maxIndex = MAX_INTEGER) + :minIndex_(minIndex), maxIndex_(maxIndex) { - indexContainer_.push_back(std::make_pair(minIndex, maxIndex)); - } + indexContainer_.push_back(std::make_pair(minIndex, maxIndex)); + } - int pop() { + int pop() { - if (indexContainer_.empty()) { - std::cerr << "" << std::endl; - } + if (indexContainer_.empty()) { + std::cerr << "" << std::endl; + } - IndexListContainerIterator i = indexContainer_.begin(); - int result; + IndexListContainerIterator i = indexContainer_.begin(); + int result; - result = indexContainer_.front().first; + result = indexContainer_.front().first; - if (indexContainer_.front().first == indexContainer_.front().second) { - indexContainer_.pop_front(); - } else if (indexContainer_.front().first < indexContainer_.front().second) { - ++indexContainer_.front().first; - } else { - std::cerr << "" << std::endl; - } + if (indexContainer_.front().first == indexContainer_.front().second) { + indexContainer_.pop_front(); + } else if (indexContainer_.front().first < indexContainer_.front().second) { + ++indexContainer_.front().first; + } else { + std::cerr << "" << std::endl; + } - return result; - } + return result; + } - /** - * - */ - void insert(int index) { - IndexListContainerIterator insertPos = internalInsert(index, index); - merge(insertPos); - } + /** + * + */ + void insert(int index) { + IndexListContainerIterator insertPos = internalInsert(index, index); + merge(insertPos); + } - /** - * Reclaims an index range - * @param beginIndex - * @param endIndex - */ - void insert(int beginIndex, int endIndex) { - IndexListContainerIterator insertPos = internalInsert(beginIndex, endIndex); - merge(insertPos); - } + /** + * Reclaims an index range + * @param beginIndex + * @param endIndex + */ + void insert(int beginIndex, int endIndex) { + IndexListContainerIterator insertPos = internalInsert(beginIndex, endIndex); + merge(insertPos); + } - /** - * Reclaims an index array. - * @param indices - */ - void insert(std::vector& indices){ + /** + * Reclaims an index array. + * @param indices + */ + void insert(std::vector& indices){ - if (indices.empty()) { - return; - } + if (indices.empty()) { + return; + } - std::sort(indices.begin(), indices.end()); - std::unique(indices.begin(), indices.end()); + std::sort(indices.begin(), indices.end()); + std::unique(indices.begin(), indices.end()); - std::vector::iterator i; - IndexListContainerIterator insertPos; - int beginIndex; + std::vector::iterator i; + IndexListContainerIterator insertPos; + int beginIndex; - beginIndex = indices[0]; + beginIndex = indices[0]; - for ( i = indices.begin() + 1 ; i != indices.end(); ++i) { - if (*i != *(i -1) + 1) { - insert(beginIndex, *(i-1)); - beginIndex = *i; - } - } + for ( i = indices.begin() + 1 ; i != indices.end(); ++i) { + if (*i != *(i -1) + 1) { + insert(beginIndex, *(i-1)); + beginIndex = *i; + } + } - } + } - std::vector getIndicesBefore(int index) { - std::vector result; - IndexListContainerIterator i; + std::vector getIndicesBefore(int index) { + std::vector result; + IndexListContainerIterator i; - for(i = indexContainer_.begin(); i != indexContainer_.end(); ++i) { - if ((*i).first > index) { - //we locate the node whose minimum index is greater that index - indexContainer_.erase(indexContainer_.begin(), i); - break; - } else if ((*i).second < index) { - //The biggest index current node hold is less than the index we want - for (int j = (*i).first; j <= (*i).second; ++j) { - result.push_back(j); - } - continue; - } else if ((*i).first == (*i).second) { - //the index happen to equal to a node which only contains one index - result.push_back((*i).first); - indexContainer_.erase(indexContainer_.begin(), i); - break; - } else { + for(i = indexContainer_.begin(); i != indexContainer_.end(); ++i) { + if ((*i).first > index) { + //we locate the node whose minimum index is greater that index + indexContainer_.erase(indexContainer_.begin(), i); + break; + } else if ((*i).second < index) { + //The biggest index current node hold is less than the index we want + for (int j = (*i).first; j <= (*i).second; ++j) { + result.push_back(j); + } + continue; + } else if ((*i).first == (*i).second) { + //the index happen to equal to a node which only contains one index + result.push_back((*i).first); + indexContainer_.erase(indexContainer_.begin(), i); + break; + } else { - for (int j = (*i).first; j < index; ++j) { - result.push_back(j); - } + for (int j = (*i).first; j < index; ++j) { + result.push_back(j); + } - (*i).first = index; - indexContainer_.erase(indexContainer_.begin(), i); - break; - } + (*i).first = index; + indexContainer_.erase(indexContainer_.begin(), i); + break; + } - } + } - return result; + return result; - } + } - int getMaxIndex() { - return maxIndex_; - } + int getMaxIndex() { + return maxIndex_; + } - private: + private: - IndexListContainerIterator internalInsert(int beginIndex, int endIndex) { + IndexListContainerIterator internalInsert(int beginIndex, int endIndex) { + + if (beginIndex > endIndex) { + std::swap(beginIndex, endIndex); + std::cerr << "" << std::endl; + } - if (beginIndex > endIndex) { - std::swap(beginIndex, endIndex); - std::cerr << "" << std::endl; - } + if (endIndex > maxIndex_) { + std::cerr << "" << std::endl; + } - if (endIndex > maxIndex_) { - std::cerr << "" << std::endl; - } - - IndexListContainerIterator j; + IndexListContainerIterator j; - IndexListContainerIterator i = indexContainer_.begin(); - for (; i != indexContainer_.end(); ++i) { - if ((*i).first > endIndex) { - indexContainer_.insert(i, std::make_pair(beginIndex, endIndex)); - return --i; - } else if ((*i).second < beginIndex) { - continue; - } else { - std::cerr << "" << std::endl; - } - } + IndexListContainerIterator i = indexContainer_.begin(); + for (; i != indexContainer_.end(); ++i) { + if ((*i).first > endIndex) { + indexContainer_.insert(i, std::make_pair(beginIndex, endIndex)); + return --i; + } else if ((*i).second < beginIndex) { + continue; + } else { + std::cerr << "" << std::endl; + } + } - indexContainer_.push_back(std::make_pair(beginIndex, endIndex)); - return --indexContainer_.end(); + indexContainer_.push_back(std::make_pair(beginIndex, endIndex)); + return --indexContainer_.end(); - } + } - void merge(IndexListContainerIterator i) { - IndexListContainerIterator j; + void merge(IndexListContainerIterator i) { + IndexListContainerIterator j; - //check whether current node can be merged with its previous node - if ( i != indexContainer_.begin()) { - j = i; - --j; - if (j != indexContainer_.begin() && (*j).second + 1 == (*i).first) { - (*i).first = (*j).first; - indexContainer_.erase(j); - } - } + //check whether current node can be merged with its previous node + if ( i != indexContainer_.begin()) { + j = i; + --j; + if (j != indexContainer_.begin() && (*j).second + 1 == (*i).first) { + (*i).first = (*j).first; + indexContainer_.erase(j); + } + } - //check whether current node can be merged with its next node - if ( i != indexContainer_.end()) { - j = i; - ++j; + //check whether current node can be merged with its next node + if ( i != indexContainer_.end()) { + j = i; + ++j; - if (j != indexContainer_.end() && (*i).second + 1 == (*j).first) { - (*i).second = (*j).second; - indexContainer_.erase(j); - } - } + if (j != indexContainer_.end() && (*i).second + 1 == (*j).first) { + (*i).second = (*j).second; + indexContainer_.erase(j); + } + } - } - int minIndex_; - int maxIndex_; - std::list > indexContainer_; -}; + } + int minIndex_; + int maxIndex_; + std::list > indexContainer_; + }; -/** - * @class LocalIndexManager LocalIndexManager.hpp "utils/LocalIndexManager.hpp" - * @brief - */ -class LocalIndexManager { - public: + /** + * @class LocalIndexManager LocalIndexManager.hpp "utils/LocalIndexManager.hpp" + * @brief + */ + class LocalIndexManager { + public: - int getNextAtomIndex() { - return atomIndexContainer_.pop(); - } + int getNextAtomIndex() { + return atomIndexContainer_.pop(); + } - std::vector getAtomIndicesBefore(int index) { - return atomIndexContainer_.getIndicesBefore(index); - } + std::vector getAtomIndicesBefore(int index) { + return atomIndexContainer_.getIndicesBefore(index); + } - void releaseAtomIndex(int index) { - atomIndexContainer_.insert(index); - } + void releaseAtomIndex(int index) { + atomIndexContainer_.insert(index); + } - void releaseAtomIndex(int beginIndex, int endIndex) { - atomIndexContainer_.insert(beginIndex, endIndex); - } + void releaseAtomIndex(int beginIndex, int endIndex) { + atomIndexContainer_.insert(beginIndex, endIndex); + } - void releaseAtomIndex(std::vector indices) { - atomIndexContainer_.insert(indices); - } + void releaseAtomIndex(std::vector indices) { + atomIndexContainer_.insert(indices); + } - int getNextRigidBodyIndex() { - return rigidBodyIndexContainer_.pop(); - } + int getNextRigidBodyIndex() { + return rigidBodyIndexContainer_.pop(); + } - std::vector getRigidBodyIndicesBefore(int index) { - return rigidBodyIndexContainer_.getIndicesBefore(index); - } + std::vector getRigidBodyIndicesBefore(int index) { + return rigidBodyIndexContainer_.getIndicesBefore(index); + } - void releaseRigidBodyIndex(int index) { - rigidBodyIndexContainer_.insert(index); - } + void releaseRigidBodyIndex(int index) { + rigidBodyIndexContainer_.insert(index); + } - void releaseRigidBodyIndex(int beginIndex, int endIndex) { - rigidBodyIndexContainer_.insert(beginIndex, endIndex); - } + void releaseRigidBodyIndex(int beginIndex, int endIndex) { + rigidBodyIndexContainer_.insert(beginIndex, endIndex); + } - void releaseRigidBodyIndex(std::vector indices) { - rigidBodyIndexContainer_.insert(indices); - } + void releaseRigidBodyIndex(std::vector indices) { + rigidBodyIndexContainer_.insert(indices); + } - private: + private: - IndexListContainer atomIndexContainer_; - IndexListContainer rigidBodyIndexContainer_; -}; + IndexListContainer atomIndexContainer_; + IndexListContainer rigidBodyIndexContainer_; + }; -} //end namespace oopse +} //end namespace OpenMD #endif //UTILS_LOCALINDEXMANAGER_HPP