OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48/**
49 * @file Vector3.hpp
50 * @author Teng Lin
51 * @date 09/14/2004
52 * @version 1.0
53 */
54
55#ifndef MATH_VECTOR3_HPP
56#define MATH_VECTOR3_HPP
57
58#include <cassert>
59#include <cmath>
60
61#include "Vector.hpp"
62
63namespace OpenMD {
64
65 /**
66 * @class Vector3 Vector3.hpp "math/Vector3.hpp"
67 * @brief
68 */
69 template<typename Real>
70 class Vector3 : public Vector<Real, 3> {
71 public:
72 using ElemType = Real;
73 using ElemPoinerType = Real*;
74
75 Vector3() : Vector<Real, 3>() {}
76
77 /** Constructs and initializes a Vector3 from x, y, z coordinates */
78 inline Vector3(Real x, Real y, Real z) {
79 this->data_[0] = x;
80 this->data_[1] = y;
81 this->data_[2] = z;
82 }
83
84 /** Constructs and initializes from an array*/
85 inline Vector3(Real* array) : Vector<Real, 3>(array) {}
86
87 inline Vector3(const Vector<Real, 3>& v) : Vector<Real, 3>(v) {}
88
89 inline Vector3<Real>& operator=(const Vector<Real, 3>& v) {
90 if (this == &v) { return *this; }
92 return *this;
93 }
94
95 /**
96 * Returns reference of the first element of Vector3.
97 * @return reference of the first element of Vector3
98 */
99 inline Real& x() { return this->data_[0]; }
100
101 /**
102 * Returns the first element of Vector3.
103 * @return the first element of Vector3
104 */
105 inline Real x() const { return this->data_[0]; }
106
107 /**
108 * Returns reference of the second element of Vector3.
109 * @return reference of the second element of Vector3
110 */
111 inline Real& y() { return this->data_[1]; }
112
113 /**
114 * Returns the second element of Vector3.
115 * @return c the second element of Vector3
116 */
117 inline Real y() const { return this->data_[1]; }
118
119 /**
120 * Returns reference of the third element of Vector3.
121 * @return reference of the third element of Vector3
122 */
123 inline Real& z() { return this->data_[2]; }
124
125 /**
126 * Returns the third element of Vector3.
127 * @return f the third element of Vector3
128 */
129 inline Real z() const { return this->data_[2]; }
130 };
131
132 /**
133 * Returns the cross product of two Vectors
134 * @param v1 first vector
135 * @param v2 second vector
136 * @return the cross product of v1 and v2
137 */
138 template<typename Real>
139 inline Vector3<Real> cross(const Vector3<Real>& v1, const Vector3<Real>& v2) {
140 Vector3<Real> result;
141
142 result.x() = v1.y() * v2.z() - v1.z() * v2.y();
143 result.y() = v1.z() * v2.x() - v1.x() * v2.z();
144 result.z() = v1.x() * v2.y() - v1.y() * v2.x();
145
146 return result;
147 }
148
149 /**
150 * Returns the linear indexing for integer vectors. Compare to
151 * Rapaport's VLinear
152 *
153 * @param p first vector
154 * @param s second vector
155 */
156 template<typename Real>
157 inline Real Vlinear(const Vector3<Real>& p, const Vector3<Real>& s) {
158 return (p.z() * s.y() + p.y()) * s.x() + p.x();
159 }
160
161 using Vector3i = Vector3<int>;
162
163 using Vector3d = Vector3<RealType>;
164
165 const Vector3d V3Zero(0.0, 0.0, 0.0);
166 const Vector3d V3X(1.0, 0.0, 0.0);
167 const Vector3d V3Y(0.0, 1.0, 0.0);
168 const Vector3d V3Z(0.0, 0.0, 1.0);
169} // namespace OpenMD
170
171#endif
Real z() const
Returns the third element of Vector3.
Definition Vector3.hpp:129
Vector3(Real x, Real y, Real z)
Constructs and initializes a Vector3 from x, y, z coordinates.
Definition Vector3.hpp:78
Real y() const
Returns the second element of Vector3.
Definition Vector3.hpp:117
Real x() const
Returns the first element of Vector3.
Definition Vector3.hpp:105
Vector3(Real *array)
Constructs and initializes from an array.
Definition Vector3.hpp:85
Fix length vector class.
Definition Vector.hpp:81
Vector< Real, Dim > & operator=(const Vector< Real, Dim > &v)
copy assignment operator
Definition Vector.hpp:96
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:139
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:114