CMS 3D CMS Logo

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