ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/Snapshot.cpp
(Generate patch)

Comparing:
trunk/src/brains/Snapshot.cpp (file contents), Revision 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
branches/development/src/brains/Snapshot.cpp (file contents), Revision 1715 by gezelter, Tue May 22 21:55:31 2012 UTC

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

Comparing:
trunk/src/brains/Snapshot.cpp (property svn:keywords), Revision 246 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
branches/development/src/brains/Snapshot.cpp (property svn:keywords), Revision 1715 by gezelter, Tue May 22 21:55:31 2012 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines