Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_Ifpack2_UQ_PCE.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef STOKHOS_IFPACK2_UQ_PCE_HPP
11 #define STOKHOS_IFPACK2_UQ_PCE_HPP
12 
13 // This header file should be included whenever compiling any Ifpack2
14 // code with Stokhos scalar types
15 
16 // MP includes and specializations
18 
19 // Specialization of LocalReciprocalThreshold functor in
20 // Ifpack2_Details_Chebyshev_def.hpp
21 namespace Ifpack2 {
22 namespace Details {
23 
24 template <typename XV, class SizeType>
26 
27 // Mean-based implementation of ReciprocalThreshold
28 template <typename S, typename ... P, class SizeType>
30  Kokkos::View< Sacado::UQ::PCE<S>*,P... >,
31  SizeType >
32 {
33  typedef Kokkos::View< Sacado::UQ::PCE<S>*,P... > XVector;
34  typedef typename XVector::array_type array_type;
35 
37  typedef SizeType size_type;
38  typedef typename array_type::non_const_value_type value_type;
39  typedef Kokkos::ArithTraits<value_type> KAT;
40  typedef typename KAT::mag_type mag_type;
41 
42  const XVector m_x;
46 
48  const XVector& x,
49  const typename XVector::non_const_value_type& min_val) :
50  m_x(x),
51  m_min_val(min_val.fastAccessCoeff(0)),
52  m_min_val_mag(KAT::abs(m_min_val)),
53  m_n_pce(Kokkos::dimension_scalar(x)) {}
54  //--------------------------------------------------------------------------
55 
56  KOKKOS_INLINE_FUNCTION
57  void operator()( const size_type i) const
58  {
59  value_type z = m_x(i).fastAccessCoeff(0);
60  if (KAT::abs(z) < m_min_val_mag)
61  z = m_min_val;
62  else
63  z = KAT::one() / z;
64  m_x(i) = z;
65  }
66 };
67 
68 template<class XV, class SizeType>
70 
71 template<class S, class ...P, class SizeType>
73  Kokkos::View< Sacado::UQ::PCE<S>*,P... >, SizeType > {
74  typedef Kokkos::View< Sacado::UQ::PCE<S>*,P... > XV;
75 
76  static void
77  compute (const XV& X,
78  const typename XV::non_const_value_type& minVal)
79  {
80  if (!Sacado::is_constant(minVal)) {
82  "LocalReciprocalThreshold not implemented for non-constant minVal");
83  }
84 
85  if (Kokkos::dimension_scalar(X) == 1) {
86  typedef typename Kokkos::FlatArrayType<XV>::type Flat_XV;
87  Flat_XV flat_X = X;
89  minVal.coeff(0) );
90  }
91  else {
93  Kokkos::parallel_for( X.extent(0), op );
94  }
95  }
96 };
97 
98 }
99 }
100 
101 #endif // STOKHOS_IFPACK2_UQ_PCE_HPP
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
V_ReciprocalThresholdSelfFunctor(const XVector &x, const typename XVector::non_const_value_type &min_val)
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
static void compute(const XV &X, const typename XV::non_const_value_type &minVal)