ATLAS Offline Software
Loading...
Searching...
No Matches
BFieldCond.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8/*
9 * Compute the Biot-Savart field due to this conductor
10 * If deriv[9] is passed, also computes the field derivatives
11 * The results are _added_ to B[] and deriv[].
12 */
13
15// We compile this package with optimization, even in debug builds; otherwise,
16// the heavy use of Eigen makes it too slow. However, from here we may call
17// to out-of-line Eigen code that is linked from other DSOs; in that case,
18// it would not be optimized. Avoid this by forcing all Eigen code
19// to be inlined here if possible.
20void
21BFieldCond::addBiotSavart(double scaleFactor,
22 const double* ATH_RESTRICT xyz,
23 double* ATH_RESTRICT B_in,
24 double* ATH_RESTRICT deriv) const
25{
26 static const double mu04pi = 1.0e-7; // mu_0/4pi
27 static const double minvsq = 10. * 10.; // (1 cm)^2
28
29 const Eigen::Map<const Eigen::Vector3d> pos(xyz);
30 Eigen::Map<Eigen::Vector3d> B(B_in);
31
32 const Eigen::Vector3d r1 = pos - m_p1;
33 const Eigen::Vector3d r2 = pos - m_p2;
34 const Eigen::Vector3d v = m_u.cross(r1);
35 const double vsq = std::max(v.squaredNorm(), minvsq);
36
37 const double r1u = r1.dot(m_u);
38
39 const double r2u = r2.dot(m_u);
40 const double r1n = r1.norm();
41
42 const double r2n = r2.norm();
43
44 const double f0 = mu04pi * m_curr * scaleFactor / vsq;
45 const double f1 = f0 * (m_finite ? r1u / r1n - r2u / r2n : 2.0);
46 const double f2 = 2.0 * f1 / vsq;
47
48 B += f1 * v;
49
50 if (deriv) {
51 Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor>> D(deriv);
52
53 D(0, 1) -= f1 * m_u(2);
54 D(0, 2) += f1 * m_u(1);
55 D(1, 0) += f1 * m_u(2);
56 D(1, 2) -= f1 * m_u(0);
57 D(2, 0) -= f1 * m_u(1);
58 D(2, 1) += f1 * m_u(0);
59
60 if (vsq > minvsq) {
61 Eigen::Vector3d w = f2 * (m_u * r1u - r1);
62
63 if (m_finite) {
64 // Finite conductor segment
65 w += f0 * ((m_u - r1 * r1u / (r1n * r1n)) / r1n -
66 (m_u - r2 * r2u / (r2n * r2n)) / r2n);
67 }
68
69 D += v * w.transpose();
70 }
71 }
72}
73
#define xyz
const Eigen::Vector3d m_u
Definition BFieldCond.h:58
void addBiotSavart(double scaleFactor, const double *ATH_RESTRICT xyz, double *ATH_RESTRICT B, double *ATH_RESTRICT deriv=nullptr) const
const Eigen::Vector3d m_p1
Definition BFieldCond.h:58
double m_curr
Definition BFieldCond.h:59
bool m_finite
Definition BFieldCond.h:51
const Eigen::Vector3d m_p2
Definition BFieldCond.h:58
#define ATH_FLATTEN
#define ATH_RESTRICT
Definition restrict.h:31