ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/visitors/ZconsVisitor.cpp
Revision: 1625
Committed: Thu Oct 21 16:22:01 2004 UTC (19 years, 8 months ago) by tim
File size: 6389 byte(s)
Log Message:
replace old GebericData with  new GenericData

File Contents

# Content
1 #include "visitors/ZconsVisitor.hpp"
2 #include <cmath>
3
4 namespace oopse {
5
6 ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), zconsReader(NULL){
7 GenericData* data;
8 DoubleGenericData* tolerance;
9 ZConsParaData* zConsParaData;
10 StringGenericData* filename;
11 DoubleGenericData* sampleTime;
12 vector<ZConsParaItem>* parameters;
13
14 this->info = info;
15 visitorName = "ZConsVisitor";
16
17 //retrieve tolerance for z-constraint molecuels
18 data = info->getProperty(ZCONSTOL_ID);
19
20 if (!data){
21 cerr << "Can not get zconstraint tolerance from SimInfo" << endl;
22 haveZcons = false;
23 return;
24 }
25 else{
26 tolerance = dynamic_cast<DoubleGenericData*>(data);
27
28 if (!tolerance){
29 cerr << "Can not get zconstraint tolerance from SimInfo" << endl;
30 haveZcons = false;
31 return;
32 }
33 else{
34 zconsTol = tolerance->getData();
35 }
36 }
37
38 //retrieve sample time of z-contraint
39 data = info->getProperty(ZCONSTIME_ID);
40
41 if (!data){
42 cerr << "Can not get zcons time from SimInfo" << endl;
43 haveZcons = false;
44 return;
45 }
46 else{
47 sampleTime = dynamic_cast<DoubleGenericData*>(data);
48
49 if (!sampleTime){
50 cerr << "Can not get zcons time from SimInfo" << endl;
51 haveZcons = false;
52 return;
53 }
54 else{
55 zconsTime = sampleTime->getData();
56 }
57 }
58
59 //retrieve index of z-constraint molecules
60 data = info->getProperty(ZCONSPARADATA_ID);
61 if (!data){
62 cerr << "Can not get index of z-constraint molecules from SimInfo" << endl;
63 haveZcons = false;
64 return;
65 }
66 else{
67 zConsParaData = dynamic_cast<ZConsParaData*>(data);
68
69 if (!zConsParaData){
70 cerr << "Can not get index of z-constraint molecules from SimInfo" << endl;
71 haveZcons = false;
72 return;
73 }
74 else{
75 vector<ZConsParaItem>::iterator i;
76 Molecule* mol;
77
78 parameters = zConsParaData->getData();
79 for(i = parameters->begin(); i != parameters->end(); ++i){
80
81 mol = findZconsMol(i->zconsIndex);
82 if(mol != NULL)
83 zconsMol.push_back(mol);
84
85 }
86
87 if(zconsMol.size() < 1){
88 cerr << "number of zconstraint molecules is less than one" << endl;
89 haveZcons = false;
90 return;
91 }
92
93 }//end if (!zConsParaData)
94
95 }//end if (!data
96
97 //retrieve output filename of z force
98 data = info->getProperty(ZCONSFILENAME_ID);
99 if (!data){
100 cerr << "Can not get filename of z-constraint output from SimInfo" << endl;
101 haveZcons = false;
102 return;
103 }
104 else{
105 filename = dynamic_cast<StringGenericData*>(data);
106
107 if (!filename){
108 cerr << "Can not get filename of z-constraint output from SimInfo" << endl;
109 haveZcons = false;
110 return;
111 }
112 else{
113 zconsFilename = filename->getData();
114 }
115 }
116
117 zconsReader = new ZConsReader(info);
118
119 if (zconsReader->hasNextFrame())
120 zconsReader->readNextFrame();
121
122 haveZcons = true;
123 }
124
125 ZConsVisitor::~ZConsVisitor(){
126 if(!zconsReader)
127 delete zconsReader;
128
129 }
130
131 void ZConsVisitor::visit(Atom* atom){
132 string prefix;
133 if(isZconstraint(atom->getIndex(), prefix))
134 internalVisit(atom, prefix);
135 }
136
137 void ZConsVisitor::visit(DirectionalAtom* datom){
138 string prefix;
139
140 if(isZconstraint(datom->getIndex(), prefix))
141 internalVisit(datom, prefix);
142 }
143
144 void ZConsVisitor::visit(RigidBody* rb){
145 string prefix;
146 vector<Atom*> atoms;
147
148 atoms = rb->getAtoms();
149
150 if(isZconstraint(atoms[0]->getIndex(), prefix))
151 internalVisit(rb, prefix);
152 }
153
154 Molecule* ZConsVisitor::findZconsMol(int index){
155 Molecule* mols;
156 mols = info->molecules;
157 for(int i =0; i < info->n_mol; i++)
158 if(index == mols[i].getMyIndex())
159 return &mols[i];
160
161 return NULL;
162 }
163
164 void ZConsVisitor::update(){
165 Molecule* mol;
166 double com[3];
167 ZConsState state;
168 Atom** atoms;
169 int natoms;
170
171 getZconsPos(info->currentTime);
172
173 for(size_t i = 0; i < zconsMol.size(); i++){
174 zconsMol[i]->getCOM(com);
175
176 if(fabs(com[2] - zconsPos[i]) < zconsTol)
177 state = zsFixed;
178 else
179 state = zsMoving;
180
181 //update the state of zconstraint atom
182 natoms = zconsMol[i]->getNAtoms();
183 atoms = zconsMol[i]->getMyAtoms();
184 for(int j =0; j < natoms; j++)
185 zconsState[atoms[j]->getIndex()] = state;
186 }
187
188 }
189
190 void ZConsVisitor::getZconsPos(double time){
191
192 vector<double> tempPos;
193 vector<double> prevPos;
194 double tempTime;
195
196 while(true){
197 tempTime = zconsReader->getCurTime();
198
199 zconsPos = zconsReader->getZConsPos();
200
201 if(tempTime >= time)
202 return;
203
204 zconsReader->readNextFrame();
205
206 }
207
208 }
209
210 void ZConsVisitor::internalVisit(StuntDouble* sd, const string& prefix){
211 GenericData* data;
212 AtomData* atomData;
213 AtomInfo* atomInfo;
214 vector<AtomInfo*>::iterator iter;
215
216
217 //if there is not atom data, just skip it
218 data = sd->getProperty("ATOMDATA");
219 if(data != NULL){
220 atomData = dynamic_cast<AtomData*>(data);
221 if(atomData == NULL)
222 return;
223 }
224 else
225 return;
226
227 for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter))
228 (atomInfo->AtomType).insert(0, prefix);
229 }
230
231
232 bool ZConsVisitor::isZconstraint(int index, string& prefix){
233 map<int, ZConsState>::iterator i;
234 string prefixString[] = {"ZF", "ZM"};
235
236 i = zconsState.find(index);
237 if(i !=zconsState.end()){
238 prefix = prefixString[(*i).second];
239 return true;
240 }
241 else{
242 prefix = "";
243 return false;
244 }
245 }
246
247 const string ZConsVisitor::toString(){
248 char buffer[65535];
249 string result;
250
251 sprintf(buffer ,"------------------------------------------------------------------\n");
252 result += buffer;
253
254 sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
255 result += buffer;
256
257 sprintf(buffer , "number of zconstraint molecule: %d\n", zconsMol.size());
258 result += buffer;
259
260 sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol);
261 result += buffer;
262
263 sprintf(buffer , "zconstraint sample time = %lf\n", zconsTime);
264 result += buffer;
265
266 sprintf(buffer , "zconstraint output filename = %s\n", zconsFilename.c_str());
267 result += buffer;
268
269 for(size_t i = 0; i < zconsMol.size(); ++i){
270 sprintf(buffer ,"zconstraint molecule[%d] = %d\n", i, zconsMol[i]->getMyIndex());
271 result += buffer;
272
273 }
274
275
276 sprintf(buffer ,"------------------------------------------------------------------\n");
277 result += buffer;
278
279 return result;
280 }
281
282
283 }//namespace oopse

Properties

Name Value
svn:executable *