OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Mesh.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 HYDRODYNAMICS_MESH_HPP_
49#define HYDRODYNAMICS_MESH_HPP_
50
51#include <config.h>
52
53#include <cassert>
54#include <string>
55#include <vector>
56
57#include "hydrodynamics/Shape.hpp"
59#include "math/Triangle.hpp"
60#include "math/Vector3.hpp"
61
62namespace OpenMD {
63 class Mesh : public Shape {
64 public:
65 Mesh() {};
66 virtual ~Mesh() {};
67 // punt on this one for now:
68 virtual bool isInterior(Vector3d pos) { return false; }
69 virtual std::pair<Vector3d, Vector3d> getBoundingBox() {
70 Vector3d bMax = facets_[0].vertex1();
71 Vector3d bMin = facets_[0].vertex1();
72
73 for (auto& t : facets_) {
74 for (int i = 0; i < 3; i++) {
75 bMax[i] = max(bMax[i], t.vertex1()[i]);
76 bMin[i] = min(bMin[i], t.vertex1()[i]);
77 bMax[i] = max(bMax[i], t.vertex2()[i]);
78 bMin[i] = min(bMin[i], t.vertex2()[i]);
79 bMax[i] = max(bMax[i], t.vertex3()[i]);
80 bMin[i] = min(bMin[i], t.vertex3()[i]);
81 }
82 }
83 return make_pair(bMax, bMin);
84 }
85 virtual bool hasAnalyticalSolution() { return false; }
86 virtual HydroProp* getHydroProp(RealType viscosity) {
87 HydroProp* props = new HydroProp();
88 props->setCenterOfResistance(V3Zero);
89 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
90 "Mesh was asked to return an analytic HydroProps.\n");
91 painCave.severity = OPENMD_ERROR;
92 painCave.isFatal = 1;
93 simError();
94 return props;
95 }
96 virtual Vector3d getOrigin() { return Vector3d(0.0); }
97 virtual bool isComposite() { return false; }
98 virtual bool isSpherical() { return false; }
99 virtual bool isMesh() { return true; }
100
101 void add(Triangle t) { facets_.push_back(t); }
102
103 void add(const Vector3d& vertex1, const Vector3d& vertex2,
104 const Vector3d& vertex3) {
105 Triangle t(vertex1, vertex2, vertex3);
106 facets_.push_back(t);
107 }
108
109 void addQuadrilateral(const Vector3d& p1, const Vector3d& p2,
110 const Vector3d& p3, const Vector3d& p4) {
111 add(p1, p2, p4);
112 add(p4, p2, p3);
113 };
114
115 void clear() { facets_.clear(); }
116
117 size_t size() { return facets_.size(); }
118
119 Mesh& scale(const Vector3d& s) {
120 double x, y, z;
121 x = ((s.x() != 0) ? s.x() : 1);
122 y = ((s.y() != 0) ? s.y() : 1);
123 z = ((s.z() != 0) ? s.z() : 1);
124 Vector3d _s(x, y, z);
125
126 Vector3d v1, v2, v3;
127 for (auto& t : facets_) {
128 v1.Vmul(t.vertex1(), _s);
129 v2.Vmul(t.vertex2(), _s);
130 v3.Vmul(t.vertex3(), _s);
131 t = {v1, v2, v3};
132 }
133 return *this;
134 }
135
136 Mesh& translate(const Vector3d& trans) {
137 Vector3d v1, v2, v3;
138 for (auto& t : facets_) {
139 v1 = t.vertex1() + trans;
140 v2 = t.vertex2() + trans;
141 v3 = t.vertex3() + trans;
142 t = {v1, v2, v3};
143 }
144 return *this;
145 }
146
147 Mesh& flipNormal() {
148 for (auto& t : facets_) {
149 t.flipNormal();
150 }
151 return *this;
152 }
153
154 void stlWrite(const std::string& filename, const std::string& name = "") {
155 std::ofstream file(filename);
156
157 file << "solid"
158 << " " << name << std::endl;
159 for (auto& t : facets_) {
160 file << "\t"
161 << "facet normal"
162 << " " << t.getUnitNormal() << std::endl;
163 file << "\t\t"
164 << "outer loop" << std::endl;
165 file << "\t\t\t"
166 << " "
167 << "vertex"
168 << " " << t.vertex1() << std::endl;
169 file << "\t\t\t"
170 << " "
171 << "vertex"
172 << " " << t.vertex2() << std::endl;
173 file << "\t\t\t"
174 << " "
175 << "vertex"
176 << " " << t.vertex3() << std::endl;
177 file << "\t\t"
178 << "endloop" << std::endl;
179 file << "\t"
180 << "endfacet" << std::endl;
181 }
182 file << "endsolid"
183 << " " << name << std::endl;
184
185 file.close();
186 }
187
188 Mesh& operator+=(const Mesh& m) {
189 facets_.insert(facets_.end(), (m.facets_).begin(), (m.facets_).end());
190 return *this;
191 }
192
193 inline void add(const Mesh& m1, const Mesh& m2) {
194 this->facets_.insert(this->facets_.end(), (m1.facets_).begin(),
195 (m1.facets_).end());
196 this->facets_.insert(this->facets_.end(), (m2.facets_).begin(),
197 (m2.facets_).end());
198 }
199
200 std::vector<Triangle> getFacets() { return facets_; }
201
202 private:
203 std::vector<Triangle> facets_;
204 };
205
206 inline Mesh operator+(const Mesh& m1, const Mesh& m2) {
207 Mesh m;
208 m.add(m1, m2);
209 return m;
210 }
211
212} // namespace OpenMD
213
214#endif /*HYDRODYNAMICS_MESH_HPP_*/
Container for information about the hydrodynamic behavior of objects interacting with surroundings.
Definition HydroProp.hpp:77
Triangle provides geometric data to OpenMD.
Definition Triangle.hpp:68
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
void Vmul(const Vector< Real, Dim > &v1, const Vector< Real, Dim > &v2)
Sets the elements of this vector to the multiplication of elements of two other vectors.
Definition Vector.hpp:288
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.