ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/visitors/ZconsVisitor.cpp
Revision: 1911
Committed: Mon Jan 10 18:05:45 2005 UTC (21 years, 6 months ago) by tim
File size: 5715 byte(s)
Log Message:
more work in zconstraint

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 gezelter 1490
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 1911
60     zconsReader_ = new ZConsReader(info);
61 gezelter 1490
62 tim 1911 if (zconsReader_->hasNextFrame())
63     zconsReader_->readNextFrame();
64 gezelter 1490
65     }
66    
67     ZConsVisitor::~ZConsVisitor(){
68 tim 1911 if(!zconsReader_)
69     delete zconsReader_;
70 gezelter 1490
71     }
72    
73     void ZConsVisitor::visit(Atom* atom){
74 tim 1911 std::string prefix;
75     if(isZconstraint(atom->getGlobalIndex(), prefix))
76     internalVisit(atom, prefix);
77 gezelter 1490 }
78    
79     void ZConsVisitor::visit(DirectionalAtom* datom){
80 tim 1911 std::string prefix;
81    
82     if(isZconstraint(datom->getGlobalIndex(), prefix))
83     internalVisit(datom, prefix);
84 gezelter 1490 }
85    
86     void ZConsVisitor::visit(RigidBody* rb){
87 tim 1911 std::string prefix;
88     std::vector<Atom*> atoms;
89    
90     atoms = rb->getAtoms();
91    
92     if(isZconstraint(atoms[0]->getGlobalIndex(), prefix))
93     internalVisit(rb, prefix);
94 gezelter 1490 }
95    
96     void ZConsVisitor::update(){
97 tim 1911 Molecule* mol;
98     Vector3d com;
99     ZConsState state;
100     std::map<int, ZConsState>::iterator i;
101     for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
102     i->second = zsMoving;
103     }
104    
105     readZconsFile(currSnapshot_->getTime());
106 gezelter 1490
107 tim 1911 const std::vector<ZconsData>& fixedZmolData = zconsReader_->getFixedZMolData();
108     std::vector<ZconsData>::const_iterator j;
109     for (j = fixedZmolData.begin(); j != fixedZmolData.end(); ++j) {
110     std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex);
111     assert(k != zmolStates_.end());
112     k->second = zsFixed;
113 tim 1702 }
114 tim 1911
115 gezelter 1490 }
116    
117 tim 1911 void ZConsVisitor::readZconsFile(double time) {
118     double tempTime;
119     while(true){
120     tempTime = zconsReader_->getCurTime();
121     if(tempTime >= time) {
122     return;
123     }
124    
125     zconsReader_->readNextFrame();
126     }
127 gezelter 1490 }
128    
129 tim 1832 void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){
130 tim 1911 GenericData* data;
131     AtomData* atomData;
132     AtomInfo* atomInfo;
133     std::vector<AtomInfo*>::iterator iter;
134 gezelter 1490
135 tim 1911 //if there is not atom data, just skip it
136     data = sd->getPropertyByName("ATOMDATA");
137     if(data != NULL){
138     atomData = dynamic_cast<AtomData*>(data);
139     if(atomData == NULL)
140     return;
141     }
142     else
143     return;
144 gezelter 1490
145 tim 1911 for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter))
146     (atomInfo->AtomType).insert(0, prefix);
147 gezelter 1490 }
148    
149    
150 tim 1911 bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){
151     std::string prefixString[] = {"ZF", "ZM"};
152     std::map<int, int>::iterator i = zatomToZmol_.find(atomIndex);
153     if (i == zatomToZmol_.end() ){
154     prefix = "";
155     return false;
156     } else {
157    
158     std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second);
159     assert(j !=zmolStates_.end());
160     prefix = prefixString[j->second];
161     return true;
162     }
163 gezelter 1490 }
164    
165 tim 1818 const std::string ZConsVisitor::toString(){
166 tim 1911 char buffer[65535];
167     std::string result;
168 gezelter 1490
169 tim 1911 sprintf(buffer ,"------------------------------------------------------------------\n");
170     result += buffer;
171 gezelter 1490
172 tim 1911 sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
173     result += buffer;
174 gezelter 1490
175 tim 1911 sprintf(buffer , "number of zconstraint molecule: %d\n", zmolStates_.size());
176     result += buffer;
177 gezelter 1490
178 tim 1911 sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol_);
179 gezelter 1490 result += buffer;
180    
181 tim 1911 sprintf(buffer , "zconstraint sample time = %lf\n", zconsTime_);
182     result += buffer;
183 gezelter 1490
184 tim 1911 sprintf(buffer , "zconstraint output filename = %s\n", zconsFilename_.c_str());
185     result += buffer;
186    
187     std::map<int, ZConsState>::iterator i;
188     int j = 0;
189     for ( i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
190     sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first);
191     result += buffer;
192     }
193 gezelter 1490
194 tim 1911 sprintf(buffer ,"------------------------------------------------------------------\n");
195     result += buffer;
196 gezelter 1490
197 tim 1911 return result;
198 gezelter 1490 }
199 tim 1625
200    
201     }//namespace oopse

Properties

Name Value
svn:executable *