ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/OtherVisitor.cpp
Revision: 1118
Committed: Mon Apr 19 03:52:27 2004 UTC (20 years, 5 months ago) by tim
File size: 7700 byte(s)
Log Message:
new implement of quickLate using visitor and composite pattern

File Contents

# User Rev Content
1 tim 1118 #include "OtherVisitor.hpp"
2     #include "DirectionalAtom.hpp"
3     #include "RigidBody.hpp"
4     #include "Molecule.hpp"
5     #include "SimInfo.hpp"
6     //----------------------------------------------------------------------------//
7     void IgnoreVisitor::visit(Atom* atom){
8     if(isIgnoreType(atom->getType()))
9     internalVisit(atom);
10     }
11    
12     void IgnoreVisitor::visit(DirectionalAtom* datom){
13     if(isIgnoreType(datom->getType()))
14     internalVisit(datom);
15     }
16    
17     void IgnoreVisitor::visit(RigidBody* rb){
18     if(isIgnoreType(rb->getType()))
19     internalVisit(rb);
20     }
21    
22     bool IgnoreVisitor::isIgnoreType(const string& name){
23     return itList.find(name) != itList.end() ? true : false;
24     }
25    
26     void IgnoreVisitor::internalVisit(StuntDouble* sd){
27     GenericData* data;
28     data = sd->getProperty("IGNORE");
29    
30     //if this stuntdoulbe is already marked as ignore just skip it
31     if (data == NULL){
32     data = new GenericData;
33     data->setID("IGNORE");
34     sd->addProperty(data);
35     }
36    
37     }
38    
39     const string IgnoreVisitor::toString(){
40     char buffer[65535];
41     set<string>::iterator i;
42    
43     sprintf(buffer,"------------------------------------------------------------------\n");
44     sprintf(buffer,"Visitor name: %s", visitorName.c_str());
45    
46     //print the ignore type list
47     sprintf(buffer, "Ignore type list contains below types:\n");
48     for(i = itList.begin(); i != itList.end(); ++i)
49     sprintf(buffer,"%s,\t", i->c_str());
50     sprintf(buffer,"\n");
51    
52     sprintf(buffer,"------------------------------------------------------------------\n");
53    
54     return buffer;
55     }
56    
57     //----------------------------------------------------------------------------//
58    
59     void WrappingVisitor::visit(Atom* atom){
60     internalVisit(atom);
61     }
62     void WrappingVisitor::visit(DirectionalAtom* datom){
63     internalVisit(datom);
64     }
65    
66     void WrappingVisitor::visit(RigidBody* rb){
67     internalVisit(rb);
68     }
69    
70     void WrappingVisitor::internalVisit(StuntDouble* sd){
71     GenericData* data;
72     AtomData* atomData;
73     AtomInfo* atomInfo;
74     double pos[3];
75     vector<AtomInfo*>::iterator i;
76    
77     data = sd->getProperty("ATOMDATA");
78     if(data != NULL)
79     atomData = dynamic_cast<AtomData*>(data);
80     if(atomData == NULL)
81     return;
82     else
83     return;
84    
85     for(atomInfo = atomData->beginAtomInfo(i); atomInfo != NULL; atomData->nextAtomInfo(i))
86     info->wrapVector(atomInfo->pos);
87    
88     }
89    
90     //----------------------------------------------------------------------------//
91    
92     ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 replicateOpt) : BaseVisitor(){
93     this->info = info;
94     visitorName = "ReplicateVisitor";
95     this->replicateOpt = replicateOpt;
96     //generate the replicate directions
97     for(int i = 0; i < replicateOpt[0]; i ++)
98     for(int j = 0; i < replicateOpt[1]; j ++)
99     for(int k = 0; i < replicateOpt[2]; k ++)
100     //skip original frame
101     if(i == 0 && j ==0 && k ==0)
102     continue;
103     else
104     dir.push_back(IntVec3(i, j, k));
105    
106     }
107     void ReplicateVisitor::visit(Atom* atom){
108     internalVisit(atom);
109     }
110     void ReplicateVisitor::visit(DirectionalAtom* datom){
111     internalVisit(datom);
112     }
113    
114     void ReplicateVisitor::visit(RigidBody* rb){
115     internalVisit(rb);
116     }
117    
118     void ReplicateVisitor::internalVisit(StuntDouble* sd){
119     GenericData* data;
120     AtomData* atomData;
121     AtomInfo* atomInfo;
122     double box[3][3];
123     vector<AtomInfo*> atomInfoList;
124     IntVec3 dir;
125    
126     //if there is not atom data, just skip it
127     data = sd->getProperty("ATOMDATA");
128     if(data != NULL)
129     atomData = dynamic_cast<AtomData*>(data);
130     if(atomData == NULL)
131     return;
132     else
133     return;
134    
135    
136     info->getBoxM(box);
137    
138     atomInfoList = atomData->getData();
139    
140     replicate(atomInfoList, atomData, box);
141    
142     }
143    
144     void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){
145     AtomInfo * newAtomInfo;
146     vector<IntVec3>::iterator dirIter;
147     vector<AtomInfo*>::iterator i;
148    
149     for(dirIter = dir.begin(); dirIter != dir.end(); ++dirIter){
150     for(i = infoList.begin(); i != infoList.end(); i++){
151     newAtomInfo = new AtomInfo;
152     *newAtomInfo = *(*i);
153    
154     for(int j = 0; j < 3; j++)
155     newAtomInfo->pos[j] += (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2];
156    
157     data->addAtomInfo(newAtomInfo);
158     }
159     }// end for(dirIter)
160     }
161    
162     const string ReplicateVisitor::toString(){
163     char buffer[65535];
164     set<string>::iterator i;
165    
166     sprintf(buffer,"------------------------------------------------------------------\n");
167     sprintf(buffer,"Visitor name: %s", visitorName.c_str());
168    
169     //print the replicate direction
170     sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]);
171     sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]);
172     sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]);
173    
174    
175     sprintf(buffer,"------------------------------------------------------------------\n");
176    
177     return buffer;
178     }
179    
180     //----------------------------------------------------------------------------//
181    
182     XYZVisitor::XYZVisitor(SimInfo* info, bool printDipole) : BaseVisitor(){
183     this->info = info;
184     visitorName = "XYZVisitor";
185     this->printDipole = printDipole;
186     }
187    
188     void XYZVisitor::visit(Atom* atom){
189     if(!isIgnore(atom))
190     internalVisit(atom);
191     }
192    
193     void XYZVisitor::visit(DirectionalAtom* datom){
194     if(!isIgnore(datom))
195     internalVisit(datom);
196     }
197    
198     void XYZVisitor::visit(RigidBody* rb){
199     if(!isIgnore(rb))
200     internalVisit(rb);
201    
202     }
203    
204     void XYZVisitor::internalVisit(StuntDouble* sd){
205     GenericData* data;
206     AtomData* atomData;
207     AtomInfo* atomInfo;
208     vector<AtomInfo*>::iterator i;
209     char buffer[1024];
210    
211     //if there is not atom data, just skip it
212     data = sd->getProperty("ATOMDATA");
213     if(data != NULL)
214     atomData = dynamic_cast<AtomData*>(data);
215     if(atomData == NULL)
216     return;
217     else
218     return;
219    
220     for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
221    
222     if(printDipole)
223     sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
224     atomInfo->AtomType,
225     atomInfo->pos[0],
226     atomInfo->pos[1],
227     atomInfo->pos[2],
228     atomInfo->dipole[0],
229     atomInfo->dipole[1],
230     atomInfo->dipole[2]);
231     else
232     sprintf(buffer, "%s%15.8f%15.8f%15.8f",
233     atomInfo->AtomType,
234     atomInfo->pos[0],
235     atomInfo->pos[1],
236     atomInfo->pos[2]);
237     }
238    
239     frame.push_back(buffer);
240    
241     }
242    
243     bool XYZVisitor::isIgnore(StuntDouble* sd){
244     GenericData* data;
245    
246     data = sd->getProperty("IGNORE");
247     return data ==NULL ? false : true;
248     }
249    
250     void XYZVisitor::writeFrame(ostream& outStream){
251     vector<string>::iterator i;
252     double box[3][3];
253     char buffer[1024];
254    
255     if(frame.size() == 0)
256     cerr << "Current Frame does not contain any atoms" << endl;
257    
258     //total number of atoms
259     outStream << frame.size() << endl;
260    
261     //write comment line
262     info->getBoxM(box);
263     sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
264     info->getTime(),
265     box[0][0], box[0][1], box[0][2],
266     box[1][0], box[1][1], box[1][2],
267     box[2][0], box[2][1], box[2][2]);
268    
269     outStream << buffer << endl;
270    
271     for(i = frame.begin(); i != frame.end(); ++i)
272     outStream << *i << endl;
273     }
274    
275     //----------------------------------------------------------------------------//
276    
277     void PrepareVisitor::internalVisit(StuntDouble * sd){
278     GenericData* data;
279     AtomData* atomData;
280    
281     //if visited property is existed, remove it
282     data = sd->getProperty("VISITED");
283     if(data != NULL){
284     sd->removeProperty("VISITED");
285     }
286    
287     //remove atomdata
288     data = sd->getProperty("ATOMDATA");
289     if(data != NULL)
290     atomData = dynamic_cast<AtomData*>(data);
291     if(atomData != NULL)
292     sd->removeProperty("ATOMDATA");
293     }
294    

Properties

Name Value
svn:executable *