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

Comparing trunk/OOPSE-4/src/applications/staticProps/DensityPlot.cpp (file contents):
Revision 2242 by tim, Fri May 27 21:11:24 2005 UTC vs.
Revision 2258 by gezelter, Mon Jun 20 16:03:30 2005 UTC

# Line 48 | Line 48 | DensityPlot::DensityPlot(SimInfo* info, const std::str
48   namespace oopse {
49  
50  
51 < DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, double len, int nrbins)
51 > DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, const std::string& cmSele, double len, int nrbins)
52    : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info),
53 +    cmSelectionScript_(cmSele), cmEvaluator_(info), cmSeleMan_(info),    
54      len_(len), nRBins_(nrbins), halfLen_(len/2)     {
55  
56      setOutputName(getPrefix(filename) + ".density");
# Line 65 | Line 66 | DensityPlot::DensityPlot(SimInfo* info, const std::str
66      if (!evaluator_.isDynamic()) {
67        seleMan_.setSelectionSet(evaluator_.evaluate());
68      }
69 +
70 +    cmEvaluator_.loadScriptString(cmSele);
71 +    if (!cmEvaluator_.isDynamic()) {
72 +      cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
73 +    }
74      
75 +    
76    }
77  
78   void DensityPlot::process() {
# Line 76 | Line 83 | void DensityPlot::process() {
83    
84    DumpReader reader(info_, dumpFilename_);    
85    int nFrames = reader.getNFrames();
86 <
87 <  for (int i = 0; i < nFrames; i += step_) {
86 >  int i;
87 >  for (i = 0; i < nFrames; i += step_) {
88      reader.readFrame(i);
89      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
90  
# Line 89 | Line 96 | void DensityPlot::process() {
96          
97      }
98      
92    Vector3d cm = info_->getCom();
93
99      if (evaluator_.isDynamic()) {
100          seleMan_.setSelectionSet(evaluator_.evaluate());
101      }
102  
103 <    int i;        
103 >    if (cmEvaluator_.isDynamic()) {
104 >        cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
105 >    }
106 >
107 >    Vector3d origin = calcNewOrigin();
108 >
109 >    Mat3x3d hmat = currentSnapshot_->getHmat();
110 >    double slabVolume = deltaR_ * hmat(0, 0) * hmat(1, 1);
111 >    
112      for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
100        Vector3d pos = sd->getPos() - cm;
101        currentSnapshot_->wrapVector(pos);
113  
114 <        int which = (pos.z() + halfLen_) / deltaR_;        
115 <        if (which < nRBins_ && which >=0 ) {
116 <          ++histogram_[which];
114 >
115 >            if (!sd->isAtom()) {
116 >                sprintf( painCave.errMsg, "Can not calculate electron density if it is not atom\n");
117 >                painCave.severity = OOPSE_ERROR;
118 >                painCave.isFatal = 1;
119 >                simError();
120 >            }
121 >            
122 >            Atom* atom = static_cast<Atom*>(sd);
123 >            GenericData* data = atom->getAtomType()->getPropertyByName("nelectron");
124 >            if (data == NULL) {
125 >                sprintf( painCave.errMsg, "Can not find Parameters for nelectron\n");
126 >                painCave.severity = OOPSE_ERROR;
127 >                painCave.isFatal = 1;
128 >                simError();
129 >            }
130 >            
131 >            DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
132 >            if (doubleData == NULL) {
133 >                sprintf( painCave.errMsg,
134 >                     "Can not cast GenericData to DoubleGenericData\n");
135 >                painCave.severity = OOPSE_ERROR;
136 >                painCave.isFatal = 1;
137 >                simError();  
138 >            }
139 >            
140 >            double nelectron = doubleData->getData();
141 >
142 >            data = atom->getAtomType()->getPropertyByName("LennardJones");
143 >            if (data == NULL) {
144 >                sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n");
145 >                painCave.severity = OOPSE_ERROR;
146 >                painCave.isFatal = 1;
147 >                simError();
148 >            }
149 >
150 >            LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
151 >            if (ljData == NULL) {
152 >                sprintf( painCave.errMsg,
153 >                     "Can not cast GenericData to LJParam\n");
154 >                painCave.severity = OOPSE_ERROR;
155 >                painCave.isFatal = 1;
156 >                simError();          
157 >            }
158 >
159 >            LJParam ljParam = ljData->getData();
160 >            double sigma = ljParam.sigma * 0.5;
161 >            double sigma2 = sigma * sigma;
162 >
163 >            Vector3d pos = sd->getPos() - origin;
164 >            /*
165 >            currentSnapshot_->wrapVector(pos);            
166 >            double wrappedZdist = pos.z() + halfLen_;
167 >            if (wrappedZdist < 0.0 || wrappedZdist > len_) {
168 >                continue;
169 >            }
170 >            
171 >            int which =wrappedZdist / deltaR_;        
172 >            density_[which] += nelectron;
173 >            */
174 >            for (int j =0; j < nRBins_; ++j) {
175 >                Vector3d tmp(pos);
176 >                double zdist =j * deltaR_ - halfLen_;
177 >                tmp[2] += zdist;
178 >                currentSnapshot_->wrapVector(tmp);
179 >
180 >                double wrappedZdist = tmp.z() + halfLen_;
181 >                if (wrappedZdist < 0.0 || wrappedZdist > len_) {
182 >                    continue;
183 >                }
184 >                
185 >                int which =wrappedZdist / deltaR_;        
186 >                density_[which] += nelectron * exp(-zdist*zdist/(sigma2*2.0)) /(slabVolume* sqrt(2*NumericConstant::PI*sigma*sigma));
187 >                    
188 >            }
189 >            
190 >            
191 >            
192          }        
193      }
108        
109  }
110  
111  //std::vector<int>::iterator it = std::max_element(histogram_.begin(), histogram_.end());
112  //int maxnum = *it;
194  
195 <  int nProcessed = nFrames / step_;
196 <  int ntot = info_->getNGlobalAtoms();
116 <  int maxnum = ntot * nProcessed;
117 <  std::transform(histogram_.begin(), histogram_.end(), density_.begin(), std::bind2nd(std::divides<double>(), maxnum));
195 >  int nProcessed = nFrames /step_;
196 >  std::transform(density_.begin(), density_.end(), density_.begin(), std::bind2nd(std::divides<double>(), nProcessed));  
197    writeDensity();
198 +        
199 +
200    
201   }
202  
203 + Vector3d DensityPlot::calcNewOrigin() {
204 +
205 +    int i;
206 +    Vector3d newOrigin(0.0);
207 +    double totalMass = 0.0;
208 +    for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
209 +        double mass = sd->getMass();
210 +        totalMass += mass;
211 +        newOrigin += sd->getPos() * mass;        
212 +    }
213 +    newOrigin /= totalMass;
214 +    return newOrigin;
215 + }
216 +
217   void DensityPlot::writeDensity() {
218      std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
219      if (ofs.is_open()) {
220        ofs << "#g(x, y, z)\n";
221 <      ofs << "#selection: (" << selectionScript_ << ")\t";
222 <      ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n";
221 >      ofs << "#selection: (" << selectionScript_ << ")\n";
222 >      ofs << "#cmSelection:(" << cmSelectionScript_ << ")\n";
223 >      ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "\tdeltaR = " << deltaR_ <<"\n";
224        for (int i = 0; i < histogram_.size(); ++i) {
225            ofs << i*deltaR_ - halfLen_ <<"\t" << density_[i]<< std::endl;
226        }        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines