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