Debian Codegraph @

packages/stokhos/src/sacado/kokkos/pce/ifpack2/Stokhos_Ifpack2_UQ_PCE.hpp

raw
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
17 #include "Stokhos_Tpetra_UQ_PCE.hpp"
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>
25 struct V_ReciprocalThresholdSelfFunctor;
26
27 // Mean-based implementation of ReciprocalThreshold
28 template <typename S, typename ... P, class SizeType>
29 struct V_ReciprocalThresholdSelfFunctor<
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
36 typedef typename array_type::execution_space execution_space;
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;
43 const value_type m_min_val;
44 const value_type m_min_val_mag;
45 const size_type m_n_pce;
46
47 V_ReciprocalThresholdSelfFunctor(
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>
69 struct LocalReciprocalThreshold;
70
71 template<class S, class ...P, class SizeType>
72 struct LocalReciprocalThreshold<
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)) {
81 Kokkos::Impl::raise_error(
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;
88 LocalReciprocalThreshold< Flat_XV, SizeType>::compute( flat_X,
89 minVal.coeff(0) );
90 }
91 else {
92 V_ReciprocalThresholdSelfFunctor<XV, SizeType> op (X, minVal);
93 Kokkos::parallel_for( X.extent(0), op );
94 }
95 }
96 };
97
98 }
99 }
100
101 #endif // STOKHOS_IFPACK2_UQ_PCE_HPP