ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/brains/PairList.cpp
Revision: 3443
Committed: Wed Sep 10 18:13:35 2008 UTC (15 years, 9 months ago) by gezelter
File size: 5399 byte(s)
Log Message:
Exclude is gone.  Replaced by a generic PairList to handle 1-2, 1-3, and
1-4 interactions as well as the exclude list

File Contents

# Content
1 /*
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 #include <functional>
43 #include <iterator>
44 #include <utility>
45
46 #include "brains/PairList.hpp"
47
48 namespace oopse {
49
50 int *PairList::getPairList() {
51
52 if (modified_) {
53 pairList_.clear();
54
55 for (std::set<std::pair<int,int> >::iterator i = pairSet_.begin();
56 i != pairSet_.end(); ++i) {
57 pairList_.push_back(i->first + 1);
58 pairList_.push_back(i->second + 1);
59 }
60 modified_ = false;
61 }
62
63 return pairList_.size() > 0 ? &(pairList_[0]) : NULL;
64 }
65
66 void PairList::addPair(int i, int j) {
67
68 if (i == j) {
69 return;
70 } else if (i > j) {
71 std::swap(i, j);
72 }
73
74 std::set<std::pair<int, int> >::iterator iter = pairSet_.find(std::make_pair(i, j));
75
76 if (iter == pairSet_.end()) {
77 pairSet_.insert(std::make_pair(i, j));
78 modified_ = true;
79 }
80 }
81
82 void PairList::addPairs(std::set<int>& set1, std::set<int>& set2) {
83 for (std::set<int>::iterator iter1 = set1.begin();
84 iter1 != set1.end(); ++ iter1) {
85 for(std::set<int>::iterator iter2 = set2.begin();
86 iter2 != set2.end(); ++ iter2) {
87 this->addPair(*iter1, *iter2);
88 }
89 }
90 }
91
92 template<typename IterType1, typename IterType2>
93 void PairList::addPairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) {
94 for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) {
95 for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) {
96 this->addPair(*iter1, * iter2);
97 }
98 }
99 }
100
101 void PairList::removePair(int i, int j) {
102 if (i == j) {
103 return;
104 } else if (i > j) {
105 std::swap(i, j);
106 }
107
108
109 std::set<std::pair<int, int> >::iterator iter = pairSet_.find(std::make_pair(i, j));
110
111 if (iter != pairSet_.end()) {
112 pairSet_.erase(iter);
113 modified_ = true;
114 }
115 }
116
117 void PairList::removePairs(std::set<int>& set1, std::set<int>& set2) {
118 for (std::set<int>::iterator iter1 = set1.begin();
119 iter1 != set1.end(); ++ iter1) {
120 for(std::set<int>::iterator iter2 = set2.begin();
121 iter2 != set2.end(); ++ iter2) {
122 this->removePair(*iter1, * iter2);
123 }
124 }
125 }
126
127 template<typename IterType1, typename IterType2>
128 void PairList::removePairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) {
129 for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) {
130 for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) {
131 this->removePair(*iter1, * iter2);
132 }
133 }
134 }
135
136 bool PairList::hasPair(int i, int j) {
137
138 if (i == j) {
139 return false;
140 } else if (i > j) {
141 std::swap(i, j);
142 }
143
144 std::set<std::pair<int, int> >::iterator iter = pairSet_.find(std::make_pair(i, j));
145 return iter == pairSet_.end() ? false : true;
146 }
147
148 int PairList::getSize() {
149 return pairSet_.size();
150 }
151
152 std::ostream& operator <<(std::ostream& o, PairList& e) {
153 std::set<std::pair<int, int> >::iterator i;
154
155 int index;
156
157 index = 0;
158
159 for(i = e.pairSet_.begin(); i != e.pairSet_.end(); ++i) {
160 o << "pairList[" << index << "] i, j: " << (*i).first << " - "
161 << (*i).second << "\n";
162 index++;
163 }
164
165 return o;
166 }
167
168 }
169
170