Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:42

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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   // Create a test context
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   // std::ofstream outf("solenoid.csv");
0040   // outf << "x;y;z;B_x;B_y;B_z" << std::endl;
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);  // greater than zero
0053       // check symmetry: at z=0 it should be exactly symmetric
0054       CHECK_CLOSE_ABS(B1, B2, tol_B);
0055 
0056       // at this point in r, go along the length
0057       for (std::size_t j = 0; j <= steps; j++) {
0058         // double z = cfg.L/steps * j - (cfg.L/2.);
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           // outf << r << ";0;" << z << ";" << B_zp_rp.x() << ";" <<
0067           // B_zp_rp.y() << ";" << B_zp_rp.z() << std::endl;
0068           // if(j>0) {
0069           // outf << r << ";0;" << -z << ";" << B_zn_rp.x() << ";" <<
0070           // B_zn_rp.y() << ";" << B_zn_rp.z() << std::endl;
0071           //}
0072           // if(i>0) {
0073           // outf << -r << ";0;" << z << ";" << B_zp_rn.x() << ";" <<
0074           // B_zp_rn.y() << ";" << B_zp_rn.z() << std::endl;
0075           //}
0076           // if(i>0 && j>0) {
0077           // outf << -r << ";0;" << -z << ";" << B_zn_rn.x() << ";" <<
0078           // B_zn_rn.y() << ";" << B_zn_rn.z() << std::endl;
0079           //}
0080 
0081           // non-zero z
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             // z components should be the same for +- r
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             // x components should be exactly opposite
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             // z components should be the same for +- z
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             // x components should be exactly opposite
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   // outf.close();
0107 }
0108 
0109 }  // namespace Acts::Test