ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
shapes/include/shapes/Torus.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 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#pragma once
21
22#include "Shape.hpp"
23
24#include <utils/Vector.hpp>
25
26namespace Shapes {
27class Torus : public Shape {
28public:
29 /** center of the shape. */
31 /** Normal axis of the shape. */
33 /** radius. */
34 double m_rad;
35 /** tube radius. */
36 double m_tube_rad;
37 /** direction -1: inside, +1 outside */
39
40 /** Unit vector in z direction */
42
43 /** Alternative e_r for the on-axis corner case */
45
46 /** @brief Calculate derived parameters. */
47 void precalc() {
49
50 /* Find a vector orthogonal to e_z via Gram-Schmidt.
51 Since {1,0,0} and {0,1,0} are independent, e_z cannot be
52 parallel to both of them. */
53 if (e_z[0] < 1.) {
54 Utils::Vector3d constexpr u_x{{1., 0., 0.}};
55 e_r_axis = u_x - (e_z * u_x) * e_z;
56 } else {
57 Utils::Vector3d constexpr u_y{{0., 1., 0.}};
58 e_r_axis = u_y - (e_z * u_y) * e_z;
59 }
61 }
62
63public:
65 : m_center({0.0, 0.0, 0.0}), m_normal({1.0, 0.0, 0.0}), m_rad(0.0),
66 m_tube_rad(0.0), m_direction(1.0) {
67 precalc();
68 }
69
70 double radius() const { return m_rad; }
71 void set_radius(double const &radius) {
72 m_rad = radius;
73 precalc();
74 }
75
76 double tube_radius() const { return m_tube_rad; }
77 void set_tube_radius(double const &tube_rad) {
79 precalc();
80 }
81
82 Utils::Vector3d const &normal() const { return m_normal; }
85 precalc();
86 }
87
89 double &direction() { return m_direction; }
90
91 void calculate_dist(const Utils::Vector3d &pos, double &dist,
92 Utils::Vector3d &vec) const override;
93};
94} // namespace Shapes
Vector implementation and trait types for boost qvm interoperability.
void set_normal(Utils::Vector3d const &normal)
void set_tube_radius(double const &tube_rad)
Utils::Vector3d e_z
Unit vector in z direction.
Utils::Vector3d m_normal
Normal axis of the shape.
void calculate_dist(const Utils::Vector3d &pos, double &dist, Utils::Vector3d &vec) const override
Definition Torus.cpp:64
Utils::Vector3d e_r_axis
Alternative e_r for the on-axis corner case.
Utils::Vector3d const & normal() const
Utils::Vector3d & center()
Utils::Vector3d m_center
center of the shape.
void set_radius(double const &radius)
double m_direction
direction -1: inside, +1 outside
double m_tube_rad
tube radius.
void precalc()
Calculate derived parameters.
Vector & normalize()
Definition Vector.hpp:167
T norm() const
Definition Vector.hpp:159
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.