ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
shapes/include/shapes/Cylinder.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 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#pragma once
23
24#include "Shape.hpp"
25
26#include <utils/Vector.hpp>
27
28#include <utility>
29
30namespace Shapes {
31class Cylinder : public Shape {
32public:
33 /** center of the cylinder. */
35 /** Axis of the cylinder. */
37 /** cylinder radius. */
38 double m_rad;
39 /** cylinder length. */
40 double m_length;
41 /** whether to ignore bottom and top cap of cylinder */
42 bool m_open;
43 /** direction -1: inside, +1 outside */
45
46 /** Center of smoothing circle */
48 /** Unit vector in z direction */
50
51 /** Alternative e_r for corner case */
53
54 /** @brief Calculate derived parameters. */
55 void precalc() {
56 m_half_length = 0.5 * m_length;
57
58 e_z = m_axis / m_axis.norm();
59
60 /* Find a vector orthogonal to e_z, since {1,0,0} and
61 {0,1,0} are independent, e_z can not be parallel to both
62 of them. Then we can do Gram-Schmidt */
63 if ((Utils::Vector3d{1., 0., 0} * e_z) < 1.)
64 e_r_axis =
65 Utils::Vector3d{1., 0., 0} - (e_z * Utils::Vector3d{1., 0., 0}) * e_z;
66 else
67 e_r_axis =
68 Utils::Vector3d{0., 1., 0} - (e_z * Utils::Vector3d{0., 1., 0}) * e_z;
69
71 }
72
73 std::pair<double, double> dist_half_pore(double r, double z) const;
74
75public:
77 : m_center({0.0, 0.0, 0.0}), m_axis({1.0, 0.0, 0.0}), m_rad(0),
78 m_length(0.0), m_open(false), m_direction(1.0) {
79 precalc();
80 }
81
82 double radius() const { return m_rad; }
83 void set_radius(double const &radius) {
84 m_rad = radius;
85 precalc();
86 }
87
88 double length() const { return m_length; }
89 void set_length(double const &length) {
91 precalc();
92 }
93
94 Utils::Vector3d const &axis() const { return m_axis; }
96 m_axis = axis;
97 precalc();
98 }
99
101 bool &open() { return m_open; }
102 double &direction() { return m_direction; }
103
104 void calculate_dist(const Utils::Vector3d &pos, double &dist,
105 Utils::Vector3d &vec) const override;
106};
107} // namespace Shapes
Vector implementation and trait types for boost qvm interoperability.
bool m_open
whether to ignore bottom and top cap of cylinder
void set_radius(double const &radius)
Utils::Vector3d m_axis
Axis of the cylinder.
double m_half_length
Center of smoothing circle.
Utils::Vector3d e_r_axis
Alternative e_r for corner case.
Utils::Vector3d e_z
Unit vector in z direction.
void set_axis(Utils::Vector3d const &axis)
double m_length
cylinder length.
void set_length(double const &length)
void calculate_dist(const Utils::Vector3d &pos, double &dist, Utils::Vector3d &vec) const override
Definition Cylinder.cpp:59
void precalc()
Calculate derived parameters.
double m_direction
direction -1: inside, +1 outside
Utils::Vector3d m_center
center of the cylinder.
std::pair< double, double > dist_half_pore(double r, double z) const
Definition Cylinder.cpp:32
Utils::Vector3d const & axis() const
Vector & normalize()
Definition Vector.hpp:167
T norm() const
Definition Vector.hpp:159