OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Vector3.hpp
Go to the documentation of this file.
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/**
46 * @file Vector3.hpp
47 * @author Teng Lin
48 * @date 09/14/2004
49 * @version 1.0
50 */
51
52#ifndef MATH_VECTOR3_HPP
53#define MATH_VECTOR3_HPP
54
55#include <cassert>
56#include <cmath>
57
58#include "Vector.hpp"
59
60namespace OpenMD {
61
62 /**
63 * @class Vector3 Vector3.hpp "math/Vector3.hpp"
64 * @brief
65 */
66 template<typename Real>
67 class Vector3 : public Vector<Real, 3> {
68 public:
69 using ElemType = Real;
70 using ElemPoinerType = Real*;
71
73
74 /** Constructs and initializes a Vector3 from x, y, z coordinates */
75 inline Vector3(Real x, Real y, Real z) {
76 this->data_[0] = x;
77 this->data_[1] = y;
78 this->data_[2] = z;
79 }
80
81 /** Constructs and initializes from an array*/
82 inline Vector3(Real* array) : Vector<Real, 3>(array) {}
83
84 inline Vector3(const Vector<Real, 3>& v) : Vector<Real, 3>(v) {}
85
86 inline Vector3<Real>& operator=(const Vector<Real, 3>& v) {
87 if (this == &v) { return *this; }
89 return *this;
90 }
91
92 /**
93 * Returns reference of the first element of Vector3.
94 * @return reference of the first element of Vector3
95 */
96 inline Real& x() { return this->data_[0]; }
97
98 /**
99 * Returns the first element of Vector3.
100 * @return the first element of Vector3
101 */
102 inline Real x() const { return this->data_[0]; }
103
104 /**
105 * Returns reference of the second element of Vector3.
106 * @return reference of the second element of Vector3
107 */
108 inline Real& y() { return this->data_[1]; }
109
110 /**
111 * Returns the second element of Vector3.
112 * @return c the second element of Vector3
113 */
114 inline Real y() const { return this->data_[1]; }
115
116 /**
117 * Returns reference of the third element of Vector3.
118 * @return reference of the third element of Vector3
119 */
120 inline Real& z() { return this->data_[2]; }
121
122 /**
123 * Returns the third element of Vector3.
124 * @return f the third element of Vector3
125 */
126 inline Real z() const { return this->data_[2]; }
127 };
128
129 /**
130 * Returns the cross product of two Vectors
131 * @param v1 first vector
132 * @param v2 second vector
133 * @return the cross product of v1 and v2
134 */
135 template<typename Real>
136 inline Vector3<Real> cross(const Vector3<Real>& v1, const Vector3<Real>& v2) {
137 Vector3<Real> result;
138
139 result.x() = v1.y() * v2.z() - v1.z() * v2.y();
140 result.y() = v1.z() * v2.x() - v1.x() * v2.z();
141 result.z() = v1.x() * v2.y() - v1.y() * v2.x();
142
143 return result;
144 }
145
146 /**
147 * Returns the linear indexing for integer vectors. Compare to
148 * Rapaport's VLinear
149 *
150 * @param p first vector
151 * @param s second vector
152 */
153 template<typename Real>
154 inline Real Vlinear(const Vector3<Real>& p, const Vector3<Real>& s) {
155 return (p.z() * s.y() + p.y()) * s.x() + p.x();
156 }
157
158 using Vector3i = Vector3<int>;
159
160 using Vector3d = Vector3<RealType>;
161
162 const Vector3d V3Zero(0.0, 0.0, 0.0);
163 const Vector3d V3X(1.0, 0.0, 0.0);
164 const Vector3d V3Y(0.0, 1.0, 0.0);
165 const Vector3d V3Z(0.0, 0.0, 1.0);
166} // namespace OpenMD
167
168#endif
Real & z()
Returns reference of the third element of Vector3.
Definition Vector3.hpp:120
Real z() const
Returns the third element of Vector3.
Definition Vector3.hpp:126
Real & x()
Returns reference of the first element of Vector3.
Definition Vector3.hpp:96
Vector3(Real x, Real y, Real z)
Constructs and initializes a Vector3 from x, y, z coordinates.
Definition Vector3.hpp:75
Real y() const
Returns the second element of Vector3.
Definition Vector3.hpp:114
Real x() const
Returns the first element of Vector3.
Definition Vector3.hpp:102
Vector3(Real *array)
Constructs and initializes from an array.
Definition Vector3.hpp:82
Real & y()
Returns reference of the second element of Vector3.
Definition Vector3.hpp:108
Fix length vector class.
Definition Vector.hpp:78
Vector< Real, Dim > & operator=(const Vector< Real, Dim > &v)
copy assignment operator
Definition Vector.hpp:93
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.
Definition Vector3.hpp:136
std::size_t Vlinear(const Vector2< std::size_t > &p, const Vector2< std::size_t > &s)
Returns the linear indexing for size_t vectors.
Definition Vector2.hpp:111