ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/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

# User Rev Content
1 tim 1710 /*
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 gezelter 1490
26 tim 1710 /**
27     * @file SimInfo.cpp
28     * @author tlin
29     * @date 11/02/2004
30     * @version 1.0
31     */
32 gezelter 1490
33 tim 1710 #include <algorithm>
34    
35 tim 1492 #include "brains/SimInfo.hpp"
36 tim 1710 #include "utils/MemoryUtils.hpp"
37 gezelter 1490
38 tim 1710 namespace oopse {
39 gezelter 1490
40 tim 1710 SimInfo::SimInfo() : nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nRigidBodies_(0),
41     nIntegrableObjects_(0), nCutoffGroups_(0), nConstraints_(0), sman_(NULL){
42 gezelter 1490
43     }
44    
45 tim 1710 SimInfo::~SimInfo() {
46     MemoryUtils::deleteVectorOfPointer(molecules_);
47     delete sman_;
48 gezelter 1490
49     }
50    
51    
52 tim 1710 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 gezelter 1490
58 tim 1710 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 gezelter 1490
67 tim 1710 return true;
68     } else {
69     return false;
70 gezelter 1490 }
71     }
72    
73 tim 1710 bool SimInfo::removeMolecule(Molecule* mol) {
74     std::vector<Molecule*>::iterator i;
75     i = std::find(molecules_.begin(), molecules_.end(), mol);
76 gezelter 1490
77 tim 1710 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 gezelter 1490
88 tim 1710 return true;
89     } else {
90     return false;
91 gezelter 1490 }
92    
93    
94 tim 1710 }
95 gezelter 1490
96 tim 1710
97     Molecule* SimInfo::beginMolecule(std::vector<Molecule*>::iterator& i) {
98     i = molecules_.begin();
99     return i == molecules_.end() ? NULL : *i;
100     }
101 gezelter 1490
102 tim 1710 Molecule* SimInfo::nextMolecule(std::vector<Molecule*>::iterator& i) {
103     ++i;
104     return i == molecules_.end() ? NULL : *i;
105 gezelter 1490 }
106    
107    
108 tim 1710 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 gezelter 1490
115 tim 1710 ndf_local = 0;
116 gezelter 1490
117 tim 1710 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
118     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
119     integrableObject = mol->nextIntegrableObject(j)) {
120 gezelter 1490
121 tim 1710 ndf_local += 3;
122 gezelter 1490
123 tim 1710 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 gezelter 1490
134 tim 1710 // n_constraints is local, so subtract them on each processor
135     ndf_local -= nConstraints_;
136 gezelter 1490
137     #ifdef IS_MPI
138 tim 1710 MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
139 gezelter 1490 #else
140 tim 1710 ndf_ = ndf_local;
141 gezelter 1490 #endif
142    
143 tim 1710 // nZconstraints is global, as are the 3 COM translations for the
144     // entire system:
145     ndf_ = ndf_ - 3 - nZconstraints;
146 gezelter 1490
147     }
148    
149 tim 1710 void SimInfo::calcNDFRaw() {
150     int ndfRaw_local;
151 gezelter 1490
152 tim 1710 std::vector<Molecule*>::iterator i;
153     std::vector<StuntDouble*>::iterator j;
154     Molecule* mol;
155     StuntDouble* integrableObject;
156 gezelter 1490
157 tim 1710 // Raw degrees of freedom that we have to set
158     ndfRaw_local = 0;
159 gezelter 1490
160 tim 1710 for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
161     for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
162     integrableObject = mol->nextIntegrableObject(j)) {
163 gezelter 1490
164 tim 1710 ndfRaw_local += 3;
165 gezelter 1490
166 tim 1710 if (integrableObject->isDirectional()) {
167     if (integrableObject->isLinear()) {
168     ndfRaw_local += 2;
169     } else {
170     ndfRaw_local += 3;
171     }
172     }
173    
174     }
175     }
176    
177 gezelter 1490 #ifdef IS_MPI
178 tim 1710 MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
179 gezelter 1490 #else
180 tim 1710 ndfRaw_ = ndfRaw_local;
181 gezelter 1490 #endif
182     }
183    
184 tim 1710 void SimInfo::calcNDFTrans() {
185     int ndfTrans_local;
186 gezelter 1490
187 tim 1710 ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
188 gezelter 1490
189    
190     #ifdef IS_MPI
191 tim 1710 MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
192 gezelter 1490 #else
193 tim 1710 ndfTrans_ = ndfTrans_local;
194 gezelter 1490 #endif
195    
196 tim 1710 ndfTrans_ = ndfTrans_ - 3 - nZconstraints;
197 gezelter 1490
198     }
199    
200    
201 tim 1710 }//end namespace oopse