OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
TestMultipoleTBase.cpp
Go to the documentation of this file.
1//
2// Tests for MultipoleTBase
3//
4// Copyright (c) 2025, Jon Thompson, STFC Rutherford Appleton Laboratory, Didcot, UK
5//
6// This file is part of OPAL.
7//
8// OPAL 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// You should have received a copy of the GNU General Public License
14// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
15//
16
18#include "gtest/gtest.h"
19
20class MultipoleTBaseTest : public testing::Test, public MultipoleTBase {
21public:
23
24 static void SetUpTestSuite() {
25 int argc = 0;
26 char** argv = nullptr;
27 ippl::initialize(argc, argv);
28 }
29
30 static void TearDownTestSuite() { ippl::finalize(); }
31
32 // Overrides of MultipoleTBase
33 void initialise() override {}
34 BGeometryBase* getGeometry() override { return nullptr; }
36 const Kokkos::View<Vector_t<double, 3>*> /*R*/,
37 Kokkos::View<Vector_t<double, 3>*> /*E*/, Kokkos::View<Vector_t<double, 3>*> /*B*/,
38 double /*scaling*/, size_t /*count*/) override {}
40 const Vector_t<double, 3>& /*R*/, Vector_t<double, 3>& /*E*/,
41 Vector_t<double, 3>& /*B*/, double /*scaling*/) override {
42 return false;
43 }
44
45 // Tanh derivative coefficient test helper
46 std::vector<double> tanhCoefficients(const unsigned int derivative) const {
47 std::vector<double> coefficients;
48 const auto numCoefficients = tanhCoefficientsHost_m.extent(1);
49 coefficients.resize(numCoefficients);
50 for (unsigned int i = 0; i < numCoefficients; ++i) {
51 coefficients[i] = tanhCoefficientsHost_m(derivative, i);
52 }
53 return coefficients;
54 }
55};
56
57// Are the derivatives of the transverse polynomial correctly calculated
58TEST_F(MultipoleTBaseTest, TransverseDerivatives) {
59 constexpr Kokkos::Array poles = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
60 Kokkos::Array<double, MaxDerivatives> derivatives{};
61 calcTransverseDerivatives(poles, 7, 1.0, derivatives);
62 EXPECT_DOUBLE_EQ(derivatives[0], 15.0);
63 EXPECT_DOUBLE_EQ(derivatives[1], 55.0);
64 EXPECT_DOUBLE_EQ(derivatives[2], 170.0);
65 EXPECT_DOUBLE_EQ(derivatives[3], 414.0);
66 EXPECT_DOUBLE_EQ(derivatives[4], 696.0);
67 EXPECT_DOUBLE_EQ(derivatives[5], 600.0);
68 EXPECT_DOUBLE_EQ(derivatives[6], 0.0);
69}
70
71// Are the tanh fringe polynomial constants calculated correctly
72TEST_F(MultipoleTBaseTest, FringeDerivativeConstants) {
73 generateTanhCoefficients(5);
74 EXPECT_EQ(tanhCoefficients(0), (std::vector<double>{0, 1, 0, 0, 0, 0, 0}));
75 EXPECT_EQ(tanhCoefficients(1), (std::vector<double>{1, 0, -1, 0, 0, 0, 0}));
76 EXPECT_EQ(tanhCoefficients(2), (std::vector<double>{0, -2, 0, 2, 0, 0, 0}));
77 EXPECT_EQ(tanhCoefficients(3), (std::vector<double>{-2, 0, 8, 0, -6, 0, 0}));
78 EXPECT_EQ(tanhCoefficients(4), (std::vector<double>{0, 16, 0, -40, 0, 24, 0}));
79 EXPECT_EQ(tanhCoefficients(5), (std::vector<double>{16, 0, -136, 0, 240, 0, -120}));
80}
81
82// Are the derivatives of the longitudinal envelope correctly calculated
83TEST_F(MultipoleTBaseTest, FringeDerivatives) {
84 Kokkos::Array<double, MaxDerivatives> derivativesNeg{};
85 Kokkos::Array<double, MaxDerivatives> derivativesPos{};
86 generateTanhCoefficients(6);
87 calcFringeDerivatives(2.0, 1.0, 1.0, -2.0, tanhCoefficientsHost_m, derivativesNeg);
88 calcFringeDerivatives(2.0, 1.0, 1.0, 2.0, tanhCoefficientsHost_m, derivativesPos);
89 EXPECT_NEAR(derivativesNeg[0], 0.49966464986953352, 1e-10);
90 EXPECT_NEAR(derivativesPos[0], 0.49966464986953352, 1e-10);
91 EXPECT_NEAR(derivativesNeg[1], 0.49932952465848707, 1e-10);
92 EXPECT_NEAR(derivativesPos[1], -0.49932952465848707, 1e-10);
93 EXPECT_NEAR(derivativesNeg[2], -0.0013400513070529474, 1e-10);
94 EXPECT_NEAR(derivativesPos[2], -0.0013400513070529474, 1e-10);
95 EXPECT_NEAR(derivativesNeg[3], -1.0026765069198489, 1e-10);
96 EXPECT_NEAR(derivativesPos[3], 1.0026765069198489, 1e-10);
97 EXPECT_NEAR(derivativesNeg[4], -0.0053386419156264964, 1e-10);
98 EXPECT_NEAR(derivativesPos[4], -0.0053386419156264964, 1e-10);
99 EXPECT_NEAR(derivativesNeg[5], 7.9893801387861263, 1e-10);
100 EXPECT_NEAR(derivativesPos[5], -7.9893801387861263, 1e-10);
101 EXPECT_NEAR(derivativesNeg[6], -0.021010422121266359, 1e-10);
102 EXPECT_NEAR(derivativesPos[6], -0.021010422121266359, 1e-10);
103}
ippl::Vector< T, Dim > Vector_t
TEST_F(MultipoleTBaseTest, TransverseDerivatives)
Abstract base class for accelerator geometry classes.
Definition Geometry.h:42
void getField(const Kokkos::View< Vector_t< double, 3 > * >, Kokkos::View< Vector_t< double, 3 > * >, Kokkos::View< Vector_t< double, 3 > * >, double, size_t) override
void initialise() override
std::vector< double > tanhCoefficients(const unsigned int derivative) const
static void TearDownTestSuite()
bool getField(const Vector_t< double, 3 > &, Vector_t< double, 3 > &, Vector_t< double, 3 > &, double) override
BGeometryBase * getGeometry() override
Kokkos::View< double ** >::host_mirror_type tanhCoefficientsHost_m