ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/brains/Snapshot.cpp
Revision: 3102
Committed: Fri Dec 29 21:43:18 2006 UTC (17 years, 8 months ago) by gezelter
File size: 5843 byte(s)
Log Message:
Adding the ability to compute Center of Mass properties on
reading in a dump file.  DumpReader must be told if it needs
to do this, however.

File Contents

# User Rev Content
1 gezelter 2204 /*
2 gezelter 1930 * 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 2204 /**
43     * @file Snapshot.cpp
44     * @author tlin
45     * @date 11/11/2004
46     * @time 10:56am
47     * @version 1.0
48     */
49 gezelter 1930
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 2204 void Snapshot::setHmat(const Mat3x3d& m) {
57 gezelter 1930 hmat_ = m;
58     invHmat_ = hmat_.inverse();
59    
60     //prepare fortran Hmat
61 tim 2759 RealType fortranHmat[9];
62     RealType fortranInvHmat[9];
63 gezelter 1930 hmat_.getArray(fortranHmat);
64     invHmat_.getArray(fortranInvHmat);
65    
66     //determine whether the box is orthoTolerance or not
67     int oldOrthoRhombic = orthoRhombic_;
68    
69 tim 2759 RealType smallDiag = fabs(hmat_(0, 0));
70 gezelter 1930 if(smallDiag > fabs(hmat_(1, 1))) smallDiag = fabs(hmat_(1, 1));
71     if(smallDiag > fabs(hmat_(2, 2))) smallDiag = fabs(hmat_(2, 2));
72 gezelter 2970 RealType tol = smallDiag * orthoTolerance_;
73 gezelter 1930
74     orthoRhombic_ = 1;
75    
76     for (int i = 0; i < 3; i++ ) {
77 gezelter 2204 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 gezelter 1930 }
86    
87     if( oldOrthoRhombic != orthoRhombic_ ){
88    
89 gezelter 2204 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 gezelter 2593 "\tThis is usually a good thing, but if you want the\n"
94 gezelter 2204 "\tNon-Orthorhombic computations, make the orthoBoxTolerance\n"
95     "\tvariable ( currently set to %G ) smaller.\n",
96 gezelter 2970 orthoTolerance_);
97 gezelter 2204 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 gezelter 2593 "\tNPTf integration. If you want to live on the edge with\n"
106 gezelter 2204 "\tthe Orthorhombic computations, make the orthoBoxTolerance\n"
107     "\tvariable ( currently set to %G ) larger.\n",
108 gezelter 2970 orthoTolerance_);
109 gezelter 2204 painCave.severity = OOPSE_WARNING;
110     simError();
111     }
112 gezelter 1930 }
113    
114     //notify fortran simulation box has changed
115     setFortranBox(fortranHmat, fortranInvHmat, &orthoRhombic_);
116 gezelter 2204 }
117 gezelter 1930
118    
119 gezelter 2204 void Snapshot::wrapVector(Vector3d& pos) {
120 gezelter 1930
121     int i;
122     Vector3d scaled;
123    
124     if( !orthoRhombic_ ){
125    
126 gezelter 2204 // calc the scaled coordinates.
127     scaled = invHmat_* pos;
128 gezelter 1930
129 gezelter 2204 // wrap the scaled coordinates
130     for (i = 0; i < 3; ++i) {
131     scaled[i] -= roundMe(scaled[i]);
132     }
133 gezelter 1930
134 gezelter 2204 // calc the wrapped real coordinates from the wrapped scaled coordinates
135     pos = hmat_ * scaled;
136 gezelter 1930
137     } else {//if it is orthoRhombic, we could improve efficiency by only caculating the diagonal element
138    
139 gezelter 2204 // calc the scaled coordinates.
140     for (i=0; i<3; i++) {
141     scaled[i] = pos[i] * invHmat_(i, i);
142     }
143 gezelter 1930
144 gezelter 2204 // wrap the scaled coordinates
145     for (i = 0; i < 3; ++i) {
146     scaled[i] -= roundMe(scaled[i]);
147     }
148 gezelter 1930
149 gezelter 2204 // 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 gezelter 1930
154     }
155    
156 gezelter 2204 }
157 gezelter 1930
158 gezelter 3102 Vector3d Snapshot::getCOM() {
159     if( !hasCOM_ ) {
160     sprintf( painCave.errMsg, "COM was requested before COM was computed!\n");
161     painCave.severity = OOPSE_ERROR;
162     simError();
163     }
164     return COM_;
165     }
166    
167     Vector3d Snapshot::getCOMvel() {
168     if( !hasCOM_ ) {
169     sprintf( painCave.errMsg, "COMvel was requested before COM was computed!\n");
170     painCave.severity = OOPSE_ERROR;
171     simError();
172     }
173     return COMvel_;
174     }
175    
176     Vector3d Snapshot::getCOMw() {
177     if( !hasCOM_ ) {
178     sprintf( painCave.errMsg, "COMw was requested before COM was computed!\n");
179     painCave.severity = OOPSE_ERROR;
180     simError();
181     }
182     return COMw_;
183     }
184    
185 gezelter 1930 }
186