34 #include "gsl/gsl_sf_gamma.h"
49 : _pointDim(0), _polyCoeffs() {
53 : _pointDim(pv._pointDim),
54 _polyCoeffs(pv._polyCoeffs.num_row(), pv._polyCoeffs.num_col(), 0.) {
60 : _pointDim(numberOfInputVariables), _polyCoeffs(polynomialCoefficients) {
65 : _pointDim(0), _polyCoeffs() {
81 for(
unsigned int i=0; i<coeff.size(); i++) {
82 int polyOrder = coeff[i].InVariables().size();
83 for(
unsigned int j=0; j<coeff[i].InVariables().size(); j++)
85 if(coeff[i].OutVariable() > valueDim) valueDim = coeff[i].OutVariable();
86 if(polyOrder > maxPolyOrder) maxPolyOrder = polyOrder;
94 for(
unsigned int j=0; j<coeff.size(); j++)
96 int dim = coeff[j].OutVariable();
112 for(
unsigned int i=0; i<
PointDimension(); i++) pointV(i+1) = point[i];
114 for(
unsigned int i=0; i<
ValueDimension(); i++) value[i] = valueV(i+1);
123 for(
unsigned int i=0; i<
ValueDimension(); i++) value(i+1) = answer(i+1);
132 polyVector(i+1) = 1.;
152 check[check_index] = poly_power;
153 nearby_points.push_back(check);
154 if (check_index+1 == check.size())
156 for (
int i = 1; i < int(poly_power); ++i)
158 for (
int i = 0; i <= int(poly_power); ++i) {
159 check[check_index] = i;
167 "SquarePolynomialVector::IndexByPower",
168 "Point dimension must be > 0"
175 std::vector<std::vector<int> > nearby_points(1, std::vector<int>(point_dim, 0));
177 int this_poly_order = 0;
178 while (
int(nearby_points.size()) < index+1) {
180 this_poly_order += 1;
208 for (
int i = 0; i < pointDimension; ++i)
228 template <
class Container >
232 std::stringstream strstr1(
"");
233 std::stringstream strstr2(
"");
234 typename Container::const_iterator it1 = container.begin();
235 typename Container::const_iterator it2 = it1;
236 while(it1!=container.end())
239 if(it1 != container.end() && it2 != container.end())
240 strstr1 << (*it1) << T_separator;
241 else strstr1 << (*it1);
245 if(
int(strstr1.str().size()) > length && length > 0) strstr2 << strstr1.str().substr(1, length);
246 else strstr2 << strstr1.str();
248 if(!pad_at_start) out << strstr2.str();
249 for(
int i=0; i<length - int(strstr2.str().size()); i++) out << str_separator;
250 if(pad_at_start) out << strstr2.str();
255 size_t maxPower = *std::max_element(index.begin(), index.end());
260 if (derivPower == NULL) {
262 "SquarePolynomialVector::Deriv",
263 "Derivative points to NULL"
269 std::vector<int> thisPower = powerKey[j];
275 double newCoeff = 1.;
277 for (
size_t k = 0; k < thisPower.size(); ++k) {
278 newPower[k] = thisPower[k] - derivPower[k];
279 if (newPower[k] < 0) {
283 newCoeff *= gsl_sf_fact(thisPower[k])/gsl_sf_fact(newPower[k]);
286 for (
size_t k = 0; k < powerKey.size(); ++k) {
288 for (
size_t l = 0; l < powerKey[k].size(); ++l) {
289 if (powerKey[k][l] != newPower[l]) {
296 newPolyCoeffs(i+1, k+1) = newCoeff*
_polyCoeffs(i+1, j+1);
std::ostream & operator<<(std::ostream &out, const Mesh::Iterator &it)
size_t num_col() const
returns number of columns in the matrix
size_t num_row() const
returns number of rows in the matrix
SquarePolynomialVector describes a vector of multivariate polynomials.
unsigned int PointDimension() const
static std::vector< std::vector< std::vector< int > > > _polyKeyByVector
static unsigned int NumberOfPolynomialCoefficients(int pointDimension, int order)
void SetCoefficients(int pointDim, MMatrix< double > coeff)
MVector< double > & MakePolyVector(const MVector< double > &point, MVector< double > &polyVector) const
static std::vector< std::vector< std::vector< int > > > _polyKeyByPower
unsigned int PolynomialOrder() const
static std::vector< int > IndexByPower(int index, int nInputVariables)
static void PrintContainer(std::ostream &out, const Container &container, char T_separator, char str_separator, int length, bool pad_at_start)
unsigned int ValueDimension() const
static bool _printHeaders
MMatrix< double > _polyCoeffs
SquarePolynomialVector Deriv(const int *derivPower) const
void PrintHeader(std::ostream &out, char int_separator='.', char str_separator=' ', int length=14, bool pad_at_start=true) const
void F(const double *point, double *value) const
static std::vector< int > IndexByVector(int index, int nInputVariables)
static void IndexByPowerRecursive(std::vector< int > check, size_t check_index, size_t poly_power, std::vector< std::vector< int > > &nearby_points)
MMatrix< double > GetCoefficientsAsMatrix() const