ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/PairList.cpp
Revision: 1465
Committed: Fri Jul 9 23:08:25 2010 UTC (15 years, 1 month ago) by chuckv
File size: 5441 byte(s)
Log Message:
Creating busticated version of OpenMD

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. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
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.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
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] Vardeman & Gezelter, in progress (2009).
40 */
41
42 #include <functional>
43 #include <iterator>
44 #include <utility>
45
46 #include "brains/PairList.hpp"
47
48 namespace OpenMD {
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

Properties

Name Value
svn:keywords Author Id Revision Date