ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
cylindrical_transformation_parameters.hpp
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#pragma once
21
22#include <cmath>
23#include <limits>
24#include <stdexcept>
25#include <string>
26
28
29namespace Utils {
30
31/**
32 * @brief A class to hold and validate parameters for a cylindrical coordinate
33 * transformations.
34 */
36public:
38 /**
39 * @brief Main constructor.
40 *
41 * @param center The origin of the cylindrical coordinates.
42 * @param axis The "z"-axis. Must be normalized.
43 * @param orientation The axis along which phi = 0. Must be normalized and
44 * orthogonal to axis.
45 */
47 Utils::Vector3d const &axis,
49 : m_center(center), m_axis(axis), m_orientation(orientation) {
50 validate();
51 }
52 /**
53 * @brief if you only provide center and axis, an orientation will be
54 * generated automatically such that it is orthogonal to axis
55 */
60
61 Utils::Vector3d center() const { return m_center; }
62 Utils::Vector3d axis() const { return m_axis; }
63 Utils::Vector3d orientation() const { return m_orientation; }
64
65private:
66 void validate() const {
67 auto constexpr eps = 10. * std::numeric_limits<double>::epsilon();
68 if (std::fabs(m_orientation * m_axis) > eps) {
69 throw std::runtime_error(
70 "CylindricalTransformationParameters: Axis and orientation must be "
71 "orthogonal. Scalar product is " +
72 std::to_string(m_orientation * m_axis));
73 }
74 if (std::fabs(m_axis.norm() - 1.) > eps) {
75 throw std::runtime_error("CylindricalTransformationParameters: Axis must "
76 "be normalized. Norm is " +
77 std::to_string(m_axis.norm()));
78 }
79 if (std::fabs(m_orientation.norm() - 1.) > eps) {
80 throw std::runtime_error("CylindricalTransformationParameters: "
81 "orientation must be normalized. Norm is " +
82 std::to_string(m_orientation.norm()));
83 }
84 }
85
86 Utils::Vector3d const m_center{};
87 Utils::Vector3d const m_axis{0., 0., 1.};
88 Utils::Vector3d const m_orientation{1., 0., 0.};
89};
90
91} // namespace Utils
A class to hold and validate parameters for a cylindrical coordinate transformations.
CylindricalTransformationParameters(Utils::Vector3d const &center, Utils::Vector3d const &axis)
if you only provide center and axis, an orientation will be generated automatically such that it is o...
CylindricalTransformationParameters(Utils::Vector3d const &center, Utils::Vector3d const &axis, Utils::Vector3d const &orientation)
Main constructor.
T norm() const
Definition Vector.hpp:138
Vector< T, N > calc_orthonormal_vector(Vector< T, N > const &vec)
Return a vector that is orthonormal to vec.