ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/Snapshot.cpp
Revision: 1540
Committed: Mon Jan 17 21:34:36 2011 UTC (14 years, 3 months ago) by gezelter
File size: 5920 byte(s)
Log Message:
changes for new parallel architecture

File Contents

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

Properties

Name Value
svn:keywords Author Id Revision Date