44 |
|
* |
45 |
|
* Created by Charles F. Vardeman II on 11/26/05. |
46 |
|
* @author Charles F. Vardeman II |
47 |
< |
* @version $Id: RhoZ.cpp,v 1.1 2005-11-30 21:00:39 chuckv Exp $ |
47 |
> |
* @version $Id: RhoZ.cpp,v 1.7 2008-06-30 17:53:42 gpuliti Exp $ |
48 |
|
* |
49 |
|
*/ |
50 |
|
|
54 |
|
#include <fstream> |
55 |
|
#include "applications/staticProps/RhoZ.hpp" |
56 |
|
#include "utils/simError.h" |
57 |
< |
|
57 |
> |
#include "io/DumpReader.hpp" |
58 |
> |
#include "primitives/Molecule.hpp" |
59 |
|
namespace oopse { |
60 |
|
|
61 |
< |
RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2, double len, int nrbins) |
62 |
< |
: RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins){ |
61 |
> |
RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, int nzbins) |
62 |
> |
: StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), nZBins_(nzbins){ |
63 |
> |
|
64 |
> |
evaluator_.loadScriptString(sele); |
65 |
> |
if (!evaluator_.isDynamic()) { |
66 |
> |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
67 |
> |
} |
68 |
|
|
69 |
< |
deltaR_ = len_ /nRBins_; |
69 |
> |
// fixed number of bins |
70 |
> |
|
71 |
> |
sliceSDLists_.resize(nZBins_); |
72 |
> |
density_.resize(nZBins_); |
73 |
|
|
65 |
– |
histogram_.resize(nRBins_); |
66 |
– |
avgRhoZ_.resize(nRBins_); |
67 |
– |
|
74 |
|
setOutputName(getPrefix(filename) + ".RhoZ"); |
75 |
|
} |
76 |
< |
|
77 |
< |
|
78 |
< |
void RhoZ::preProcess() { |
79 |
< |
std::fill(avgRhoZ_.begin(), avgRhoZ_.end(), 0.0); |
80 |
< |
} |
81 |
< |
|
82 |
< |
void RhoZ::initalizeHistogram() { |
83 |
< |
std::fill(histogram_.begin(), histogram_.end(), 0); |
84 |
< |
} |
85 |
< |
|
86 |
< |
|
87 |
< |
void RhoZ::processHistogram() { |
88 |
< |
|
89 |
< |
int nPairs = getNPairs(); |
90 |
< |
double volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume(); |
91 |
< |
double pairDensity = nPairs /volume * 2.0; |
92 |
< |
double pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0; |
93 |
< |
|
94 |
< |
for(int i = 0 ; i < histogram_.size(); ++i){ |
76 |
> |
|
77 |
> |
void RhoZ::process() { |
78 |
> |
Molecule* mol; |
79 |
> |
RigidBody* rb; |
80 |
> |
StuntDouble* sd; |
81 |
> |
SimInfo::MoleculeIterator mi; |
82 |
> |
Molecule::RigidBodyIterator rbIter; |
83 |
> |
|
84 |
> |
DumpReader reader(info_, dumpFilename_); |
85 |
> |
int nFrames = reader.getNFrames(); |
86 |
> |
nProcessed_ = nFrames/step_; |
87 |
> |
|
88 |
> |
for (int istep = 0; istep < nFrames; istep += step_) { |
89 |
> |
reader.readFrame(istep); |
90 |
> |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
91 |
> |
|
92 |
> |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
93 |
> |
//change the positions of atoms which belong to the rigidbodies |
94 |
> |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
95 |
> |
rb->updateAtoms(); |
96 |
> |
} |
97 |
> |
} |
98 |
> |
|
99 |
> |
int i; |
100 |
> |
for (i=0; i < nZBins_; i++) { |
101 |
> |
sliceSDLists_[i].clear(); |
102 |
> |
} |
103 |
> |
|
104 |
> |
RealType sliceVolume = currentSnapshot_->getVolume() /nZBins_; |
105 |
> |
Mat3x3d hmat = currentSnapshot_->getHmat(); |
106 |
> |
zBox_.push_back(hmat(2,2)); |
107 |
|
|
108 |
< |
double rLower = i * deltaR_; |
109 |
< |
double rUpper = rLower + deltaR_; |
110 |
< |
double volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); |
111 |
< |
double nIdeal = volSlice * pairConstant; |
108 |
> |
RealType halfBoxZ_ = hmat(2,2) / 2.0; |
109 |
> |
|
110 |
> |
if (evaluator_.isDynamic()) { |
111 |
> |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
112 |
> |
} |
113 |
|
|
114 |
< |
avgRhoZ_[i] += histogram_[i] / nIdeal; |
114 |
> |
//wrap the stuntdoubles into a cell |
115 |
> |
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
116 |
> |
Vector3d pos = sd->getPos(); |
117 |
> |
if (usePeriodicBoundaryConditions_) |
118 |
> |
currentSnapshot_->wrapVector(pos); |
119 |
> |
sd->setPos(pos); |
120 |
> |
} |
121 |
> |
|
122 |
> |
//determine which atom belongs to which slice |
123 |
> |
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
124 |
> |
Vector3d pos = sd->getPos(); |
125 |
> |
// shift molecules by half a box to have bins start at 0 |
126 |
> |
int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2)); |
127 |
> |
sliceSDLists_[binNo].push_back(sd); |
128 |
> |
} |
129 |
> |
|
130 |
> |
//loop over the slices to calculate the densities |
131 |
> |
for (i = 0; i < nZBins_; i++) { |
132 |
> |
RealType totalMass = 0; |
133 |
> |
for (int k = 0; k < sliceSDLists_[i].size(); ++k) { |
134 |
> |
totalMass += sliceSDLists_[i][k]->getMass(); |
135 |
> |
} |
136 |
> |
density_[i] += totalMass/sliceVolume; |
137 |
> |
} |
138 |
|
} |
139 |
|
|
140 |
+ |
writeDensity(); |
141 |
+ |
|
142 |
|
} |
143 |
|
|
100 |
– |
void RhoZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) { |
101 |
– |
|
102 |
– |
if (sd1 == sd2) { |
103 |
– |
return; |
104 |
– |
} |
105 |
– |
|
106 |
– |
Vector3d pos1 = sd1->getPosZ(); |
107 |
– |
Vector3d pos2 = sd2->getPosZ(); |
108 |
– |
Vector3d r12 = pos2 - pos1; |
109 |
– |
currentSnapshot_->wrapVector(r12); |
110 |
– |
|
111 |
– |
double distance = r12.length(); |
112 |
– |
|
113 |
– |
if (distance < len_) { |
114 |
– |
int whichBin = distance / deltaR_; |
115 |
– |
histogram_[whichBin] += 2; |
116 |
– |
} |
117 |
– |
} |
144 |
|
|
145 |
|
|
146 |
< |
void RhoZ::writeRdf() { |
146 |
> |
void RhoZ::writeDensity() { |
147 |
> |
|
148 |
> |
// compute average box length: |
149 |
> |
std::vector<RealType>::iterator j; |
150 |
> |
RealType zSum = 0.0; |
151 |
> |
for (j = zBox_.begin(); j != zBox_.end(); ++j) { |
152 |
> |
zSum += *j; |
153 |
> |
} |
154 |
> |
RealType zAve = zSum / zBox_.size(); |
155 |
> |
|
156 |
|
std::ofstream rdfStream(outputFilename_.c_str()); |
157 |
|
if (rdfStream.is_open()) { |
158 |
< |
rdfStream << "#radial distribution function\n"; |
159 |
< |
rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; |
160 |
< |
rdfStream << "selection2: (" << selectionScript2_ << ")\n"; |
161 |
< |
rdfStream << "#r\tcorrValue\n"; |
162 |
< |
for (int i = 0; i < avgRhoZ_.size(); ++i) { |
163 |
< |
double r = deltaR_ * (i + 0.5); |
164 |
< |
rdfStream << r << "\t" << avgRhoZ_[i]/nProcessed_ << "\n"; |
158 |
> |
rdfStream << "#RhoZ\n"; |
159 |
> |
rdfStream << "#nFrames:\t" << nProcessed_ << "\n"; |
160 |
> |
rdfStream << "#selection: (" << selectionScript_ << ")\n"; |
161 |
> |
rdfStream << "#z\tdensity\n"; |
162 |
> |
for (int i = 0; i < density_.size(); ++i) { |
163 |
> |
RealType z = zAve * (i+0.5)/density_.size(); |
164 |
> |
rdfStream << z << "\t" << 1.660535*density_[i]/nProcessed_ << "\n"; |
165 |
|
} |
166 |
|
|
167 |
|
} else { |