45#include "applications/dynamicProps/CurrentDensityAutoCorrFunc.hpp"
47#include "types/FixedChargeAdapter.hpp"
48#include "types/FluctuatingChargeAdapter.hpp"
49#include "utils/Revision.hpp"
53 CurrentDensityAutoCorrFunc::CurrentDensityAutoCorrFunc(
SimInfo* info,
54 const string& filename,
56 const string& sele2) :
57 SystemACF<RealType>(info, filename, sele1, sele2) {
58 setCorrFuncType(
"Current Density Auto Correlation Function");
59 setOutputName(
getPrefix(dumpFilename_) +
".currentDensityCorr");
61 AtomTypeSet osTypes = seleMan1_.getSelectedAtomTypes();
62 std::copy(osTypes.begin(), osTypes.end(), std::back_inserter(outputTypes_));
64 Jc_.resize(nFrames_, V3Zero);
65 JcCount_.resize(nFrames_, 0);
67 typeJc_.resize(nFrames_);
68 typeCounts_.resize(nFrames_);
69 myHistogram_.resize(nTimeBins_);
71 for (
int i = 0; i < nFrames_; ++i) {
72 typeJc_[i].resize(outputTypes_.size(), V3Zero);
73 typeCounts_[i].resize(outputTypes_.size(), 0);
75 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
76 myHistogram_[i].resize(outputTypes_.size() + 1, 0.0);
79 thermo_ =
new Thermo(info_);
82 void CurrentDensityAutoCorrFunc::computeProperty1(
int frame) {
85 std::vector<AtomType*>::iterator at;
95 atype =
static_cast<Atom*
>(sd1)->getAtomType();
97 if (fca.isFixedCharge()) q = fca.getCharge();
99 if (fqa.isFluctuatingCharge()) q += sd1->
getFlucQPos();
102 at = std::find(outputTypes_.begin(), outputTypes_.end(), atype);
103 if (at != outputTypes_.end()) {
104 typeIndex = std::distance(outputTypes_.begin(), at);
106 if (typeIndex != -1) {
107 typeCounts_[frame][typeIndex]++;
108 typeJc_[frame][typeIndex] += q * v;
115 RealType vol = thermo_->getVolume();
117 Jc_[frame] /= (vol * Constants::currentDensityConvert);
118 for (
unsigned int j = 0; j < outputTypes_.size(); j++) {
119 typeJc_[frame][j] /= (vol * Constants::currentDensityConvert);
123 void CurrentDensityAutoCorrFunc::correlateFrames(
int frame1,
int frame2,
125 RealType corrVal(0.0);
126 corrVal =
dot(Jc_[frame1], Jc_[frame2]);
127 myHistogram_[timeBin][0] += corrVal;
129 for (
unsigned int j = 0; j < outputTypes_.size(); j++) {
130 corrVal =
dot(typeJc_[frame1][j], typeJc_[frame2][j]);
131 myHistogram_[timeBin][j + 1] += corrVal;
137 void CurrentDensityAutoCorrFunc::postCorrelate() {
138 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
139 for (
unsigned int j = 0; j < outputTypes_.size() + 1; j++) {
141 myHistogram_[i][j] /= count_[i];
143 myHistogram_[i][j] = 0.0;
149 void CurrentDensityAutoCorrFunc::writeCorrelate() {
150 ofstream ofs(outputFilename_.c_str());
155 ofs <<
"# " << getCorrFuncType() <<
"\n";
156 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
157 ofs <<
"# " << r.getBuildDate() <<
"\n";
158 ofs <<
"# selection script1: \"" << selectionScript1_;
159 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
160 if (!paramString_.empty())
161 ofs <<
"# parameters: " << paramString_ <<
"\n";
162 ofs <<
"# units = Amps^2 m^-4\n";
163 if (!labelString_.empty())
164 ofs <<
"#time\t" << labelString_ <<
"\n";
166 ofs <<
"#time\tcorrVal\t(";
168 for (
unsigned int j = 0; j < outputTypes_.size(); j++) {
169 ofs << outputTypes_[j]->getName() <<
"\t";
174 for (
unsigned int i = 0; i < nTimeBins_; ++i) {
175 ofs << times_[i] - times_[0] <<
"\t";
176 for (
unsigned int j = 0; j < outputTypes_.size() + 1; j++) {
177 ofs << myHistogram_[i][j] <<
'\t';
183 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
184 "CurrentDensityAutoCorrFunc::writeCorrelate Error: failed to "
186 outputFilename_.c_str());
187 painCave.isFatal = 1;
AtomType is what OpenMD looks to for unchanging data about an atom.
StuntDouble * nextSelected(int &i)
Finds the next selected StuntDouble in the selection.
StuntDouble * beginSelected(int &i)
Finds the first selected StuntDouble in the selection.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Vector3d getVel()
Returns the current velocity of this stuntDouble.
RealType getFlucQPos()
Returns the current fluctuating charge of this stuntDouble.
bool isAtom()
Tests if this stuntDouble is an atom.
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)