ImpactX
Loading...
Searching...
No Matches
SpinMap.H
Go to the documentation of this file.
1/* Copyright 2022-2024 The Regents of the University of California, through Lawrence
2 * Berkeley National Laboratory (subject to receipt of any required
3 * approvals from the U.S. Dept. of Energy). All rights reserved.
4 *
5 * This file is part of ImpactX.
6 *
7 * Authors: Chad Mitchell, Axel Huebl
8 * License: BSD-3-Clause-LBNL
9 */
10#ifndef IMPACTX_ELEMENT_SPIN_MAP_H
11#define IMPACTX_ELEMENT_SPIN_MAP_H
12
14#include "mixin/alignment.H"
15#include "mixin/beamoptic.H"
17#include "mixin/spintransport.H"
18#include "mixin/named.H"
19#include "mixin/nofinalize.H"
20
21#include <AMReX_Extension.H>
22#include <AMReX_Math.H>
23#include <AMReX_REAL.H>
24#include <AMReX_SIMD.H>
25#include <AMReX_SmallMatrix.H>
26
27#include <cmath>
28#include <stdexcept>
29
31
34
35namespace impactx::elements
36{
37 struct SpinMap
38 : public mixin::Named,
39 public mixin::BeamOptic<SpinMap>,
40 public mixin::LinearTransport<SpinMap>,
41 public mixin::Alignment,
43 public mixin::NoFinalize,
44 public amrex::simd::Vectorized<amrex::simd::native_simd_size_particlereal>
45 {
46 static constexpr auto type = "SpinMap";
48
64 Vector3 const & v,
65 Map3x6 const & A,
69 amrex::ParticleReal rotation_degree = 0,
70 std::optional<std::string> name = std::nullopt
71 )
72 : Named(std::move(name)),
73 Alignment(dx, dy, rotation_degree)
74 {
77 m_ds = ds;
78 }
79
81 void reverse ()
82 {
83 throw std::runtime_error("SpinMap: reverse() is not yet supported.");
84
85 /* Reversibility: This works but is hacky
86 for (int i = 1; i <= 3; ++i) {
87 m_spin_rotation_vector(i) = -m_spin_rotation_vector(i);
88 for (int j = 1; j <= 6; ++j) {
89 m_spin_orbit_coupling(i,j) = -m_spin_orbit_coupling(i,j);
90 }
91 }
92 m_reversed = !m_reversed;
93 */
94 }
95
97 using BeamOptic::operator();
98
111 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
114 [[maybe_unused]] T_Real & AMREX_RESTRICT x,
115 [[maybe_unused]] T_Real & AMREX_RESTRICT y,
116 [[maybe_unused]] T_Real & AMREX_RESTRICT t,
117 [[maybe_unused]] T_Real & AMREX_RESTRICT px,
118 [[maybe_unused]] T_Real & AMREX_RESTRICT py,
119 [[maybe_unused]] T_Real & AMREX_RESTRICT pt,
120 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
121 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
122 ) const
123 {
124 // This element does nothing to the phase space variables.
125 }
126
132 void operator() ([[maybe_unused]] RefPart & AMREX_RESTRICT refpart) const
133 {
134 // This element does nothing to the reference particle.
135 }
136
142 int nslice () const
143 {
144 return 1;
145 }
146
153 {
154 return m_ds;
155 }
156
157
172 template<typename T_Real=amrex::ParticleReal, typename T_IdCpu=uint64_t>
175 [[maybe_unused]] T_Real & AMREX_RESTRICT x,
176 [[maybe_unused]] T_Real & AMREX_RESTRICT y,
177 [[maybe_unused]] T_Real & AMREX_RESTRICT t,
178 [[maybe_unused]] T_Real & AMREX_RESTRICT px,
179 [[maybe_unused]] T_Real & AMREX_RESTRICT py,
180 [[maybe_unused]] T_Real & AMREX_RESTRICT pt,
181 [[maybe_unused]] T_Real & AMREX_RESTRICT sx,
182 [[maybe_unused]] T_Real & AMREX_RESTRICT sy,
183 [[maybe_unused]] T_Real & AMREX_RESTRICT sz,
184 [[maybe_unused]] T_IdCpu & AMREX_RESTRICT idcpu,
185 [[maybe_unused]] RefPart const & AMREX_RESTRICT refpart
186 ) const
187 {
188 using namespace amrex::literals; // for _rt and _prt
189
190 // initialize the three components of the axis-angle vector
191 T_Real lambdax = 0_prt;
192 T_Real lambday = 0_prt;
193 T_Real lambdaz = 0_prt;
194
195 // input phase space 6-vector
197 x, px, y, py, t, pt
198 };
199
200 // determine the rotation vector for off-design particles
201 amrex::SmallVector<T_Real, 3, 1> const vectorout = m_spin_orbit_coupling * vectorin;
202
203 // assign updated values
204 lambdax = vectorout(1);
205 lambday = vectorout(2);
206 lambdaz = vectorout(3);
207
208 /* Reversibility: This works but is hacky
209 T_Real const design_lambdax = m_spin_rotation_vector(1);
210 T_Real const design_lambday = m_spin_rotation_vector(2);
211 T_Real const design_lambdaz = m_spin_rotation_vector(3);
212
213 if (m_reversed) {
214 // The inverse map applies the inverse design rotation first,
215 // then the inverse orbit-dependent rotation.
216 rotate_spin(
217 design_lambdax,
218 design_lambday,
219 design_lambdaz,
220 sx, sy, sz
221 );
222 rotate_spin(lambdax,lambday,lambdaz,sx,sy,sz);
223 } else {
224 rotate_spin(lambdax,lambday,lambdaz,sx,sy,sz);
225 rotate_spin(
226 design_lambdax,
227 design_lambday,
228 design_lambdaz,
229 sx, sy, sz
230 );
231 }
232 */
233
234 { /* non-reversible block, replace with the above block to test */
235 // push the spin vector using the generator just determined
236 rotate_spin(lambdax,lambday,lambdaz,sx,sy,sz);
237
238 // specify the design rotation vector
239 lambdax = m_spin_rotation_vector(1);
240 lambday = m_spin_rotation_vector(2);
241 lambdaz = m_spin_rotation_vector(3);
242
243 // push the spin vector using the generator just determined
244 rotate_spin(lambdax,lambday,lambdaz,sx,sy,sz);
245 } /* end of non-reversible block, replace with the above block to test */
246
247 // phase space push (the identity for this element)
248 (*this)(x, y, t, px, py, pt, idcpu, refpart);
249 }
250
251
253 using LinearTransport::operator();
254
261 Map6x6
262 transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
263 {
265 return R;
266 }
267
268 Vector3 m_spin_rotation_vector; // 3x1 axis-angle vector for design spin rotation
269 Map3x6 m_spin_orbit_coupling; // 3x6 spin-orbit coupling matrix
270 amrex::ParticleReal m_ds; // finite ds allowed for bookkeeping, but we do not allow slicing
271 /* Reversibility: This works but is hacky */
272 // bool m_reversed = false; // apply inverse spin rotations in reverse order after reverse()
273 };
274
275} // namespace impactx
276
278
279#endif // IMPACTX_ELEMENT_SPIN_MAP_H
#define AMREX_FORCE_INLINE
#define AMREX_RESTRICT
#define AMREX_GPU_HOST_DEVICE
#define AMREX_GPU_HOST
#define IMPACTX_PUSH_EXTERN_TEMPLATE(ElementType)
Definition PushAll.H:78
amrex::SmallMatrix< amrex::ParticleReal, 3, 6, amrex::Order::F, 1 > Map3x6
Definition SpinMap.H:32
amrex::SmallMatrix< amrex::ParticleReal, 3, 1, amrex::Order::F, 1 > Vector3
Definition SpinMap.H:33
amrex_particle_real ParticleReal
SmallMatrix< T, N, 1, Order::F, StartIndex > SmallVector
Definition All.H:56
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
amrex::SmallMatrix< amrex::ParticleReal, 6, 6, amrex::Order::F, 1 > Map6x6
Definition CovarianceMatrix.H:20
static constexpr __host__ __device__ SmallMatrix< T, NRows, NCols, ORDER, StartIndex > Identity() noexcept
Definition ReferenceParticle.H:33
Definition SpinMap.H:45
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void spin_and_phasespace_push(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT t, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py, T_Real &AMREX_RESTRICT pt, T_Real &AMREX_RESTRICT sx, T_Real &AMREX_RESTRICT sy, T_Real &AMREX_RESTRICT sz, T_IdCpu &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition SpinMap.H:174
static constexpr auto type
Definition SpinMap.H:46
void reverse()
Definition SpinMap.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal ds() const
Definition SpinMap.H:152
amrex::ParticleReal m_ds
Definition SpinMap.H:270
SpinMap(Vector3 const &v, Map3x6 const &A, amrex::ParticleReal ds=0, amrex::ParticleReal dx=0, amrex::ParticleReal dy=0, amrex::ParticleReal rotation_degree=0, std::optional< std::string > name=std::nullopt)
Definition SpinMap.H:63
Vector3 m_spin_rotation_vector
Definition SpinMap.H:268
ImpactXParticleContainer::ParticleType PType
Definition SpinMap.H:47
AMREX_GPU_HOST AMREX_FORCE_INLINE Map6x6 transport_map(RefPart const &AMREX_RESTRICT refpart) const
Definition SpinMap.H:262
Map3x6 m_spin_orbit_coupling
Definition SpinMap.H:269
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int nslice() const
Definition SpinMap.H:142
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(T_Real &AMREX_RESTRICT x, T_Real &AMREX_RESTRICT y, T_Real &AMREX_RESTRICT t, T_Real &AMREX_RESTRICT px, T_Real &AMREX_RESTRICT py, T_Real &AMREX_RESTRICT pt, T_IdCpu &AMREX_RESTRICT idcpu, RefPart const &AMREX_RESTRICT refpart) const
Definition SpinMap.H:113
Definition alignment.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dy() const
Definition alignment.H:146
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal dx() const
Definition alignment.H:136
Alignment(amrex::ParticleReal dx, amrex::ParticleReal dy, amrex::ParticleReal rotation_degree)
Definition alignment.H:36
Definition beamoptic.H:436
Definition lineartransport.H:50
Definition named.H:29
AMREX_GPU_HOST Named(std::optional< std::string > name)
Definition named.H:57
AMREX_FORCE_INLINE std::string name() const
Definition named.H:122
Definition nofinalize.H:22
Definition spintransport.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void rotate_spin(T_Real const &AMREX_RESTRICT lambdax, T_Real const &AMREX_RESTRICT lambday, T_Real const &AMREX_RESTRICT lambdaz, T_Real &AMREX_RESTRICT sx, T_Real &AMREX_RESTRICT sy, T_Real &AMREX_RESTRICT sz) const
Definition spintransport.H:48