48#include "applications/staticProps/Kirkwood.hpp"
54#include "types/MultipoleAdapter.hpp"
55#include "utils/Revision.hpp"
56#include "utils/simError.h"
60 Kirkwood::Kirkwood(
SimInfo* info,
const std::string& filename,
61 const std::string& sele1,
const std::string& sele2,
62 RealType len,
int nrbins) :
65 setAnalysisType(
"Distance-dependent Kirkwood G-factor");
66 setOutputName(
getPrefix(filename) +
".kirkwood");
68 deltaR_ = len_ / nBins_;
70 histogram_.resize(nBins_);
71 avgKirkwood_.resize(nBins_);
72 std::stringstream params;
73 params <<
" len = " << len_ <<
", nrbins = " << nBins_;
74 const std::string paramString = params.str();
75 setParameterString(paramString);
78 void Kirkwood::preProcess() {
79 std::fill(avgKirkwood_.begin(), avgKirkwood_.end(), 0.0);
82 void Kirkwood::initializeHistogram() {
83 std::fill(histogram_.begin(), histogram_.end(), 0);
86 void Kirkwood::processHistogram() {
87 int nSelected1 = seleMan1_.getSelectionCount();
88 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
89 avgKirkwood_[i] += histogram_[i] / nSelected1;
93 void Kirkwood::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
94 if (sd1 == sd2) {
return; }
95 bool usePeriodicBoundaryConditions_ =
96 info_->getSimParams()->getUsePeriodicBoundaryConditions();
98 Vector3d pos1 = sd1->getPos();
99 Vector3d pos2 = sd2->getPos();
100 Vector3d r12 = pos2 - pos1;
101 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
105 AtomType* atype1 =
static_cast<Atom*
>(sd1)->getAtomType();
106 AtomType* atype2 =
static_cast<Atom*
>(sd2)->getAtomType();
108 MultipoleAdapter ma1 = MultipoleAdapter(atype1);
109 MultipoleAdapter ma2 = MultipoleAdapter(atype2);
113 RealType dotProduct(0.0);
115 if (ma1.isDipole()) {
116 d1 = sd1->getDipole();
118 if (ma2.isDipole()) {
119 d2 = sd2->getDipole();
121 dotProduct =
dot(d1, d2);
125 if (distance < len_) {
126 int whichBin = int(distance / deltaR_);
128 for (
unsigned int i = whichBin; i < nBins_; i++) {
129 histogram_[i] += dotProduct;
134 void Kirkwood::writeRdf() {
135 std::ofstream ofs(outputFilename_.c_str());
138 ofs <<
"# " << getAnalysisType() <<
"\n";
139 ofs <<
"# OpenMD " << r.getFullRevision() <<
"\n";
140 ofs <<
"# " << r.getBuildDate() <<
"\n";
141 ofs <<
"# selection script1: \"" << selectionScript1_;
142 ofs <<
"\"\tselection script2: \"" << selectionScript2_ <<
"\"\n";
143 if (!paramString_.empty())
144 ofs <<
"# parameters: " << paramString_ <<
"\n";
146 ofs <<
"#r\tcorrValue\n";
147 for (
unsigned int i = 0; i < avgKirkwood_.size(); ++i) {
148 RealType r = deltaR_ * (i + 0.5);
149 ofs << r <<
"\t" << avgKirkwood_[i] / nProcessed_ <<
"\n";
152 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
153 "Kirkwood: unable to open %s\n", outputFilename_.c_str());
154 painCave.isFatal = 1;
160 KirkwoodQuadrupoles::KirkwoodQuadrupoles(SimInfo* info,
161 const std::string& filename,
162 const std::string& sele1,
163 const std::string& sele2,
164 RealType len,
int nrbins) :
165 Kirkwood(info, filename, sele1, sele2, len, nrbins) {
166 setAnalysisType(
"Distance-dependent Kirkwood G-factor for quadrupoles");
167 setOutputName(
getPrefix(filename) +
".kirkwoodQ");
170 void KirkwoodQuadrupoles::collectHistogram(StuntDouble* sd1,
172 if (sd1 == sd2) {
return; }
173 bool usePeriodicBoundaryConditions_ =
174 info_->getSimParams()->getUsePeriodicBoundaryConditions();
176 Vector3d pos1 = sd1->getPos();
177 Vector3d pos2 = sd2->getPos();
178 Vector3d r12 = pos2 - pos1;
179 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
183 AtomType* atype1 =
static_cast<Atom*
>(sd1)->getAtomType();
184 AtomType* atype2 =
static_cast<Atom*
>(sd2)->getAtomType();
186 MultipoleAdapter ma1 = MultipoleAdapter(atype1);
187 MultipoleAdapter ma2 = MultipoleAdapter(atype2);
196 RealType quadrupoleProduct(0.0);
204 if (ma1.isQuadrupole()) {
205 Q1 = sd1->getQuadrupole();
208 Q1 /= sqrt(3.0 * Q1dQ1 - trQ1 * trQ1);
212 if (ma2.isQuadrupole()) {
213 Q2 = sd2->getQuadrupole();
216 Q2 /= sqrt(3.0 * Q2dQ2 - trQ2 * trQ2);
220 quadrupoleProduct = 3.0 *
doubleDot(Q1, Q2) - trQ1 * trQ2;
224 if (distance < len_) {
225 int whichBin = int(distance / deltaR_);
227 for (
unsigned int i = whichBin; i < nBins_; i++) {
228 histogram_[i] += quadrupoleProduct;
Radial Distribution Function.
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 doubleDot(const RectMatrix< Real, Row, Col > &t1, const RectMatrix< Real, Row, Col > &t2)
Returns the tensor contraction (double dot product) of two rank 2 tensors (or Matrices).
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
std::string getPrefix(const std::string &str)
Real distance(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the distance between two DynamicVectors.