15#include <fmt/format.h>
29 std::array<std::array<double, kNofCoeff + 3>,
kNofCoeff> A = {{}};
42 std::array<double, 3> field;
45 std::array<double, kNofCoeff> m = {{}};
48 for (
double x = -xMax;
x <= xMax;
x += dx) {
49 for (
double y = -yMax;
y <= yMax;
y += dy) {
50 std::tie(field[0], field[1], field[2]) = fieldFn(
x,
y, zRef);
61 m[k--] = xFactor * m[j];
72 A[i][j] += w * m[i] * m[j];
75 for (
int j = 0; j < 3; ++j) {
87 double factor = A[j][k] / A[k][k];
89 A[j][i] -= factor * A[k][i];
94 for (
int j = k - 1; j >= 0; --j) {
95 double factor = A[j][k] / A[k][k];
97 A[j][i] -= factor * A[k][i];
116 constexpr char indentChar =
'\t';
117 std::stringstream msg;
118 std::string indent(indentLevel, indentChar);
122 msg << indent << format(
"FieldSlice: zRef = {} cm", Cnv(fZref));
124 std::array<std::string, kNofCoeff> m;
126 m[kNofCoeff - 1] =
"";
127 for (
int i = kNofCoeff - 2; i >= kNofCoeff - 1 - kPolDegree; --i) {
128 m[i] = format(
"y{}", kNofCoeff - i - 1);
130 int k = ((kPolDegree - 1) * (kPolDegree + 2)) / 2;
131 for (
int i = kPolDegree; i > 0; --i) {
132 std::string
x = format(
"x{}", kPolDegree - i + 1);
133 for (
int j = kNofCoeff - 1; j >= kNofCoeff - i; --j) {
137 m[kNofCoeff - 1] =
"1";
139 msg <<
'\n' << indent << format(
"{:>15} {:>15} {:>15} {:>15}",
"Monomial",
"Bx",
"By",
"Bz");
140 for (
int i = 0; i < kNofCoeff; ++i) {
141 msg <<
'\n' << indent << format(
"{:>15} {:>15} {:>15} {:>15}", m[i], Cnv(fBx[i]), Cnv(fBy[i]), Cnv(fBz[i]));
152 for (
int i = 0; i < kNofCoeff; ++i) {
A class for a magnetic field approximation on a transverse plane (source)
A magnetic field approximation on the two-dimensional plane.
void CheckConsistency() const
Consistency checker.
CoeffArray_t fBx
Approximation coefficients for the x-component of the field.
CoeffArray_t fBz
Approximation coefficients for the z-component of the field.
static constexpr int kNofCoeff
Number of coefficients.
static constexpr int kPolDegree
Approximation polynomial degree.
CoeffArray_t fBy
Approximation coefficients for the y-component of the field.
std::string ToString(int indentLevel=0, int verbose=1) const
String representation of the class content.
Magnetic flux density vector.
DataOut Cast(const DataT &val)
Converts a value of type DataT to type DataOut.
void CheckSimdVectorEquality(fvec v, const char *name)
Checks, if a SIMD vector horizontally equal TODO: Find this method in the VC!
std::function< std::tuple< double, double, double >(double, double, double)> FieldFn_t
Magnetic field function type Signature: tuple<Bx, By, Bz>(x, y, z);.