ImpactX
Loading...
Searching...
No Matches
NonlinearLensInvariants.H
Go to the documentation of this file.
1/* Copyright 2022-2023 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_INVARIANTS_H
11#define IMPACTX_INVARIANTS_H
12
14
15#include <AMReX_Extension.H>
16#include <AMReX_REAL.H>
17#include <AMReX_GpuComplex.H>
18#include <AMReX_Math.H>
19
20#include <cmath>
21
22
24{
32 {
34
40 struct Data {
41 amrex::ParticleReal H;
42 amrex::ParticleReal I;
43 };
44
55 amrex::ParticleReal const alpha,
56 amrex::ParticleReal const beta,
57 amrex::ParticleReal const tn,
58 amrex::ParticleReal const cn )
59 : m_alpha(alpha), m_beta(beta), m_tn(tn), m_cn(cn)
60 {
61 }
62
73 amrex::ParticleReal const x,
74 amrex::ParticleReal const y,
75 amrex::ParticleReal const px,
76 amrex::ParticleReal const py
77 ) const
78 {
79 using namespace amrex::literals; // for _rt and _prt
81
82 // a complex type with two amrex::ParticleReal
84
85 // convert transverse phase space coordinates to normalized units
86 amrex::ParticleReal const xn = x/(m_cn*std::sqrt(m_beta));
87 amrex::ParticleReal const yn = y/(m_cn*std::sqrt(m_beta));
88 amrex::ParticleReal const pxn = px*std::sqrt(m_beta)/m_cn + m_alpha*xn;
89 amrex::ParticleReal const pyn = py*std::sqrt(m_beta)/m_cn + m_alpha*yn;
90
91 // assign complex position zeta = x + iy
92 Complex const zeta(xn, yn);
93 Complex const zetaconj(xn, -yn);
94 Complex const re1(1.0_prt, 0.0_prt);
95 Complex const im1(0.0_prt, 1.0_prt);
96
97 // compute croot = sqrt(1-zeta**2)
98 Complex croot = powi<2>(zeta);
99 croot = re1 - croot;
100 croot = amrex::sqrt(croot);
101
102 // compute carcsin = arcsin(zeta)
103 Complex carcsin = im1*zeta + croot;
104 carcsin = -im1*amrex::log(carcsin);
105
106 // compute complex potential appearing in H invariant
107 Complex Hpotential = zeta/croot;
108 Hpotential = Hpotential*carcsin;
109
110 // compute complex potential appearing in I invariant
111 Complex Ipotential = (zeta+zetaconj)/croot;
112 Ipotential = Ipotential*carcsin;
113
114 // evaluate real parts
115 amrex::ParticleReal Hinv = Hpotential.m_real;
116 amrex::ParticleReal Iinv = Ipotential.m_real;
117
118 // compute invariants H and I
119 amrex::ParticleReal const Jz = xn*pyn - yn*pxn;
120 Hinv = (powi<2>(xn) + powi<2>(yn) + powi<2>(pxn) + powi<2>(pyn))/2
121 + m_tn*Hinv;
122 Iinv = powi<2>(Jz) + powi<2>(pxn) + powi<2>(xn) + m_tn*Iinv;
123
124 return {Hinv, Iinv};
125
126 }
127
128 private:
129 amrex::ParticleReal m_alpha;
130 amrex::ParticleReal m_beta;
131 amrex::ParticleReal m_tn;
132 amrex::ParticleReal m_cn;
133 };
134
135} // namespace impactx
136
137#endif // IMPACTX_INVARIANTS_H
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
amrex::GpuComplex< amrex::Real > Complex
constexpr T powi(T x) noexcept
__host__ __device__ GpuComplex< T > log(const GpuComplex< T > &a_z) noexcept
__host__ __device__ GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Definition CovarianceMatrixMath.H:25
Definition NonlinearLensInvariants.H:40
amrex::ParticleReal I
second phase space function ("second invariant")
Definition NonlinearLensInvariants.H:42
amrex::ParticleReal H
first phase space function (Hamiltonian)
Definition NonlinearLensInvariants.H:41
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Data operator()(amrex::ParticleReal const x, amrex::ParticleReal const y, amrex::ParticleReal const px, amrex::ParticleReal const py) const
Definition NonlinearLensInvariants.H:72
ImpactXParticleContainer::ParticleType PType
Definition NonlinearLensInvariants.H:33
amrex::ParticleReal m_beta
Twiss alpha.
Definition NonlinearLensInvariants.H:130
NonlinearLensInvariants(amrex::ParticleReal const alpha, amrex::ParticleReal const beta, amrex::ParticleReal const tn, amrex::ParticleReal const cn)
Definition NonlinearLensInvariants.H:54
amrex::ParticleReal m_tn
Twiss beta (m)
Definition NonlinearLensInvariants.H:131
amrex::ParticleReal m_cn
dimensionless strength of the nonlinear insert
Definition NonlinearLensInvariants.H:132
amrex::ParticleReal m_alpha
Definition NonlinearLensInvariants.H:129