18#ifndef ABSBEAMLINE_MULTIPOLET_BASE_H
19#define ABSBEAMLINE_MULTIPOLET_BASE_H
106 KOKKOS_INLINE_FUNCTION
static double factorial(
unsigned int n);
108 KOKKOS_INLINE_FUNCTION
static double powerInteger(
double x,
unsigned int n);
111 const Kokkos::Array<double, MultipoleTConfig::NumPoles>& poles,
112 unsigned int numDerivatives,
double x,
113 Kokkos::Array<double, MaxDerivatives>& derivatives);
114 template <
class ViewType>
116 const double& s0,
const double& lambdaLeft,
const double& lambdaRight,
double s,
117 const ViewType& tanhCoefficients, Kokkos::Array<double, MaxDerivatives>& derivatives);
121 KOKKOS_INLINE_FUNCTION
static void calcPowers(
122 double value,
unsigned int maxPower, Kokkos::Array<double, MaxPowerInteger>& powers);
125KOKKOS_INLINE_FUNCTION
127 static constexpr double factorialTable[
MaxFactorial + 1] = {
147 121645100408832000.0,
148 2432902008176640000.0};
149 return factorialTable[n];
152KOKKOS_INLINE_FUNCTION
165KOKKOS_INLINE_FUNCTION
167 const Kokkos::Array<double, MultipoleTConfig::NumPoles>& poles,
168 const unsigned int numDerivatives,
const double x,
169 Kokkos::Array<double, MaxDerivatives>& derivatives) {
170 Kokkos::Array<double, MultipoleTConfig::NumPoles> coefficients = poles;
171 for (
unsigned int i = 0; i < numDerivatives; ++i) {
179 coefficients[j] = coefficients[j + 1] *
static_cast<double>(j + 1);
185template <
class ViewType>
187 const double& s0,
const double& lambdaLeft,
const double& lambdaRight,
const double s,
188 const ViewType& tanhCoefficients, Kokkos::Array<double, MaxDerivatives>& derivatives) {
189 const double tLeft = Kokkos::tanh((s + s0) / lambdaLeft);
190 const double tRight = Kokkos::tanh((s - s0) / lambdaRight);
191 double lambdaLeftN = 1.0;
192 double lambdaRightN = 1.0;
193 const unsigned int numDerivatives = tanhCoefficients.extent(0);
194 const unsigned int numCoefficients = tanhCoefficients.extent(1);
195 for (
unsigned int i = 0; i < numDerivatives; ++i) {
198 double tRightN = 1.0;
199 double leftTerm = 0.0;
200 double rightTerm = 0.0;
201 for (
unsigned int j = 0; j < numCoefficients; ++j) {
202 const auto coeff = tanhCoefficients(i, j);
203 leftTerm += coeff * tLeftN;
204 rightTerm += coeff * tRightN;
209 derivatives[i] = (leftTerm / lambdaLeftN - rightTerm / lambdaRightN) / 2;
211 lambdaLeftN *= lambdaLeft;
212 lambdaRightN *= lambdaRight;
216KOKKOS_INLINE_FUNCTION
236 const double value,
const unsigned int maxPower,
237 Kokkos::Array<double, MaxPowerInteger>& powers) {
239 for (
unsigned int i = 1; i <= maxPower; i++) {
240 powers[i] = powers[i - 1] * value;
ippl::Vector< T, Dim > Vector_t
Template PIC bunch: IPPL PicManager, shared field mesh/solver, and multiple particle containers.
Abstract base class for accelerator geometry classes.
virtual ~MultipoleTBase()=default
static constexpr size_t MaxPowerInteger
static KOKKOS_INLINE_FUNCTION Vector_t< double, 3 > rotateFrame(const Vector_t< double, 3 > &R, const MultipoleTConfig &config)
static KOKKOS_INLINE_FUNCTION double powerInteger(double x, unsigned int n)
static KOKKOS_INLINE_FUNCTION void calcTransverseDerivatives(const Kokkos::Array< double, MultipoleTConfig::NumPoles > &poles, unsigned int numDerivatives, double x, Kokkos::Array< double, MaxDerivatives > &derivatives)
static KOKKOS_INLINE_FUNCTION void calcPowers(double value, unsigned int maxPower, Kokkos::Array< double, MaxPowerInteger > &powers)
static constexpr unsigned int MaxDerivatives
virtual void getField(Kokkos::View< Vector_t< double, 3 > * >, Kokkos::View< Vector_t< double, 3 > * >, Kokkos::View< Vector_t< double, 3 > * >, double, size_t)=0
static constexpr size_t MaxFactorial
Kokkos::View< double ** > tanhCoefficientsGpu_m
virtual void initialise()=0
virtual BGeometryBase * getGeometry()=0
static KOKKOS_INLINE_FUNCTION void calcFringeDerivatives(const double &s0, const double &lambdaLeft, const double &lambdaRight, double s, const ViewType &tanhCoefficients, Kokkos::Array< double, MaxDerivatives > &derivatives)
static KOKKOS_INLINE_FUNCTION double factorial(unsigned int n)
Kokkos::View< double ** >::host_mirror_type tanhCoefficientsHost_m
virtual bool getField(const Vector_t< double, 3 > &, Vector_t< double, 3 > &, Vector_t< double, 3 > &, double)=0
void generateTanhCoefficients(unsigned int numDerivatives)
static constexpr unsigned int NumPoles