1 |
gezelter |
507 |
/* |
2 |
gezelter |
246 |
* 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 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
10 |
gezelter |
246 |
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
gezelter |
246 |
* 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 |
gezelter |
1390 |
* |
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, 24107 (2008). |
39 |
gezelter |
1665 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
gezelter |
246 |
*/ |
42 |
|
|
|
43 |
gezelter |
507 |
/** |
44 |
|
|
* @file Snapshot.cpp |
45 |
|
|
* @author tlin |
46 |
|
|
* @date 11/11/2004 |
47 |
|
|
* @time 10:56am |
48 |
|
|
* @version 1.0 |
49 |
|
|
*/ |
50 |
gezelter |
246 |
|
51 |
|
|
#include "brains/Snapshot.hpp" |
52 |
|
|
#include "utils/NumericConstant.hpp" |
53 |
|
|
#include "utils/simError.h" |
54 |
|
|
#include "utils/Utility.hpp" |
55 |
jmarr |
1401 |
#include <cstdio> |
56 |
|
|
|
57 |
gezelter |
1390 |
namespace OpenMD { |
58 |
gezelter |
246 |
|
59 |
gezelter |
507 |
void Snapshot::setHmat(const Mat3x3d& m) { |
60 |
gezelter |
246 |
hmat_ = m; |
61 |
|
|
invHmat_ = hmat_.inverse(); |
62 |
|
|
|
63 |
|
|
//prepare fortran Hmat |
64 |
tim |
963 |
RealType fortranHmat[9]; |
65 |
|
|
RealType fortranInvHmat[9]; |
66 |
gezelter |
246 |
hmat_.getArray(fortranHmat); |
67 |
|
|
invHmat_.getArray(fortranInvHmat); |
68 |
|
|
|
69 |
|
|
//determine whether the box is orthoTolerance or not |
70 |
|
|
int oldOrthoRhombic = orthoRhombic_; |
71 |
|
|
|
72 |
tim |
963 |
RealType smallDiag = fabs(hmat_(0, 0)); |
73 |
gezelter |
246 |
if(smallDiag > fabs(hmat_(1, 1))) smallDiag = fabs(hmat_(1, 1)); |
74 |
|
|
if(smallDiag > fabs(hmat_(2, 2))) smallDiag = fabs(hmat_(2, 2)); |
75 |
gezelter |
1021 |
RealType tol = smallDiag * orthoTolerance_; |
76 |
gezelter |
246 |
|
77 |
|
|
orthoRhombic_ = 1; |
78 |
|
|
|
79 |
|
|
for (int i = 0; i < 3; i++ ) { |
80 |
gezelter |
507 |
for (int j = 0 ; j < 3; j++) { |
81 |
|
|
if (i != j) { |
82 |
|
|
if (orthoRhombic_) { |
83 |
|
|
if ( fabs(hmat_(i, j)) >= tol) |
84 |
|
|
orthoRhombic_ = 0; |
85 |
|
|
} |
86 |
|
|
} |
87 |
|
|
} |
88 |
gezelter |
246 |
} |
89 |
|
|
|
90 |
|
|
if( oldOrthoRhombic != orthoRhombic_ ){ |
91 |
|
|
|
92 |
gezelter |
507 |
if( orthoRhombic_ ) { |
93 |
|
|
sprintf( painCave.errMsg, |
94 |
gezelter |
1390 |
"OpenMD is switching from the default Non-Orthorhombic\n" |
95 |
gezelter |
507 |
"\tto the faster Orthorhombic periodic boundary computations.\n" |
96 |
gezelter |
890 |
"\tThis is usually a good thing, but if you want the\n" |
97 |
gezelter |
507 |
"\tNon-Orthorhombic computations, make the orthoBoxTolerance\n" |
98 |
|
|
"\tvariable ( currently set to %G ) smaller.\n", |
99 |
gezelter |
1021 |
orthoTolerance_); |
100 |
gezelter |
1390 |
painCave.severity = OPENMD_INFO; |
101 |
gezelter |
507 |
simError(); |
102 |
|
|
} |
103 |
|
|
else { |
104 |
|
|
sprintf( painCave.errMsg, |
105 |
gezelter |
1390 |
"OpenMD is switching from the faster Orthorhombic to the more\n" |
106 |
gezelter |
507 |
"\tflexible Non-Orthorhombic periodic boundary computations.\n" |
107 |
|
|
"\tThis is usually because the box has deformed under\n" |
108 |
gezelter |
890 |
"\tNPTf integration. If you want to live on the edge with\n" |
109 |
gezelter |
507 |
"\tthe Orthorhombic computations, make the orthoBoxTolerance\n" |
110 |
|
|
"\tvariable ( currently set to %G ) larger.\n", |
111 |
gezelter |
1021 |
orthoTolerance_); |
112 |
gezelter |
1390 |
painCave.severity = OPENMD_WARNING; |
113 |
gezelter |
507 |
simError(); |
114 |
|
|
} |
115 |
gezelter |
246 |
} |
116 |
|
|
|
117 |
|
|
//notify fortran simulation box has changed |
118 |
gezelter |
1550 |
// setFortranBox(fortranHmat, fortranInvHmat, &orthoRhombic_); |
119 |
gezelter |
507 |
} |
120 |
gezelter |
246 |
|
121 |
|
|
|
122 |
gezelter |
1568 |
void Snapshot::wrapVector(Vector3d& pos) { |
123 |
gezelter |
1562 |
|
124 |
|
|
Vector3d scaled = scaleVector(pos); |
125 |
gezelter |
1568 |
|
126 |
gezelter |
1562 |
for (int i = 0; i < 3; i++) |
127 |
|
|
scaled[i] -= roundMe(scaled[i]); |
128 |
gezelter |
246 |
|
129 |
gezelter |
1562 |
if( !orthoRhombic_ ) |
130 |
gezelter |
507 |
pos = hmat_ * scaled; |
131 |
gezelter |
1562 |
else { |
132 |
gezelter |
246 |
|
133 |
gezelter |
507 |
// calc the wrapped real coordinates from the wrapped scaled coordinates |
134 |
gezelter |
1562 |
for (int i=0; i<3; i++) { |
135 |
gezelter |
507 |
pos[i] = scaled[i] * hmat_(i, i); |
136 |
gezelter |
1540 |
} |
137 |
gezelter |
246 |
} |
138 |
gezelter |
507 |
} |
139 |
gezelter |
246 |
|
140 |
gezelter |
1562 |
inline Vector3d Snapshot::scaleVector(Vector3d& pos) { |
141 |
|
|
|
142 |
|
|
Vector3d scaled; |
143 |
|
|
|
144 |
|
|
if( !orthoRhombic_ ) |
145 |
|
|
scaled = invHmat_* pos; |
146 |
|
|
else { |
147 |
|
|
// calc the scaled coordinates. |
148 |
|
|
for (int i=0; i<3; i++) |
149 |
|
|
scaled[i] = pos[i] * invHmat_(i, i); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
return scaled; |
153 |
|
|
} |
154 |
|
|
|
155 |
gezelter |
1104 |
Vector3d Snapshot::getCOM() { |
156 |
|
|
if( !hasCOM_ ) { |
157 |
|
|
sprintf( painCave.errMsg, "COM was requested before COM was computed!\n"); |
158 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
159 |
gezelter |
1104 |
simError(); |
160 |
|
|
} |
161 |
|
|
return COM_; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
Vector3d Snapshot::getCOMvel() { |
165 |
|
|
if( !hasCOM_ ) { |
166 |
|
|
sprintf( painCave.errMsg, "COMvel was requested before COM was computed!\n"); |
167 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
168 |
gezelter |
1104 |
simError(); |
169 |
|
|
} |
170 |
|
|
return COMvel_; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
Vector3d Snapshot::getCOMw() { |
174 |
|
|
if( !hasCOM_ ) { |
175 |
|
|
sprintf( painCave.errMsg, "COMw was requested before COM was computed!\n"); |
176 |
gezelter |
1390 |
painCave.severity = OPENMD_ERROR; |
177 |
gezelter |
1104 |
simError(); |
178 |
|
|
} |
179 |
|
|
return COMw_; |
180 |
|
|
} |
181 |
gezelter |
246 |
} |
182 |
|
|
|