Stokhos::HermiteBasis<ordinal_type, value_type>:: HermiteBasis(ordinal_type p, const HermiteBasis& basis) : RecurrenceBasis<ordinal_type, value_type>(p, basis) { // Compute coefficients in 3-term recurrsion computeRecurrenceCoefficients(p+1, this->alpha, this->beta, this->delta, this->gamma); // Setup rest of recurrence basis this->setup(); }
Stokhos::ClenshawCurtisLegendreBasis<ordinal_type, value_type>:: ClenshawCurtisLegendreBasis(ordinal_type p, bool normalize, bool isotropic_) : RecurrenceBasis<ordinal_type, value_type>("Legendre", p, normalize), isotropic(isotropic_) { // Compute coefficients in 3-term recurrsion computeRecurrenceCoefficients(p+1, this->alpha, this->beta, this->delta); // Setup rest of recurrence basis this->setup(); }
void Stokhos::RecurrenceBasis<ordinal_type, value_type>:: setup() { bool is_normalized = computeRecurrenceCoefficients(p+1, alpha, beta, delta, gamma); if (normalize && !is_normalized) { normalizeRecurrenceCoefficients(alpha, beta, delta, gamma); } // Compute norms -- when polynomials are normalized, this should work // out to one (norms[0] == 1, delta[k] == 1, beta[k] == gamma[k] norms[0] = beta[0]/(gamma[0]*gamma[0]); for (ordinal_type k=1; k<=p; k++) { norms[k] = (beta[k]/gamma[k])*(delta[k-1]/delta[k])*norms[k-1]; } }
Stokhos::DiscretizedStieltjesBasis<ordinal_type,value_type>:: DiscretizedStieltjesBasis(const std::string& label, const ordinal_type& p, value_type (*weightFn)(const value_type&), const value_type& leftEndPt, const value_type& rightEndPt, bool normalize) : RecurrenceBasis<ordinal_type,value_type>(std::string("DiscretizedStieltjes -- ") + label, p, normalize), scaleFactor(1), leftEndPt_(leftEndPt), rightEndPt_(rightEndPt), weightFn_(weightFn) { // Set up quadrature points for discretized stieltjes procedure Teuchos::RCP<const Stokhos::LegendreBasis<ordinal_type,value_type> > quadBasis = Teuchos::rcp(new Stokhos::LegendreBasis<ordinal_type,value_type>(this->p)); quadBasis->getQuadPoints(200*this->p, quad_points, quad_weights, quad_values); // Compute coefficients in 3-term recurrsion computeRecurrenceCoefficients(p+1, this->alpha, this->beta, this->delta); // Setup rest of recurrence basis this->setup(); }
void Stokhos::RecurrenceBasis<ordinal_type,value_type>:: getQuadPoints(ordinal_type quad_order, Teuchos::Array<value_type>& quad_points, Teuchos::Array<value_type>& quad_weights, Teuchos::Array< Teuchos::Array<value_type> >& quad_values) const { //This is a transposition into C++ of Gautschi's code for taking the first // N recurrance coefficient and generating a N point quadrature rule. // The MATLAB version is available at // http://www.cs.purdue.edu/archives/2002/wxg/codes/gauss.m ordinal_type num_points = static_cast<ordinal_type>(std::ceil((quad_order+1)/2.0)); Teuchos::Array<value_type> a(num_points,0); Teuchos::Array<value_type> b(num_points,0); Teuchos::Array<value_type> c(num_points,0); Teuchos::Array<value_type> d(num_points,0); // If we don't have enough recurrance coefficients, get some more. if(num_points > p+1) { bool is_normalized = computeRecurrenceCoefficients(num_points, a, b, c, d); if (!is_normalized) normalizeRecurrenceCoefficients(a, b, c, d); } else { //else just take the ones we already have. for(ordinal_type n = 0; n<num_points; n++) { a[n] = alpha[n]; b[n] = beta[n]; c[n] = delta[n]; d[n] = gamma[n]; } if (!normalize) normalizeRecurrenceCoefficients(a, b, c, d); } // With normalized coefficients, A is symmetric and tri-diagonal, with // diagonal = a, and off-diagonal = b, starting at b[1] Teuchos::SerialDenseMatrix<ordinal_type,value_type> eig_vectors(num_points, num_points); Teuchos::Array<value_type> workspace(2*num_points); ordinal_type info_flag; Teuchos::LAPACK<ordinal_type,value_type> my_lapack; // compute the eigenvalues (stored in a) and right eigenvectors. if (num_points == 1) my_lapack.STEQR('I', num_points, &a[0], &b[0], eig_vectors.values(), num_points, &workspace[0], &info_flag); else my_lapack.STEQR('I', num_points, &a[0], &b[1], eig_vectors.values(), num_points, &workspace[0], &info_flag); // eigenvalues are sorted by STEQR quad_points.resize(num_points); quad_weights.resize(num_points); for (ordinal_type i=0; i<num_points; i++) { quad_points[i] = a[i]; if (std::abs(quad_points[i]) < quad_zero_tol) quad_points[i] = 0.0; quad_weights[i] = beta[0]*eig_vectors[i][0]*eig_vectors[i][0]; } // Evalute basis at gauss points quad_values.resize(num_points); for (ordinal_type i=0; i<num_points; i++) { quad_values[i].resize(p+1); evaluateBases(quad_points[i], quad_values[i]); } }