1 |
gezelter |
2003 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
|
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
28 |
|
|
* arising out of the use of or inability to use software, even if the |
29 |
|
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
|
* such damages. |
31 |
|
|
* |
32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
|
|
* research, please cite the appropriate papers when you publish your |
34 |
|
|
* work. Good starting points are: |
35 |
|
|
* |
36 |
|
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
|
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
|
|
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
|
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
|
*/ |
42 |
|
|
|
43 |
|
|
#include "applications/dynamicProps/FreqFlucCorrFunc.hpp" |
44 |
|
|
#include "primitives/Atom.hpp" |
45 |
|
|
#include "types/MultipoleAdapter.hpp" |
46 |
|
|
#include "utils/simError.h" |
47 |
|
|
|
48 |
|
|
namespace OpenMD { |
49 |
gezelter |
2004 |
FreqFlucCorrFunc::FreqFlucCorrFunc(SimInfo* info, const std::string& filename, |
50 |
|
|
const std::string& sele1, |
51 |
|
|
const std::string& sele2, |
52 |
gezelter |
2003 |
long long int memSize) |
53 |
gezelter |
2004 |
: ParticleTimeCorrFunc(info, filename, sele1, sele2, |
54 |
|
|
DataStorage::dslElectricField | |
55 |
|
|
DataStorage::dslAmat | DataStorage::dslDipole, |
56 |
|
|
memSize){ |
57 |
gezelter |
2003 |
|
58 |
|
|
setCorrFuncType("FreqFluc Correlation Function"); |
59 |
|
|
setOutputName(getPrefix(dumpFilename_) + ".ffcorr"); |
60 |
|
|
|
61 |
|
|
} |
62 |
|
|
|
63 |
gezelter |
2004 |
RealType FreqFlucCorrFunc::calcCorrVal(int frame1, int frame2, |
64 |
|
|
StuntDouble* sd1, StuntDouble* sd2) { |
65 |
gezelter |
2003 |
|
66 |
|
|
Vector3d e1; |
67 |
|
|
Vector3d u1; |
68 |
|
|
Vector3d e2; |
69 |
|
|
Vector3d u2; |
70 |
|
|
|
71 |
|
|
e1 = sd1->getElectricField(frame1); |
72 |
|
|
|
73 |
|
|
if (sd1->isRigidBody()) { |
74 |
|
|
u1 = sd1->getA(frame1).getRow(2); |
75 |
|
|
} else { |
76 |
|
|
AtomType* at = static_cast<Atom*>(sd1)->getAtomType(); |
77 |
|
|
MultipoleAdapter ma = MultipoleAdapter(at); |
78 |
|
|
|
79 |
|
|
if (ma.isDipole()) { |
80 |
|
|
u1 = sd1->getDipole(frame1); |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
e2 = sd2->getElectricField(frame2); |
85 |
|
|
|
86 |
|
|
if (sd2->isRigidBody()) { |
87 |
|
|
u2 = sd2->getA(frame2).getRow(2); |
88 |
|
|
} else { |
89 |
|
|
AtomType* at = static_cast<Atom*>(sd2)->getAtomType(); |
90 |
|
|
MultipoleAdapter ma = MultipoleAdapter(at); |
91 |
|
|
|
92 |
|
|
if (ma.isDipole()) { |
93 |
|
|
u2 = sd2->getDipole(frame2); |
94 |
|
|
} |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
return (dot(u1, e1) - mean_) * (dot(u2, e2) - mean_); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
void FreqFlucCorrFunc::validateSelection(const SelectionManager& seleMan) { |
102 |
|
|
StuntDouble* sd; |
103 |
|
|
int i; |
104 |
|
|
for (sd = seleMan1_.beginSelected(i); sd != NULL; |
105 |
|
|
sd = seleMan1_.nextSelected(i)) { |
106 |
|
|
|
107 |
|
|
if (!sd->isRigidBody()) { |
108 |
|
|
|
109 |
|
|
AtomType* at = static_cast<Atom*>(sd)->getAtomType(); |
110 |
|
|
MultipoleAdapter ma = MultipoleAdapter(at); |
111 |
|
|
|
112 |
|
|
if (!ma.isDipole()) { |
113 |
|
|
sprintf(painCave.errMsg, |
114 |
|
|
"FreqFlucCorrFunc::validateSelection Error: selection is not a RigidBody or does\n" |
115 |
|
|
"\tnot have a dipole\n"); |
116 |
|
|
painCave.isFatal = 1; |
117 |
|
|
simError(); |
118 |
|
|
} |
119 |
|
|
} |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
void FreqFlucCorrFunc::preCorrelate() { |
124 |
|
|
mean_ = 0.0; |
125 |
|
|
RealType sum(0.0); |
126 |
|
|
int count(0); |
127 |
|
|
StuntDouble* sd1; |
128 |
|
|
Vector3d e1; |
129 |
|
|
Vector3d u1; |
130 |
|
|
int ii; |
131 |
|
|
std::cerr << "preCorrelating to compute mean values\n"; |
132 |
|
|
// dump files can be enormous, so read them in block-by-block: |
133 |
|
|
int nblocks = bsMan_->getNBlocks(); |
134 |
|
|
bool firsttime = true; |
135 |
|
|
for (int i = 0; i < nblocks; ++i) { |
136 |
|
|
bsMan_->loadBlock(i); |
137 |
|
|
assert(bsMan_->isBlockActive(i)); |
138 |
|
|
SnapshotBlock block1 = bsMan_->getSnapshotBlock(i); |
139 |
|
|
for (int j = block1.first; j < block1.second; ++j) { |
140 |
|
|
|
141 |
|
|
// go snapshot-by-snapshot through this block: |
142 |
|
|
Snapshot* snap = bsMan_->getSnapshot(j); |
143 |
|
|
|
144 |
|
|
// update the positions and velocities of the atoms belonging |
145 |
|
|
// to rigid bodies: |
146 |
|
|
|
147 |
|
|
updateFrame(j); |
148 |
|
|
for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL; sd1 = seleMan1_.nextSelected(ii)) { |
149 |
|
|
e1 = sd1->getElectricField(j); |
150 |
|
|
|
151 |
|
|
if (sd1->isRigidBody()) { |
152 |
|
|
u1 = sd1->getA(j).getRow(2); |
153 |
|
|
} else { |
154 |
|
|
AtomType* at = static_cast<Atom*>(sd1)->getAtomType(); |
155 |
|
|
MultipoleAdapter ma = MultipoleAdapter(at); |
156 |
|
|
|
157 |
|
|
if (ma.isDipole()) { |
158 |
|
|
u1 = sd1->getDipole(j); |
159 |
|
|
} |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
RealType value = dot(u1, e1); |
163 |
|
|
|
164 |
|
|
sum += value; |
165 |
|
|
count++; |
166 |
|
|
} |
167 |
|
|
} |
168 |
gezelter |
2004 |
bsMan_->unloadBlock(i); |
169 |
gezelter |
2003 |
} |
170 |
|
|
|
171 |
|
|
mean_ = sum / RealType(count); |
172 |
|
|
std::cerr << "done with preCorrelation\n"; |
173 |
|
|
} |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
|