Пример #1
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
exp(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    ordinal_type pa = a.size();
    ordinal_type pc;
    if (pa > 1)
        pc = sz;
    else
        pc = 1;
    if (c.size() != pc)
        c.resize(pc);

    const value_type* ca = a.coeff();
    value_type* cc = c.coeff();

    if (pa > 1) {
        TEUCHOS_TEST_FOR_EXCEPTION(pa != pc, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::exp()"
                                   << ":  Arguments have incompatible sizes:  "
                                   << "a.size() = " << pa << ", c.size() = " << pc
                                   << ".");
        int nup = pc-1;
        if (method == TAYLOR) {
            int nrm = 1;
            UQ_EXP_F77(ca, cc, &dim, &nup, &rtol, &nrm);
        }
        else
            UQ_EXP_INT_F77(ca, cc, &nup);
    }
    else
        cc[0] = std::exp(ca[0]);
}
    UnitTestSetup() {
      rtol = 1e-4;
      atol = 1e-5;
      crtol = 1e-12;
      catol = 1e-12;
      a = 3.1;
      const OrdinalType d = 2;
      const OrdinalType p = 7;
      
      // Create product basis
      Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<OrdinalType,ValueType> > > bases(d);
      for (OrdinalType i=0; i<d; i++)
	bases[i] = 
	  Teuchos::rcp(new Stokhos::LegendreBasis<OrdinalType,ValueType>(p));
      basis =
	Teuchos::rcp(new Stokhos::CompletePolynomialBasis<OrdinalType,ValueType>(bases));
      
      // Constant expansion
      exp = 
	Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion<OrdinalType,ValueType>());
      
      // Create approximation
      cx.reset(basis, 1);
      cx.term(0, 0) = a;
      cu.reset(basis, 1);
      cu2.reset(basis, 1);
    }
