Пример #1
0
void
Stokhos::PseudoSpectralOrthogPolyExpansion<ordinal_type, value_type, point_compare_type, node_type>::
binary_op(const FuncT& func,
          OrthogPolyApprox<ordinal_type, value_type, node_type>& c, 
          const OrthogPolyApprox<ordinal_type, value_type, node_type>& a, 
          const 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 = 1;
  else
    pc = sz;
  if (c.size() != pc)
    c.resize(pc);

  if (pc == 1) {
    c[0] = func(a[0], b[0]);
    return;
  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::PSExp -- PP Binary Polynomial Evaluation");
#endif

  // Evaluate input
  SDV a_sdv(Teuchos::View, const_cast<value_type*>(a.coeff()), pa);
  SDV b_sdv(Teuchos::View, const_cast<value_type*>(b.coeff()), pb);
  ps_op->transformPCE2QP(1.0, a_sdv, avals, 0.0, false);
  ps_op->transformPCE2QP(1.0, b_sdv, bvals, 0.0, false);

  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::PSExp -- PP Binary Function Evaluation");
#endif

    // Evaluate function
  for (ordinal_type qp=0; qp<nqp; qp++)
    fvals[qp] = func(avals[qp], bvals[qp]);

  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::PSExp -- PP Binary Polynomial Integration");
#endif

  // Integrate
  SDV c_sdv(Teuchos::View, c.coeff(), pc);
  ps_op->transformQP2PCE(1.0, fvals, c_sdv, 0.0, false);

  }
}
Пример #2
0
void
Stokhos::QuadOrthogPolyExpansion<int, float, Stokhos::CUDAStorage<int, float> >::
unary_op(const FuncT& func,
         OrthogPolyApprox<int, float, CUDAStorage<int,float> >& c, 
         const OrthogPolyApprox<int, float, CUDAStorage<int,float> >& a)
{
  int pa = a.size();
  int pc;
  if (a.size() == 1)
    pc = 1;
  else
    pc = sz;
  if (c.size() != pc)
    c.resize(pc);

  if (pc == 1) {
    c[0] = func(a[0]);
    return;
  }

  float *qv_ptr = thrust::raw_pointer_cast(qv.data());
  float *sqv_ptr = thrust::raw_pointer_cast(sqv.data());
  const float *a_ptr = thrust::raw_pointer_cast(a.coeff());
  float *c_ptr = thrust::raw_pointer_cast(c.coeff());
  float *avals_ptr = thrust::raw_pointer_cast(avals.data());
  float *fvals_ptr = thrust::raw_pointer_cast(fvals.data());

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- Unary Polynomial Evaluation");
#endif

  // Evaluate input
  cublasSgemv('T', pa, nqp, 1.0, qv_ptr, sz, a_ptr, 1, 0.0, avals_ptr, 1);

  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- Unary Function Evaluation");
#endif

  // Evaluate function
  thrust::transform(avals.begin(), avals.end(), fvals.begin(), func);
  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- Unary Polynomial Integration");
#endif

  // Integrate
  cublasSgemv('N', pc, nqp, 1.0, sqv_ptr, sz, fvals_ptr, 1, 0.0, c_ptr, 1);

  }
}
void
Stokhos::QuadOrthogPolyExpansion<ordinal_type, value_type>::
binary_op(const FuncT& func,
          OrthogPolyApprox<ordinal_type, value_type>& c, 
          const OrthogPolyApprox<ordinal_type, value_type>& a, 
          const OrthogPolyApprox<ordinal_type, value_type>& b)
{
  ordinal_type pa = a.size();
  ordinal_type pb = b.size();
  ordinal_type pc;
  if (pa == 1 && pb == 1)
    pc = 1;
  else
    pc = sz;
  if (c.size() != pc)
    c.resize(pc);

  if (pc == 1) {
    c[0] = func(a[0], b[0]);
    return;
  }

  {
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- PP Binary Polynomial Evaluation");

  // Evaluate input
  blas.GEMV(Teuchos::TRANS, pa, nqp, 1.0, &qv[0], sz, a.coeff(), 1, 0.0,
            &avals[0], 1);
  blas.GEMV(Teuchos::TRANS, pb, nqp, 1.0, &qv[0], sz, b.coeff(), 1, 0.0,
            &bvals[0], 1);

  }

  {
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- PP Binary Function Evaluation");

    // Evaluate function
  for (ordinal_type qp=0; qp<nqp; qp++)
    fvals[qp] = func(avals[qp], bvals[qp])*quad_weights[qp];

  }

  {
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- PP Binary Polynomial Integration");

  // Integrate
  blas.GEMV(Teuchos::NO_TRANS, pc, nqp, 1.0, &sqv[0], sz, &fvals[0], 1, 0.0,
            c.coeff(), 1);

  }
}
Пример #4
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];
    }
}
Пример #5
0
void
Stokhos::PseudoSpectralOrthogPolyExpansion<ordinal_type, value_type, point_compare_type, node_type>::
nary_op(const FuncT& func,
	OrthogPolyApprox<ordinal_type, value_type, node_type>& c, 
	const OrthogPolyApprox<ordinal_type, value_type, node_type>** na)
{
  const int N = FuncT::N;
  bool is_constant = true;
  for (int i=0; i<N; i++) {
    if (na[i]->size() > 1) {
      is_constant = false;
      break;
    }
  }
  ordinal_type pc;
  if (is_constant)
    pc = 1;
  else
    pc = sz;
  if (c.size() != pc)
    c.resize(pc);

  if (pc == 1) {
    value_type val[N];
    for (int i=0; i<N; i++)
      val[i] = (*na[i])[0];
    c[0] = func(val);
    return;
  }

  if (N >= navals.size())
    navals.resize(N+1);
  if (navals[N].size() != N) {
    navals[N].resize(N);
    for (int i=0; i<N; i++)
      navals[N][i].resize(nqp);
  }
  
  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::PSExp -- N(" << N << ")-ary Polynomial Evaluation");
#endif

  // Evaluate input
  for (int i=0; i<N; i++) {
    SDV sdv(Teuchos::View, const_cast<value_type*>(na[i]->coeff()), 
	    na[i]->size());
    ps_op->transformPCE2QP(1.0, sdv, navals[N][i], 0.0, false);
  }

  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::PSExp -- N(" << N << ")-ary Function Evaluation");
#endif

  // Evaluate function
  value_type val[N];
  for (ordinal_type qp=0; qp<nqp; qp++) {
    for (int i=0; i<N; i++)
      val[i] = navals[N][i][qp];
    fvals[qp] = func(val);
  }

  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::PSExp -- N(" << N << ")-ary Polynomial Integration");
#endif

  // Integrate
  SDV c_sdv(Teuchos::View, c.coeff(), pc);
  ps_op->transformQP2PCE(1.0, fvals, c_sdv, 0.0, false);

  }
}
Пример #6
0
void
Stokhos::QuadOrthogPolyExpansion<int, float, Stokhos::CUDAStorage<int,float> >::
nary_op(const FuncT& func,
	OrthogPolyApprox<int, float, Stokhos::CUDAStorage<int,float> >& c, 
	const OrthogPolyApprox<int, float, Stokhos::CUDAStorage<int,float> >** na)
{
  const int N = FuncT::N;
  bool is_constant = true;
  for (int i=0; i<N; i++) {
    if (na[i]->size() > 1) {
      is_constant = false;
      break;
    }
  }
  int pc;
  if (is_constant)
    pc = 1;
  else
    pc = sz;
  if (c.size() != pc)
    c.resize(pc);

  if (pc == 1) {
    float val[N];
    for (int i=0; i<N; i++)
      val[i] = (*na[i])[0];
    c[0] = func(val);
    return;
  }

  if (N >= navals.size())
    navals.resize(N+1);
  if (navals[N].size() != N) {
    navals[N].resize(N);
    for (int i=0; i<N; i++)
      navals[N][i].resize(nqp);
  }

  float *qv_ptr = thrust::raw_pointer_cast(qv.data());
  float *sqv_ptr = thrust::raw_pointer_cast(sqv.data());
  float *c_ptr = thrust::raw_pointer_cast(c.coeff());
  float *fvals_ptr = thrust::raw_pointer_cast(fvals.data());

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- N(" << N << ")-ary Polynomial Evaluation");
#endif

  // Evaluate input
  for (int i=0; i<N; i++) {
    int pa = na[i]->size();
    const float *na_ptr = thrust::raw_pointer_cast(na[i]->coeff());
    float *navals_ptr = thrust::raw_pointer_cast(navals[N][i].data());
    cublasSgemv('T', pa, nqp, 1.0, qv_ptr, sz, na_ptr, 1, 0.0, navals_ptr, 1);
  }

  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- N(" << N << ")-ary Function Evaluation");
#endif

  // Evaluate function
  thrust::transform(
    thrust::make_zip_iterator(make_tuple_N<N,navals_type>::begin(navals[N])), 
    thrust::make_zip_iterator(make_tuple_N<N,navals_type>::end(navals[N])), 
    fvals.begin(), 
    func);

  }

  {
#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
  TEUCHOS_FUNC_TIME_MONITOR("Stokhos::QuadExp -- N(" << N << ")-ary Polynomial Integration");
#endif

  // Integrate
  cublasSgemv('N', pc, nqp, 1.0, sqv_ptr, sz, fvals_ptr, 1, 0.0, c_ptr, 1);

  }
}
Пример #7
0
 void load(OrthogPolyApprox<ordinal_type, value_type, S>& v) {
   coeff_.load(v.coeff());
 }
Пример #8
0
 void init(const OrthogPolyApprox<ordinal_type, value_type, S>& v) {
   coeff_.init(v.coeff());
 }