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