Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
SpheroCylinder.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <shapes/SpheroCylinder.hpp>
23
24#include <utils/Vector.hpp>
25
26#include <cmath>
27
28namespace Shapes {
29
30void SpheroCylinder::calculate_dist(const Utils::Vector3d &pos, double &dist,
31 Utils::Vector3d &vec) const {
32 /* Coordinate transform to cylinder coords
33 with origin at m_center. */
34
35 /* Vector cylinder center<->particle */
36 Utils::Vector3d const c_dist = pos - m_center;
37
38 auto const z = e_z * c_dist;
39 auto const r_vec = c_dist - z * e_z;
40 auto const r = r_vec.norm();
41
42 /* If exactly on the axis, chose e_r orthogonal
43 to e_z. */
44 auto const e_r = (r == 0) ? e_r_axis : r_vec / r;
45
46 /* The pore has mirror symmetry in z with regard to
47 the center in the {r,z} system. We calculate always
48 for the z > 0 case, and flip the result if appropriate. */
49 double dr;
50 double z_abs = std::abs(z);
51 double side = 1;
52
53 if (r >= m_rad ||
54 (z_abs >= m_half_length &&
55 std::sqrt(r * r + std::pow(z_abs - m_half_length, 2)) > m_rad)) {
56 /* Outside */
57 if (z_abs >= m_half_length) {
58 /* Closest feature: hemisphere */
59 double dir = 1;
60 if (z < 0)
61 dir = -1;
62 Utils::Vector3d c_dist_cap = pos - (m_center + dir * e_z * m_half_length);
63 dist = c_dist_cap.norm() - m_rad;
64 c_dist_cap.normalize();
65 vec = dist * c_dist_cap;
66 dist *= m_direction;
67 return;
68 }
69 /* Closest feature: cylinder */
70 dr = -(r - m_rad);
71
72 } else {
73 side = -1;
74 /* Inside */
75 if (z_abs <= m_half_length) {
76 /* Closest feature: cylinder */
77 dr = m_rad - r;
78 } else {
79 /* Closest feature: hemisphere */
80 double dir = 1;
81 if (z < 0)
82 dir = -1;
83 Utils::Vector3d c_dist_cap =
84 -(pos - (m_center + dir * e_z * m_half_length));
85 dist = m_rad - c_dist_cap.norm();
86 c_dist_cap.normalize();
87 vec = dist * c_dist_cap;
88 dist *= -m_direction;
89 return;
90 }
91 }
92
93 dist = std::abs(dr) * m_direction * side;
94 vec = -dr * e_r;
95}
96} // namespace Shapes
Vector implementation and trait types for boost qvm interoperability.
Utils::Vector3d e_r_axis
Alternative e_r for corner case.
double m_half_length
Center of smoothing circle.
Utils::Vector3d m_center
center of the cylinder.
void calculate_dist(const Utils::Vector3d &pos, double &dist, Utils::Vector3d &vec) const override
double m_direction
direction -1: inside, +1 outside
Utils::Vector3d e_z
Unit vector in z direction.
Vector & normalize()
Definition Vector.hpp:148
T norm() const
Definition Vector.hpp:139