File indexing completed on 2025-01-18 09:12:42
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0014 #include "Acts/MagneticField/SolenoidBField.hpp"
0015 #include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
0016 #include "Acts/Utilities/Result.hpp"
0017
0018 #include <cstddef>
0019
0020 using namespace Acts::UnitLiterals;
0021
0022 namespace Acts::Test {
0023
0024 BOOST_AUTO_TEST_CASE(TestSolenoidBField) {
0025
0026 MagneticFieldContext mfContext = MagneticFieldContext();
0027
0028 SolenoidBField::Config cfg{};
0029 cfg.length = 5.8_m;
0030 cfg.radius = (2.56 + 2.46) * 0.5 * 0.5_m;
0031 cfg.nCoils = 1154;
0032 cfg.bMagCenter = 2_T;
0033 SolenoidBField bField(cfg);
0034
0035 auto cache = bField.makeCache(mfContext);
0036 CHECK_CLOSE_ABS(bField.getField({0, 0, 0}, cache).value(),
0037 Vector3(0, 0, 2.0_T), 1e-6_T);
0038
0039
0040
0041
0042 double tol = 1e-6;
0043 double tol_B = 1e-6_T;
0044 std::size_t steps = 20;
0045 for (std::size_t i = 0; i < steps; i++) {
0046 double r = 1.5 * cfg.radius / steps * i;
0047 BOOST_TEST_CONTEXT("r=" << r) {
0048 Vector3 B1 = bField.getField({r, 0, 0}, cache).value();
0049 Vector3 B2 = bField.getField({-r, 0, 0}, cache).value();
0050 CHECK_SMALL(B1.x(), tol);
0051 CHECK_SMALL(B1.y(), tol);
0052 BOOST_CHECK_GT(std::abs(B1.z()), tol_B);
0053
0054 CHECK_CLOSE_ABS(B1, B2, tol_B);
0055
0056
0057 for (std::size_t j = 0; j <= steps; j++) {
0058
0059 double z = (1.5 * cfg.length / 2.) / steps * j;
0060 BOOST_TEST_CONTEXT("z=" << z) {
0061 Vector3 B_zp_rp = bField.getField({r, 0, z}, cache).value();
0062 Vector3 B_zn_rp = bField.getField({r, 0, -z}, cache).value();
0063 Vector3 B_zp_rn = bField.getField({-r, 0, z}, cache).value();
0064 Vector3 B_zn_rn = bField.getField({-r, 0, -z}, cache).value();
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 BOOST_CHECK_GT(std::abs(B_zp_rp.z()), tol_B);
0083 BOOST_CHECK_GT(std::abs(B_zn_rp.z()), tol_B);
0084 BOOST_CHECK_GT(std::abs(B_zn_rn.z()), tol_B);
0085 BOOST_CHECK_GT(std::abs(B_zp_rn.z()), tol_B);
0086 if (i > 0) {
0087
0088 CHECK_CLOSE_ABS(B_zp_rp.z(), B_zp_rn.z(), tol_B);
0089 CHECK_CLOSE_ABS(B_zn_rp.z(), B_zn_rn.z(), tol_B);
0090
0091 CHECK_CLOSE_ABS(B_zp_rp.x(), -B_zp_rn.x(), tol_B);
0092 CHECK_CLOSE_ABS(B_zn_rp.x(), -B_zn_rn.x(), tol_B);
0093 }
0094 if (j > 0) {
0095
0096 CHECK_CLOSE_ABS(B_zp_rp.z(), B_zn_rp.z(), tol_B);
0097 CHECK_CLOSE_ABS(B_zp_rn.z(), B_zn_rn.z(), tol_B);
0098
0099 CHECK_CLOSE_ABS(B_zp_rp.x(), -B_zn_rp.x(), tol_B);
0100 CHECK_CLOSE_ABS(B_zp_rn.x(), -B_zn_rn.x(), tol_B);
0101 }
0102 }
0103 }
0104 }
0105 }
0106
0107 }
0108
0109 }