ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/visitors/ZconsVisitor.cpp
Revision: 1702
Committed: Wed Nov 3 18:00:36 2004 UTC (19 years, 8 months ago) by tim
File size: 6654 byte(s)
Log Message:
ForceFiled get compiled. Still a long way to go ......

File Contents

# User Rev Content
1 tim 1492 #include "visitors/ZconsVisitor.hpp"
2 gezelter 1490 #include <cmath>
3    
4 tim 1625 namespace oopse {
5    
6 gezelter 1490 ZConsVisitor::ZConsVisitor(SimInfo* info) : BaseVisitor(), zconsReader(NULL){
7     GenericData* data;
8 tim 1625 DoubleGenericData* tolerance;
9 gezelter 1490 ZConsParaData* zConsParaData;
10 tim 1625 StringGenericData* filename;
11     DoubleGenericData* sampleTime;
12 gezelter 1490 vector<ZConsParaItem>* parameters;
13    
14     this->info = info;
15     visitorName = "ZConsVisitor";
16    
17     //retrieve tolerance for z-constraint molecuels
18 tim 1701 data = info->getPropertyByName(ZCONSTOL_ID);
19 gezelter 1490
20     if (!data){
21     cerr << "Can not get zconstraint tolerance from SimInfo" << endl;
22     haveZcons = false;
23     return;
24     }
25     else{
26 tim 1625 tolerance = dynamic_cast<DoubleGenericData*>(data);
27 gezelter 1490
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 tim 1701 data = info->getPropertyByName(ZCONSTIME_ID);
40 gezelter 1490
41     if (!data){
42     cerr << "Can not get zcons time from SimInfo" << endl;
43     haveZcons = false;
44     return;
45     }
46     else{
47 tim 1625 sampleTime = dynamic_cast<DoubleGenericData*>(data);
48 gezelter 1490
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 tim 1701 data = info->getPropertyByName(ZCONSPARADATA_ID);
61 gezelter 1490 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 tim 1701 data = info->getPropertyByName(ZCONSFILENAME_ID);
99 gezelter 1490 if (!data){
100     cerr << "Can not get filename of z-constraint output from SimInfo" << endl;
101     haveZcons = false;
102     return;
103     }
104     else{
105 tim 1625 filename = dynamic_cast<StringGenericData*>(data);
106 gezelter 1490
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 tim 1702 if(isZconstraint(atom->getLocalIndex(), prefix))
134 gezelter 1490 internalVisit(atom, prefix);
135     }
136    
137     void ZConsVisitor::visit(DirectionalAtom* datom){
138     string prefix;
139    
140 tim 1702 if(isZconstraint(datom->getLocalIndex(), prefix))
141 gezelter 1490 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 tim 1702 if(isZconstraint(atoms[0]->getLocalIndex(), prefix))
151 gezelter 1490 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 tim 1702 if(index == mols[i].getGlobalIndex())
159 gezelter 1490 return &mols[i];
160    
161     return NULL;
162     }
163    
164     void ZConsVisitor::update(){
165     Molecule* mol;
166 tim 1702 Vector3d com;
167 gezelter 1490 ZConsState state;
168 tim 1702 //Atom** atoms;
169     //int natoms;
170 gezelter 1490
171     getZconsPos(info->currentTime);
172    
173     for(size_t i = 0; i < zconsMol.size(); i++){
174 tim 1702 com = zconsMol[i]->getCom();
175 gezelter 1490
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 tim 1702 //natoms = zconsMol[i]->getNAtoms();
183     //atoms = zconsMol[i]->getMyAtoms();
184     //for(int j =0; j < natoms; j++)
185     // zconsState[atoms[j]->getLocalIndex()] = state;
186    
187     std::vector<Atom*>::iterator j;
188     for (Atom* atom = zconsMol[i]->beginAtom(j); atom != NULL; atom = zconsMol[i]->nextAtom(j)) {
189     zconsState[atom->getLocalIndex()] = state;
190     }
191 gezelter 1490 }
192    
193     }
194    
195     void ZConsVisitor::getZconsPos(double time){
196    
197     vector<double> tempPos;
198     vector<double> prevPos;
199     double tempTime;
200    
201     while(true){
202     tempTime = zconsReader->getCurTime();
203    
204     zconsPos = zconsReader->getZConsPos();
205    
206     if(tempTime >= time)
207     return;
208    
209     zconsReader->readNextFrame();
210    
211     }
212    
213     }
214    
215     void ZConsVisitor::internalVisit(StuntDouble* sd, const string& prefix){
216     GenericData* data;
217     AtomData* atomData;
218     AtomInfo* atomInfo;
219     vector<AtomInfo*>::iterator iter;
220    
221    
222     //if there is not atom data, just skip it
223 tim 1701 data = sd->getPropertyByName("ATOMDATA");
224 gezelter 1490 if(data != NULL){
225     atomData = dynamic_cast<AtomData*>(data);
226     if(atomData == NULL)
227     return;
228     }
229     else
230     return;
231    
232     for(atomInfo = atomData->beginAtomInfo(iter); atomInfo; atomInfo = atomData->nextAtomInfo(iter))
233     (atomInfo->AtomType).insert(0, prefix);
234     }
235    
236    
237     bool ZConsVisitor::isZconstraint(int index, string& prefix){
238     map<int, ZConsState>::iterator i;
239     string prefixString[] = {"ZF", "ZM"};
240    
241     i = zconsState.find(index);
242     if(i !=zconsState.end()){
243     prefix = prefixString[(*i).second];
244     return true;
245     }
246     else{
247     prefix = "";
248     return false;
249     }
250     }
251    
252     const string ZConsVisitor::toString(){
253     char buffer[65535];
254     string result;
255    
256     sprintf(buffer ,"------------------------------------------------------------------\n");
257     result += buffer;
258    
259     sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
260     result += buffer;
261    
262     sprintf(buffer , "number of zconstraint molecule: %d\n", zconsMol.size());
263     result += buffer;
264    
265     sprintf(buffer , "zconstraint tolerance = %lf\n", zconsTol);
266     result += buffer;
267    
268     sprintf(buffer , "zconstraint sample time = %lf\n", zconsTime);
269     result += buffer;
270    
271     sprintf(buffer , "zconstraint output filename = %s\n", zconsFilename.c_str());
272     result += buffer;
273    
274     for(size_t i = 0; i < zconsMol.size(); ++i){
275 tim 1702 sprintf(buffer ,"zconstraint molecule[%d] = %d\n", i, zconsMol[i]->getGlobalIndex());
276 gezelter 1490 result += buffer;
277    
278     }
279    
280    
281     sprintf(buffer ,"------------------------------------------------------------------\n");
282     result += buffer;
283    
284     return result;
285     }
286 tim 1625
287    
288     }//namespace oopse

Properties

Name Value
svn:executable *