File indexing completed on 2023-03-17 11:14:37
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
0017
0018
0019
0020
0021 namespace magfieldparam {
0022
0023 struct poly2d_term {
0024 double coeff;
0025 unsigned np[2];
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
0039
0040
0041
0042
0043
0044
0045 class poly2d_base {
0046
0047 protected:
0048
0049
0050 static double rval;
0051 static double zval;
0052
0053 static double **rz_pow;
0054 static unsigned NTab;
0055 static unsigned NPwr;
0056 static bool rz_set;
0057
0058 static const double MIN_COEFF;
0059
0060 static std::set<poly2d_base *> poly2d_base_set;
0061
0062
0063 static void SetTabSize(const unsigned N);
0064 static void FillTable(const double r, const double z);
0065
0066 static void AdjustTab();
0067
0068
0069 std::vector<poly2d_term> data;
0070 unsigned max_pwr;
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();
0099 void Compress() { Collect(); }
0100
0101 void Diff(int nvar);
0102 void Int(int nvar);
0103 void IncPow(int nvar);
0104 void DecPow(int nvar);
0105
0106 void Scale(const double C);
0107
0108
0109 double Eval();
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 };
0124 }
0125
0126 #endif