CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/MagneticField/ParametrizedEngine/plugins/HarmBasis3DCyl.cc

Go to the documentation of this file.
00001 
00002 //                                                                             //
00003 //  HarmBasis3DCyl: set of basis harmonic polynomials in cylindrical CS        //
00004 //                                                                             //
00006 
00007 #include "HarmBasis3DCyl.h"
00008 
00009 using namespace magfieldparam;
00010 
00011 
00012 //_______________________________________________________________________________
00013 HarmBasis3DCyl::HarmBasis3DCyl(const unsigned N)
00014 {
00015 //Construct a basis of dimension N
00016 //
00017    Dim = N;
00018    Len = N*(N+2);
00019    
00020    L_k = new int [Len];
00021    M_k = new int [Len];
00022    
00023    P_k    = new double [Len];
00024    Br_k   = new double [Len];
00025    Bz_k   = new double [Len];
00026    Bphi_k = new double [Len];
00027    
00028    PtB.reserve(N);
00029    BrB.reserve(N);
00030    BzB.reserve(N);
00031    BphiB.reserve(N);
00032    
00033    rz_harm_poly::IncNPwr(N); //In order to prevent GetMaxPow() calls
00034    unsigned M, vLen, k = 0;
00035    for (unsigned L = 1; L <= N; ++L) {
00036       vLen = L+1;
00037       harm_poly_vec Pt_vec;   Pt_vec.reserve(vLen);
00038       harm_poly_vec Br_vec;   Br_vec.reserve(vLen);
00039       harm_poly_vec Bz_vec;   Bz_vec.reserve(vLen);
00040       harm_poly_vec Bphi_vec; Bphi_vec.reserve(vLen);
00041 
00042       Pt_vec.push_back  (rz_harm_poly(L));
00043       Br_vec.push_back  (Pt_vec[0].GetDiff(0));
00044       Bz_vec.push_back  (Pt_vec[0].GetDiff(1));
00045       Bphi_vec.push_back(rz_harm_poly());
00046       Bphi_vec[0].CheatL(L);
00047       
00048       L_k[k] = L; M_k[k] = 0; ++k;
00049 
00050       for (M = 1; M <= L; ++M) {
00051          Pt_vec.push_back  (Pt_vec[M-1].LadderUp());
00052          Br_vec.push_back  (Pt_vec[M].GetDiff(0));
00053          Bz_vec.push_back  (Pt_vec[M].GetDiff(1));
00054          Bphi_vec.push_back(Pt_vec[M].GetDecPow(0));
00055          Bphi_vec[M].Scale(M);
00056          L_k[k] = L; M_k[k] =  M; ++k;
00057          L_k[k] = L; M_k[k] = -M; ++k;
00058       }
00059       PtB.push_back  (Pt_vec);
00060       BrB.push_back  (Br_vec);
00061       BzB.push_back  (Bz_vec);
00062       BphiB.push_back(Bphi_vec);
00063    }
00064 }
00065 
00066 //_______________________________________________________________________________
00067 HarmBasis3DCyl::~HarmBasis3DCyl()
00068 {
00069    delete [] Bphi_k;
00070    delete [] Bz_k;
00071    delete [] Br_k;
00072    delete [] P_k;
00073    delete [] M_k;
00074    delete [] L_k;
00075 }
00076 
00077 //_______________________________________________________________________________
00078 void HarmBasis3DCyl::EvalRZ(harm_poly_arr &B, double *val)
00079 {
00080 //Fills the linear array val[Len] with values of basis polynomials.
00081 //Private function, intended for internal use only.
00082 //
00083    unsigned M;
00084    double   V;
00085    rz_harm_poly *P;
00086    for (unsigned L = 1, k = 0; L <= Dim; ++L, ++k) {
00087       (*val) = B[k][0].Eval(); ++val;
00088       for (M = 1; M <= L; ++M) {
00089          P = &(B[k][M]);
00090          V = P->Eval();
00091          (*val) = V*P->GetCos(); ++val;
00092          (*val) = V*P->GetSin(); ++val;
00093       }
00094    }
00095 }
00096 
00097 //_______________________________________________________________________________
00098 void HarmBasis3DCyl::EvalBphi()
00099 {
00100 //Fills the array Bphi_k[Len] with values of phi-basis polynomials.
00101 //
00102    unsigned M;
00103    double   V;
00104    double  *val = Bphi_k;
00105    rz_harm_poly *P;
00106    for (unsigned L = 1, k = 0; L <= Dim; ++L, ++k) {
00107       (*val) = 0.; ++val;
00108       for (M = 1; M <= L; ++M) {
00109          P = &(BphiB[k][M]);
00110          V = P->Eval();
00111          (*val) = -V*P->GetSin(); ++val;
00112          (*val) =  V*P->GetCos(); ++val;
00113       }
00114    }
00115 }
00116 
00117 //_______________________________________________________________________________
00118 double HarmBasis3DCyl::GetVal(double *coeff, double *basis)
00119 {
00120 //return value of the expansion with coefficients coeff[Len] for the basis
00121 //Private function, intended for internal use only.
00122 //
00123    double S = 0.;
00124    for (unsigned k = 0; k < Len; ++k) S += coeff[k]*basis[k];
00125    return S;
00126 }
00127 
00128 //_______________________________________________________________________________
00129 void HarmBasis3DCyl::Print(harm_poly_arr &B, std::ostream &out)
00130 {
00131    unsigned jL, jM, wdt = 60;
00132    char fc1 = '-', fc0 = out.fill(fc1);
00133    for (jL = 0; jL < B.size(); ++jL) {
00134       out << std::setw(wdt) << fc1 << std::endl;
00135       out << "Basis subset " << jL+1 << std::endl;
00136       out << std::setw(wdt) << fc1 << std::endl;
00137       for (jM = 0; jM < B[jL].size(); ++jM) {
00138          B[jL][jM].Print(out);
00139       }
00140    }
00141    out.fill(fc0);
00142 }
00143 
00144 //_______________________________________________________________________________
00145 void HarmBasis3DCyl::Print(std::ostream &out)
00146 {
00147    out << "BASIS POLYNOMIALS FOR THE POTENTIAL:\n" << std::endl;
00148    PrintPtB(out);
00149    out << "\nBASIS POLYNOMIALS FOR R-COMPONENT   OF THE FIELD:\n" << std::endl;
00150    PrintBrB(out);
00151    out << "\nBASIS POLYNOMIALS FOR Z-COMPONENT   OF THE FIELD:\n" << std::endl;
00152    PrintBzB(out);
00153    out << "\nBASIS POLYNOMIALS FOR PHI-COMPONENT OF THE FIELD:\n" << std::endl;
00154    PrintBphiB(out);
00155 }
00156