void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
minus(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& a, 
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& b)
{
  ordinal_type pa = a.size();
  ordinal_type pb = b.size();
  ordinal_type pc = pa > pb ? pa : pb;
  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 > pb) {
    for (ordinal_type i=0; i<pb; i++)
      cc[i] = ca[i] - cb[i];
    for (ordinal_type i=pb; i<pc; i++)
      cc[i] = ca[i];
  }
  else {
    for (ordinal_type i=0; i<pa; i++)
      cc[i] = ca[i] - cb[i];
    for (ordinal_type i=pa; i<pc; i++)
      cc[i] = -cb[i];
  }
}
Example #2
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];
}
Example #3
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]);
}
Example #4
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]);
}
Example #5
0
void
Stokhos::PseudoSpectralOrthogPolyExpansion<ordinal_type, value_type, point_compare_type, node_type>::
divide(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)
{
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::OrthogPolyExpansionBase::divide(OPA,OPA)");
#endif
  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 {
    if (use_quad_for_division)
      binary_op(div_quad_func(), c, a, b);
    else
      OrthogPolyExpansionBase<ordinal_type, value_type, node_type>::divide(c, a, b);
  }
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
timesEqual(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
           const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& x)
{
  if (use_quad_for_times) {
    binary_op(times_quad_func(), c, c, x);
    return;
  }

  ordinal_type p = c.size();
  ordinal_type xp = x.size();
  ordinal_type pc;
  if (p > 1 && xp > 1)
    pc = sz;
  else
    pc = p*xp;
  TEST_FOR_EXCEPTION(sz < pc, std::logic_error,
		     "Stokhos::QuadOrthogPolyExpansion::timesEqual()" <<
		     ":  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 (p > 1 && xp > 1) {
    // Copy c coefficients into temporary array
    value_type* tc = Stokhos::ds_array<value_type>::get_and_fill(cc,p);
    value_type tmp, cijk;
    ordinal_type i,j;
    for (ordinal_type k=0; k<pc; k++) {
      tmp = value_type(0.0);
      ordinal_type n = Cijk->num_values(k);
      for (ordinal_type l=0; l<n; l++) {
	Cijk->value(k,l,i,j,cijk);
	if (i < p && j < xp)
	  tmp += cijk*tc[i]*xc[j];
      }
      cc[k] = tmp / basis->norm_squared(k);
    }
  }
  else if (p > 1) {
    for (ordinal_type i=0; i<p; i++)
      cc[i] *= xc[0];
  }
  else if (xp > 1) {
    for (ordinal_type i=1; i<xp; i++)
      cc[i] = cc[0]*xc[i];
    cc[0] *= xc[0];
  }
  else {
    cc[0] *= xc[0];
  }
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
times(Stokhos::OrthogPolyApprox<ordinal_type, value_type>& c, 
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& a, 
      const Stokhos::OrthogPolyApprox<ordinal_type, value_type>& b)
{
  if (use_quad_for_times) {
    binary_op(times_quad_func(), c, a, b);
    return;
  }

  ordinal_type pa = a.size();
  ordinal_type pb = b.size();
  ordinal_type pc;
  if (pa > 1 && pb > 1)
    pc = sz;
  else
    pc = pa*pb;
  TEST_FOR_EXCEPTION(sz < pc, std::logic_error,
		     "Stokhos::QuadOrthogPolyExpansion::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) {
    value_type tmp, cijk;
    ordinal_type i,j;
    for (ordinal_type k=0; k<pc; k++) {
      tmp = value_type(0.0);
      ordinal_type n = Cijk->num_values(k);
      for (ordinal_type l=0; l<n; l++) {
    	Cijk->value(k,l,i,j,cijk);
	if (i < pa && j < pb)
	  tmp += cijk*ca[i]*cb[j];
      }
      cc[k] = tmp / basis->norm_squared(k);
    }
  }
  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];
  }
}
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];
}
Example #9
0
void
Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type, value_type>::
timesEqual(
    Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c,
    const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& x)
{
    ordinal_type p = c.size();
    ordinal_type xp = x.size();
    ordinal_type pc;
    if (p > 1 && xp > 1)
        pc = sz;
    else
        pc = p*xp;
    TEUCHOS_TEST_FOR_EXCEPTION(sz < pc, std::logic_error,
                               "Stokhos::ForUQTKOrthogPolyExpansion::timesEqual()" <<
                               ":  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 (p > 1 && xp > 1) {
        TEUCHOS_TEST_FOR_EXCEPTION(pc != xp, std::logic_error,
                                   "Stokhos::ForUQTKOrthogPolyExpansion::timesEqual()"
                                   << ":  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_PROD2_F77(cc, xc, tc, &nup);
        Stokhos::ds_array<value_type>::copy(tc, cc, p);
    }
    else if (p > 1) {
        for (ordinal_type i=0; i<p; i++)
            cc[i] *= xc[0];
    }
    else if (xp > 1) {
        for (ordinal_type i=1; i<xp; i++)
            cc[i] = cc[0]*xc[i];
        cc[0] *= xc[0];
    }
    else {
        cc[0] *= xc[0];
    }
}
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);
}
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];
}
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];
}
Example #14
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];
    }
}
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>::
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);
}
Example #17
0
void
Stokhos::PseudoSpectralOrthogPolyExpansion<ordinal_type, value_type, point_compare_type, node_type>::
divideEqual(
  Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& c, 
  const Stokhos::OrthogPolyApprox<ordinal_type, value_type, node_type>& x)
{
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::OrthogPolyExpansionBase::divideEqual(OPA)");
#endif
  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 {
    if (use_quad_for_division)
      binary_op(div_quad_func(), c, c, x);
    else
      OrthogPolyExpansionBase<ordinal_type, value_type, node_type>::divideEqual(c, x);
  }
}
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];
  }
}