ordinal_type
Stokhos::PecosOneDOrthogPolyBasis<ordinal_type,value_type>::
pointGrowth(ordinal_type n) const
{
  if (n % ordinal_type(2) == ordinal_type(1))
    return n + ordinal_type(1);
  return n;
}
Exemplo n.º 2
0
void
Stokhos::LanczosPCEBasis<ordinal_type, value_type>::
transformCoeffsFromLanczos(const value_type *in, value_type *out) const
{
  Teuchos::BLAS<ordinal_type, value_type> blas;
  ordinal_type sz = fromStieltjesMat.numRows();
  blas.GEMV(Teuchos::NO_TRANS, sz, this->p+1, 
	    value_type(1.0), fromStieltjesMat.values(), sz, 
	    in, ordinal_type(1), value_type(0.0), out, ordinal_type(1));
}
void
Stokhos::MonoProjPCEBasis<ordinal_type, value_type>::
transformCoeffs(const value_type *in, value_type *out) const
{
  // Transform coefficients to normalized basis
  Teuchos::BLAS<ordinal_type, value_type> blas;
  blas.GEMV(Teuchos::NO_TRANS, pce_sz, this->p+1, 
	    value_type(1.0), basis_vecs.values(), pce_sz, 
	    in, ordinal_type(1), value_type(0.0), out, ordinal_type(1));

  // Transform from normalized to original
  for (ordinal_type i=0; i<pce_sz; i++)
    out[i] /= pce_norms[i];
}
Exemplo n.º 4
0
ordinal_type
Stokhos::RecurrenceBasis<ordinal_type,value_type>::
pointGrowth(ordinal_type n) const
{
    if (growth == SLOW_GROWTH) {
        if (n % ordinal_type(2) == ordinal_type(1))
            return n + ordinal_type(1);
        else
            return n;
    }

    // else moderate
    return n;
}
Exemplo n.º 5
0
ordinal_type
Stokhos::RecurrenceBasis<ordinal_type,value_type>::
coefficientGrowth(ordinal_type n) const
{
    if (growth == SLOW_GROWTH)
        return n;

    // else moderate
    return ordinal_type(2)*n;
}
ordinal_type
Stokhos::GaussPattersonLegendreBasis<ordinal_type,value_type>::
quadDegreeOfExactness(ordinal_type n) const
{
  // Based on the above structure, we find the largest l s.t. 2^{l+1}-1 <= n,
  // which is floor(log2(n+1)-1) and compute p = 3*2^l-1
  if (n == ordinal_type(1))
    return 1;
  ordinal_type l = std::floor(std::log(n+1.0)/std::log(2.0)-1.0);
  return (3 << l) - 1; // 3*std::pow(2,l)-1;
}
void
Stokhos::GaussPattersonLegendreBasis<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
{
#ifdef HAVE_STOKHOS_DAKOTA
  // Gauss-Patterson points have the following structure 
  // (cf. http://people.sc.fsu.edu/~jburkardt/f_src/patterson_rule/patterson_rule.html):
  //  Level l  Num points n   Precision p
  //  -----------------------------------
  //    0        1                1
  //    1        3                5
  //    2        7                11
  //    3        15               23
  //    4        31               47
  //    5        63               95
  //    6        127              191
  //    7        255              383
  // Thus for l > 0, n = 2^{l+1}-1 and p = 3*2^l-1.  So for a given quadrature
  // order p, we find the smallest l s.t. 3*s^l-1 >= p and then compute the
  // number of points n from the above.  In this case, l = ceil(log2((p+1)/3))
  ordinal_type num_points;
  if (quad_order <= ordinal_type(1))
    num_points = 1;
  else {
    ordinal_type l = std::ceil(std::log((quad_order+1.0)/3.0)/std::log(2.0));
    num_points = (1 << (l+1)) - 1; // std::pow(2,l+1)-1;
  }
  
  quad_points.resize(num_points);
  quad_weights.resize(num_points);
  quad_values.resize(num_points);

  webbur::patterson_lookup(num_points, &quad_points[0], &quad_weights[0]);

  for (ordinal_type i=0; i<num_points; i++) {
    quad_weights[i] *= 0.5;  // scale to unit measure
    quad_values[i].resize(this->p+1);
    this->evaluateBases(quad_points[i], quad_values[i]);
  }

#else
  TEUCHOS_TEST_FOR_EXCEPTION(
    true, std::logic_error, "Clenshaw-Curtis requires TriKota to be enabled!");
#endif
}
ordinal_type
Stokhos::PecosOneDOrthogPolyBasis<ordinal_type,value_type>::
quadDegreeOfExactness(ordinal_type n) const
{
  return ordinal_type(2)*n-ordinal_type(1);
}
Exemplo n.º 9
0
Stokhos::SmolyakPseudoSpectralOperator<ordinal_type,value_type,point_compare_type>:: 
SmolyakPseudoSpectralOperator(
  const SmolyakBasis<ordinal_type,value_type,coeff_compare_type>& smolyak_basis, 
  bool use_smolyak_apply,
  bool use_pst,
  const point_compare_type& point_compare) :
  use_smolyak(use_smolyak_apply),
  points(point_compare) {

  typedef SmolyakBasis<ordinal_type,value_type,coeff_compare_type> smolyak_basis_type;
  typedef typename smolyak_basis_type::tensor_product_basis_type tensor_product_basis_type;

  // Generate sparse grid and tensor operators
  coeff_sz = smolyak_basis.size();
  ordinal_type dim = smolyak_basis.dimension();
  ordinal_type num_terms = smolyak_basis.getNumSmolyakTerms();
  for (ordinal_type i=0; i<num_terms; ++i) {
    
    // Get tensor product basis for given term
    Teuchos::RCP<const tensor_product_basis_type> tp_basis = 
      smolyak_basis.getTensorProductBasis(i);
    
    // Get coefficient multi-index defining basis orders
    multiindex_type coeff_index = tp_basis->getMaxOrders();
    
    // Apply growth rule to cofficient multi-index
    multiindex_type point_growth_index(dim);
    for (ordinal_type j=0; j<dim; ++j) {
      point_growth_index[j] = 
	smolyak_basis.getCoordinateBases()[j]->pointGrowth(coeff_index[j]);
    }
    
    // Build tensor product operator for given index
    Teuchos::RCP<operator_type> op = 
      Teuchos::rcp(new operator_type(*tp_basis, use_pst,
				     point_growth_index));
    if (use_smolyak)
      operators.push_back(op);
    
    // Get smolyak cofficient for given index
    value_type c = smolyak_basis.getSmolyakCoefficient(i);
    if (use_smolyak)
      smolyak_coeffs.push_back(c);
    
    // Include points in union over all sets
    typename operator_type::set_iterator op_set_iterator = op->set_begin();
    typename operator_type::set_iterator op_set_end = op->set_end();
    for (; op_set_iterator != op_set_end; ++op_set_iterator) {
      const point_type& point = op_set_iterator->first;
      value_type w = op_set_iterator->second.first;
      set_iterator si = points.find(point);
      if (si == points.end())
	points[point] = std::make_pair(c*w,ordinal_type(0));
      else
	si->second.first += c*w;
    }
    
  }
  
  // Generate linear ordering of points
  ordinal_type idx = 0;
  point_map.resize(points.size());
  for (set_iterator si = points.begin(); si != points.end(); ++si) {
    si->second.second = idx;
    point_map[idx] = si->first;
    ++idx;
  }  
  
  if (use_smolyak) {
    
    // Build gather/scatter maps into global domain/range for each operator
    gather_maps.resize(operators.size());
    scatter_maps.resize(operators.size());
    for (ordinal_type i=0; i<operators.size(); i++) {
      Teuchos::RCP<operator_type> op = operators[i];
      
      gather_maps[i].reserve(op->point_size());
      typename operator_type::iterator op_iterator = op->begin();
      typename operator_type::iterator op_end = op->end();
      for (; op_iterator != op_end; ++op_iterator) {
	gather_maps[i].push_back(points[*op_iterator].second);
      }
      
      Teuchos::RCP<const tensor_product_basis_type> tp_basis = 
	smolyak_basis.getTensorProductBasis(i);
      ordinal_type op_coeff_sz = tp_basis->size();
      scatter_maps[i].reserve(op_coeff_sz);
      for (ordinal_type j=0; j<op_coeff_sz; ++j) {
	scatter_maps[i].push_back(smolyak_basis.index(tp_basis->term(j)));
      }
    }
  }
      
  //else {
    
    // Generate quadrature operator
    ordinal_type nqp = points.size();
    ordinal_type npc = coeff_sz;
    qp2pce.reshape(npc,nqp);
    pce2qp.reshape(nqp,npc);
    qp2pce.putScalar(1.0);
    pce2qp.putScalar(1.0);
    Teuchos::Array<value_type> vals(npc);
    for (set_iterator si = points.begin(); si != points.end(); ++si) {
      ordinal_type j = si->second.second;
      value_type w = si->second.first;
      point_type point = si->first;
      smolyak_basis.evaluateBases(point, vals);
      for (ordinal_type i=0; i<npc; ++i) {
	qp2pce(i,j) = w*vals[i] / smolyak_basis.norm_squared(i);
	pce2qp(j,i) = vals[i];
      }
    }
    //}
  
}
Exemplo n.º 10
0
ordinal_type
Stokhos::RecurrenceBasis<ordinal_type,value_type>::
quadDegreeOfExactness(ordinal_type n) const
{
    return ordinal_type(2)*n-ordinal_type(1);
}