ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
SimplePore.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <shapes/SimplePore.hpp>
21
22#include <utils/Vector.hpp>
23#include <utils/math/sqr.hpp>
24
25#include <cassert>
26#include <cmath>
27#include <utility>
28
29namespace Shapes {
30/**
31 * @brief Calculate the distance function in the coordinates of the cylinder.
32 *
33 * @param r Distance from the cylinder axis.
34 * @param z Distance from the center along the axis.
35 *
36 * @returns The distance vector from the surface in the cylinder system.
37 */
38std::pair<double, double> SimplePore::dist_half_pore(double r, double z) const {
39 assert(z >= 0.0);
40 assert(r >= 0.0);
41
42 /*
43 * We have to find the line that splits area (1), where r determines
44 * the distance, from area (2), where z determines the distance.
45 * In area (3) we have to consider z and r to determine the distance.
46 * The line that separates area (1) from area (2) has parametric equation
47 * @f$ r = c_z + c_r - z @f$.
48 *
49 * | . ^ r
50 * | (2) . |
51 * | . |
52 * ........|.. (1) |
53 * ^ \ : |
54 * | \_________|
55 * c_r | (3) : |
56 * | :<------>|
57 * v : c_z |
58 * z <-----------------+
59 */
60
61 if ((z <= c_z) && (r <= (c_z + c_r - z))) {
62 /* Cylinder section, inner, area (1) */
63 return {m_rad - r, 0};
64 }
65 if (((z >= c_z) && (r >= c_r)) || ((z <= c_z) && (r > (c_z + c_r - z)))) {
66 /* Wall section and outer cylinder, area (2) */
67 return {0, m_half_length - z};
68 }
69 /* Smoothing area (3) */
70 /* Vector to center of torus segment */
71 auto const dr = c_r - r;
72 auto const dz = c_z - z;
73
74 /* Rescale to surface */
75 auto const d = std::sqrt(dr * dr + dz * dz);
76 auto const fac = (d - m_smoothing_rad) / d;
77
78 return {fac * dr, fac * dz};
79}
80
81void SimplePore::calculate_dist(const Utils::Vector3d &pos, double &dist,
82 Utils::Vector3d &vec) const {
83 /* Coordinate transform to cylinder coords
84 with origin at m_center. */
85 auto const c_dist = pos - m_center;
86 auto const z = e_z * c_dist;
87 auto const r_vec = c_dist - z * e_z;
88 auto const r = r_vec.norm();
89
90 /* If exactly on the axis, chose e_r orthogonal
91 to e_z. */
92 auto const e_r = (r == 0) ? e_r_axis : r_vec / r;
93
94 /* The pore has mirror symmetry in z with regard to
95 the center in the {r,z} system. We calculate always
96 for the z > 0 case, and flip the result if appropriate. */
97 auto [dr, dz] = dist_half_pore(r, std::abs(z));
98
99 double side = -1;
100 if (((dz == 0) && (r <= m_rad)) || // cylinder section
101 ((dr == 0) && (std::abs(z) > m_half_length))) { // ||
102 side = 1;
103 } else {
104 // smoothing area
105 if (std::abs(z) >= c_z) {
106 auto const d_sq = Utils::sqr(r - c_r) + Utils::sqr(z - c_z);
107 if (d_sq > Utils::sqr(m_smoothing_rad)) {
108 side = 1;
109 }
110 }
111 }
112
113 if (z <= 0.0) {
114 dz *= -1;
115 }
116
117 dist = std::sqrt(dr * dr + dz * dz) * side;
118 vec = -dr * e_r - dz * e_z;
119}
120} // namespace Shapes
Vector implementation and trait types for boost qvm interoperability.
void calculate_dist(const Utils::Vector3d &pos, double &dist, Utils::Vector3d &vec) const override
T norm() const
Definition Vector.hpp:138
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:28