ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/Snapshot.cpp
Revision: 1112
Committed: Wed Jan 3 20:47:00 2007 UTC (18 years, 4 months ago) by chuckv
Original Path: trunk/src/brains/Snapshot.cpp
File size: 5844 byte(s)
Log Message:
Changes to add thetacorr to dynamic props and fixes to radial rcorr.

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