OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
CoordinateSystemTrafo.h
Go to the documentation of this file.
1#ifndef COORDINATESYSTEMTRAFO
2#define COORDINATESYSTEMTRAFO
3
4#include <Kokkos_Core.hpp>
5#include "Algorithms/Matrix.h"
7
41public:
42 /* ============================== Constructors ============================== */
45
47
55 CoordinateSystemTrafo(const ippl::Vector<double, 3>& origin, const Quaternion& orientation);
56
58 void invert();
59
62 /* ========================================================================== */
63 /* ======================== Transformation Functions ======================== */
65 ippl::Vector<double, 3> transformTo(const ippl::Vector<double, 3>& r) const;
66
68 ippl::Vector<double, 3> transformFrom(const ippl::Vector<double, 3>& r) const;
69
71 ippl::Vector<double, 3> rotateTo(const ippl::Vector<double, 3>& r) const;
72
74 ippl::Vector<double, 3> rotateFrom(const ippl::Vector<double, 3>& r) const;
75
82 template <typename ViewType>
83 void transformBunchTo(ViewType Rview, size_t nLocal) const;
84
86 template <typename ViewType>
87 void transformBunchFrom(ViewType Rview, size_t nLocal) const;
88
90 template <typename ViewType>
91 void rotateBunchTo(ViewType Pview, size_t nLocal) const;
92
94 template <typename ViewType>
95 void rotateBunchFrom(ViewType Pview, size_t nLocal) const;
96 /* ========================================================================== */
97 /* =============================== Operators ================================ */
99
109
110 void operator*=(const CoordinateSystemTrafo& right);
111 /* ========================================================================== */
112 /* =============================== Getters ================================== */
113 ippl::Vector<double, 3> getOrigin() const;
114 Quaternion getRotation() const;
116 /* ========================================================================== */
117 /* =============================== Print ==================================== */
118 void print(std::ostream&) const;
119
120private:
122 ippl::Vector<double, 3> origin_m;
123
126
129};
130
131/* ======== Print ======== */
132inline std::ostream& operator<<(std::ostream& os, const CoordinateSystemTrafo& trafo) {
133 trafo.print(os);
134 return os;
135}
136
137inline Inform& operator<<(Inform& os, const CoordinateSystemTrafo& trafo) {
138 trafo.print(os.getStream());
139 return os;
140}
141
142inline void CoordinateSystemTrafo::print(std::ostream& os) const {
143 os << "Origin: " << origin_m << "\n"
144 << "z-axis: " << orientation_m.conjugate().rotate(ippl::Vector<double, 3>(0, 0, 1)) << "\n"
145 << "x-axis: " << orientation_m.conjugate().rotate(ippl::Vector<double, 3>(1, 0, 0));
146}
147
148inline ippl::Vector<double, 3> CoordinateSystemTrafo::transformTo(
149 const ippl::Vector<double, 3>& r) const {
150 const ippl::Vector<double, 3> delta = r - origin_m;
151 return prod_vector(rotationMatrix_m, delta);
152}
153
154inline ippl::Vector<double, 3> CoordinateSystemTrafo::transformFrom(
155 const ippl::Vector<double, 3>& r) const {
156 return rotateFrom(r) + origin_m;
157}
158
159inline ippl::Vector<double, 3> CoordinateSystemTrafo::rotateTo(
160 const ippl::Vector<double, 3>& r) const {
161 return prod_vector(rotationMatrix_m, r);
162}
163
164inline ippl::Vector<double, 3> CoordinateSystemTrafo::rotateFrom(
165 const ippl::Vector<double, 3>& r) const {
167}
168
169inline ippl::Vector<double, 3> CoordinateSystemTrafo::getOrigin() const { return origin_m; }
170
172
174
176 CoordinateSystemTrafo result(*this);
177 result.invert();
178
179 return result;
180}
181
182template <typename ViewType>
183inline void CoordinateSystemTrafo::transformBunchTo(ViewType Rview, size_t nLocal) const {
185 ippl::Vector<double, 3> ori = origin_m;
186 Kokkos::parallel_for(
187 "transformBunchTo", nLocal, KOKKOS_LAMBDA(const size_t i) {
188 ippl::Vector<double, 3> delta = Rview(i) - ori;
189 Rview(i) = prod_vector(rot, delta);
190 });
191}
192
193template <typename ViewType>
194inline void CoordinateSystemTrafo::transformBunchFrom(ViewType Rview, size_t nLocal) const {
196 ippl::Vector<double, 3> ori = origin_m;
197 Kokkos::parallel_for(
198 "transformBunchFrom", nLocal, KOKKOS_LAMBDA(const size_t i) {
199 Rview(i) = prod_vector_transpose(rot, Rview(i)) + ori;
200 });
201}
202
203template <typename ViewType>
204inline void CoordinateSystemTrafo::rotateBunchTo(ViewType Pview, size_t nLocal) const {
206 Kokkos::parallel_for(
207 "rotateBunchTo", nLocal,
208 KOKKOS_LAMBDA(const size_t i) { Pview(i) = prod_vector(rot, Pview(i)); });
209}
210
211template <typename ViewType>
212inline void CoordinateSystemTrafo::rotateBunchFrom(ViewType Pview, size_t nLocal) const {
214 Kokkos::parallel_for(
215 "rotateBunchFrom", nLocal,
216 KOKKOS_LAMBDA(const size_t i) { Pview(i) = prod_vector_transpose(rot, Pview(i)); });
217}
218
219#endif
std::ostream & operator<<(std::ostream &os, const CoordinateSystemTrafo &trafo)
KOKKOS_INLINE_FUNCTION T prod_vector(const matrix_t< Rows, Cols > &rotation, const T &vect)
Definition Matrix.h:106
KOKKOS_INLINE_FUNCTION T prod_vector_transpose(const matrix_t< Rows, Cols > &rotation, const T &vect)
Definition Matrix.h:123
Rigid spatial transform between a parent frame and a local frame.
ippl::Vector< double, 3 > getOrigin() const
matrix3x3_t rotationMatrix_m
Cached rotation matrix for the same parent-to-local mapping.
void rotateBunchFrom(ViewType Pview, size_t nLocal) const
Apply rotateFrom() to a Kokkos view of vectors such as momenta.
ippl::Vector< double, 3 > transformFrom(const ippl::Vector< double, 3 > &r) const
Map a point from the local frame back to the parent frame.
ippl::Vector< double, 3 > rotateFrom(const ippl::Vector< double, 3 > &r) const
Rotate a vector from the local frame back into the parent frame.
matrix3x3_t getRotationMatrix() const
ippl::Vector< double, 3 > rotateTo(const ippl::Vector< double, 3 > &r) const
Rotate a vector from the parent frame into the local frame.
CoordinateSystemTrafo()
Construct the identity transform.
void operator*=(const CoordinateSystemTrafo &right)
void rotateBunchTo(ViewType Pview, size_t nLocal) const
Apply rotateTo() to a Kokkos view of vectors such as momenta.
CoordinateSystemTrafo & operator=(const CoordinateSystemTrafo &right)=default
void transformBunchTo(ViewType Rview, size_t nLocal) const
Apply transformTo() to a Kokkos view of particle positions.
ippl::Vector< double, 3 > transformTo(const ippl::Vector< double, 3 > &r) const
Map a point from the parent frame to the local frame.
void transformBunchFrom(ViewType Rview, size_t nLocal) const
Apply transformFrom() to a Kokkos view of particle positions.
void print(std::ostream &) const
CoordinateSystemTrafo inverted() const
Return the inverse transform.
ippl::Vector< double, 3 > origin_m
Local origin expressed in the parent frame.
CoordinateSystemTrafo operator*(const CoordinateSystemTrafo &right) const
Compose two transforms.
Quaternion orientation_m
Quaternion whose rotation maps parent-frame vectors into local-frame vectors.
Quaternion getRotation() const
void invert()
Invert the transform in place.
Quaternion storage and rotation algebra used by OPALX geometry code.
Quaternion conjugate() const
Return the quaternion conjugate .
ippl::Vector< double, 3 > rotate(const ippl::Vector< double, 3 > &) const
Rotate a spatial vector by a unit quaternion.