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. Acknowledgement of the program authors must be made in any |
10 |
* publication of scientific results based in part on use of the |
11 |
* program. An acceptable form of acknowledgement is citation of |
12 |
* the article in which the program was described (Matthew |
13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
* |
18 |
* 2. Redistributions of source code must retain the above copyright |
19 |
* notice, this list of conditions and the following disclaimer. |
20 |
* |
21 |
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
* notice, this list of conditions and the following disclaimer in the |
23 |
* documentation and/or other materials provided with the |
24 |
* distribution. |
25 |
* |
26 |
* This software is provided "AS IS," without a warranty of any |
27 |
* kind. All express or implied conditions, representations and |
28 |
* warranties, including any implied warranty of merchantability, |
29 |
* fitness for a particular purpose or non-infringement, are hereby |
30 |
* excluded. The University of Notre Dame and its licensors shall not |
31 |
* be liable for any damages suffered by licensee as a result of |
32 |
* using, modifying or distributing the software or its |
33 |
* derivatives. In no event will the University of Notre Dame or its |
34 |
* licensors be liable for any lost revenue, profit or data, or for |
35 |
* direct, indirect, special, consequential, incidental or punitive |
36 |
* damages, however caused and regardless of the theory of liability, |
37 |
* arising out of the use of or inability to use software, even if the |
38 |
* University of Notre Dame has been advised of the possibility of |
39 |
* such damages. |
40 |
*/ |
41 |
|
42 |
/** |
43 |
* @file Snapshot.cpp |
44 |
* @author tlin |
45 |
* @date 11/11/2004 |
46 |
* @time 10:56am |
47 |
* @version 1.0 |
48 |
*/ |
49 |
|
50 |
#include "brains/Snapshot.hpp" |
51 |
#include "utils/NumericConstant.hpp" |
52 |
#include "utils/simError.h" |
53 |
#include "utils/Utility.hpp" |
54 |
namespace oopse { |
55 |
|
56 |
void Snapshot::setHmat(const Mat3x3d& m) { |
57 |
hmat_ = m; |
58 |
invHmat_ = hmat_.inverse(); |
59 |
|
60 |
//prepare fortran Hmat |
61 |
RealType fortranHmat[9]; |
62 |
RealType fortranInvHmat[9]; |
63 |
hmat_.getArray(fortranHmat); |
64 |
invHmat_.getArray(fortranInvHmat); |
65 |
|
66 |
//determine whether the box is orthoTolerance or not |
67 |
int oldOrthoRhombic = orthoRhombic_; |
68 |
|
69 |
RealType smallDiag = fabs(hmat_(0, 0)); |
70 |
if(smallDiag > fabs(hmat_(1, 1))) smallDiag = fabs(hmat_(1, 1)); |
71 |
if(smallDiag > fabs(hmat_(2, 2))) smallDiag = fabs(hmat_(2, 2)); |
72 |
RealType tol = smallDiag * orthoTolerance_; |
73 |
|
74 |
orthoRhombic_ = 1; |
75 |
|
76 |
for (int i = 0; i < 3; i++ ) { |
77 |
for (int j = 0 ; j < 3; j++) { |
78 |
if (i != j) { |
79 |
if (orthoRhombic_) { |
80 |
if ( fabs(hmat_(i, j)) >= tol) |
81 |
orthoRhombic_ = 0; |
82 |
} |
83 |
} |
84 |
} |
85 |
} |
86 |
|
87 |
if( oldOrthoRhombic != orthoRhombic_ ){ |
88 |
|
89 |
if( orthoRhombic_ ) { |
90 |
sprintf( painCave.errMsg, |
91 |
"OOPSE is switching from the default Non-Orthorhombic\n" |
92 |
"\tto the faster Orthorhombic periodic boundary computations.\n" |
93 |
"\tThis is usually a good thing, but if you want the\n" |
94 |
"\tNon-Orthorhombic computations, make the orthoBoxTolerance\n" |
95 |
"\tvariable ( currently set to %G ) smaller.\n", |
96 |
orthoTolerance_); |
97 |
painCave.severity = OOPSE_INFO; |
98 |
simError(); |
99 |
} |
100 |
else { |
101 |
sprintf( painCave.errMsg, |
102 |
"OOPSE is switching from the faster Orthorhombic to the more\n" |
103 |
"\tflexible Non-Orthorhombic periodic boundary computations.\n" |
104 |
"\tThis is usually because the box has deformed under\n" |
105 |
"\tNPTf integration. If you want to live on the edge with\n" |
106 |
"\tthe Orthorhombic computations, make the orthoBoxTolerance\n" |
107 |
"\tvariable ( currently set to %G ) larger.\n", |
108 |
orthoTolerance_); |
109 |
painCave.severity = OOPSE_WARNING; |
110 |
simError(); |
111 |
} |
112 |
} |
113 |
|
114 |
//notify fortran simulation box has changed |
115 |
setFortranBox(fortranHmat, fortranInvHmat, &orthoRhombic_); |
116 |
} |
117 |
|
118 |
|
119 |
void Snapshot::wrapVector(Vector3d& pos) { |
120 |
|
121 |
int i; |
122 |
Vector3d scaled; |
123 |
|
124 |
if( !orthoRhombic_ ){ |
125 |
|
126 |
// calc the scaled coordinates. |
127 |
scaled = invHmat_* pos; |
128 |
|
129 |
// wrap the scaled coordinates |
130 |
for (i = 0; i < 3; ++i) { |
131 |
scaled[i] -= roundMe(scaled[i]); |
132 |
} |
133 |
|
134 |
// calc the wrapped real coordinates from the wrapped scaled coordinates |
135 |
pos = hmat_ * scaled; |
136 |
|
137 |
} else {//if it is orthoRhombic, we could improve efficiency by only caculating the diagonal element |
138 |
|
139 |
// calc the scaled coordinates. |
140 |
for (i=0; i<3; i++) { |
141 |
scaled[i] = pos[i] * invHmat_(i, i); |
142 |
} |
143 |
|
144 |
// wrap the scaled coordinates |
145 |
for (i = 0; i < 3; ++i) { |
146 |
scaled[i] -= roundMe(scaled[i]); |
147 |
} |
148 |
|
149 |
// calc the wrapped real coordinates from the wrapped scaled coordinates |
150 |
for (i=0; i<3; i++) { |
151 |
pos[i] = scaled[i] * hmat_(i, i); |
152 |
} |
153 |
|
154 |
} |
155 |
|
156 |
} |
157 |
|
158 |
} |
159 |
|