48#include "applications/dynamicProps/CurrentDensityAutoCorrFunc.hpp"
50#include "types/FixedChargeAdapter.hpp"
51#include "types/FluctuatingChargeAdapter.hpp"
52#include "utils/Revision.hpp"
56 CurrentDensityAutoCorrFunc::CurrentDensityAutoCorrFunc(
SimInfo* info,
57 const string& filename,
59 const string& sele2) :
60 SystemACF<RealType>(info, filename, sele1, sele2) {
61 setCorrFuncType(
"Current Density Auto Correlation Function");
62 setOutputName(
getPrefix(dumpFilename_) +
".currentDensityCorr");
64 AtomTypeSet osTypes = seleMan1_.getSelectedAtomTypes();
65 std::copy(osTypes.begin(), osTypes.end(), std::back_inserter(outputTypes_));
67 Jc_.resize(nFrames_, V3Zero);
68 JcCount_.resize(nFrames_, 0);
70 typeJc_.resize(nFrames_);
71 typeCounts_.resize(nFrames_);
72 myHistogram_.resize(nTimeBins_);
74 for (
int i = 0; i < nFrames_; ++i) {
75 typeJc_[i].resize(outputTypes_.size(), V3Zero);
76 typeCounts_[i].resize(outputTypes_.size(), 0);
78 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
79 myHistogram_[i].resize(outputTypes_.size() + 1, 0.0);
82 thermo_ =
new Thermo(info_);
85 void CurrentDensityAutoCorrFunc::computeProperty1(
int frame) {
88 std::vector<AtomType*>::iterator at;
91 for (sd1 = seleMan1_.beginSelected(i); sd1 != NULL;
92 sd1 = seleMan1_.nextSelected(i)) {
93 Vector3d v = sd1->getVel();
98 atype =
static_cast<Atom*
>(sd1)->getAtomType();
99 FixedChargeAdapter fca = FixedChargeAdapter(atype);
100 if (fca.isFixedCharge()) q = fca.getCharge();
101 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype);
102 if (fqa.isFluctuatingCharge()) q += sd1->getFlucQPos();
105 at = std::find(outputTypes_.begin(), outputTypes_.end(), atype);
106 if (at != outputTypes_.end()) {
107 typeIndex = std::distance(outputTypes_.begin(), at);
109 if (typeIndex != -1) {
110 typeCounts_[frame][typeIndex]++;
111 typeJc_[frame][typeIndex] += q * v;
118 RealType vol = thermo_->getVolume();
120 Jc_[frame] /= (vol * Constants::currentDensityConvert);
121 for (
unsigned int j = 0; j < outputTypes_.size(); j++) {
122 typeJc_[frame][j] /= (vol * Constants::currentDensityConvert);
126 void CurrentDensityAutoCorrFunc::correlateFrames(
int frame1,
int frame2,
128 RealType corrVal(0.0);
129 corrVal =
dot(Jc_[frame1], Jc_[frame2]);
130 myHistogram_[timeBin][0] += corrVal;
132 for (
unsigned int j = 0; j < outputTypes_.size(); j++) {
133 corrVal =
dot(typeJc_[frame1][j], typeJc_[frame2][j]);
134 myHistogram_[timeBin][j + 1] += corrVal;
140 void CurrentDensityAutoCorrFunc::postCorrelate() {
141 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
142 for (
unsigned int j = 0; j < outputTypes_.size() + 1; j++) {
144 myHistogram_[i][j] /= count_[i];
146 myHistogram_[i][j] = 0.0;
152 void CurrentDensityAutoCorrFunc::writeCorrelate() {
153 ofstream ofs(outputFilename_.c_str());
158 ofs <<
"# " << getCorrFuncType() <<
"\n";
159 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
160 ofs <<
"# " << r.getBuildDate() <<
"\n";
161 ofs <<
"# selection script1: \"" << selectionScript1_;
162 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
163 if (!paramString_.empty())
164 ofs <<
"# parameters: " << paramString_ <<
"\n";
165 ofs <<
"# units = Amps^2 m^-4\n";
166 if (!labelString_.empty())
167 ofs <<
"#time\t" << labelString_ <<
"\n";
169 ofs <<
"#time\tcorrVal\t(";
171 for (
unsigned int j = 0; j < outputTypes_.size(); j++) {
172 ofs << outputTypes_[j]->getName() <<
"\t";
177 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
178 ofs << times_[i] - times_[0] <<
"\t";
179 for (
unsigned int j = 0; j < outputTypes_.size() + 1; j++) {
180 ofs << myHistogram_[i][j] <<
'\t';
186 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
187 "CurrentDensityAutoCorrFunc::writeCorrelate Error: failed to "
189 outputFilename_.c_str());
190 painCave.isFatal = 1;
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
std::string getPrefix(const std::string &str)