Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Kokkos_InnerProductSpaceTraits_UQ_PCE.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Stokhos Package
5// Copyright (2009) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38//
39// ***********************************************************************
40// @HEADER
41
42#ifndef KOKKOS_INNER_PRODUCT_SPACE_TRAITS_UQ_PCE_HPP
43#define KOKKOS_INNER_PRODUCT_SPACE_TRAITS_UQ_PCE_HPP
44
45#include "Sacado_UQ_PCE.hpp"
46#include "Kokkos_InnerProductSpaceTraits.hpp"
48
49//----------------------------------------------------------------------------
50// Specializations of Kokkos::InnerProductSpaceTraits for Sacado::UQ::PCE
51// scalar type
52//----------------------------------------------------------------------------
53
54namespace Kokkos {
55namespace Details {
56
57template <typename S>
58class InnerProductSpaceTraits< Sacado::UQ::PCE<S> > {
59public:
61
62 typedef typename val_type::value_type base_value_type;
63 typedef typename val_type::ordinal_type ordinal_type;
64 typedef InnerProductSpaceTraits<base_value_type> BIT;
65 typedef typename BIT::dot_type base_dot_type;
66
67 typedef typename ArithTraits<val_type>::mag_type mag_type;
69
70 static KOKKOS_FORCEINLINE_FUNCTION
71 mag_type norm (const val_type& x) {
72 //return ArithTraits<val_type>::abs (x);
73 const ordinal_type sz = x.size();
74 mag_type nrm = mag_type(0);
75 for (ordinal_type i=0; i<sz; ++i) {
76 const mag_type n = BIT::norm( x.fastAccessCoeff(i) );
77 nrm += n*n;
78 }
79 return std::sqrt(nrm);
80 }
81
82 static KOKKOS_FORCEINLINE_FUNCTION
83 dot_type dot (const val_type& x, const val_type& y) {
84 const ordinal_type xsz = x.size();
85 const ordinal_type ysz = y.size();
86 const ordinal_type sz = xsz > ysz ? xsz : ysz;
87
88 dot_type r = dot_type(0);
89 if (x.hasFastAccess(sz) && y.hasFastAccess(sz))
90 for (ordinal_type i=0; i<sz; ++i)
91 r += BIT::dot( x.fastAccessCoeff(i), y.fastAccessCoeff(i) );
92 else
93 for (ordinal_type i=0; i<sz; ++i)
94 r += BIT::dot( x.coeff(i), y.coeff(i) );
95
96 return r;
97 }
98
99};
100
101template <typename S>
102class InnerProductSpaceTraits< const Sacado::UQ::PCE<S> > {
103public:
105
106 typedef typename val_type::value_type base_value_type;
107 typedef typename val_type::ordinal_type ordinal_type;
108 typedef InnerProductSpaceTraits<base_value_type> BIT;
109 typedef typename BIT::dot_type base_dot_type;
110
111 typedef typename ArithTraits<val_type>::mag_type mag_type;
113
114 static KOKKOS_FORCEINLINE_FUNCTION
115 mag_type norm (const val_type& x) {
116 //return ArithTraits<val_type>::abs (x);
117 const ordinal_type sz = x.size();
118 mag_type nrm = mag_type(0);
119 for (ordinal_type i=0; i<sz; ++i) {
120 const mag_type n = BIT::norm( x.fastAccessCoeff(i) );
121 nrm += n*n;
122 }
123 return std::sqrt(nrm);
124 }
125
126 static KOKKOS_FORCEINLINE_FUNCTION
127 dot_type dot (const val_type& x, const val_type& y) {
128 const ordinal_type xsz = x.size();
129 const ordinal_type ysz = y.size();
130 const ordinal_type sz = xsz > ysz ? xsz : ysz;
131
132 dot_type r = dot_type(0);
133 if (x.hasFastAccess(sz) && y.hasFastAccess(sz))
134 for (ordinal_type i=0; i<sz; ++i)
135 r += BIT::dot( x.fastAccessCoeff(i), y.fastAccessCoeff(i) );
136 else
137 for (ordinal_type i=0; i<sz; ++i)
138 r += BIT::dot( x.coeff(i), y.coeff(i) );
139
140 return r;
141 }
142
143};
144
145}
146}
147
148#endif /* #ifndef KOKKOS_INNER_PRODUCT_SPACE_TRAITS_UQ_PCE_HPP */
static KOKKOS_FORCEINLINE_FUNCTION mag_type norm(const val_type &x)
static KOKKOS_FORCEINLINE_FUNCTION dot_type dot(const val_type &x, const val_type &y)
static KOKKOS_FORCEINLINE_FUNCTION dot_type dot(const val_type &x, const val_type &y)