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-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#ifndef SRC_SHAPES_CYLINDER_HPP
23#define SRC_SHAPES_CYLINDER_HPP
24
25#include "Shape.hpp"
26
27#include <utils/Vector.hpp>
28
29#include <utility>
30
31namespace Shapes {
32class Cylinder : public Shape {
33public:
34 /** center of the cylinder. */
36 /** Axis of the cylinder. */
38 /** cylinder radius. */
39 double m_rad;
40 /** cylinder length. */
41 double m_length;
42 /** whether to ignore bottom and top cap of cylinder */
43 bool m_open;
44 /** direction -1: inside, +1 outside */
46
47 /** Center of smoothing circle */
49 /** Unit vector in z direction */
51
52 /** Alternative e_r for corner case */
54
55 /** @brief Calculate derived parameters. */
56 void precalc() {
57 m_half_length = 0.5 * m_length;
58
59 e_z = m_axis / m_axis.norm();
60
61 /* Find a vector orthogonal to e_z, since {1,0,0} and
62 {0,1,0} are independent, e_z can not be parallel to both
63 of them. Then we can do Gram-Schmidt */
64 if ((Utils::Vector3d{1., 0., 0} * e_z) < 1.)
65 e_r_axis =
66 Utils::Vector3d{1., 0., 0} - (e_z * Utils::Vector3d{1., 0., 0}) * e_z;
67 else
68 e_r_axis =
69 Utils::Vector3d{0., 1., 0} - (e_z * Utils::Vector3d{0., 1., 0}) * e_z;
70
72 }
73
74 std::pair<double, double> dist_half_pore(double r, double z) const;
75
76public:
78 : m_center({0.0, 0.0, 0.0}), m_axis({1.0, 0.0, 0.0}), m_rad(0),
79 m_length(0.0), m_open(false), m_direction(1.0) {
80 precalc();
81 }
82
83 double radius() const { return m_rad; }
84 void set_radius(double const &radius) {
85 m_rad = radius;
86 precalc();
87 }
88
89 double length() const { return m_length; }
90 void set_length(double const &length) {
92 precalc();
93 }
94
95 Utils::Vector3d const &axis() const { return m_axis; }
97 m_axis = axis;
98 precalc();
99 }
100
102 bool &open() { return m_open; }
103 double &direction() { return m_direction; }
104
105 void calculate_dist(const Utils::Vector3d &pos, double &dist,
106 Utils::Vector3d &vec) const override;
107};
108} // namespace Shapes
109#endif
Vector implementation and trait types for boost qvm interoperability.
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
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:140
T norm() const
Definition Vector.hpp:131