Go to the documentation of this file.00001 #ifndef poly2d_base_h
00002 #define poly2d_base_h
00003
00004 #include <iostream>
00005 #include <fstream>
00006 #include <iomanip>
00007 #include <vector>
00008 #include <set>
00009 #include <cstring>
00010
00011 #include <cmath>
00012 #include <float.h>
00013
00015
00016
00017
00019
00020
00021 namespace magfieldparam {
00022
00023 struct poly2d_term {
00024 double coeff;
00025 unsigned np[2];
00026
00027 poly2d_term() {memset(this, 0, sizeof(*this));}
00028 poly2d_term(double C, unsigned nr, unsigned nz)
00029 {
00030 coeff = C; np[0] = nr; np[1] = nz;
00031 }
00032 void Print(std::ostream &out = std::cout, bool first_term = true);
00033 };
00034
00036
00037
00038
00039
00040
00042
00043
00044 class poly2d_base {
00045
00046 protected:
00047
00048
00049 static double rval;
00050 static double zval;
00051
00052 static double **rz_pow;
00053 static unsigned NTab;
00054 static unsigned NPwr;
00055 static bool rz_set;
00056
00057 static const double MIN_COEFF;
00058
00059 static std::set<poly2d_base*> poly2d_base_set;
00060
00061
00062 static void SetTabSize(const unsigned N);
00063 static void FillTable (const double r, const double z);
00064
00065 static void AdjustTab();
00066
00067
00068 std::vector<poly2d_term> data;
00069 unsigned max_pwr;
00070
00071 public:
00072 static void IncNPwr(const unsigned N) {if (N > NPwr) NPwr = N;}
00073 static int GetMaxPow();
00074 static unsigned Count() { return poly2d_base_set.size();}
00075 static void PrintTab(std::ostream &out = std::cout, const std::streamsize prec = 5);
00076
00077 static void SetPoint(const double r, const double z);
00078
00079 poly2d_base() {
00080 max_pwr = 0;
00081 poly2d_base_set.insert(this);
00082 }
00083 poly2d_base(const poly2d_base &S) {
00084 data = S.data;
00085 max_pwr = S.max_pwr;
00086 poly2d_base_set.insert(this);
00087 }
00088
00089 virtual ~poly2d_base();
00090
00091 bool IsOn() { return bool(data.size());}
00092 bool IsRZSet() { return rz_set;}
00093
00094 void Collect();
00095 void Compress() { Collect();}
00096
00097 void Diff (int nvar);
00098 void Int (int nvar);
00099 void IncPow(int nvar);
00100 void DecPow(int nvar);
00101
00102 void Scale(const double C);
00103
00104
00105 double Eval();
00106 double GetVal() {if (rz_set) return Eval(); else return 0.;}
00107 double GetVal(const double r, const double z) { SetPoint(r,z); return Eval();}
00108
00109 void Print(std::ostream &out = std::cout, const std::streamsize prec = 5);
00110
00111 };
00112 }
00113
00114 #endif