OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Triangle.hpp
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#ifndef MATH_FACET_HPP
49#define MATH_FACET_HPP
50
51#include <config.h>
52
53#include <vector>
54
56#include "math/Vector3.hpp"
58
59namespace OpenMD {
60
61 /**
62 * @class Triangle
63 *
64 * Triangle provides geometric data to OpenMD. Triangle includes
65 * information about the normal, centroid and the atoms
66 * that belong to this triangle.
67 */
68 class Triangle {
69 public:
70 Triangle();
71 Triangle(Vector3d P1, Vector3d P2, Vector3d P3);
72 virtual ~Triangle() {};
73
74 void setUnitNormal(Vector3d normal) {
75 unitnormal_ = normal;
76 HaveUnitNormal_ = true;
77 }
78
79 void addVertices(Vector3d P1, Vector3d P2, Vector3d P3);
80
81 void addVertexSD(StuntDouble* thisSD) { vertexSD_.push_back(thisSD); }
82
83 std::vector<StuntDouble*> getVertices() { return vertexSD_; }
84
85 void setArea(RealType area) {
86 area_ = area;
87 HaveArea_ = true;
88 }
89
90 Vector3d getNormal() {
91 if (HaveNormal_) {
92 return normal_;
93 } else {
94 return computeNormal();
95 }
96 }
97 Vector3d getUnitNormal() {
98 if (HaveUnitNormal_) {
99 return unitnormal_;
100 } else {
101 return computeUnitNormal();
102 }
103 }
104
105 void flipNormal() {
106 std::swap(vertices_[1], vertices_[2]);
107
108 // Compute some quantites like a,b,c
109 a_ = vertices_[0] - vertices_[1];
110 b_ = vertices_[0] - vertices_[2];
111 c_ = vertices_[1] - vertices_[2];
112
113 HaveUnitNormal_ = false;
114 HaveNormal_ = false;
115 }
116
117 RealType getArea() {
118 if (HaveArea_) {
119 return area_;
120 } else {
121 return computeArea();
122 }
123 }
124
125 RealType computeArea();
126 Vector3d computeNormal();
127 Vector3d computeCentroid();
128 Vector3d computeUnitNormal();
129
130 void setCentroid(Vector3d centroid) {
131 centroid_ = centroid;
132 HaveCentroid_ = true;
133 }
134
135 Vector3d getCentroid() {
136 if (HaveCentroid_) {
137 return centroid_;
138 } else {
139 return computeCentroid();
140 }
141 }
142
143 Vector3d getFacetVelocity() { return facetVelocity_; }
144
145 void setFacetVelocity(Vector3d facetVelocity) {
146 facetVelocity_ = facetVelocity;
147 }
148
149 void setFacetMass(RealType mass) { mass_ = mass; }
150
151 RealType getFacetMass() { return mass_; }
152
153 Vector3d vertex1() const { return vertices_[0]; }
154 Vector3d vertex2() const { return vertices_[1]; }
155 Vector3d vertex3() const { return vertices_[2]; }
156
157 RealType a() { return a_.length(); }
158
159 RealType b() { return b_.length(); }
160
161 RealType c() { return c_.length(); }
162
163 RealType getHydroLength() {
164 RealType a1 = a();
165 RealType b1 = b();
166 RealType c1 = c();
167 RealType t1 = a1 + b1 + c1;
168 RealType t4 = a1 + b1 - c1;
169
170 return 32.0 * c1 / log(t1 * t1 / t4 / t4);
171 }
172
173 RealType getIncircleRadius() { return 2.0 * getArea() / (a() + b() + c()); }
174
175 RealType getCircumcircleRadius() {
176 RealType a1 = a();
177 RealType b1 = b();
178 RealType c1 = c();
179 RealType t1 = a1 + b1 + c1;
180 RealType t2 = -a1 + b1 + c1;
181 RealType t3 = a1 - b1 + c1;
182 RealType t4 = a1 + b1 - c1;
183 return a1 * b1 * c1 / sqrt(t1 * t2 * t3 * t4);
184 }
185
186 Mat3x3d computeHydrodynamicTensor(RealType viscosity);
187
188 Vector3d cartesionToBarycentric(Vector3d p) {
189 RealType area = getArea();
190
191 Vector3d v0 = vertices_[0] - p;
192 Vector3d v1 = vertices_[1] - p;
193 Vector3d v2 = vertices_[2] - p;
194
195 RealType u = 0.5 * cross(v1, v2).length() / area;
196 RealType v = 0.5 * cross(v0, v2).length() / area;
197 RealType w = 0.5 * cross(v0, v1).length() / area;
198
199 return Vector3d(u, v, w);
200 }
201
202 Vector3d barycentricToCartesian(const Vector3d& barycentric) const {
203 return barycentric.x() * vertices_[0] + barycentric.y() * vertices_[1] +
204 barycentric.z() * vertices_[2];
205 }
206
207 private:
208 Mat3x3d hydro_tensor(const Vector3d& ri, const Vector3d& rj0,
209 const Vector3d& rj1, const Vector3d& rj2, RealType s,
210 RealType viscosity);
211
212 /* Local Indentity of vertex atoms in pos array*/
213 std::vector<StuntDouble*> vertexSD_;
214 Vector3d normal_;
215 Vector3d unitnormal_;
216 Vector3d centroid_;
217 Vector3d vertices_[3];
218 RealType area_;
219 RealType mass_;
220 Vector3d facetVelocity_;
221 // Length of triangle sides
222 Vector3d a_, b_, c_;
223 bool HaveArea_;
224 bool HaveNormal_;
225 bool HaveUnitNormal_;
226 bool HaveCentroid_;
227
228 }; // End class Triangle
229
230} // namespace OpenMD
231
232#endif // MATH_FACET_HPP
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Real & z()
Returns reference of the third element of Vector3.
Definition Vector3.hpp:123
Real & x()
Returns reference of the first element of Vector3.
Definition Vector3.hpp:99
Real & y()
Returns reference of the second element of Vector3.
Definition Vector3.hpp:111
Real length() const
Returns the length of this vector.
Definition Vector.hpp:397
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