1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
45 |
|
#include "utils/StringUtils.hpp" |
46 |
|
namespace oopse { |
47 |
|
|
48 |
< |
ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), info_(info), zconsReader_(NULL){ |
48 |
> |
ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), info_(info), zconsReader_(NULL){ |
49 |
|
|
50 |
|
visitorName = "ZConsVisitor"; |
51 |
|
currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
52 |
|
Globals* simParam = info_->getSimParams(); |
53 |
|
|
54 |
|
if (simParam->haveZconstraintTime()){ |
55 |
< |
zconsTime_ = simParam->getZconsTime(); |
55 |
> |
zconsTime_ = simParam->getZconsTime(); |
56 |
|
} |
57 |
|
else{ |
58 |
< |
sprintf(painCave.errMsg, |
59 |
< |
"ZConstraint error: If you use a ZConstraint,\n" |
60 |
< |
"\tyou must set zconsTime.\n"); |
61 |
< |
painCave.isFatal = 1; |
62 |
< |
simError(); |
58 |
> |
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 |
|
} |
64 |
|
|
65 |
|
if (simParam->haveZconsTol()){ |
66 |
< |
zconsTol_ = simParam->getZconsTol(); |
66 |
> |
zconsTol_ = simParam->getZconsTol(); |
67 |
|
} |
68 |
|
else{ |
69 |
< |
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(); |
69 |
> |
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)); |
82 |
> |
int zmolIndex = stamp[i]->getMolIndex(); |
83 |
> |
zmolStates_.insert(std::make_pair(zmolIndex, zsMoving)); |
84 |
|
} |
85 |
|
|
86 |
|
|
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 |
< |
} |
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 |
|
} |
99 |
|
|
100 |
|
zconsFilename_ = getPrefix(info_->getFinalConfigFileName()) + ".fz"; |
102 |
|
zconsReader_ = new ZConsReader(info); |
103 |
|
|
104 |
|
if (zconsReader_->hasNextFrame()) |
105 |
< |
zconsReader_->readNextFrame(); |
105 |
> |
zconsReader_->readNextFrame(); |
106 |
|
|
107 |
< |
} |
107 |
> |
} |
108 |
|
|
109 |
< |
ZConsVisitor::~ZConsVisitor(){ |
110 |
< |
if(!zconsReader_) |
111 |
< |
delete zconsReader_; |
109 |
> |
ZConsVisitor::~ZConsVisitor(){ |
110 |
> |
if(!zconsReader_) |
111 |
> |
delete zconsReader_; |
112 |
|
|
113 |
< |
} |
113 |
> |
} |
114 |
|
|
115 |
< |
void ZConsVisitor::visit(Atom* atom){ |
115 |
> |
void ZConsVisitor::visit(Atom* atom){ |
116 |
|
std::string prefix; |
117 |
|
if(isZconstraint(atom->getGlobalIndex(), prefix)) |
118 |
< |
internalVisit(atom, prefix); |
119 |
< |
} |
118 |
> |
internalVisit(atom, prefix); |
119 |
> |
} |
120 |
|
|
121 |
< |
void ZConsVisitor::visit(DirectionalAtom* datom){ |
121 |
> |
void ZConsVisitor::visit(DirectionalAtom* datom){ |
122 |
|
std::string prefix; |
123 |
|
|
124 |
|
if(isZconstraint(datom->getGlobalIndex(), prefix)) |
125 |
< |
internalVisit(datom, prefix); |
126 |
< |
} |
125 |
> |
internalVisit(datom, prefix); |
126 |
> |
} |
127 |
|
|
128 |
< |
void ZConsVisitor::visit(RigidBody* rb){ |
128 |
> |
void ZConsVisitor::visit(RigidBody* rb){ |
129 |
|
std::string prefix; |
130 |
|
std::vector<Atom*> atoms; |
131 |
|
|
132 |
|
atoms = rb->getAtoms(); |
133 |
|
|
134 |
|
if(isZconstraint(atoms[0]->getGlobalIndex(), prefix)) |
135 |
< |
internalVisit(rb, prefix); |
136 |
< |
} |
135 |
> |
internalVisit(rb, prefix); |
136 |
> |
} |
137 |
|
|
138 |
< |
void ZConsVisitor::update(){ |
138 |
> |
void ZConsVisitor::update(){ |
139 |
|
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; |
144 |
> |
i->second = zsMoving; |
145 |
|
} |
146 |
|
|
147 |
|
readZconsFile(currSnapshot_->getTime()); |
149 |
|
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; |
152 |
> |
std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex); |
153 |
> |
assert(k != zmolStates_.end()); |
154 |
> |
k->second = zsFixed; |
155 |
|
} |
156 |
|
|
157 |
< |
} |
157 |
> |
} |
158 |
|
|
159 |
< |
void ZConsVisitor::readZconsFile(double time) { |
159 |
> |
void ZConsVisitor::readZconsFile(double time) { |
160 |
|
double tempTime; |
161 |
|
while(zconsReader_->hasNextFrame()){ |
162 |
< |
tempTime = zconsReader_->getCurTime(); |
163 |
< |
if(tempTime >= time) { |
164 |
< |
return; |
165 |
< |
} |
162 |
> |
tempTime = zconsReader_->getCurTime(); |
163 |
> |
if(tempTime >= time) { |
164 |
> |
return; |
165 |
> |
} |
166 |
|
|
167 |
< |
zconsReader_->readNextFrame(); |
167 |
> |
zconsReader_->readNextFrame(); |
168 |
|
} |
169 |
< |
} |
169 |
> |
} |
170 |
|
|
171 |
< |
void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){ |
171 |
> |
void ZConsVisitor::internalVisit(StuntDouble* sd, const std::string& prefix){ |
172 |
|
GenericData* data; |
173 |
|
AtomData* atomData; |
174 |
|
AtomInfo* atomInfo; |
177 |
|
//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 |
< |
} |
180 |
> |
atomData = dynamic_cast<AtomData*>(data); |
181 |
> |
if(atomData == NULL) |
182 |
> |
return; |
183 |
> |
} |
184 |
|
else |
185 |
< |
return; |
185 |
> |
return; |
186 |
|
|
187 |
|
for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter)) |
188 |
< |
(atomInfo->atomTypeName).insert(0, prefix); |
189 |
< |
} |
188 |
> |
(atomInfo->atomTypeName).insert(0, prefix); |
189 |
> |
} |
190 |
|
|
191 |
|
|
192 |
< |
bool ZConsVisitor::isZconstraint(int atomIndex, std::string& prefix){ |
192 |
> |
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; |
196 |
> |
prefix = ""; |
197 |
> |
return false; |
198 |
|
} else { |
199 |
|
|
200 |
< |
std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second); |
201 |
< |
assert(j !=zmolStates_.end()); |
202 |
< |
prefix = prefixString[j->second]; |
203 |
< |
return true; |
200 |
> |
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 |
< |
} |
205 |
> |
} |
206 |
|
|
207 |
< |
const std::string ZConsVisitor::toString(){ |
207 |
> |
const std::string ZConsVisitor::toString(){ |
208 |
|
char buffer[65535]; |
209 |
|
std::string result; |
210 |
|
|
229 |
|
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; |
232 |
> |
sprintf(buffer ,"zconstraint molecule[%d] = %d\n", j++, i->first); |
233 |
> |
result += buffer; |
234 |
|
} |
235 |
|
|
236 |
|
sprintf(buffer ,"------------------------------------------------------------------\n"); |
237 |
|
result += buffer; |
238 |
|
|
239 |
|
return result; |
240 |
< |
} |
240 |
> |
} |
241 |
|
|
242 |
|
|
243 |
|
}//namespace oopse |