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 #if KOKKOS_VERSION >= 40799
40  typedef KokkosKernels::ArithTraits<value_type> KAT;
41 #else
42  typedef Kokkos::ArithTraits<value_type> KAT;
43 #endif
44  typedef typename KAT::mag_type mag_type;
45 
46  const XVector m_x;
50 
52  const XVector& x,
53  const typename XVector::non_const_value_type& min_val) :
54  m_x(x),
55  m_min_val(min_val.fastAccessCoeff(0)),
56  m_min_val_mag(KAT::abs(m_min_val)),
57  m_n_pce(Kokkos::dimension_scalar(x)) {}
58  //--------------------------------------------------------------------------
59 
60  KOKKOS_INLINE_FUNCTION
61  void operator()( const size_type i) const
62  {
63  value_type z = m_x(i).fastAccessCoeff(0);
64  if (KAT::abs(z) < m_min_val_mag)
65  z = m_min_val;
66  else
67  z = KAT::one() / z;
68  m_x(i) = z;
69  }
70 };
71 
72 template<class XV, class SizeType>
74 
75 template<class S, class ...P, class SizeType>
77  Kokkos::View< Sacado::UQ::PCE<S>*,P... >, SizeType > {
78  typedef Kokkos::View< Sacado::UQ::PCE<S>*,P... > XV;
79 
80  static void
81  compute (const XV& X,
82  const typename XV::non_const_value_type& minVal)
83  {
84  if (!Sacado::is_constant(minVal)) {
86  "LocalReciprocalThreshold not implemented for non-constant minVal");
87  }
88 
89  if (Kokkos::dimension_scalar(X) == 1) {
90  typedef typename Kokkos::FlatArrayType<XV>::type Flat_XV;
91  Flat_XV flat_X = X;
93  minVal.coeff(0) );
94  }
95  else {
97  Kokkos::parallel_for( X.extent(0), op );
98  }
99  }
100 };
101 
102 }
103 }
104 
105 #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)