ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Torus.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#include <cmath>
20#include <shapes/Torus.hpp>
21#include <utils/Vector.hpp>
22#include <utils/math/sqr.hpp>
23
24namespace Shapes {
25
26void Torus::calculate_dist(const Utils::Vector3d &pos, double &dist,
27 Utils::Vector3d &vec) const {
28 /* Coordinate transform to cylinder coords
29 with origin at m_center. */
30 Utils::Vector3d const c_dist = pos - m_center;
31 auto const z = e_z * c_dist;
32 auto const r_vec = c_dist - z * e_z;
33 auto const r = r_vec.norm();
34
35 dist = (std::sqrt(Utils::sqr(r - m_rad) + z * z) - m_tube_rad) * m_direction;
36 Utils::Vector3d const dir_vec = c_dist - r_vec * m_rad / r;
37 auto const dir_vec_norm = dir_vec / dir_vec.norm();
38 vec = dir_vec_norm * std::abs(dist);
39}
40} // namespace Shapes
Vector implementation and trait types for boost qvm interoperability.
Utils::Vector3d e_z
Unit vector in z direction.
void calculate_dist(const Utils::Vector3d &pos, double &dist, Utils::Vector3d &vec) const override
Definition Torus.cpp:26
Utils::Vector3d m_center
center of the shape.
double m_direction
direction -1: inside, +1 outside
double m_tube_rad
tube radius.
T norm() const
Definition Vector.hpp:138
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
Definition sqr.hpp:28