ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/sequentialProps/ContactAngle2.cpp
Revision: 2073
Committed: Sat Mar 7 23:52:07 2015 UTC (10 years, 1 month ago) by gezelter
File size: 9372 byte(s)
Log Message:
added a skipToken function to StringTokenizer, and used this to 
remove some silly warnings on compilation. 

File Contents

# Content
1 /*
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 <algorithm>
44 #include <functional>
45 #include "applications/sequentialProps/ContactAngle2.hpp"
46 #include "utils/simError.h"
47 #include "io/DumpReader.hpp"
48 #include "primitives/Molecule.hpp"
49 #include "utils/NumericConstant.hpp"
50 #include "utils/PhysicalConstants.hpp"
51 #include "math/Eigenvalue.hpp"
52
53 namespace OpenMD {
54
55 ContactAngle2::ContactAngle2(SimInfo* info, const std::string& filename,
56 const std::string& sele, RealType solidZ,
57 RealType threshDens, RealType bufferLength,
58 int nrbins, int nzbins)
59 : SequentialAnalyzer(info, filename), solidZ_(solidZ),
60 threshDens_(threshDens), bufferLength_(bufferLength), nRBins_(nrbins),
61 nZBins_(nzbins), selectionScript_(sele), seleMan_(info),
62 evaluator_(info) {
63
64 setOutputName(getPrefix(filename) + ".ca2");
65
66 evaluator_.loadScriptString(sele);
67
68 if (!evaluator_.isDynamic()) {
69 seleMan_.setSelectionSet(evaluator_.evaluate());
70 }
71 }
72
73 void ContactAngle2::doFrame() {
74 StuntDouble* sd;
75 int i;
76
77 // set up the bins for density analysis
78
79 Mat3x3d hmat = info_->getSnapshotManager()->getCurrentSnapshot()->getHmat();
80 RealType len = std::min(hmat(0, 0), hmat(1, 1));
81 RealType zLen = hmat(2,2);
82
83 RealType dr = len / (RealType) nRBins_;
84 RealType dz = zLen / (RealType) nZBins_;
85
86 std::vector<std::vector<RealType> > histo;
87 histo.resize(nRBins_);
88 for (unsigned int i = 0; i < histo.size(); ++i){
89 histo[i].resize(nZBins_);
90 std::fill(histo[i].begin(), histo[i].end(), 0.0);
91 }
92
93 if (evaluator_.isDynamic()) {
94 seleMan_.setSelectionSet(evaluator_.evaluate());
95 }
96
97
98 RealType mtot = 0.0;
99 Vector3d com(V3Zero);
100 RealType mass;
101
102 for (sd = seleMan_.beginSelected(i); sd != NULL;
103 sd = seleMan_.nextSelected(i)) {
104 mass = sd->getMass();
105 mtot += mass;
106 com += sd->getPos() * mass;
107 }
108
109 com /= mtot;
110
111 // now that we have the centroid, we can make cylindrical density maps
112 Vector3d pos;
113 RealType r;
114 RealType z;
115
116 for (sd = seleMan_.beginSelected(i); sd != NULL;
117 sd = seleMan_.nextSelected(i)) {
118 pos = sd->getPos() - com;
119
120 // r goes from zero upwards
121 r = sqrt(pow(pos.x(), 2) + pow(pos.y(), 2));
122 // z is possibly symmetric around 0
123 z = pos.z();
124
125 int whichRBin = int(r / dr);
126 int whichZBin = int( (zLen/2.0 + z) / dz);
127
128 if ((whichRBin < int(nRBins_)) && (whichZBin >= 0) && (whichZBin < int(nZBins_))) {
129 histo[whichRBin][whichZBin] += sd->getMass();
130 }
131
132 }
133
134 for(unsigned int i = 0 ; i < histo.size(); ++i){
135
136 RealType rL = i * dr;
137 RealType rU = rL + dr;
138 RealType volSlice = NumericConstant::PI * dz * (( rU*rU ) - ( rL*rL ));
139
140 for (unsigned int j = 0; j < histo[i].size(); ++j) {
141 histo[i][j] *= PhysicalConstants::densityConvert / volSlice;
142 }
143 }
144
145 std::vector<Vector<RealType, 2> > points;
146 points.clear();
147
148 for (unsigned int j = 0; j < nZBins_; ++j) {
149
150 // The z coordinates were measured relative to the selection
151 // center of mass. However, we're interested in the elevation
152 // above the solid surface. Also, the binning was done around
153 // zero with enough bins to cover the zLength of the box:
154
155 RealType thez = com.z() - solidZ_ - zLen/2.0 + dz * (j + 0.5);
156 bool aboveThresh = false;
157 bool foundThresh = false;
158 int rloc = 0;
159
160 for (std::size_t i = 0; i < nRBins_; ++i) {
161
162 if (histo[i][j] >= threshDens_) aboveThresh = true;
163
164 if (aboveThresh && (histo[i][j] <= threshDens_)) {
165 rloc = i;
166 foundThresh = true;
167 aboveThresh = false;
168 }
169
170 }
171 if (foundThresh) {
172 Vector<RealType,2> point;
173 point[0] = dr*(rloc+0.5);
174 point[1] = thez;
175
176 if (thez > bufferLength_) {
177 points.push_back( point );
178 }
179 }
180 }
181
182 int numPoints = points.size();
183
184 // Compute the average of the data points.
185 Vector<RealType, 2> average = points[0];
186 int i0;
187 for (i0 = 1; i0 < numPoints; ++i0) {
188 average += points[i0];
189 }
190 RealType invNumPoints = ((RealType)1)/(RealType)numPoints;
191 average *= invNumPoints;
192
193 DynamicRectMatrix<RealType> mat(4, 4);
194 int row, col;
195 for (row = 0; row < 4; ++row) {
196 for (col = 0; col < 4; ++col){
197 mat(row,col) = 0.0;
198 }
199 }
200 for (int i = 0; i < numPoints; ++i) {
201 RealType x = points[i][0];
202 RealType y = points[i][1];
203 RealType x2 = x*x;
204 RealType y2 = y*y;
205 RealType xy = x*y;
206 RealType r2 = x2+y2;
207 RealType xr2 = x*r2;
208 RealType yr2 = y*r2;
209 RealType r4 = r2*r2;
210
211 mat(0,1) += x;
212 mat(0,2) += y;
213 mat(0,3) += r2;
214 mat(1,1) += x2;
215 mat(1,2) += xy;
216 mat(1,3) += xr2;
217 mat(2,2) += y2;
218 mat(2,3) += yr2;
219 mat(3,3) += r4;
220 }
221 mat(0,0) = (RealType)numPoints;
222
223 for (row = 0; row < 4; ++row) {
224 for (col = 0; col < row; ++col) {
225 mat(row,col) = mat(col,row);
226 }
227 }
228
229 for (row = 0; row < 4; ++row) {
230 for (col = 0; col < 4; ++col) {
231 mat(row,col) *= invNumPoints;
232 }
233 }
234
235 JAMA::Eigenvalue<RealType> eigensystem(mat);
236 DynamicRectMatrix<RealType> evects(4, 4);
237 DynamicVector<RealType> evals(4);
238
239 eigensystem.getRealEigenvalues(evals);
240 eigensystem.getV(evects);
241
242 DynamicVector<RealType> evector = evects.getColumn(0);
243 RealType inv = ((RealType)1)/evector[3]; // beware zero divide
244 RealType coeff[3];
245 for (row = 0; row < 3; ++row) {
246 coeff[row] = inv*evector[row];
247 }
248
249 Vector<RealType, 2> center;
250
251 center[0] = -((RealType)0.5)*coeff[1];
252 center[1] = -((RealType)0.5)*coeff[2];
253 RealType radius = sqrt(fabs(center[0]*center[0] + center[1]*center[1]
254 - coeff[0]));
255
256 int i1;
257 for (i1 = 0; i1 < 100; ++i1) {
258 // Update the iterates.
259 Vector<RealType, 2> current = center;
260
261 // Compute average L, dL/da, dL/db.
262 RealType lenAverage = (RealType)0;
263 Vector<RealType, 2> derLenAverage = Vector<RealType, 2>(0.0);
264 for (i0 = 0; i0 < numPoints; ++i0) {
265 Vector<RealType, 2> diff = points[i0] - center;
266 RealType length = diff.length();
267 if (length > 1e-6) {
268 lenAverage += length;
269 RealType invLength = ((RealType)1)/length;
270 derLenAverage -= invLength*diff;
271 }
272 }
273 lenAverage *= invNumPoints;
274 derLenAverage *= invNumPoints;
275
276 center = average + lenAverage*derLenAverage;
277 radius = lenAverage;
278
279 Vector<RealType, 2> diff = center - current;
280 if (fabs(diff[0]) <= 1e-6 && fabs(diff[1]) <= 1e-6) {
281 break;
282 }
283 }
284
285 RealType zCen = center[1];
286 RealType rDrop = radius;
287 RealType ca;
288
289 if (fabs(zCen) > rDrop) {
290 ca = 180.0;
291 } else {
292 ca = 90.0 + asin(zCen/rDrop)*(180.0/M_PI);
293 }
294
295 values_.push_back( ca );
296
297 }
298 }
299
300

Properties

Name Value
svn:executable *