Пример #3
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
divide(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
       const value_type& a,
       const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& b)
{
    ordinal_type pb = b.size();
    ordinal_type pc;
    if (pb > 1)
        pc = sz;
    else
        pc = 1;
    if (c.size() != pc)
        c.resize(pc);

    const value_type* cb = b.coeff();
    value_type* cc = c.coeff();

    if (pb > 1) {
        TEUCHOS_TEST_FOR_EXCEPTION(pb != pc, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::divide()"
                                   << ":  Arguments have incompatible sizes:  "
                                   << "b.size() = " << pb
                                   << ", required size = " << pc << ".");

        value_type* ca = Stokhos::ds_array<value_type>::get_and_fill(pc);
        ca[0] = a;
        int nup = pc-1;
        UQ_DIV_F77(ca, cb, cc, &nup);
    }
    else
        cc[0] = a / cb[0];
}
Пример #4
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
sqrt(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
     const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    ordinal_type pa = a.size();
    ordinal_type pc;
    if (pa > 1)
        pc = sz;
    else
        pc = 1;
    if (c.size() != pc)
        c.resize(pc);

    const value_type* ca = a.coeff();
    value_type* cc = c.coeff();

    if (pa > 1) {
        TEUCHOS_TEST_FOR_EXCEPTION(pa != pc, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::sqrt()"
                                   << ":  Arguments have incompatible sizes:  "
                                   << "a.size() = " << pa << ", c.size() = " << pc
                                   << ".");
        int iguess = 0;
        int nup = pc-1;
        UQ_SQRT_F77(ca, cc, &nup, &iguess);
    }
    else
        cc[0] = std::sqrt(ca[0]);
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
plusEqual(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
          const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& x)
{
  if (c.size() < 1)
    c.resize(1);
  c[0] += x[0];
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
unaryMinus(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
	   const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& a)
{
  if (c.size() < 1)
    c.resize(1);
  c[0] = -a[0];
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
divideEqual(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
            const value_type& val)
{
    if (c.size() < 1)
        c.resize(1);
    c[0] /= val;
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
atanh(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (c.size() < 1)
        c.resize(1);
    c[0] = 0.5*std::log((value_type(1.0)+a[0])/(value_type(1.0)-a[0]));
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
asinh(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (c.size() < 1)
        c.resize(1);
    c[0] = std::log(a[0]+std::sqrt(a[0]*a[0]+value_type(1.0)));
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
abs(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (c.size() < 1)
        c.resize(1);
    c[0] = std::fabs(a[0]);
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
tanh(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& t,
     const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (t.size() < 1)
        t.resize(1);
    t[0] = std::tanh(a[0]);
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
sinh(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& s,
     const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (s.size() < 1)
        s.resize(1);
    s[0] = std::sinh(a[0]);
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
min(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a,
    const value_type& b)
{
    if (c.size() < 1)
        c.resize(1);
    c[0] = std::min(a[0], b);
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
times(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& a, 
      const value_type& b)
{
  if (c.size() < 1)
    c.resize(1);
  c[0] = a[0] * b;
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
divide(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
       const value_type& a,
       const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& b)
{
    if (c.size() < 1)
        c.resize(1);
    c[0] = a / b[0];
}
void
Stokhos::ConstantOrthogPolyExpansion<ordinal_type, value_type>::
max(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
    const value_type& a, 
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& b)
{
  if (c.size() < 1)
    c.resize(1);
  c[0] = std::max(a, b[0]);
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
divideEqual(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
	    const value_type& val)
{
  ordinal_type pc = c.size();
  value_type* cc = c.coeff();
  for (ordinal_type i=0; i<pc; i++)
    cc[i] /= val;
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
minusEqual(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
           const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& x)
{
  ordinal_type xp = x.size();
  if (c.size() < xp)
    c.resize(xp);

  value_type* cc = c.coeff();
  const value_type* xc = x.coeff();
  for (ordinal_type i=0; i<xp; i++)
    cc[i] -= xc[i];
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
unaryMinus(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
	   const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& a)
{
  ordinal_type pc = a.size();
  if (c.size() != pc)
    c.resize(pc);

  value_type* cc = c.coeff();
  const value_type* ca = a.coeff();

  for (ordinal_type i=0; i<pc; i++)
    cc[i] = -ca[i];
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
divideEqual(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
            const Stokhos::OrthogPolyApprox<ordinal_type, value_type >& x)
{
  if (x.size() == 1) {
    ordinal_type p = c.size();
    value_type* cc = c.coeff();
    const value_type* xc = x.coeff();
    for (ordinal_type i=0; i<p; i++)
      cc[i] /= xc[0];
  }
  else
    binary_op(div_quad_func(), c, c, x);
}
Пример #21
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
atanh(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (a.size() == 1) {
        if (c.size() != 1)
            c.resize(1);
        c[0] = 0.5*std::log((value_type(1.0)+a[0])/(value_type(1.0)-a[0]));
    }
    else
        TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::atanh()"
                                   << ":  Method not implemented!");
}
Пример #22
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
log10(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (a.size() > 1) {
        log(c,a);
        divide(c,c,std::log(10.0));
    }
    else {
        if (c.size() != 1)
            c.resize(1);
        c[0] = std::log10(a[0]);
    }
}
Пример #23
0
void
Stokhos::AlgebraicOrthogPolyExpansion<ordinal_type, value_type>::
sqrt(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c, 
     const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
  if (a.size() == 1) {
    if (c.size() != 1)
      c.resize(1);
    c[0] = std::sqrt(a[0]);
  }
  else
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
		       "Stokhos::AlgebraicOrthogPolyExpansion::sqrt()" 
		       << ":  Method not implemented!");
}
Пример #24
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
tan(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& t,
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (a.size() == 1) {
        if (t.size() != 1)
            t.resize(1);
        t[0] = std::tan(a[0]);
    }
    else
        TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::tan()"
                                   << ":  Method not implemented!");
}
Пример #25
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
atan2(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
      const value_type& a,
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& b)
{
    if (b.size() == 1) {
        if (c.size() != 1)
            c.resize(1);
        c[0] = std::atan2(a, b[0]);
    }
    else
        TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::atan2()"
                                   << ":  Method not implemented!");
}
Пример #26
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
pow(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
    const value_type& a,
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& b)
{
    if (b.size() > 1) {
        times(c,std::log(a),b);
        exp(c,c);
    }
    else {
        if (c.size() != 1)
            c.resize(1);
        c[0] = std::pow(a, b[0]);
    }
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
times(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
      const value_type& a, 
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& b)
{
  ordinal_type pc = b.size();
  if (c.size() != pc)
    c.resize(pc);

  const value_type* cb = b.coeff();
  value_type* cc = c.coeff();

  for (ordinal_type i=0; i<pc; i++)
    cc[i] = a*cb[i];
}
Пример #28
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
pow(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a,
    const value_type& b)
{
    if (a.size() > 1) {
        log(c,a);
        timesEqual(c,b);
        exp(c,c);
    }
    else {
        if (c.size() != 1)
            c.resize(1);
        c[0] = std::pow(a[0], b);
    }
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
plus(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
     const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& a, 
     const value_type& b)
{
  ordinal_type pc = a.size();
  if (c.size() != pc)
    c.resize(pc);

  const value_type* ca = a.coeff();
  value_type* cc = c.coeff();

  cc[0] = ca[0] + b;
  for (ordinal_type i=1; i<pc; i++)
    cc[i] = ca[i];
}
  bool comparePCEs(const PCEType& a1,
                   const std::string& a1_name,
                   const Stokhos::OrthogPolyApprox<OrdinalType,ValueType>&a2,
                   const std::string& a2_name,
                   const ValueType& rel_tol, const ValueType& abs_tol,
                   Teuchos::FancyOStream& out)
  {
    bool success = true;

    out << "Comparing " << a1_name << " == " << a2_name << " ... ";

    const OrdinalType n = a1.size();

    // Compare sizes
    if (a2.size() != n) {
      out << "\nError, "<<a1_name<<".size() = "<<a1.size()<<" == "
          << a2_name<<".size() = "<<a2.size()<<" : failed!\n";
      return false;
    }

    // Compare elements
    for( OrdinalType i = 0; i < n; ++i ) {
      ValueType nrm = std::sqrt(a2.basis()->norm_squared(i));
      ValueType err = std::abs(a1.coeff(i) - a2[i]) / nrm;
      ValueType tol =
        abs_tol + rel_tol*std::max(std::abs(a1.coeff(i)),std::abs(a2[i]))/nrm;
      if (err  > tol) {
        out
          <<"\nError, relErr("<<a1_name<<"["<<i<<"],"
          <<a2_name<<"["<<i<<"]) = relErr("<<a1.coeff(i)<<","<<a2[i]<<") = "
          <<err<<" <= tol = "<<tol<<": failed!\n";
        success = false;
      }
    }
    if (success) {
      out << "passed\n";
    }
    else {
      out << std::endl
          << a1_name << " = " << a1 << std::endl
          << a2_name << " = " << a2 << std::endl;
    }

    return success;
  }