ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/staticProps/RadialDistrFunc.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/applications/staticProps/RadialDistrFunc.cpp (file contents):
Revision 1994 by tim, Thu Feb 10 18:14:03 2005 UTC vs.
Revision 2037 by tim, Wed Feb 16 19:36:30 2005 UTC

# Line 42 | Line 42
42   #include <algorithm>
43  
44   #include "RadialDistrFunc.hpp"
45 <
45 > #include "io/DumpReader.hpp"
46 > #include "primitives/Molecule.hpp"
47   namespace oopse {
48  
49   RadialDistrFunc::        RadialDistrFunc(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2)
50          : info_(info), currentSnapshot_(NULL), dumpFilename_(filename), step_(1),
51 <          selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info), evaluator2_(info){
51 >          selectionScript1_(sele1), selectionScript2_(sele2), evaluator1_(info), evaluator2_(info),
52 >          seleMan1_(info), seleMan2_(info), common_(info), sele1_minus_common_(info), sele2_minus_common_(info){
53            
54      evaluator1_.loadScriptString(sele1);
55      evaluator2_.loadScriptString(sele2);
56  
57 <    if (!evaluator1_->isDynamic()) {
58 <            seleMan1_.setSelectionSet(evaluator1_->evaluate());
57 >    if (!evaluator1_.isDynamic()) {
58 >            seleMan1_.setSelectionSet(evaluator1_.evaluate());
59      }
60 <    if (!evaluator2_->isDynamic()) {
61 <            seleMan2_.setSelectionSet(evaluator2_->evaluate());
60 >    if (!evaluator2_.isDynamic()) {
61 >            seleMan2_.setSelectionSet(evaluator2_.evaluate());
62      }
63  
64 +    if (!evaluator1_.isDynamic() && !evaluator2_.isDynamic()) {
65 +        //if all selections are static,  we can precompute the number of real pairs    
66 +        common_ = seleMan1_ & seleMan2_;
67 +        sele1_minus_common_ = seleMan1_ - common_;
68 +        sele2_minus_common_ = seleMan2_ - common_;      
69 +
70 +        int nSelected1 = seleMan1_.getSelectionCount();
71 +        int nSelected2 = seleMan2_.getSelectionCount();
72 +        int nIntersect = common_.getSelectionCount();
73 +        
74 +        nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;            
75 +    }
76 +    
77   }
78  
79   void RadialDistrFunc::process() {
80 <
80 >    Molecule* mol;
81 >    RigidBody* rb;
82 >    SimInfo::MoleculeIterator mi;
83 >    Molecule::RigidBodyIterator rbIter;
84 >    
85      preProcess();
86      
87      DumpReader reader(info_, dumpFilename_);    
88 <    int nFrames = reader->getNFrames();
89 <    nProcessed_ = nFrames / step_ + 1;
88 >    int nFrames = reader.getNFrames();
89 >    nProcessed_ = nFrames / step_;
90 >
91      for (int i = 0; i < nFrames; i += step_) {
92 <        reader->readFrame(i);
92 >        reader.readFrame(i);
93          currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
94  
95 <        if (evaluator1_->isDynamic()) {
96 <            seleMan1_.setSelectionSet(evaluator1_->evaluate());
95 >        if (evaluator1_.isDynamic()) {
96 >            seleMan1_.setSelectionSet(evaluator1_.evaluate());
97          }
98 <        if (evaluator2_->isDynamic()) {
99 <            seleMan2_.setSelectionSet(evaluator2_->evaluate());
98 >        if (evaluator2_.isDynamic()) {
99 >            seleMan2_.setSelectionSet(evaluator2_.evaluate());
100          }
101  
102 +        for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
103 +
104 +            //change the positions of atoms which belong to the rigidbodies
105 +            for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
106 +                rb->updateAtoms();
107 +            }
108 +        }
109 +        
110          initalizeHistogram();
111  
84        StuntDouble* sd1;
85        int j;
86        for (sd1 = seleMan1_->beginSelected(j); sd1 != NULL; sd1 = seleMan1_->nextSelected(j)) {
112  
113 <            StuntDouble* sd2;
114 <            int k;
115 <            for (sd2 = seleMan2_->beginSelected(k); sd2 != NULL; sd2 = seleMan2_->nextSelected(k)) {
116 <                collectHistogram(sd1, sd2);
117 <            }            
113 >        
114 >        //selections may overlap.
115 >        //
116 >        // |s1 -c | c |
117 >        //            | c |s2 - c|
118 >        //
119 >        // s1 : number of selected stuntdoubles in selection1
120 >        // s2 : number of selected stuntdoubles in selection2
121 >        // c   : number of intersect stuntdouble between selection1 and selection2
122 >        //when loop over the pairs, we can divide the looping into 3 stages
123 >        //stage 1 :     [s1-c]      [s2]
124 >        //stage 2 :     [c]            [s2 - c]
125 >        //stage 3 :     [c]            [c]
126 >        //stage 1 and stage 2 are completly non-overlapping
127 >        //stage 3 are completely overlapping
128 >
129 >        if (evaluator1_.isDynamic() || evaluator2_.isDynamic()) {
130 >
131 >            common_ = seleMan1_ & seleMan2_;
132 >            sele1_minus_common_ = seleMan1_ - common_;
133 >            sele2_minus_common_ = seleMan2_ - common_;            
134 >            int nSelected1 = seleMan1_.getSelectionCount();
135 >            int nSelected2 = seleMan2_.getSelectionCount();
136 >            int nIntersect = common_.getSelectionCount();
137 >            
138 >            nPairs_ = nSelected1 * nSelected2 - (nIntersect +1) * nIntersect/2;                      
139          }
140  
141 +        processNonOverlapping(sele1_minus_common_, seleMan2_);
142 +        processNonOverlapping(common_, sele2_minus_common_);        
143 +        processOverlapping(common_);
144 +        
145 +        
146          processHistogram();
147          
148      }
# Line 101 | Line 152 | void RadialDistrFunc::process() {
152      writeRdf();
153   }
154  
155 + void RadialDistrFunc::processNonOverlapping( SelectionManager& sman1, SelectionManager& sman2) {
156 +    StuntDouble* sd1;
157 +    StuntDouble* sd2;
158 +    int i;    
159 +    int j;
160 +    
161 +    for (sd1 = sman1.beginSelected(i); sd1 != NULL; sd1 = sman1.nextSelected(i)) {
162 +
163 +        for (sd2 = sman2.beginSelected(j); sd2 != NULL; sd2 = sman2.nextSelected(j)) {
164 +            collectHistogram(sd1, sd2);
165 +        }            
166 +    }
167 +
168   }
169 +
170 + void RadialDistrFunc::processOverlapping( SelectionManager& sman) {
171 +    StuntDouble* sd1;
172 +    StuntDouble* sd2;
173 +    int i;    
174 +    int j;
175 +
176 +    //basically, it is the same as below loop
177 +    //for (int i = 0;  i < n; ++i )
178 +    //  for (int j = i + 1; j < n; ++j) {}
179 +    
180 +    for (sd1 = sman.beginSelected(i); sd1 != NULL; sd1 = sman.nextSelected(i)) {                    
181 +        for (j  = i, sd2 = sman.nextSelected(j); sd2 != NULL; sd2 = sman.nextSelected(j)) {
182 +            collectHistogram(sd1, sd2);
183 +        }            
184 +    }
185 +
186 + }
187 +
188 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines