OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
BoundaryElementModel.cpp
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#include "hydrodynamics/BoundaryElementModel.hpp"
49
50#include "hydrodynamics/Mesh.hpp"
52#include "math/LU.hpp"
54#include "math/integration/StrangFixCowperTriangleQuadrature.hpp"
55#include "math/integration/TriangleQuadrature.hpp"
56#include "utils/Constants.hpp"
57#include "utils/simError.h"
58
59namespace OpenMD {
60
61 BoundaryElementModel::BoundaryElementModel() : ApproximateModel() {}
62
63 std::size_t BoundaryElementModel::assignElements() {
64 if (shape_ != NULL) {
65 if (shape_->isMesh()) {
66 createTriangles(dynamic_cast<Mesh*>(shape_));
67 } else {
68 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
69 "BoundaryElementModel::assignElements Error: No mesh was "
70 "given as the shape\n");
71 painCave.severity = OPENMD_ERROR;
72 painCave.isFatal = 1;
73 simError();
74 }
75 return elements_.size();
76 }
77 return 0;
78 }
79
80 void BoundaryElementModel::createTriangles(Mesh* m) {
81 if (m != NULL) {
82 std::string name = m->getName();
83 std::vector<Triangle> facets = m->getFacets();
84 for (std::vector<Triangle>::iterator i = facets.begin();
85 i != facets.end(); ++i) {
86 HydrodynamicsElement currTri;
87 currTri.name = name;
88 currTri.pos = (*i).getCentroid();
89 currTri.t = (*i);
90 elements_.push_back(currTri);
91 }
92 }
93 }
94
95 void BoundaryElementModel::checkElement(std::size_t i) {}
96
97 void BoundaryElementModel::writeElements(std::ostream& os) {
98 std::vector<HydrodynamicsElement>::iterator iter;
99 std::string name = shape_->getName();
100 os << "solid"
101 << " " << name << std::endl;
102 for (iter = elements_.begin(); iter != elements_.end(); ++iter) {
103 Triangle t = iter->t;
104 Vector3d n = t.getUnitNormal();
105 Vector3d v1 = t.vertex1();
106 Vector3d v2 = t.vertex2();
107 Vector3d v3 = t.vertex3();
108 os << " "
109 << "facet normal"
110 << " " << n[0] << " " << n[1] << " " << n[2] << std::endl;
111 os << " "
112 << "outer loop" << std::endl;
113 os << " "
114 << " "
115 << "vertex"
116 << " " << v1[0] << " " << v1[1] << " " << v1[2] << std::endl;
117 os << " "
118 << " "
119 << "vertex"
120 << " " << v2[0] << " " << v2[1] << " " << v2[2] << std::endl;
121 os << " "
122 << " "
123 << "vertex"
124 << " " << v3[0] << " " << v3[1] << " " << v3[2] << std::endl;
125 os << " "
126 << "endloop" << std::endl;
127 os << " "
128 << "endfacet" << std::endl;
129 }
130 os << "endsolid"
131 << " " << name << std::endl;
132 }
133
134 Mat3x3d BoundaryElementModel::interactionTensor(const std::size_t i,
135 const std::size_t j,
136 const RealType viscosity) {
137 Mat3x3d B;
138 Mat3x3d I = SquareMatrix3<RealType>::identity();
139
140 StrangFixCowperTriangleQuadratureRule rule(6);
141
142 Vector3d centroid = elements_[i].pos;
143 Triangle t = elements_[j].t;
144
145 auto Tij = [&t, &centroid, &I, &viscosity](const Vector3d& p) {
146 // p are in barycentric coordinates
147 Vector3d r = t.barycentricToCartesian(p);
148 Vector3d ab = centroid - r;
149 RealType abl = ab.length();
150 Mat3x3d T;
151 T = (I + outProduct(ab, ab) / (abl * abl));
152 T /= (8.0 * Constants::PI * viscosity * abl);
153 return T;
154 };
155
156 B = TriangleQuadrature<RectMatrix<RealType, 3, 3>, RealType>::Integrate(
157 Tij, rule, 1.0);
158
159 centroid = elements_[j].pos;
160 t = elements_[i].t;
161
162 auto Tji = [&t, &centroid, &I, &viscosity](const Vector3d& p) {
163 // p are in barycentric coordinates
164 Vector3d r = t.barycentricToCartesian(p);
165 Vector3d ab = centroid - r;
166 RealType abl = ab.length();
167 Mat3x3d T;
168 T = (I + outProduct(ab, ab) / (abl * abl));
169 T /= (8.0 * Constants::PI * viscosity * abl);
170 return T;
171 };
172
173 B += TriangleQuadrature<RectMatrix<RealType, 3, 3>, RealType>::Integrate(
174 Tji, rule, 1.0);
175 B *= 0.5;
176 return B;
177 }
178} // namespace OpenMD
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.