56#include "applications/staticProps/SurfaceDiffusion.hpp"
63#include "utils/simError.h"
67 SurfaceDiffusion::SurfaceDiffusion(
SimInfo* info,
const std::string& filename,
68 const std::string& sele, RealType) :
70 selectionScript_(sele), evaluator_(info), seleMan1_(info) {
71 evaluator_.loadScriptString(sele);
72 if (!evaluator_.isDynamic()) {
73 seleMan1_.setSelectionSet(evaluator_.evaluate());
78 selectionCount_ = seleMan1_.getSelectionCount();
79 cout <<
"SelectionCount_: " << selectionCount_ <<
"\n";
81 moBool_.resize(selectionCount_);
82 positions_.resize(selectionCount_);
85 singleMoveDistance_ = 2.0;
88 void SurfaceDiffusion::process() {
90 bool usePeriodicBoundaryConditions_ =
91 info_->getSimParams()->getUsePeriodicBoundaryConditions();
93 DumpReader reader(info_, dumpFilename_);
94 int nFrames = reader.getNFrames();
96 nProcessed_ = nFrames / step_;
100 for (
int i = 0; i < selectionCount_; i++) {
101 moBool_[i].resize(nFrames);
102 positions_[i].resize(nFrames);
112 for (
int istep = 0; istep < nFrames; istep += step_) {
114 reader.readFrame(istep);
115 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
119 for (sd = seleMan1_.beginSelected(iterator); sd != NULL;
120 sd = seleMan1_.nextSelected(iterator)) {
121 Vector3d pos = sd->getPos();
122 positions_[index][istep] = pos;
127 cout <<
"Position Array size: " << positions_.size() <<
"\n";
128 cout <<
"Frames analyzed: " << positions_[0].size() <<
"\n";
130 for (std::size_t i = 0; i < positions_.size(); i++) {
131 int frameIndex = positions_[i].size();
132 for (
int j = 1; j < frameIndex; j++) {
133 Vector3d posF1 = positions_[i][j - 1];
134 Vector3d posF2 = positions_[i][j];
135 Vector3d diff = posF2 - posF1;
136 if (usePeriodicBoundaryConditions_) {
137 currentSnapshot_->wrapVector(diff);
139 double dist = diff.
length();
140 if (dist > singleMoveDistance_) {
141 moBool_[i][j] =
true;
143 moBool_[i][j] =
false;
148 int mobileAtomCount = 0;
149 for (std::size_t i = 0; i < moBool_.size(); i++) {
150 int frameIndex = moBool_[i].size();
151 bool mobileAtom =
false;
152 for (
int j = 0; j < frameIndex; j++) {
153 mobileAtom = mobileAtom || moBool_[i][j];
155 moBool_[i][0] = mobileAtom;
157 if (mobileAtom) { mobileAtomCount++; }
160 cout <<
"Mobile atom count: " << mobileAtomCount <<
"\n";
166 positions2_.resize(mobileAtomCount);
167 moBool2_.resize(mobileAtomCount);
169 for (std::size_t i = 0; i < positions_.size(); i++) {
170 int frameCount = positions_[i].size();
172 for (
int j = 0; j < frameCount; j++) {
173 positions2_[pos2index].push_back(positions_[i][j]);
174 moBool2_[pos2index].push_back(moBool_[i][j]);
183 cout <<
"positions_ has been cleared: " << positions_.size() <<
"\n";
184 cout <<
"positions2_ has been filled: " << positions2_.size() <<
"\n";
185 cout <<
"positions2_ has " << positions2_[0].size() <<
" frames\n";
188 positionCorrelation();
191 std::ofstream diffStream;
192 setOutputName(
getPrefix(filename_) +
".Mdiffusion");
193 diffStream.open(outputFilename_.c_str());
194 diffStream <<
"#X&Y diffusion amounts\n";
195 diffStream <<
"#singleMoveDistance_: " << singleMoveDistance_ <<
"\n";
196 diffStream <<
"#Number of mobile atoms: " << positions2_.size() <<
"\n";
197 diffStream <<
"#time, <x(t)-x(0)>, <y(t)-y(0)>, <r(t)-r(0)>\n";
199 for (std::size_t i = 0; i < xHist_.size(); i++) {
200 diffStream << i <<
", " << xHist_[i] <<
", " << yHist_[i] <<
", "
201 << rHist_[i] <<
"\n";
206 void SurfaceDiffusion::positionCorrelation() {
207 RealType xDist = 0.0;
208 RealType yDist = 0.0;
209 RealType rDist = 0.0;
218 int frameResize = positions2_[0].size();
219 xHist_.resize(frameResize);
220 yHist_.resize(frameResize);
221 rHist_.resize(frameResize);
222 count_.resize(frameResize);
226 for (std::size_t i = 0; i < positions2_.size(); i++) {
227 int frames = positions2_[i].size() - 1;
231 for (
int j = 0; j < frames; j++) {
234 if (moBool2_[i][j + 1]) {
235 for (std::size_t k = j; k < positions2_[0].size(); k++) {
242 kPos = positions2_[i][k];
243 jPos = positions2_[i][j];
244 xDist = kPos.x() - jPos.x();
245 xDist = xDist * xDist;
247 yDist = kPos.y() - jPos.y();
248 yDist = yDist * yDist;
250 rDist = (kPos - jPos).lengthSquare();
253 xHist_[timeShift] += xDist;
254 yHist_[timeShift] += yDist;
255 rHist_[timeShift] += rDist;
261 cout <<
"X, Y, R calculated\n";
263 for (std::size_t i = 0; i < xHist_.size(); i++) {
264 xHist_[i] = xHist_[i] / (count_[i]);
265 yHist_[i] = yHist_[i] / (count_[i]);
266 rHist_[i] = rHist_[i] / (count_[i]);
268 cout <<
"X, Y, R normalized\n";
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Real length() const
Returns the length of this vector.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)