16 #define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
18 #include <boost/exception/exception.hpp>
19 #include <boost/math/special_functions/ellint_1.hpp>
20 #include <boost/math/special_functions/ellint_2.hpp>
33 return MagneticFieldProvider::Cache::make<Cache>(mctx);
39 Vector2 rzField = multiCoilField(rzPos, m_scale);
40 Vector3 xyzField(0, 0, rzField[1]);
44 Vector3 rDir =
Vector3(position.x(), position.y(), 0).normalized();
45 xyzField += rDir * rzField[0];
57 return multiCoilField(position, m_scale);
70 for (
size_t coil = 0; coil <
m_cfg.nCoils; coil++) {
72 Vector2(pos[0], pos[1] +
m_cfg.length * 0.5 - m_dz * (coil + 0.5));
73 resultField += singleCoilField(shiftedPos, scale);
81 return {B_r(pos, scale), B_z(pos, scale)};
89 using boost::math::ellint_1;
94 using boost::math::ellint_2;
96 double r = std::abs(pos[0]);
110 double k_2 = k2(r, z);
111 double k = std::sqrt(k_2);
113 scale * k * z / (4 * M_PI * std::sqrt(
m_cfg.radius * r * r * r));
115 double B = (2. - k_2) / (2. - 2. * k_2) * ellint_2(k_2) - ellint_1(k_2);
118 return r / pos[0] * constant * B;
126 using boost::math::ellint_1;
131 using boost::math::ellint_2;
133 double r = std::abs(pos[0]);
144 double res = scale / 2. * m_R2 / (std::sqrt(m_R2 + z * z) * (m_R2 + z *
z));
148 double k_2 = k2(r, z);
149 double k = std::sqrt(k_2);
150 double constant = scale * k / (4 * M_PI * std::sqrt(
m_cfg.radius * r));
151 double B = ((
m_cfg.radius +
r) * k_2 - 2. * r) / (2. * r * (1. - k_2)) *
163 return 4 *
m_cfg.radius * r /