ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/brains/SimInfo.cpp
Revision: 1710
Committed: Thu Nov 4 19:48:22 2004 UTC (19 years, 7 months ago) by tim
File size: 5609 byte(s)
Log Message:
adding Stats class

File Contents

# Content
1 /*
2 * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project
3 *
4 * Contact: oopse@oopse.org
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
10 * All we ask is that proper credit is given for our work, which includes
11 * - but is not limited to - adding the above copyright notice to the beginning
12 * of your source code files, and to any copyright notice that you may distribute
13 * with programs based on this work.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 */
25
26 /**
27 * @file SimInfo.cpp
28 * @author tlin
29 * @date 11/02/2004
30 * @version 1.0
31 */
32
33 #include <algorithm>
34
35 #include "brains/SimInfo.hpp"
36 #include "utils/MemoryUtils.hpp"
37
38 namespace oopse {
39
40 SimInfo::SimInfo() : nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0),
41 nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), sman_(NULL){
42
43 }
44
45 SimInfo::~SimInfo() {
46 MemoryUtils::deleteVectorOfPointer(molecules_);
47 delete sman_;
48
49 }
50
51
52 bool SimInfo::addMolecule(Molecule* mol) {
53 std::vector<Molecule*>::iterator i;
54 i = std::find(molecules_.begin(), molecules_.end(), mol);
55 if (i != molecules_.end() ) {
56 molecules_.push_back(mol);
57
58 nAtoms_ += mol->getNAtoms();
59 nBonds_ += mol->getNBonds();
60 nBends_ += mol->getNBends();
61 nTorsions_ += mol->getNTorsions();
62 nRigidBodies_ += mol->getNRigidBodies();
63 nIntegrableObjects_ += mol->getNIntegrableObjects();
64 nCutoffGroups_ += mol->getNCutoffGroups();
65 nConstraints_ += mol->getNConstraints();
66
67 return true;
68 } else {
69 return false;
70 }
71 }
72
73 bool SimInfo::removeMolecule(Molecule* mol) {
74 std::vector<Molecule*>::iterator i;
75 i = std::find(molecules_.begin(), molecules_.end(), mol);
76
77 if (i != molecules_.end() ) {
78 molecules_.push_back(mol);
79 nAtoms_ -= mol->getNAtoms();
80 nBonds_ -= mol->getNBonds();
81 nBends_ -= mol->getNBends();
82 nTorsions_ -= mol->getNTorsions();
83 nRigidBodies_ -= mol->getNRigidBodies();
84 nIntegrableObjects_ -= mol->getNIntegrableObjects();
85 nCutoffGroups_ -= mol->getNCutoffGroups();
86 nConstraints_ -= mol->getNConstraints();
87
88 return true;
89 } else {
90 return false;
91 }
92
93
94 }
95
96
97 Molecule* SimInfo::beginMolecule(std::vector<Molecule*>::iterator& i) {
98 i = molecules_.begin();
99 return i == molecules_.end() ? NULL : *i;
100 }
101
102 Molecule* SimInfo::nextMolecule(std::vector<Molecule*>::iterator& i) {
103 ++i;
104 return i == molecules_.end() ? NULL : *i;
105 }
106
107
108 void SimInfo::calcNDF() {
109 int ndf_local;
110 std::vector<Molecule*>::iterator i;
111 std::vector<StuntDouble*>::iterator j;
112 Molecule* mol;
113 StuntDouble* integrableObject;
114
115 ndf_local = 0;
116
117 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
118 for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
119 integrableObject = mol->nextIntegrableObject(j)) {
120
121 ndf_local += 3;
122
123 if (integrableObject->isDirectional()) {
124 if (integrableObject->isLinear()) {
125 ndf_local += 2;
126 } else {
127 ndf_local += 3;
128 }
129 }
130
131 }//end for (integrableObject)
132 }// end for (mol)
133
134 // n_constraints is local, so subtract them on each processor
135 ndf_local -= nConstraints_;
136
137 #ifdef IS_MPI
138 MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
139 #else
140 ndf_ = ndf_local;
141 #endif
142
143 // nZconstraints is global, as are the 3 COM translations for the
144 // entire system:
145 ndf_ = ndf_ - 3 - nZconstraints;
146
147 }
148
149 void SimInfo::calcNDFRaw() {
150 int ndfRaw_local;
151
152 std::vector<Molecule*>::iterator i;
153 std::vector<StuntDouble*>::iterator j;
154 Molecule* mol;
155 StuntDouble* integrableObject;
156
157 // Raw degrees of freedom that we have to set
158 ndfRaw_local = 0;
159
160 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
161 for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
162 integrableObject = mol->nextIntegrableObject(j)) {
163
164 ndfRaw_local += 3;
165
166 if (integrableObject->isDirectional()) {
167 if (integrableObject->isLinear()) {
168 ndfRaw_local += 2;
169 } else {
170 ndfRaw_local += 3;
171 }
172 }
173
174 }
175 }
176
177 #ifdef IS_MPI
178 MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
179 #else
180 ndfRaw_ = ndfRaw_local;
181 #endif
182 }
183
184 void SimInfo::calcNDFTrans() {
185 int ndfTrans_local;
186
187 ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
188
189
190 #ifdef IS_MPI
191 MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
192 #else
193 ndfTrans_ = ndfTrans_local;
194 #endif
195
196 ndfTrans_ = ndfTrans_ - 3 - nZconstraints;
197
198 }
199
200
201 }//end namespace oopse