Esempio n. 1
0
void
Stokhos::AlgebraicOrthogPolyExpansion<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 (a.size() == 1) {
    if (c.size() != 1)
      c.resize(1);
    c[0] = std::log(a[0]+std::sqrt(a[0]*a[0]+value_type(1.0)));
  }
  else
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
		       "Stokhos::AlgebraicOrthogPolyExpansion::asinh()" 
		       << ":  Method not implemented!");
}
Esempio n. 2
0
void
Stokhos::AlgebraicOrthogPolyExpansion<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 (a.size() == 1) {
    if (t.size() != 1)
      t.resize(1);
    t[0] = std::tanh(a[0]);
  }
  else
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
		       "Stokhos::AlgebraicOrthogPolyExpansion::tanh()" 
		       << ":  Method not implemented!");
}
Esempio n. 3
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
atan2(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) {
        if (c.size() != 1)
            c.resize(1);
        c[0] = std::atan2(a[0], b);
    }
    else
        TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::atan2()"
                                   << ":  Method not implemented!");
}
Esempio n. 4
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>::
divide(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();

  for (ordinal_type i=0; i<pc; i++)
    cc[i] = ca[i]/b;
}
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];
}
Esempio n. 7
0
void
Stokhos::AlgebraicOrthogPolyExpansion<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) {
    if (c.size() != 1)
      c.resize(1);
    c[0] = std::pow(a, b[0]);
  }
  else
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
		       "Stokhos::AlgebraicOrthogPolyExpansion::pow()" 
		       << ":  Method not implemented!");
}
Esempio n. 8
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);
    }
}
Esempio n. 9
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
times(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a,
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& b)
{
    ordinal_type pa = a.size();
    ordinal_type pb = b.size();
    ordinal_type pc;
    if (pa > 1 && pb > 1)
        pc = sz;
    else
        pc = pa*pb;
    TEUCHOS_TEST_FOR_EXCEPTION(sz < pc, std::logic_error,
                               "Stokhos::ForUQTKOrthogPolyExpansion::times()" <<
                               ":  Expansion size (" << sz <<
                               ") is too small for computation.");
    if (c.size() != pc)
        c.resize(pc);

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

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

        int nup = pc-1;
        UQ_PROD2_F77(ca, cb, cc, &nup);
    }
    else if (pa > 1) {
        for (ordinal_type i=0; i<pc; i++)
            cc[i] = ca[i]*cb[0];
    }
    else if (pb > 1) {
        for (ordinal_type i=0; i<pc; i++)
            cc[i] = ca[0]*cb[i];
    }
    else {
        cc[0] = ca[0]*cb[0];
    }
}
Esempio n. 10
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
cosh(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
     const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a)
{
    if (a.size() > 1) {
        // cosh(x) = (exp(x) + exp(-x))/2.0
        Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type> t(a);
        timesEqual(t, -1.0);
        exp(c, a);
        exp(t, t);
        this->plusEqual(c, t);
        divideEqual(c, 2.0);
    }
    else {
        if (c.size() != 1)
            c.resize(1);
        c[0] = std::cosh(a[0]);
    }
}
Esempio n. 11
0
void
Stokhos::ForUQTKOrthogPolyExpansion<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 (a.size() > 1) {
        // sinh(x) = (exp(x) - exp(-x))/2.0
        Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type> t(a);
        timesEqual(t, -1.0);
        exp(s, a);
        exp(t, t);
        this->minusEqual(s, t);
        divideEqual(s, 2.0);
    }
    else {
        if (s.size() != 1)
            s.resize(1);
        s[0] = std::sinh(a[0]);
    }
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
divide(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
       const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& a, 
       const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& b)
{
  if (b.size() == 1) {
    ordinal_type pc = a.size();
    if (c.size() != pc)
      c.resize(pc);

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

    for (ordinal_type i=0; i<pc; i++)
      cc[i] = ca[i]/cb[0];
  }
  else
    binary_op(div_quad_func(), c, a, b);
}
Esempio n. 13
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
divideEqual(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
            const OrthogPolyApprox<ordinal_type, value_type, node_type>& x)
{
    ordinal_type p = c.size();
    ordinal_type xp = x.size();
    ordinal_type pc;
    if (xp > 1)
        pc = sz;
    else
        pc = p;
    TEUCHOS_TEST_FOR_EXCEPTION(sz < pc, std::logic_error,
                               "Stokhos::ForUQTKOrthogPolyExpansion::divideEqual()" <<
                               ":  Expansion size (" << sz <<
                               ") is too small for computation.");
    if (c.size() != pc)
        c.resize(pc);

    value_type* cc = c.coeff();
    const value_type* xc = x.coeff();

    if (xp > 1) {
        TEUCHOS_TEST_FOR_EXCEPTION(pc != xp, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::divideEqual()"
                                   << ":  Arguments have incompatible sizes:  "
                                   << "x.size() = " << xp << ", c.size() = " << pc << ".");

        // Copy c coefficients into temporary array
        value_type* tc = Stokhos::ds_array<value_type>::get_and_fill(cc,pc);

        int nup = pc-1;
        UQ_DIV_F77(tc, xc, cc, &nup);

    }
    else {
        for (ordinal_type i=0; i<pc; i++)
            cc[i] /= xc[0];
    }
}
Esempio n. 14
0
void
Stokhos::ForUQTKOrthogPolyExpansion<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 (a.size() > 1) {
        // tanh(x) = (exp(x) - exp(-x))/(exp(x) + exp(-x))
        Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type> s(a);
        Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type> c(a);
        timesEqual(s, -1.0);
        exp(s, s);
        exp(c, a);
        this->minus(t, c, s);
        this->plusEqual(c, s);
        divideEqual(t, c);
    }
    else {
        if (t.size() != 1)
            t.resize(1);
        t[0] = std::tanh(a[0]);
    }
}
void
Stokhos::CGDivisionExpansionStrategy<ordinal_type,value_type,node_type>::
divide(Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
       const value_type& alpha,
       const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& a, 
       const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& b,
       const value_type& beta)
{
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::CGDivisionStrategy::divide()");
#endif

  
  ordinal_type sz = basis->size();
  ordinal_type pa = a.size();
  ordinal_type pb = b.size();
  
  ordinal_type pc;
  if (pb > 1)
    pc = sz;
  else
    pc = pa;
  if (c.size() != pc)
    c.resize(pc);
 
  const value_type* ca = a.coeff();
  const value_type* cb = b.coeff();


  value_type* cc = c.coeff();

  if (pb > 1) {
    // Compute A
    A->putScalar(0.0);
    typename Cijk_type::k_iterator k_begin = Cijk->k_begin();
    typename Cijk_type::k_iterator k_end = Cijk->k_end();
    
    if (pb < Cijk->num_k())
      k_end = Cijk->find_k(pb);
    value_type cijk;
    ordinal_type i,j,k;
    for (typename Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
      k = index(k_it);
      for (typename Cijk_type::kj_iterator j_it = Cijk->j_begin(k_it); 
	   j_it != Cijk->j_end(k_it); ++j_it) {
	j = index(j_it);
	for (typename Cijk_type::kji_iterator i_it = Cijk->i_begin(j_it);
	     i_it  != Cijk->i_end(j_it); ++i_it) {       
	  i = index(i_it);
	  cijk = value(i_it);
	  (*A)(i,j) += cijk*cb[k];
	}
      }
    }

    // Compute B
    B->putScalar(0.0);
    for (ordinal_type i=0; i<pa; i++)
      (*B)(i,0) = ca[i]*basis->norm_squared(i);

    Teuchos::SerialDenseMatrix<ordinal_type,value_type> D(sz, 1);
    //Equilibrate the linear system
    if (equil == 1){
      //Create diag mtx of max row entries
      for (ordinal_type i=0; i<sz; i++){
	Teuchos::SerialDenseMatrix<ordinal_type, value_type> r(Teuchos::View, *A, 1, sz, i, 0);
	D(i,0)=sqrt(r.normOne());
      }


      //Compute inv(D)*A*inv(D)
      for (ordinal_type i=0; i<sz; i++){
	for (ordinal_type j=0; j<sz; j++){
	  (*A)(i,j)=(*A)(i,j)/(D(i,0)*D(j,0));
	}
      }

      //Scale b by inv(D)
      for (ordinal_type i=0; i<sz; i++){
	(*B)(i,0)=(*B)(i,0)/D(i,0);
      }

    }

    if (linear == 1){
      //Compute M, the linear matrix to be used in the preconditioner

      pb = basis->dimension()+1;

      M->putScalar(0.0);
      if (pb < Cijk->num_k())
	k_end = Cijk->find_k(pb);
      for (typename Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
	k = index(k_it);
	for ( typename Cijk_type::kj_iterator j_it = Cijk->j_begin(k_it);
	      j_it != Cijk->j_end(k_it); ++j_it) {
	  j = index(j_it);
	  for ( typename Cijk_type::kji_iterator i_it = Cijk->i_begin(j_it);
		i_it  != Cijk->i_end(j_it); ++i_it) {
	    i = index(i_it);
	    cijk = value(i_it);
	    (*M)(i,j) += cijk*cb[k];
	  }
	}
      }
      
      //Scale M
      if (equil == 1){
	//Compute inv(D)*M*inv(D)
	for (ordinal_type i=0; i<sz; i++){
	  for (ordinal_type j=0; j<sz; j++){
	    (*M)(i,j)=(*M)(i,j)/(D(i,0)*D(j,0));
	  }
 	}
      }
      CG(*A,*X,*B, max_it, tol, prec_iter, basis->order(), basis->dimension(), PrecNum, *M, diag);
    }
    
    else{
      
      CG(*A,*X,*B, max_it, tol, prec_iter, basis->order(), basis->dimension(), PrecNum, *A, diag);
    }
    
    if (equil == 1 ) {
      //Rescale X 
      for (ordinal_type i=0; i<sz; i++){
	(*X)(i,0)=(*X)(i,0)/D(i,0);
      }
    }
   
    // Compute c
    for (ordinal_type i=0; i<pc; i++)
      cc[i] = alpha*(*X)(i,0) + beta*cc[i];
  }
  else {
    for (ordinal_type i=0; i<pc; i++)
      cc[i] = alpha*ca[i]/cb[0] + beta*cc[i];
  }
}