CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HarmBasis3DCyl.cc
Go to the documentation of this file.
1 // //
3 // HarmBasis3DCyl: set of basis harmonic polynomials in cylindrical CS //
4 // //
6 
7 #include "HarmBasis3DCyl.h"
8 
9 using namespace magfieldparam;
10 
11 //_______________________________________________________________________________
13  //Construct a basis of dimension N
14  //
15  Dim = N;
16  Len = N * (N + 2);
17 
18  L_k = new int[Len];
19  M_k = new int[Len];
20 
21  P_k = new double[Len];
22  Br_k = new double[Len];
23  Bz_k = new double[Len];
24  Bphi_k = new double[Len];
25 
26  PtB.reserve(N);
27  BrB.reserve(N);
28  BzB.reserve(N);
29  BphiB.reserve(N);
30 
31  rz_harm_poly::IncNPwr(N); //In order to prevent GetMaxPow() calls
32  unsigned M, vLen, k = 0;
33  for (unsigned L = 1; L <= N; ++L) {
34  vLen = L + 1;
35  harm_poly_vec Pt_vec;
36  Pt_vec.reserve(vLen);
37  harm_poly_vec Br_vec;
38  Br_vec.reserve(vLen);
39  harm_poly_vec Bz_vec;
40  Bz_vec.reserve(vLen);
41  harm_poly_vec Bphi_vec;
42  Bphi_vec.reserve(vLen);
43 
44  Pt_vec.push_back(rz_harm_poly(L));
45  Br_vec.push_back(Pt_vec[0].GetDiff(0));
46  Bz_vec.push_back(Pt_vec[0].GetDiff(1));
47  Bphi_vec.push_back(rz_harm_poly());
48  Bphi_vec[0].CheatL(L);
49 
50  L_k[k] = L;
51  M_k[k] = 0;
52  ++k;
53 
54  for (M = 1; M <= L; ++M) {
55  Pt_vec.push_back(Pt_vec[M - 1].LadderUp());
56  Br_vec.push_back(Pt_vec[M].GetDiff(0));
57  Bz_vec.push_back(Pt_vec[M].GetDiff(1));
58  Bphi_vec.push_back(Pt_vec[M].GetDecPow(0));
59  Bphi_vec[M].Scale(M);
60  L_k[k] = L;
61  M_k[k] = M;
62  ++k;
63  L_k[k] = L;
64  M_k[k] = -M;
65  ++k;
66  }
67  PtB.push_back(Pt_vec);
68  BrB.push_back(Br_vec);
69  BzB.push_back(Bz_vec);
70  BphiB.push_back(Bphi_vec);
71  }
72 }
73 
74 //_______________________________________________________________________________
76  delete[] Bphi_k;
77  delete[] Bz_k;
78  delete[] Br_k;
79  delete[] P_k;
80  delete[] M_k;
81  delete[] L_k;
82 }
83 
84 //_______________________________________________________________________________
86  //Fills the linear array val[Len] with values of basis polynomials.
87  //Private function, intended for internal use only.
88  //
89  unsigned M;
90  double V;
91  rz_harm_poly *P;
92  for (unsigned L = 1, k = 0; L <= Dim; ++L, ++k) {
93  (*val) = B[k][0].Eval();
94  ++val;
95  for (M = 1; M <= L; ++M) {
96  P = &(B[k][M]);
97  V = P->Eval();
98  (*val) = V * P->GetCos();
99  ++val;
100  (*val) = V * P->GetSin();
101  ++val;
102  }
103  }
104 }
105 
106 //_______________________________________________________________________________
108  //Fills the array Bphi_k[Len] with values of phi-basis polynomials.
109  //
110  unsigned M;
111  double V;
112  double *val = Bphi_k;
113  rz_harm_poly *P;
114  for (unsigned L = 1, k = 0; L <= Dim; ++L, ++k) {
115  (*val) = 0.;
116  ++val;
117  for (M = 1; M <= L; ++M) {
118  P = &(BphiB[k][M]);
119  V = P->Eval();
120  (*val) = -V * P->GetSin();
121  ++val;
122  (*val) = V * P->GetCos();
123  ++val;
124  }
125  }
126 }
127 
128 //_______________________________________________________________________________
129 double HarmBasis3DCyl::GetVal(double *coeff, double *basis) {
130  //return value of the expansion with coefficients coeff[Len] for the basis
131  //Private function, intended for internal use only.
132  //
133  double S = 0.;
134  for (unsigned k = 0; k < Len; ++k)
135  S += coeff[k] * basis[k];
136  return S;
137 }
138 
139 //_______________________________________________________________________________
140 void HarmBasis3DCyl::Print(harm_poly_arr &B, std::ostream &out) {
141  unsigned jL, jM, wdt = 60;
142  char fc1 = '-', fc0 = out.fill(fc1);
143  for (jL = 0; jL < B.size(); ++jL) {
144  out << std::setw(wdt) << fc1 << std::endl;
145  out << "Basis subset " << jL + 1 << std::endl;
146  out << std::setw(wdt) << fc1 << std::endl;
147  for (jM = 0; jM < B[jL].size(); ++jM) {
148  B[jL][jM].Print(out);
149  }
150  }
151  out.fill(fc0);
152 }
153 
154 //_______________________________________________________________________________
155 void HarmBasis3DCyl::Print(std::ostream &out) {
156  out << "BASIS POLYNOMIALS FOR THE POTENTIAL:\n" << std::endl;
157  PrintPtB(out);
158  out << "\nBASIS POLYNOMIALS FOR R-COMPONENT OF THE FIELD:\n" << std::endl;
159  PrintBrB(out);
160  out << "\nBASIS POLYNOMIALS FOR Z-COMPONENT OF THE FIELD:\n" << std::endl;
161  PrintBzB(out);
162  out << "\nBASIS POLYNOMIALS FOR PHI-COMPONENT OF THE FIELD:\n" << std::endl;
163  PrintBphiB(out);
164 }
Definition: APVGainStruct.h:7
void PrintBrB(std::ostream &out=std::cout)
void PrintBphiB(std::ostream &out=std::cout)
HarmBasis3DCyl(const unsigned N=18)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
static void IncNPwr(const unsigned N)
Definition: poly2d_base.h:73
std::vector< harm_poly_vec > harm_poly_arr
Definition: HarmBasis3DCyl.h:9
std::vector< rz_harm_poly > harm_poly_vec
Definition: HarmBasis3DCyl.h:8
#define N
Definition: blowfish.cc:9
void Print(harm_poly_arr &B, std::ostream &out=std::cout)
void EvalRZ(harm_poly_arr &B, double *val)
std::pair< OmniClusterRef, TrackingParticleRef > P
void PrintBzB(std::ostream &out=std::cout)
void PrintPtB(std::ostream &out=std::cout)
double GetVal(double *coeff, double *basis)