File indexing completed on 2024-04-06 12:22:33
0001 #include "BFit.h"
0002 #include <cstring>
0003
0004 using namespace std;
0005 using namespace magfieldparam;
0006
0007
0008
0009 #ifdef BFit_PW
0010 const double BFit::Z_nom[4] = {-2.37615687260664e-2, -1.86400109250045e-2, -1.80502358070104e-2, -1.60470955291956e-2};
0011
0012 const double BFit::B_nom[4] = {2.02156567013928,
0013 3.51622117206486,
0014 3.81143026675623,
0015 4.01242188708911};
0016
0017 const double BFit::C_nom[4][16] = {{1.0,
0018 -3.61278802720839e-3,
0019 6.36561393690475e-6,
0020 8.32541914664693e-5,
0021 -2.42108313492765e-6,
0022 -1.87295909297299e-5,
0023 3.06832709074461e-7,
0024 1.91827319271226e-6,
0025 -2.15392717311725e-8,
0026 -1.25266203359502e-7,
0027 3.87507522135914e-10,
0028 4.85518568040635e-9,
0029 4.42080729840719e-11,
0030 -8.83065447433858e-11,
0031 -2.41380148377896e-12,
0032 0.0},
0033 {1.0,
0034 -5.04020236643808e-3,
0035 2.03224205921125e-6,
0036 6.79444854179620e-5,
0037 -1.98082200052911e-6,
0038 -1.93324798138490e-5,
0039 3.15120940544812e-7,
0040 1.82623212354924e-6,
0041 -3.30483297560429e-8,
0042 -1.13251951654739e-7,
0043 1.96974144659278e-9,
0044 4.25153392971594e-9,
0045 -6.12986034064675e-11,
0046 -7.59031334826116e-11,
0047 6.40295019219590e-13,
0048 0.0},
0049 {1.0,
0050 -5.23012318846739e-3,
0051 8.80302231241395e-7,
0052 6.51341641212249e-5,
0053 -1.68564063895995e-6,
0054 -1.93693613146655e-5,
0055 2.58178734098114e-7,
0056 1.81311192824207e-6,
0057 -2.79301520182866e-8,
0058 -1.11679980224632e-7,
0059 1.72615649164433e-9,
0060 4.17328869038146e-9,
0061 -5.72514160410955e-11,
0062 -7.41998111228714e-11,
0063 7.30938527053447e-13,
0064 0.0},
0065 {1.0,
0066 -5.34172971309074e-3,
0067 2.48943649506081e-7,
0068 6.23054033447814e-5,
0069 -1.60390978074464e-6,
0070 -1.92618217244767e-5,
0071 2.42461261622770e-7,
0072 1.78772142159379e-6,
0073 -2.61432416866515e-8,
0074 -1.09159464672341e-7,
0075 1.62705377496138e-9,
0076 4.02967933726133e-9,
0077 -5.48168162195020e-11,
0078 -7.00249566028285e-11,
0079 8.22254619144001e-13,
0080 0.0}};
0081 #else
0082 const double BFit::dZ_0 = -2.62328760352034e-2;
0083 const double BFit::dZ_2 = 5.94363870284212e-4;
0084
0085 const double BFit::C_0[16] = {1.0,
0086 -2.52864632909442e-3,
0087 8.76365790071351e-6,
0088 9.19077286315044e-5,
0089 -2.49284256023752e-6,
0090 -1.80143891826520e-5,
0091 2.29295162454016e-7,
0092 1.96139195659245e-6,
0093 -3.47342625923464e-9,
0094 -1.32147627969588e-7,
0095 -1.50735830442900e-9,
0096 5.17724172101696e-9,
0097 1.54539960459831e-10,
0098 -9.30914368388717e-11,
0099 -5.20466591966397e-12,
0100 0.0};
0101
0102 const double BFit::C_2[16] = {0.0,
0103 -2.96314154618866e-4,
0104 -6.04246295125223e-7,
0105 -2.22393436573694e-6,
0106 2.84133631738674e-9,
0107 -2.07090716476209e-7,
0108 2.55850963123821e-8,
0109 -1.06689136150163e-8,
0110 -5.48842256680751e-9,
0111 1.78987539969165e-9,
0112 5.57809366992069e-10,
0113 -8.25055601520632e-11,
0114 -3.18509299957904e-11,
0115 1.11714602344300e-12,
0116 7.90102331886296e-13,
0117 0.0};
0118
0119 const double BFit::C_4[16] = {0.0,
0120 7.57194953855834e-6,
0121 4.48169046115052e-9,
0122 2.49606093449927e-8,
0123 3.42264285146368e-9,
0124 7.95338846845187e-9,
0125 -1.57711106312732e-9,
0126 1.02715424120585e-11,
0127 2.57261485255293e-10,
0128 -2.41682937761163e-11,
0129 -2.27894837943020e-11,
0130 7.98570801347331e-13,
0131 1.17889573705870e-12,
0132 1.64571374852252e-14,
0133 -2.60212133934707e-14,
0134 0.0};
0135 #endif
0136
0137 BFit::BFit() {
0138 dZ = 0.;
0139 memset(C, 0, 16 * sizeof(double));
0140 rz_poly *P_base = new rz_poly(16);
0141
0142 Bz_base = new rz_poly(P_base->Diff(1));
0143 Bz_base->SetOFF(1);
0144
0145 Br_base = new rz_poly(P_base->Diff(0));
0146 Br_base->SetOFF(0);
0147
0148 delete P_base;
0149 }
0150
0151
0152 void BFit::SetField(double B) {
0153
0154
0155 unsigned int jj;
0156
0157 #ifdef BFit_PW
0158 unsigned int kk = 1;
0159 double w_0, w_1;
0160 if (B <= B_nom[0]) {
0161 dZ = Z_nom[0];
0162 for (jj = 0; jj < 16; ++jj) {
0163 C[jj] = B * C_nom[0][jj];
0164 }
0165 } else if (B >= B_nom[3]) {
0166 dZ = Z_nom[3];
0167 for (jj = 0; jj < 16; ++jj) {
0168 C[jj] = B * C_nom[3][jj];
0169 }
0170 } else {
0171 while (B_nom[kk] < B)
0172 ++kk;
0173 w_1 = (B - B_nom[kk - 1]) / (B_nom[kk] - B_nom[kk - 1]);
0174 w_0 = 1.0 - w_1;
0175 dZ = Z_nom[kk - 1] * w_0 + Z_nom[kk] * w_1;
0176 for (jj = 0; jj < 16; ++jj) {
0177 C[jj] = B * (C_nom[kk - 1][jj] * w_0 + C_nom[kk][jj] * w_1);
0178 }
0179 }
0180 #else
0181 double B2 = B * B;
0182 dZ = dZ_0 + dZ_2 * B2;
0183 for (jj = 0; jj < 16; ++jj) {
0184 C[jj] = B * ((C_4[jj] * B2 + C_2[jj]) * B2 + C_0[jj]);
0185 }
0186 #endif
0187 }
0188
0189
0190 void BFit::GetField(double r, double z, double phi, double &Br, double &Bz, double &Bphi) const {
0191
0192
0193
0194
0195 double zc = z + dZ;
0196
0197 Bz = Bz_base->GetSVal(r, zc, C);
0198 Br = Br_base->GetSVal(r, zc, C + 1);
0199 Bphi = 0.;
0200 }