ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/dynamicProps/FreqFlucCorrFunc.cpp
Revision: 2003
Committed: Sun Jun 1 19:28:44 2014 UTC (11 years, 3 months ago) by gezelter
File size: 6015 byte(s)
Log Message:
Added Frequency Fluctuation Correlation Function

File Contents

# User Rev Content
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     FreqFlucCorrFunc::FreqFlucCorrFunc(SimInfo* info, const std::string& filename,
50     const std::string& sele1, const std::string& sele2,
51     long long int memSize)
52     : ParticleTimeCorrFunc(info, filename, sele1, sele2, DataStorage::dslElectricField |
53     DataStorage::dslAmat | DataStorage::dslDipole, memSize){
54    
55     setCorrFuncType("FreqFluc Correlation Function");
56     setOutputName(getPrefix(dumpFilename_) + ".ffcorr");
57    
58     }
59    
60     RealType FreqFlucCorrFunc::calcCorrVal(int frame1, int frame2, StuntDouble* sd1, StuntDouble* sd2) {
61    
62     Vector3d e1;
63     Vector3d u1;
64     Vector3d e2;
65     Vector3d u2;
66    
67     e1 = sd1->getElectricField(frame1);
68    
69     if (sd1->isRigidBody()) {
70     u1 = sd1->getA(frame1).getRow(2);
71     } else {
72     AtomType* at = static_cast<Atom*>(sd1)->getAtomType();
73     MultipoleAdapter ma = MultipoleAdapter(at);
74    
75     if (ma.isDipole()) {
76     u1 = sd1->getDipole(frame1);
77     }
78     }
79    
80     e2 = sd2->getElectricField(frame2);
81    
82     if (sd2->isRigidBody()) {
83     u2 = sd2->getA(frame2).getRow(2);
84     } else {
85     AtomType* at = static_cast<Atom*>(sd2)->getAtomType();
86     MultipoleAdapter ma = MultipoleAdapter(at);
87    
88     if (ma.isDipole()) {
89     u2 = sd2->getDipole(frame2);
90     }
91     }
92    
93     return (dot(u1, e1) - mean_) * (dot(u2, e2) - mean_);
94     }
95    
96    
97     void FreqFlucCorrFunc::validateSelection(const SelectionManager& seleMan) {
98     StuntDouble* sd;
99     int i;
100     for (sd = seleMan1_.beginSelected(i); sd != NULL;
101     sd = seleMan1_.nextSelected(i)) {
102    
103     if (!sd->isRigidBody()) {
104    
105     AtomType* at = static_cast<Atom*>(sd)->getAtomType();
106     MultipoleAdapter ma = MultipoleAdapter(at);
107    
108     if (!ma.isDipole()) {
109     sprintf(painCave.errMsg,
110     "FreqFlucCorrFunc::validateSelection Error: selection is not a RigidBody or does\n"
111     "\tnot have a dipole\n");
112     painCave.isFatal = 1;
113     simError();
114     }
115     }
116     }
117     }
118    
119     void FreqFlucCorrFunc::preCorrelate() {
120     mean_ = 0.0;
121     RealType sum(0.0);
122     int count(0);
123     StuntDouble* sd1;
124     Vector3d e1;
125     Vector3d u1;
126     int ii;
127     std::cerr << "preCorrelating to compute mean values\n";
128     // dump files can be enormous, so read them in block-by-block:
129     int nblocks = bsMan_->getNBlocks();
130     bool firsttime = true;
131     for (int i = 0; i < nblocks; ++i) {
132     bsMan_->loadBlock(i);
133     assert(bsMan_->isBlockActive(i));
134     SnapshotBlock block1 = bsMan_->getSnapshotBlock(i);
135     for (int j = block1.first; j < block1.second; ++j) {
136    
137     // go snapshot-by-snapshot through this block:
138     Snapshot* snap = bsMan_->getSnapshot(j);
139    
140     // update the positions and velocities of the atoms belonging
141     // to rigid bodies:
142    
143     updateFrame(j);
144     for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL; sd1 = seleMan1_.nextSelected(ii)) {
145     e1 = sd1->getElectricField(j);
146    
147     if (sd1->isRigidBody()) {
148     u1 = sd1->getA(j).getRow(2);
149     } else {
150     AtomType* at = static_cast<Atom*>(sd1)->getAtomType();
151     MultipoleAdapter ma = MultipoleAdapter(at);
152    
153     if (ma.isDipole()) {
154     u1 = sd1->getDipole(j);
155     }
156     }
157    
158     RealType value = dot(u1, e1);
159    
160     sum += value;
161     count++;
162     }
163     }
164     }
165    
166     mean_ = sum / RealType(count);
167     std::cerr << "done with preCorrelation\n";
168     }
169     }
170    
171