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