OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
DLM.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include "DLM.hpp"
46
47namespace OpenMD {
48
49 void DLM::doRotate(StuntDouble* sd, Vector3d& ji, RealType dt) {
50 RealType dt2 = 0.5 * dt;
51 RealType angle;
52
53 RotMat3x3d A = sd->getA();
54 Mat3x3d I = sd->getI();
55
56 // use the angular velocities to propagate the rotation matrix a full time
57 // step
58 if (sd->isLinear()) {
59 int i = sd->linearAxis();
60 int j = (i + 1) % 3;
61 int k = (i + 2) % 3;
62
63 angle = dt2 * ji[j] / I(j, j);
64 rotateStep(k, i, angle, ji, A);
65
66 angle = dt * ji[k] / I(k, k);
67 rotateStep(i, j, angle, ji, A);
68
69 angle = dt2 * ji[j] / I(j, j);
70 rotateStep(k, i, angle, ji, A);
71
72 } else {
73 // rotate about the x-axis
74 angle = dt2 * ji[0] / I(0, 0);
75 rotateStep(1, 2, angle, ji, A);
76
77 // rotate about the y-axis
78 angle = dt2 * ji[1] / I(1, 1);
79 rotateStep(2, 0, angle, ji, A);
80
81 // rotate about the z-axis
82 angle = dt * ji[2] / I(2, 2);
83 rotateStep(0, 1, angle, ji, A);
84
85 // rotate about the y-axis
86 angle = dt2 * ji[1] / I(1, 1);
87 rotateStep(2, 0, angle, ji, A);
88
89 // rotate about the x-axis
90 angle = dt2 * ji[0] / I(0, 0);
91 rotateStep(1, 2, angle, ji, A);
92 }
93
94 sd->setA(A);
95 }
96
97 void DLM::rotateStep(int axes1, int axes2, RealType angle, Vector3d& ji,
98 RotMat3x3d& A) {
99 RealType sinAngle;
100 RealType cosAngle;
101 // RealType angleSqr;
102 // RealType angleSqrOver4;
103 // RealType top, bottom;
104
105 RotMat3x3d tempA(A); // initialize the tempA
106 Vector3d tempJ(0.0);
107
108 RotMat3x3d rot = RotMat3x3d::identity(); // initalize rot as a unit matrix
109
110 // use a small angle aproximation for sin and cosine
111
112 // angleSqr = angle * angle;
113 // angleSqrOver4 = angleSqr / 4.0;
114 // top = 1.0 - angleSqrOver4;
115 // bottom = 1.0 + angleSqrOver4;
116
117 // cosAngle = top / bottom;
118 // sinAngle = angle / bottom;
119
120 // or don't use the small angle approximation:
121 cosAngle = cos(angle);
122 sinAngle = sin(angle);
123 rot(axes1, axes1) = cosAngle;
124 rot(axes2, axes2) = cosAngle;
125
126 rot(axes1, axes2) = sinAngle;
127 rot(axes2, axes1) = -sinAngle;
128
129 // rotate the momentum acoording to: ji[] = rot[][] * ji[]
130 ji = rot * ji;
131
132 // This code comes from converting an algorithm detailed in
133 // J. Chem. Phys. 107 (15), pp. 5840-5851 by Dullweber,
134 // Leimkuhler and McLachlan (DLM) for use in our code.
135 // In Appendix A, the DLM paper has the change to the rotation
136 // matrix as: Q = Q * rot.transpose(), but our rotation matrix
137 // A is actually equivalent to Q.transpose(). This fact can be
138 // seen on page 5849 of the DLM paper where a lab frame
139 // dipole \mu_i(t) is expressed in terms of a body-fixed
140 // reference orientation, \bar{\mu_i} and the rotation matrix, Q:
141 // \mu_i(t) = Q * \bar{\mu_i}
142 // Our code computes lab frame vectors from body-fixed reference
143 // vectors using:
144 // v_{lab} = A.transpose() * v_{body}
145 // (See StuntDouble.hpp for confirmation of this fact).
146 //
147 // So, using the identity:
148 // (A * B).transpose() = B.transpose() * A.transpose(), we
149 // get the equivalent of Q = Q * rot.transpose() for our code to be:
150
151 A = rot * A;
152 }
153
154} // namespace OpenMD
static SquareMatrix< RealType, Dim > identity()
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.