ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/visitors/ZconsVisitor.cpp
Revision: 1930
Committed: Wed Jan 12 22:41:40 2005 UTC (19 years, 5 months ago) by gezelter
File size: 7922 byte(s)
Log Message:
merging new_design branch into OOPSE-2.0

File Contents

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

Properties

Name Value
svn:executable *