ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
rotation.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#ifndef ROTATION_H
22#define ROTATION_H
23/** \file
24 * This file contains all subroutines required to process rotational motion.
25 */
26
27#include "config/config.hpp"
28
29#ifdef ROTATION
30
31#include "Particle.hpp"
32#include "ParticleRange.hpp"
33
34#include <utils/Vector.hpp>
35#include <utils/mask.hpp>
37#include <utils/matrix.hpp>
38#include <utils/quaternion.hpp>
39
40#include <cassert>
41#include <cmath>
42#include <limits>
43#include <utility>
44
45/** @brief Propagate angular velocities and update quaternions on a
46 * particle.
47 */
48void propagate_omega_quat_particle(Particle &p, double time_step);
49
50void convert_torque_propagate_omega(Particle &p, double time_step);
51
52/** Convert torques to the body-fixed frame before the integration loop. */
53void convert_initial_torques(const ParticleRange &particles);
54
55// Frame conversion routines
56inline Utils::Vector3d
58 return p.quat() * vec;
59}
60
62 const Utils::Vector3d &v) {
63 assert(p.quat().norm() > 0.0);
64 return rotation_matrix(p.quat()).transposed() * v;
65}
66
67/**
68 * @brief Transform matrix from body- to space-fixed frame.
69 *
70 * Given a linear map represented by \f$ A \in \mathbb{R}^{3 \times 3}\f$
71 * in the body-fixed frame, this returns the matrix \f$ A \in \mathbb{R}^{3
72 * \times 3}\f$ representing the map in the space-fixed frame. They are related
73 * by the map between the space-fixed and body-fixed frame \f$O\f$ like
74 *
75 * \f[
76 * A' = O A O^T.
77 * \f]
78 *
79 * @tparam T Scalar type
80 * @param quat quaternion to transform from, i.e. the rotation
81 * that transforms space- to body-fixed frame.
82 * @param A Matrix representation in body-fixed coordinates.
83 * @return Matrix representation in space-fixed coordinates.
84 */
85template <class T>
87 const Utils::Matrix<T, 3, 3> &A) {
88 auto const O = rotation_matrix(quat);
89 return O * A * O.transposed();
90}
91
92/**
93 * @brief Transform matrix from body- to space-fixed frame.
94 * @tparam T Scalar type
95 * @param p Particle transforming from.
96 * @param A Matrix representation in body-fixed coordinates.
97 * @return Matrix representation in space-fixed coordinates.
98 */
99template <class T>
101 return convert_body_to_space(p.quat(), A);
102}
103
104#ifdef DIPOLES
105
106/** convert a dipole moment to quaternions and dipolar strength */
107inline std::pair<Utils::Quaternion<double>, double>
110 return {quat, dip.norm()};
111}
112
113#endif
114
115/** Rotate the particle p around the body-frame defined NORMALIZED axis
116 * @p aBodyFrame by amount @p phi.
117 */
120 const Utils::Vector3d &axis_body_frame,
121 const double phi) {
122 // Rotation turned off entirely?
123 if (!p.can_rotate())
124 return p.quat();
125 if (std::abs(phi) > std::numeric_limits<double>::epsilon())
126 return p.quat() *
127 boost::qvm::rot_quat(mask(p.rotation(), axis_body_frame), phi);
128 return p.quat();
129}
130
131/** Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi
132 */
134 const Utils::Vector3d &axis_space_frame,
135 const double phi) {
136 if (std::abs(phi) > std::numeric_limits<double>::epsilon()) {
137 // Convert rotation axis to body-fixed frame
138 Utils::Vector3d axis = convert_vector_space_to_body(p, axis_space_frame);
139 p.quat() = local_rotate_particle_body(p, axis, phi);
140 }
141}
142
144 auto const torque = convert_vector_space_to_body(p, p.torque());
145 p.torque() = mask(p.rotation(), torque);
146}
147
148#endif // ROTATION
149#endif
Vector implementation and trait types for boost qvm interoperability.
__global__ float float * torque
A range of particles.
T norm() const
Definition Vector.hpp:131
This file contains the defaults for ESPResSo.
Quaternion algebra.
Matrix implementation and trait types for boost qvm interoperability.
Quaternion< T > convert_director_to_quaternion(Vector< T, 3 > const &d)
Convert director to quaternion.
Quaternion implementation and trait types for boost qvm interoperability.
auto convert_body_to_space(const Utils::Quaternion< double > &quat, const Utils::Matrix< T, 3, 3 > &A)
Transform matrix from body- to space-fixed frame.
Definition rotation.hpp:86
void convert_torque_to_body_frame_apply_fix(Particle &p)
Definition rotation.hpp:143
void convert_initial_torques(const ParticleRange &particles)
Convert torques to the body-fixed frame before the integration loop.
Definition rotation.cpp:188
Utils::Vector3d convert_vector_body_to_space(const Particle &p, const Utils::Vector3d &vec)
Definition rotation.hpp:57
void propagate_omega_quat_particle(Particle &p, double time_step)
Propagate angular velocities and update quaternions on a particle.
Definition rotation.cpp:125
void convert_torque_propagate_omega(Particle &p, double time_step)
Definition rotation.cpp:159
std::pair< Utils::Quaternion< double >, double > convert_dip_to_quat(const Utils::Vector3d &dip)
convert a dipole moment to quaternions and dipolar strength
Definition rotation.hpp:108
Utils::Vector3d convert_vector_space_to_body(const Particle &p, const Utils::Vector3d &v)
Definition rotation.hpp:61
Utils::Quaternion< double > local_rotate_particle_body(Particle const &p, const Utils::Vector3d &axis_body_frame, const double phi)
Rotate the particle p around the body-frame defined NORMALIZED axis aBodyFrame by amount phi.
Definition rotation.hpp:119
void local_rotate_particle(Particle &p, const Utils::Vector3d &axis_space_frame, const double phi)
Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi.
Definition rotation.hpp:133
Struct holding all information for one particle.
Definition Particle.hpp:393
bool can_rotate() const
Definition Particle.hpp:458
auto const & quat() const
Definition Particle.hpp:475
auto const & rotation() const
Definition Particle.hpp:456
auto const & torque() const
Definition Particle.hpp:477
Matrix representation with static size.
Definition matrix.hpp:65
Matrix< T, Cols, Rows > transposed() const
Retrieve a transposed copy of the matrix.
Definition matrix.hpp:189
Quaternion representation.