ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/visitors/ZconsVisitor.cpp
Revision: 1912
Committed: Mon Jan 10 20:52:07 2005 UTC (21 years, 6 months ago) by tim
File size: 5846 byte(s)
Log Message:
zconstraint method is working now

File Contents

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

Properties

Name Value
svn:executable *