ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/visitors/ZconsVisitor.cpp
Revision: 2759
Committed: Wed May 17 21:51:42 2006 UTC (18 years, 2 months ago) by tim
File size: 7872 byte(s)
Log Message:
Adding single precision capabilities to c++ side

File Contents

# User Rev Content
1 gezelter 2204 /*
2 gezelter 1930 * 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 <cmath>
43 tim 1492 #include "visitors/ZconsVisitor.hpp"
44 gezelter 1930 #include "primitives/Molecule.hpp"
45     #include "utils/StringUtils.hpp"
46 tim 2469 #include "types/ZconsStamp.hpp"
47 tim 1625 namespace oopse {
48    
49 gezelter 2204 ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), info_(info), zconsReader_(NULL){
50 gezelter 1490
51 gezelter 1930 visitorName = "ZConsVisitor";
52     currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
53     Globals* simParam = info_->getSimParams();
54 gezelter 1490
55 tim 2364 if (simParam->haveZconsTime()){
56 gezelter 2204 zconsTime_ = simParam->getZconsTime();
57 gezelter 1490 }
58     else{
59 gezelter 2204 sprintf(painCave.errMsg,
60     "ZConstraint error: If you use a ZConstraint,\n"
61     "\tyou must set zconsTime.\n");
62     painCave.isFatal = 1;
63     simError();
64 gezelter 1490 }
65    
66 gezelter 1930 if (simParam->haveZconsTol()){
67 gezelter 2204 zconsTol_ = simParam->getZconsTol();
68 gezelter 1490 }
69     else{
70 gezelter 2204 zconsTol_ = 0.01;
71     sprintf(painCave.errMsg,
72     "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n"
73     "\tOOPSE will use a default value of %f.\n"
74     "\tTo set the tolerance, use the zconsTol variable.\n",
75     zconsTol_);
76     painCave.isFatal = 0;
77     simError();
78 gezelter 1930 }
79    
80 tim 2469 int nZconstraints = simParam->getNZconsStamps();
81     std::vector<ZConsStamp*> stamp = simParam->getZconsStamps();
82 gezelter 1930 for (int i = 0; i < nZconstraints; i++){
83 gezelter 2204 int zmolIndex = stamp[i]->getMolIndex();
84     zmolStates_.insert(std::make_pair(zmolIndex, zsMoving));
85 gezelter 1490 }
86    
87    
88 gezelter 1930 //fill zatomToZmol_ array
89     /** @todo only works for single version now*/
90     std::map<int, ZConsState>::iterator j;
91     for (j = zmolStates_.begin(); j != zmolStates_.end(); ++j) {
92 gezelter 2204 Molecule* mol = info_->getMoleculeByGlobalIndex(j->first);
93     assert(mol != NULL);
94     Molecule::AtomIterator ai;
95     Atom* at;
96     for (at = mol->beginAtom(ai); at != NULL; at = mol->nextAtom(ai)) {
97     zatomToZmol_.insert(std::make_pair(at->getGlobalIndex(), mol->getGlobalIndex()));
98     }
99 gezelter 1490 }
100    
101 gezelter 1930 zconsFilename_ = getPrefix(info_->getFinalConfigFileName()) + ".fz";
102    
103     zconsReader_ = new ZConsReader(info);
104 gezelter 1490
105 gezelter 1930 if (zconsReader_->hasNextFrame())
106 gezelter 2204 zconsReader_->readNextFrame();
107 gezelter 1490
108 gezelter 2204 }
109 gezelter 1490
110 gezelter 2204 ZConsVisitor::~ZConsVisitor(){
111     if(!zconsReader_)
112     delete zconsReader_;
113 gezelter 1490
114 gezelter 2204 }
115 gezelter 1490
116 gezelter 2204 void ZConsVisitor::visit(Atom* atom){
117 gezelter 1930 std::string prefix;
118     if(isZconstraint(atom->getGlobalIndex(), prefix))
119 gezelter 2204 internalVisit(atom, prefix);
120     }
121 gezelter 1490
122 gezelter 2204 void ZConsVisitor::visit(DirectionalAtom* datom){
123 gezelter 1930 std::string prefix;
124    
125     if(isZconstraint(datom->getGlobalIndex(), prefix))
126 gezelter 2204 internalVisit(datom, prefix);
127     }
128 gezelter 1490
129 gezelter 2204 void ZConsVisitor::visit(RigidBody* rb){
130 gezelter 1930 std::string prefix;
131     std::vector<Atom*> atoms;
132 gezelter 1490
133 gezelter 1930 atoms = rb->getAtoms();
134 gezelter 1490
135 gezelter 1930 if(isZconstraint(atoms[0]->getGlobalIndex(), prefix))
136 gezelter 2204 internalVisit(rb, prefix);
137     }
138 gezelter 1490
139 gezelter 2204 void ZConsVisitor::update(){
140 gezelter 1930 Molecule* mol;
141     Vector3d com;
142     ZConsState state;
143     std::map<int, ZConsState>::iterator i;
144     for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
145 gezelter 2204 i->second = zsMoving;
146 gezelter 1930 }
147    
148     readZconsFile(currSnapshot_->getTime());
149 gezelter 1490
150 gezelter 1930 const std::vector<ZconsData>& fixedZmolData = zconsReader_->getFixedZMolData();
151     std::vector<ZconsData>::const_iterator j;
152     for (j = fixedZmolData.begin(); j != fixedZmolData.end(); ++j) {
153 gezelter 2204 std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex);
154     assert(k != zmolStates_.end());
155     k->second = zsFixed;
156 gezelter 1930 }
157    
158 gezelter 2204 }
159 gezelter 1490
160 tim 2759 void ZConsVisitor::readZconsFile(RealType time) {
161     RealType tempTime;
162 gezelter 1930 while(zconsReader_->hasNextFrame()){
163 gezelter 2204 tempTime = zconsReader_->getCurTime();
164     if(tempTime >= time) {
165     return;
166     }
167 gezelter 1930
168 gezelter 2204 zconsReader_->readNextFrame();
169 gezelter 1930 }
170 gezelter 2204 }
171 gezelter 1490
172 gezelter 2204 void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){
173 gezelter 1930 GenericData* data;
174     AtomData* atomData;
175     AtomInfo* atomInfo;
176     std::vector<AtomInfo*>::iterator iter;
177 gezelter 1490
178 gezelter 1930 //if there is not atom data, just skip it
179     data = sd->getPropertyByName("ATOMDATA");
180     if(data != NULL){
181 gezelter 2204 atomData = dynamic_cast<AtomData*>(data);
182     if(atomData == NULL)
183     return;
184     }
185 gezelter 1930 else
186 gezelter 2204 return;
187 gezelter 1490
188 gezelter 1930 for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter))
189 gezelter 2204 (atomInfo->atomTypeName).insert(0, prefix);
190     }
191 gezelter 1490
192    
193 gezelter 2204 bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){
194 gezelter 1930 std::string prefixString[] = {"ZF", "ZM"};
195     std::map<int, int>::iterator i = zatomToZmol_.find(atomIndex);
196     if (i == zatomToZmol_.end() ){
197 gezelter 2204 prefix = "";
198     return false;
199 gezelter 1930 } else {
200 gezelter 1490
201 gezelter 2204 std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second);
202     assert(j !=zmolStates_.end());
203     prefix = prefixString[j->second];
204     return true;
205 gezelter 1930 }
206 gezelter 2204 }
207 gezelter 1490
208 gezelter 2204 const std::string ZConsVisitor::toString(){
209 gezelter 1930 char buffer[65535];
210     std::string result;
211 gezelter 1490
212 gezelter 1930 sprintf(buffer ,"------------------------------------------------------------------\n");
213     result += buffer;
214 gezelter 1490
215 gezelter 1930 sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
216     result += buffer;
217 gezelter 1490
218 gezelter 1930 sprintf(buffer , "number of zconstraint molecule: %d\n", zmolStates_.size());
219     result += buffer;
220 gezelter 1490
221 gezelter 1930 sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol_);
222     result += buffer;
223 gezelter 1490
224 gezelter 1930 sprintf(buffer , "zconstraint sample time = %lf\n", zconsTime_);
225     result += buffer;
226 gezelter 1490
227 gezelter 1930 sprintf(buffer , "zconstraint output filename = %s\n", zconsFilename_.c_str());
228 gezelter 1490 result += buffer;
229    
230 gezelter 1930 std::map<int, ZConsState>::iterator i;
231     int j = 0;
232     for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
233 gezelter 2204 sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first);
234     result += buffer;
235 gezelter 1930 }
236 gezelter 1490
237 gezelter 1930 sprintf(buffer ,"------------------------------------------------------------------\n");
238     result += buffer;
239 gezelter 1490
240 gezelter 1930 return result;
241 gezelter 2204 }
242 tim 1625
243    
244     }//namespace oopse

Properties

Name Value
svn:executable *