00001
00029 #ifndef LINEAR
00030 #define LINEAR
00031
00032 #include "Shape.h"
00033
00063 template <size_t SPD>
00064 class Linear: public Shape {
00065 public:
00070
00072 Linear (const size_t * iMap = 0);
00073
00074 inline virtual ~Linear () {}
00075
00076 Linear (const Linear<SPD> &);
00077
00078 virtual inline Linear<SPD> * clone () const {
00079 return new Linear<SPD> (*this);
00080 }
00081
00082
00083 inline size_t getNumFunctions () const {
00084 return SPD + 1;
00085 }
00086 inline size_t getNumVariables () const {
00087 return SPD;
00088 }
00089
00090
00091
00095 double getVal (size_t a, const double *x) const;
00101 double getDVal (size_t a, const double *x, size_t i) const;
00102
00103 private:
00104 size_t bctMap[SPD + 1];
00105 };
00106
00107 template<size_t SPD>
00108 Linear<SPD>::Linear (const size_t * iMap) {
00109 for (size_t a = 0; a < SPD + 1; a++)
00110 bctMap[a] = a;
00111
00112 if (iMap != 0) {
00113 for (size_t a = 0; a < SPD + 1; a++) {
00114 bctMap[a] = iMap[a];
00115 }
00116 }
00117
00118 return;
00119 }
00120
00121 template<size_t SPD>
00122 Linear<SPD>::Linear (const Linear<SPD> &Lin) {
00123 for (size_t a = 0; a < SPD + 1; a++) {
00124 bctMap[a] = Lin.bctMap[a];
00125 }
00126 }
00127
00128 template<size_t SPD>
00129 double Linear<SPD>::getVal (size_t a, const double *x) const {
00130 if (bctMap[a] != SPD) {
00131 return x[bctMap[a]];
00132 }
00133 else {
00134 double va = 0;
00135
00136 for (size_t k = 0; k < SPD; k++) {
00137 va += x[k];
00138 }
00139
00140 return 1 - va;
00141 }
00142 }
00143
00144 template<size_t SPD>
00145 double Linear<SPD>::getDVal (size_t a, const double *x, size_t i) const {
00146 if (bctMap[a] != SPD) {
00147 return bctMap[a] == i ? 1 : 0;
00148 } else {
00149 return -1;
00150 }
00151 }
00152
00153 #endif