# Project CMSSW displayed by LXR

File indexing completed on 2024-04-06 12:22:34

```0001 #ifndef poly2d_base_h
0002 #define poly2d_base_h
0003
0004 #include <iostream>
0005 #include <fstream>
0006 #include <iomanip>
0007 #include <vector>
0008 #include <set>
0009 #include <cstring>
0010
0011 #include <cmath>
0012 #include <cfloat>  //in order to use DBL_EPSILON (1+DBL_EPSILON > 1)
0013
0014 /////////////////////////////////////////////////////////////////////////////////
0015 //                                                                             //
0016 //  The "poly2d_term" represent a term of a polynomial of 2 variables.         //
0017 //                                                                             //
0018 /////////////////////////////////////////////////////////////////////////////////
0019
0020 //_______________________________________________________________________________
0021 namespace magfieldparam {
0022
0023   struct poly2d_term {
0024     double coeff;    //Coefficient of the term
0025     unsigned np[2];  //Powers of variables
0026
0027     poly2d_term() { memset(this, 0, sizeof(*this)); }
0028     poly2d_term(double C, unsigned nr, unsigned nz) {
0029       coeff = C;
0030       np[0] = nr;
0031       np[1] = nz;
0032     }
0033     void Print(std::ostream &out = std::cout, bool first_term = true);
0034   };
0035
0036   /////////////////////////////////////////////////////////////////////////////////
0037   //                                                                             //
0038   //  Base class that represent a polynomial of 2 variables. It isn't supposed   //
0039   //  to be used directly and provides no way of setting coefficients directly.  //
0040   //  Such methods must be defined in derived classes.                           //
0041   //                                                                             //
0042   /////////////////////////////////////////////////////////////////////////////////
0043
0044   //_______________________________________________________________________________
0045   class poly2d_base {  // a general polynomial of 2 variables
0046
0047   protected:
0048     //Group of static members for the class memory management
0049     //----------------------------------------------------------------------------
0050     static double rval;  //last r-value used in calculation
0051     static double zval;  //last z-value used in calculation
0052
0053     static double **rz_pow;  //table with calculated r^n*z^m values
0054     static unsigned NTab;    //rz_pow table size
0055     static unsigned NPwr;    //max power in use by CLASS
0056     static bool rz_set;
0057
0058     static const double MIN_COEFF;  //Threshold for assigning a coeff. to 0
0059
0060     static std::set<poly2d_base *> poly2d_base_set;  //Set of all poly2d_base objects
0061     //   static std::set<poly2d_base*, less<poly2d_base*> > poly2d_base_set;  //Set of all poly2d_base objects
0062
0063     static void SetTabSize(const unsigned N);  //Set rz-table size
0064     static void FillTable(const double r, const double z);
0065
0067     //----------------------------------------------------------------------------
0068
0069     std::vector<poly2d_term> data;  //polynomial terms
0070     unsigned max_pwr;               //max power in use by INSTANCE
0071
0072   public:
0073     static void IncNPwr(const unsigned N) {
0074       if (N > NPwr)
0075         NPwr = N;
0076     }
0077     static int GetMaxPow();
0078     static unsigned Count() { return poly2d_base_set.size(); }
0079     static void PrintTab(std::ostream &out = std::cout, const std::streamsize prec = 5);
0080
0081     static void SetPoint(const double r, const double z);
0082
0083     poly2d_base() {
0084       max_pwr = 0;
0085       poly2d_base_set.insert(this);
0086     }
0087     poly2d_base(const poly2d_base &S) {
0088       data = S.data;
0089       max_pwr = S.max_pwr;
0090       poly2d_base_set.insert(this);
0091     }
0092
0093     virtual ~poly2d_base();
0094
0095     bool IsOn() { return bool(!data.empty()); }
0096     bool IsRZSet() { return rz_set; }
0097
0098     void Collect();  //Collect terms and remove zero terms
0099     void Compress() { Collect(); }
0100
0101     void Diff(int nvar);    //differentiate the polynomial by variable# nvar
0102     void Int(int nvar);     //Integrate the polynomial by variable# nvar
0103     void IncPow(int nvar);  //Multiply the polynomial by variable# nvar
0104     void DecPow(int nvar);  //Divide the polynomial by variable# nvar
0105
0106     void Scale(const double C);
0107     //   poly2d_base& operator*=(const double C) { Scale(C); return *this;}
0108
0109     double Eval();  //Evaluation with no check that rz_pow table exist
0110     double GetVal() {
0111       if (rz_set)
0112         return Eval();
0113       else
0114         return 0.;
0115     }
0116     double GetVal(const double r, const double z) {
0117       SetPoint(r, z);
0118       return Eval();
0119     }
0120
0121     void Print(std::ostream &out = std::cout, const std::streamsize prec = 5);
0122
0123   };  //Class poly2d_base
0124 }  // namespace magfieldparam
0125
0126 #endif```