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