Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_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 SACADO_UQ_PCE_HPP
43 #define SACADO_UQ_PCE_HPP
44 
45 #include "Stokhos_ConfigDefs.h"
46 
47 #ifdef HAVE_STOKHOS_SACADO
48 
49 #include "Kokkos_Macros.hpp"
50 
51 #include "Sacado_Traits.hpp"
52 #include "Sacado_mpl_apply.hpp"
53 #include "Stokhos_Is_Constant.hpp"
54 
56 
57 #include <cmath>
58 #include <algorithm> // for std::min and std::max
59 #include <ostream> // for std::ostream
60 #include <initializer_list>
61 
62 namespace Sacado {
63 
64  // Forward declaration
65  template <typename Storage>
66  KOKKOS_INLINE_FUNCTION
68 
70  namespace UQ {
71 
73 
77  template <typename Storage >
78  class PCE {
79 
80  template <class> friend class PCE;
81 
82  public:
83 
85  typedef Storage storage_type;
86 
87  typedef typename storage_type::value_type value_type;
90  typedef typename storage_type::pointer pointer;
91  typedef typename storage_type::volatile_pointer volatile_pointer;
92  typedef typename storage_type::const_pointer const_pointer;
93  typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
94  typedef typename storage_type::reference reference;
95  typedef typename storage_type::volatile_reference volatile_reference;
96  typedef typename storage_type::const_reference const_reference;
97  typedef typename storage_type::const_volatile_reference const_volatile_reference;
98 
100  typedef typename ScalarType<value_type>::type scalar_type;
101 
103  //typedef Stokhos::OrthogPolyBasis<ordinal_type,value_type> basis_type;
104 
108 
110  template <typename S>
111  struct apply {
112  typedef PCE<S> type;
113  };
114 
116 
119  KOKKOS_INLINE_FUNCTION
120  PCE() = default;
121 
123 
126  KOKKOS_INLINE_FUNCTION
127  PCE(const value_type& x) : cijk_(), s_(1, x) {}
128 
130 
133  template <typename M>
134  KOKKOS_INLINE_FUNCTION
136  cijk_(cijkVal), s_(cijk_.dimension()) {}
137 
139 
142  template <typename M>
143  KOKKOS_INLINE_FUNCTION
145  ordinal_type sz) : cijk_(cijkVal), s_(sz) {}
146 
148 
152  template <typename M>
153  KOKKOS_INLINE_FUNCTION
155  ordinal_type sz, pointer v, bool owned) :
156  cijk_(cijkVal), s_(sz,v,owned) {}
157 
159  KOKKOS_INLINE_FUNCTION
160  PCE(const PCE& x) : cijk_(x.cijk_), s_(1,x.fastAccessCoeff(0)) {
161  if (x.size() > 1 && !is_constant(x))
162  s_ = x.s_;
163  }
164 
166  KOKKOS_INLINE_FUNCTION
167  PCE(const volatile PCE& x) :
168  cijk_(const_cast<const my_cijk_type&>(x.cijk_)),
169  s_(1,value_type(x.fastAccessCoeff(0))) {
170  if (x.size() > 1 && !is_constant(x))
171  s_ = x.s_;
172  }
173 
175 
178  PCE(std::initializer_list<value_type> l) :
179  cijk_(), s_(l.size(), l.begin()) {}
180 
182  KOKKOS_INLINE_FUNCTION
183  ~PCE() = default;
184 
186  KOKKOS_INLINE_FUNCTION
187  void init(const_reference v) { s_.init(v); }
188 
190  KOKKOS_INLINE_FUNCTION
191  void init(const_reference v) volatile { s_.init(v); }
192 
194  KOKKOS_INLINE_FUNCTION
195  void init(const_pointer v) { s_.init(v); }
196 
198  KOKKOS_INLINE_FUNCTION
199  void init(const_pointer v) volatile { s_.init(v); }
200 
202  template <typename S>
203  KOKKOS_INLINE_FUNCTION
204  void init(const PCE<S>& v) { s_.init(v.coeff()); }
205 
207  template <typename S>
208  KOKKOS_INLINE_FUNCTION
209  void init(const PCE<S>& v) volatile { s_.init(v.coeff()); }
210 
212  KOKKOS_INLINE_FUNCTION
213  void load(pointer v) { s_.load(v); }
214 
216  KOKKOS_INLINE_FUNCTION
217  void load(pointer v) volatile { s_.load(v); }
218 
220  template <typename S>
221  KOKKOS_INLINE_FUNCTION
222  void load(PCE<S>& v) { s_.load(v.coeff()); }
223 
225  template <typename S>
226  KOKKOS_INLINE_FUNCTION
227  void load(PCE<S>& v) volatile { s_.load(v.coeff()); }
228 
230 
233  template <typename M>
234  KOKKOS_INLINE_FUNCTION
236  cijk_ = cijkVal;
237  s_.resize(cijk_.dimension());
238  }
239 
241 
244  template <typename M>
245  KOKKOS_INLINE_FUNCTION
246  void reset(const Stokhos::CrsProductTensor<value_type, execution_space, M>& cijkVal) volatile {
247  cijk_ = cijkVal;
248  s_.resize(cijk_.dimension());
249  }
250 
252 
255  template <typename M>
256  KOKKOS_INLINE_FUNCTION
258  cijk_ = cijkVal;
259  s_.resize(sz);
260  }
261 
263 
266  template <typename M>
267  KOKKOS_INLINE_FUNCTION
268  void reset(const Stokhos::CrsProductTensor<value_type, execution_space, M>& cijkVal, ordinal_type sz) volatile {
269  cijk_ = cijkVal;
270  s_.resize(sz);
271  }
272 
274 
283  KOKKOS_INLINE_FUNCTION
284  void copyForWrite() { }
285 
286  /*
288  KOKKOS_INLINE_FUNCTION
289  value_type evaluate(const Teuchos::Array<value_type>& point) const;
290 
292  KOKKOS_INLINE_FUNCTION
293  value_type evaluate(const Teuchos::Array<value_type>& point,
294  const Teuchos::Array<value_type>& bvals) const;
295  */
296 
298  KOKKOS_INLINE_FUNCTION
299  value_type mean() const { return this->fastAccessCoeff(0); }
300 
302  KOKKOS_INLINE_FUNCTION
303  value_type standard_deviation() const;
304 
306  KOKKOS_INLINE_FUNCTION
307  value_type two_norm() const {
308  return std::sqrt(this->two_norm_squared());
309  }
310 
312  KOKKOS_INLINE_FUNCTION
313  value_type two_norm_squared() const;
314 
316  KOKKOS_INLINE_FUNCTION
317  value_type inner_product(const PCE& x) const;
318 
320  KOKKOS_INLINE_FUNCTION
321  bool isEqualTo(const PCE& x) const;
322 
324  KOKKOS_INLINE_FUNCTION
325  bool isEqualTo(const PCE& x) const volatile;
326 
331 
333  KOKKOS_INLINE_FUNCTION
334  PCE<Storage>& operator=(const value_type val);
335 
337  KOKKOS_INLINE_FUNCTION
338  /*volatile*/ PCE<Storage>& operator=(const value_type val) volatile;
339 
341  KOKKOS_INLINE_FUNCTION
342  PCE<Storage>& operator=(const PCE<Storage>& x);
343 
345  KOKKOS_INLINE_FUNCTION
346  PCE<Storage>& operator=(const volatile PCE<Storage>& x);
347 
349  KOKKOS_INLINE_FUNCTION
350  /*volatile*/ PCE<Storage>& operator=(const PCE<Storage>& x) volatile;
351 
353  KOKKOS_INLINE_FUNCTION
354  /*volatile*/ PCE<Storage>& operator=(const volatile PCE<Storage>& x) volatile;
355 
357  template <typename S>
358  KOKKOS_INLINE_FUNCTION
359  PCE<Storage>& operator=(const PCE<S>& x) {
360  // Don't copy cijk as it may be on a different device
361  const ordinal_type sz_new = x.size();
362  s_.resize(sz_new);
363  for (ordinal_type i=0; i<sz_new; i++)
364  s_[i] = x.s_[i];
365 
366  // For DyamicStorage as a view (is_owned=false), we need to set
367  // the trailing entries when assigning a constant vector (because
368  // the copy constructor in this case doesn't reset the size of this)
369  const ordinal_type sz = s_.size();
370  if (sz > sz_new)
371  for (ordinal_type i=sz_new; i<sz; i++)
372  s_[i] = value_type(0);
373 
374  return *this;
375  }
376 
378 
381  PCE& operator=(std::initializer_list<value_type> l) {
382  const ordinal_type lsz = l.size();
383  if (lsz != s_.size())
384  s_.resize(lsz);
385  s_.init(l.begin(), lsz);
386  return *this;
387  }
388 
390 
393  /*volatile*/ PCE&
394  operator=(std::initializer_list<value_type> l) volatile {
395  const ordinal_type lsz = l.size();
396  if (lsz != s_.size())
397  s_.resize(lsz);
398  s_.init(l.begin(), lsz);
399  return const_cast<PCE&>(*this);
400  }
401 
403 
408 
409  /*
411  KOKKOS_INLINE_FUNCTION
412  Teuchos::RCP<const basis_type> basis() const { return s_.basis(); }
413  */
414 
416  KOKKOS_INLINE_FUNCTION
417  my_cijk_type cijk() const { return cijk_; }
418 
420  KOKKOS_INLINE_FUNCTION
421  my_cijk_type cijk() const volatile {
422  return const_cast<const my_cijk_type&>(cijk_);
423  }
424 
426 
431 
433  KOKKOS_INLINE_FUNCTION
434  const_volatile_reference val() const volatile { return s_[0]; }
435 
437  KOKKOS_INLINE_FUNCTION
438  const_reference val() const { return s_[0]; }
439 
441  KOKKOS_INLINE_FUNCTION
442  volatile_reference val() volatile { return s_[0]; }
443 
445  KOKKOS_INLINE_FUNCTION
446  reference val() { return s_[0]; }
447 
449 
454 
456  KOKKOS_INLINE_FUNCTION
457  ordinal_type size() const { return s_.size();}
458 
460  KOKKOS_INLINE_FUNCTION
461  ordinal_type size() const volatile { return s_.size();}
462 
464  KOKKOS_INLINE_FUNCTION
465  bool hasFastAccess(ordinal_type sz) const { return s_.size()>=sz;}
466 
468  KOKKOS_INLINE_FUNCTION
469  bool hasFastAccess(ordinal_type sz) const volatile {
470  return s_.size()>=sz;
471  }
472 
474  KOKKOS_INLINE_FUNCTION
475  const_pointer coeff() const { return s_.coeff();}
476 
478  KOKKOS_INLINE_FUNCTION
479  const_volatile_pointer coeff() const volatile { return s_.coeff();}
480 
482  KOKKOS_INLINE_FUNCTION
483  volatile_pointer coeff() volatile { return s_.coeff();}
484 
486  KOKKOS_INLINE_FUNCTION
487  pointer coeff() { return s_.coeff();}
488 
490  KOKKOS_INLINE_FUNCTION
491  value_type coeff(ordinal_type i) const {
492  value_type tmp= i<s_.size() ? s_[i]:value_type(0.); return tmp;}
493 
495  KOKKOS_INLINE_FUNCTION
496  value_type coeff(ordinal_type i) const volatile {
497  value_type tmp= i<s_.size() ? s_[i]:value_type(0.); return tmp;}
498 
500  KOKKOS_INLINE_FUNCTION
501  const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
502  return s_[i];}
503 
505  KOKKOS_INLINE_FUNCTION
506  const_reference fastAccessCoeff(ordinal_type i) const {
507  return s_[i];}
508 
510  KOKKOS_INLINE_FUNCTION
511  volatile_reference fastAccessCoeff(ordinal_type i) volatile {
512  return s_[i];}
513 
515  KOKKOS_INLINE_FUNCTION
516  reference fastAccessCoeff(ordinal_type i) {
517  return s_[i];}
518 
519  /*
521  KOKKOS_INLINE_FUNCTION
522  reference term(ordinal_type dimension, ordinal_type order) {
523  return s_.term(dimension, order); }
524 
526  KOKKOS_INLINE_FUNCTION
527  const_reference term(ordinal_type dimension, ordinal_type order) const {
528  return s_.term(dimension, order); }
529 
531  KOKKOS_INLINE_FUNCTION
532  Teuchos::Array<ordinal_type> order(ordinal_type term) const {
533  return s_.order(term); }
534  */
535 
537  KOKKOS_INLINE_FUNCTION
538  pointer begin() { return s_.coeff(); }
539 
541  KOKKOS_INLINE_FUNCTION
542  const_pointer begin() const { return s_.coeff(); }
543 
545  KOKKOS_INLINE_FUNCTION
546  volatile_pointer begin() volatile { return s_.coeff(); }
547 
549  KOKKOS_INLINE_FUNCTION
550  const_volatile_pointer begin() const volatile { return s_.coeff(); }
551 
553  KOKKOS_INLINE_FUNCTION
554  const_pointer cbegin() const { return s_.coeff(); }
555 
557  KOKKOS_INLINE_FUNCTION
558  const_volatile_pointer cbegin() const volatile { return s_.coeff(); }
559 
561  KOKKOS_INLINE_FUNCTION
562  pointer end() { return s_.coeff() + s_.size(); }
563 
565  KOKKOS_INLINE_FUNCTION
566  const_pointer end() const { return s_.coeff() + s_.size(); }
567 
569  KOKKOS_INLINE_FUNCTION
570  volatile_pointer end() volatile { return s_.coeff() + s_.size(); }
571 
573  KOKKOS_INLINE_FUNCTION
574  const_volatile_pointer end() const volatile { return s_.coeff() + s_.size(); }
575 
577  KOKKOS_INLINE_FUNCTION
578  const_pointer cend() const { return s_.coeff()+ s_.size(); }
579 
581  KOKKOS_INLINE_FUNCTION
582  const_volatile_pointer cend() const volatile { return s_.coeff()+ s_.size(); }
583 
585 
590 
592  KOKKOS_INLINE_FUNCTION
593  PCE operator + () const { return *this; }
594 
596  KOKKOS_INLINE_FUNCTION
597  PCE operator + () const volatile { return *this; }
598 
600  KOKKOS_INLINE_FUNCTION
601  PCE operator - () const;
602 
604  KOKKOS_INLINE_FUNCTION
605  PCE operator - () const volatile;
606 
608  KOKKOS_INLINE_FUNCTION
609  PCE& operator += (const value_type x) {
610  s_[0] += x;
611  return *this;
612  }
613 
615  KOKKOS_INLINE_FUNCTION
616  /*volatile*/ PCE& operator += (const value_type x) volatile {
617  s_[0] += x;
618  return const_cast<PCE&>(*this);
619  }
620 
622  KOKKOS_INLINE_FUNCTION
623  PCE& operator -= (const value_type x) {
624  s_[0] -= x;
625  return *this;
626  }
627 
629  KOKKOS_INLINE_FUNCTION
630  /*volatile*/ PCE& operator -= (const value_type x) volatile {
631  s_[0] -= x;
632  return const_cast<PCE&>(*this);
633  }
634 
636  KOKKOS_INLINE_FUNCTION
637  PCE& operator *= (const value_type x);
638 
640  KOKKOS_INLINE_FUNCTION
641  /*volatile*/ PCE& operator *= (const value_type x) volatile;
642 
644  KOKKOS_INLINE_FUNCTION
645  PCE& operator /= (const value_type x);
646 
648  KOKKOS_INLINE_FUNCTION
649  /*volatile*/ PCE& operator /= (const value_type x) volatile;
650 
652  KOKKOS_INLINE_FUNCTION
653  PCE& operator += (const PCE& x);
654 
656  KOKKOS_INLINE_FUNCTION
657  PCE& operator += (const volatile PCE& x) {
658  return *this += const_cast<const PCE&>(x);
659  }
660 
662  KOKKOS_INLINE_FUNCTION
663  /*volatile*/ PCE& operator += (const PCE& x) volatile {
664  return const_cast<PCE&>(*this) += x;
665  }
666 
668  KOKKOS_INLINE_FUNCTION
669  /*volatile*/ PCE& operator += (const volatile PCE& x) volatile {
670  return const_cast<PCE&>(*this) += const_cast<const PCE&>(x);
671  }
672 
674  KOKKOS_INLINE_FUNCTION
675  PCE& operator -= (const PCE& x);
676 
678  KOKKOS_INLINE_FUNCTION
679  PCE& operator -= (const volatile PCE& x) {
680  return *this -= const_cast<const PCE&>(x);
681  }
682 
684  KOKKOS_INLINE_FUNCTION
685  /*volatile*/ PCE& operator -= (const PCE& x) volatile {
686  return const_cast<PCE&>(*this) -= x;
687  }
688 
690  KOKKOS_INLINE_FUNCTION
691  /*volatile*/ PCE& operator -= (const volatile PCE& x) volatile {
692  return const_cast<PCE&>(*this) -= const_cast<const PCE&>(x);
693  }
694 
696  KOKKOS_INLINE_FUNCTION
697  PCE& operator *= (const PCE& x);
698 
700  KOKKOS_INLINE_FUNCTION
701  PCE& operator *= (const volatile PCE& x) {
702  return *this *= const_cast<const PCE&>(x);
703  }
704 
706  KOKKOS_INLINE_FUNCTION
707  /*volatile*/ PCE& operator *= (const PCE& x) volatile {
708  return const_cast<PCE&>(*this) *= x;
709  }
710 
712  KOKKOS_INLINE_FUNCTION
713  /*volatile*/ PCE& operator *= (const volatile PCE& x) volatile {
714  return const_cast<PCE&>(*this) *= const_cast<const PCE&>(x);
715  }
716 
718  KOKKOS_INLINE_FUNCTION
719  PCE& operator /= (const PCE& x);
720 
722  KOKKOS_INLINE_FUNCTION
723  PCE& operator /= (const volatile PCE& x) {
724  return *this /= const_cast<const PCE&>(x);
725  }
726 
728  KOKKOS_INLINE_FUNCTION
729  /*volatile*/ PCE& operator /= (const PCE& x) volatile {
730  return const_cast<PCE&>(*this) /= x;
731  }
732 
734  KOKKOS_INLINE_FUNCTION
735  /*volatile*/ PCE& operator /= (const volatile PCE& x) volatile {
736  return const_cast<PCE&>(*this) /= const_cast<const PCE&>(x);
737  }
738 
740  KOKKOS_INLINE_FUNCTION
741  PCE& operator++() {
742  ++(s_[0]);
743  return *this;
744  }
745 
747  KOKKOS_INLINE_FUNCTION
748  volatile PCE& operator++() volatile {
749  ++(s_[0]);
750  return *this;
751  }
752 
754  KOKKOS_INLINE_FUNCTION
755  PCE operator++(int) {
756  PCE tmp(*this);
757  ++(*this);
758  return tmp;
759  }
760 
762  KOKKOS_INLINE_FUNCTION
763  PCE operator++(int) volatile {
764  PCE tmp(*this);
765  ++(*this);
766  return tmp;
767  }
768 
770  KOKKOS_INLINE_FUNCTION
771  PCE& operator--() {
772  --(s_[0]);
773  return *this;
774  }
775 
777  KOKKOS_INLINE_FUNCTION
778  volatile PCE& operator--() volatile {
779  --(s_[0]);
780  return *this;
781  }
782 
784  KOKKOS_INLINE_FUNCTION
785  PCE operator--(int) {
786  PCE tmp(*this);
787  --(*this);
788  return tmp;
789  }
790 
792  KOKKOS_INLINE_FUNCTION
793  PCE operator--(int) volatile {
794  PCE tmp(*this);
795  --(*this);
796  return tmp;
797  }
798 
799 
800 
802 
803  protected:
804 
805  typedef typename my_cijk_type::size_type cijk_size_type;
806 
808  my_cijk_type cijk_;
809 
810  Storage s_;
811 
812  private:
813 
814  //PCE division using CG with diagonal preconditioning
815 // KOKKOS_INLINE_FUNCTION
816 // void CG_divide(const PCE& a, const PCE& b, PCE& c);
817 
818 
819  }; // class PCE
820 
821  template <typename Storage>
822  KOKKOS_INLINE_FUNCTION
823  void CG_divide(const PCE<Storage>& a, const PCE<Storage>& b, PCE<Storage>& c);
824 
825  // Operations
826  template <typename Storage>
827  KOKKOS_INLINE_FUNCTION
828  PCE<Storage>
829  operator+(const PCE<Storage>& a, const PCE<Storage>& b);
830 
831  template <typename Storage>
832  KOKKOS_INLINE_FUNCTION
833  PCE<Storage>
834  operator+(const volatile PCE<Storage>& a, const PCE<Storage>& b) {
835  return const_cast<const PCE<Storage>&>(a) + b;
836  }
837 
838  template <typename Storage>
839  KOKKOS_INLINE_FUNCTION
840  PCE<Storage>
841  operator+(const PCE<Storage>& a, const volatile PCE<Storage>& b) {
842  return a + const_cast<const PCE<Storage>&>(b);
843  }
844 
845  template <typename Storage>
846  KOKKOS_INLINE_FUNCTION
847  PCE<Storage>
848  operator+(const volatile PCE<Storage>& a, const volatile PCE<Storage>& b) {
849  return const_cast<const PCE<Storage>&>(a) +
850  const_cast<const PCE<Storage>&>(b);
851  }
852 
853  template <typename Storage>
854  KOKKOS_INLINE_FUNCTION
855  PCE<Storage>
856  operator+(const typename PCE<Storage>::value_type& a,
857  const PCE<Storage>& b);
858 
859  template <typename Storage>
860  KOKKOS_INLINE_FUNCTION
861  PCE<Storage>
862  operator+(const PCE<Storage>& a,
863  const typename PCE<Storage>::value_type& b);
864 
865  template <typename Storage>
866  KOKKOS_INLINE_FUNCTION
867  PCE<Storage>
868  operator-(const PCE<Storage>& a, const PCE<Storage>& b);
869 
870  template <typename Storage> PCE<Storage>
871  KOKKOS_INLINE_FUNCTION
872  operator-(const typename PCE<Storage>::value_type& a,
873  const PCE<Storage>& b);
874 
875  template <typename Storage>
876  KOKKOS_INLINE_FUNCTION
877  PCE<Storage>
878  operator-(const PCE<Storage>& a,
879  const typename PCE<Storage>::value_type& b);
880 
881  template <typename Storage>
882  KOKKOS_INLINE_FUNCTION
883  PCE<Storage>
884  operator*(const PCE<Storage>& a, const PCE<Storage>& b);
885 
886  template <typename Storage>
887  KOKKOS_INLINE_FUNCTION
888  PCE<Storage>
889  operator*(const typename PCE<Storage>::value_type& a,
890  const PCE<Storage>& b);
891 
892  template <typename Storage> PCE<Storage>
893  KOKKOS_INLINE_FUNCTION
894  operator*(const PCE<Storage>& a,
895  const typename PCE<Storage>::value_type& b);
896 
897  template <typename Storage>
898  KOKKOS_INLINE_FUNCTION
899  PCE<Storage>
900  operator/(const PCE<Storage>& a, const PCE<Storage>& b);
901 
902  template <typename Storage>
903  KOKKOS_INLINE_FUNCTION
904  PCE<Storage>
905  operator/(const typename PCE<Storage>::value_type& a,
906  const PCE<Storage>& b);
907 
908  template <typename Storage>
909  KOKKOS_INLINE_FUNCTION
910  PCE<Storage>
911  operator/(const PCE<Storage>& a,
912  const typename PCE<Storage>::value_type& b);
913 
914  template <typename Storage>
915  KOKKOS_INLINE_FUNCTION
916  PCE<Storage>
917  exp(const PCE<Storage>& a);
918 
919  template <typename Storage>
920  KOKKOS_INLINE_FUNCTION
921  PCE<Storage>
922  log(const PCE<Storage>& a);
923 
924  template <typename Storage>
925  KOKKOS_INLINE_FUNCTION
926  void
927  log(PCE<Storage>& c, const PCE<Storage>& a);
928 
929  template <typename Storage>
930  KOKKOS_INLINE_FUNCTION
931  PCE<Storage>
932  log10(const PCE<Storage>& a);
933 
934  template <typename Storage>
935  KOKKOS_INLINE_FUNCTION
936  PCE<Storage>
937  sqrt(const PCE<Storage>& a);
938 
939  template <typename Storage>
940  KOKKOS_INLINE_FUNCTION
941  PCE<Storage>
942  cbrt(const PCE<Storage>& a);
943 
944  template <typename Storage>
945  KOKKOS_INLINE_FUNCTION
946  PCE<Storage>
947  pow(const PCE<Storage>& a, const PCE<Storage>& b);
948 
949  template <typename Storage>
950  KOKKOS_INLINE_FUNCTION
951  PCE<Storage>
952  pow(const typename PCE<Storage>::value_type& a, const PCE<Storage>& b);
953 
954  template <typename Storage> PCE<Storage>
955  KOKKOS_INLINE_FUNCTION
956  pow(const PCE<Storage>& a,
957  const typename PCE<Storage>::value_type& b);
958 
959  template <typename Storage>
960  KOKKOS_INLINE_FUNCTION
961  PCE<Storage>
962  cos(const PCE<Storage>& a);
963 
964  template <typename Storage>
965  KOKKOS_INLINE_FUNCTION
966  PCE<Storage>
967  sin(const PCE<Storage>& a);
968 
969  template <typename Storage>
970  KOKKOS_INLINE_FUNCTION
971  PCE<Storage>
972  tan(const PCE<Storage>& a);
973 
974  template <typename Storage>
975  KOKKOS_INLINE_FUNCTION
976  PCE<Storage>
977  cosh(const PCE<Storage>& a);
978 
979  template <typename Storage>
980  KOKKOS_INLINE_FUNCTION
981  PCE<Storage>
982  sinh(const PCE<Storage>& a);
983 
984  template <typename Storage>
985  KOKKOS_INLINE_FUNCTION
986  PCE<Storage>
987  tanh(const PCE<Storage>& a);
988 
989  template <typename Storage>
990  KOKKOS_INLINE_FUNCTION
991  PCE<Storage>
992  acos(const PCE<Storage>& a);
993 
994  template <typename Storage>
995  KOKKOS_INLINE_FUNCTION
996  PCE<Storage>
997  asin(const PCE<Storage>& a);
998 
999  template <typename Storage>
1000  KOKKOS_INLINE_FUNCTION
1001  PCE<Storage>
1002  atan(const PCE<Storage>& a);
1003 
1004  template <typename Storage>
1005  KOKKOS_INLINE_FUNCTION
1006  PCE<Storage>
1007  atan2(const PCE<Storage>& a, const PCE<Storage>& b);
1008 
1009  template <typename Storage>
1010  KOKKOS_INLINE_FUNCTION
1011  PCE<Storage>
1012  atan2(const typename PCE<Storage>::value_type& a,
1013  const PCE<Storage>& b);
1014 
1015  template <typename Storage>
1016  KOKKOS_INLINE_FUNCTION
1017  PCE<Storage>
1018  atan2(const PCE<Storage>& a,
1019  const typename PCE<Storage>::value_type& b);
1020 
1021  template <typename Storage>
1022  KOKKOS_INLINE_FUNCTION
1023  PCE<Storage>
1024  acosh(const PCE<Storage>& a);
1025 
1026  template <typename Storage>
1027  KOKKOS_INLINE_FUNCTION
1028  PCE<Storage>
1029  asinh(const PCE<Storage>& a);
1030 
1031  template <typename Storage>
1032  KOKKOS_INLINE_FUNCTION
1033  PCE<Storage>
1034  atanh(const PCE<Storage>& a);
1035 
1036  template <typename Storage>
1037  KOKKOS_INLINE_FUNCTION
1038  PCE<Storage>
1039  abs(const PCE<Storage>& a);
1040 
1041  template <typename Storage>
1042  KOKKOS_INLINE_FUNCTION
1043  PCE<Storage>
1044  fabs(const PCE<Storage>& a);
1045 
1046  template <typename Storage>
1047  KOKKOS_INLINE_FUNCTION
1048  PCE<Storage>
1049  ceil(const PCE<Storage>& a);
1050 
1051  // template <typename Storage>
1052  // KOKKOS_INLINE_FUNCTION
1053  // PCE<Storage>
1054  // max(const PCE<Storage>& a, const PCE<Storage>& b);
1055 
1056  template <typename Storage>
1057  KOKKOS_INLINE_FUNCTION
1058  PCE<Storage>
1059  max(const typename PCE<Storage>::value_type& a,
1060  const PCE<Storage>& b);
1061 
1062  template <typename Storage>
1063  KOKKOS_INLINE_FUNCTION
1064  PCE<Storage>
1065  max(const PCE<Storage>& a,
1066  const typename PCE<Storage>::value_type& b);
1067 
1068  // template <typename Storage>
1069  // KOKKOS_INLINE_FUNCTION
1070  // PCE<Storage>
1071  // min(const PCE<Storage>& a, const PCE<Storage>& b);
1072 
1073  template <typename Storage>
1074  KOKKOS_INLINE_FUNCTION
1075  PCE<Storage>
1076  min(const typename PCE<Storage>::value_type& a,
1077  const PCE<Storage>& b);
1078 
1079  template <typename Storage>
1080  KOKKOS_INLINE_FUNCTION
1081  PCE<Storage>
1082  min(const PCE<Storage>& a,
1083  const typename PCE<Storage>::value_type& b);
1084 
1085  template <typename Storage>
1086  KOKKOS_INLINE_FUNCTION
1087  bool
1088  operator==(const PCE<Storage>& a, const PCE<Storage>& b);
1089 
1090  template <typename Storage>
1091  KOKKOS_INLINE_FUNCTION
1092  bool
1093  operator==(const typename PCE<Storage>::value_type& a,
1094  const PCE<Storage>& b);
1095 
1096  template <typename Storage>
1097  KOKKOS_INLINE_FUNCTION
1098  bool
1099  operator==(const PCE<Storage>& a,
1100  const typename PCE<Storage>::value_type& b);
1101 
1102  template <typename Storage>
1103  KOKKOS_INLINE_FUNCTION
1104  bool
1105  operator!=(const PCE<Storage>& a, const PCE<Storage>& b);
1106 
1107  template <typename Storage>
1108  KOKKOS_INLINE_FUNCTION
1109  bool
1110  operator!=(const typename PCE<Storage>::value_type& a,
1111  const PCE<Storage>& b);
1112 
1113  template <typename Storage>
1114  KOKKOS_INLINE_FUNCTION
1115  bool
1116  operator!=(const PCE<Storage>& a,
1117  const typename PCE<Storage>::value_type& b);
1118 
1119  template <typename Storage>
1120  KOKKOS_INLINE_FUNCTION
1121  bool
1122  operator<=(const PCE<Storage>& a,
1123  const PCE<Storage>& b);
1124 
1125  template <typename Storage>
1126  KOKKOS_INLINE_FUNCTION
1127  bool
1129  const PCE<Storage>& b);
1130 
1131  template <typename Storage>
1132  KOKKOS_INLINE_FUNCTION
1133  bool
1134  operator<=(const PCE<Storage>& a,
1135  const typename PCE<Storage>::value_type& b);
1136 
1137  template <typename Storage>
1138  KOKKOS_INLINE_FUNCTION
1139  bool
1140  operator>=(const PCE<Storage>& a, const PCE<Storage>& b);
1141 
1142  template <typename Storage>
1143  KOKKOS_INLINE_FUNCTION
1144  bool
1145  operator>=(const typename PCE<Storage>::value_type& a,
1146  const PCE<Storage>& b);
1147 
1148  template <typename Storage>
1149  KOKKOS_INLINE_FUNCTION
1150  bool
1151  operator>=(const PCE<Storage>& a,
1152  const typename PCE<Storage>::value_type& b);
1153 
1154  template <typename Storage>
1155  KOKKOS_INLINE_FUNCTION
1156  bool
1157  operator<(const PCE<Storage>& a, const PCE<Storage>& b);
1158 
1159  template <typename Storage>
1160  KOKKOS_INLINE_FUNCTION
1161  bool
1163  const PCE<Storage>& b);
1164 
1165  template <typename Storage>
1166  KOKKOS_INLINE_FUNCTION
1167  bool
1168  operator<(const PCE<Storage>& a,
1169  const typename PCE<Storage>::value_type& b);
1170 
1171  template <typename Storage>
1172  KOKKOS_INLINE_FUNCTION
1173  bool
1174  operator>(const PCE<Storage>& a, const PCE<Storage>& b);
1175 
1176  template <typename Storage>
1177  KOKKOS_INLINE_FUNCTION
1178  bool
1179  operator>(const typename PCE<Storage>::value_type& a,
1180  const PCE<Storage>& b);
1181 
1182  template <typename Storage>
1183  KOKKOS_INLINE_FUNCTION
1184  bool
1185  operator>(const PCE<Storage>& a,
1186  const typename PCE<Storage>::value_type& b);
1187 
1188  template <typename Storage>
1189  std::ostream&
1190  operator << (std::ostream& os, const PCE<Storage>& a);
1191 
1192  template <typename Storage>
1193  std::istream&
1194  operator >> (std::istream& os, PCE<Storage>& a);
1195 
1197  struct PCEPartition {
1198  unsigned begin ;
1199  unsigned end ;
1200 
1201  template< typename iType0 , typename iType1 >
1202  KOKKOS_INLINE_FUNCTION
1203  PCEPartition( const iType0 & i0 , const iType1 & i1 ) :
1204  begin(i0), end(i1) {}
1205  };
1206 
1207 /* template <typename Storage>
1208  KOKKOS_INLINE_FUNCTION
1209  void
1210  PCE<Storage>::
1211  CG_divide(const PCE<Storage>& a, const PCE<Storage>& b, PCE<Storage>& c) {
1212 // typedef typename PCE<Storage>::ordinal_type ordinal_type;
1213 // typedef typename PCE<Storage>::value_type value_type;
1214 
1215  const ordinal_type size = c.size();
1216  //Needed scalars
1217  value_type alpha, beta, rTz, rTz_old, resid;
1218 
1219  //Needed temporary PCEs
1220  PCE<Storage> r(a.cijk(),size);
1221  PCE<Storage> p(a.cijk(),size);
1222  PCE<Storage> bp(a.cijk(),size);
1223  PCE<Storage> z(a.cijk(),size);
1224 
1225  //compute residual = a - b*c
1226  r = a - b*c;
1227  z = r/b.coeff(0);
1228  p = z;
1229  resid = r.two_norm();
1230  //Compute <r,z>=rTz (L2 inner product)
1231  rTz = r.inner_product(z);
1232  ordinal_type k = 0;
1233  value_type tol = 1e-6;
1234  while ( resid > tol && k < 100){
1235  //Compute b*p
1236  bp = b*p;
1237 
1238  //Compute alpha = <r,z>/<p,b*p>
1239  alpha = rTz/p.inner_product(bp);
1240 
1241  //Check alpha is positive!
1242  //Update the solution c = c + alpha*p
1243  c = c + alpha*p;
1244  rTz_old = rTz;
1245 
1246  //Compute the new residual r = r - alpha*b*p
1247  r = r - alpha*bp;
1248  resid = r.two_norm();
1249 
1250  //Compute beta = rTz_new/ rTz_old and new p
1251  z = r/b.coeff(0);
1252  rTz = r.inner_product(z);
1253  beta = rTz/rTz_old;
1254  p = z + beta*p;
1255  k++;
1256  }
1257 // return c;
1258  }
1259 */
1260 
1261  template <typename S>
1262  void memcpy(PCE<S>* dst, const PCE<S>* src, const size_t sz) {
1263  const size_t n = sz / sizeof(PCE<S>);
1264  for (size_t i=0; i<n; ++i)
1265  dst[i] = src[i];
1266  }
1267 
1268  } // namespace PCE
1269 
1271  template <typename T> struct is_uq_pce {
1272  static const bool value = false;
1273  };
1274  template <typename S> struct is_uq_pce< UQ::PCE<S> > {
1275  static const bool value = true;
1276  };
1277  template <typename T> struct is_uq_pce< const T > {
1278  static const bool value = is_uq_pce<T>::value;
1279  };
1280  template <typename T> struct is_uq_pce< T* > {
1281  static const bool value = is_uq_pce<T>::value;
1282  };
1283  template <typename T> struct is_uq_pce< T[] > {
1284  static const bool value = is_uq_pce<T>::value;
1285  };
1286  template <typename T, unsigned N> struct is_uq_pce< T[N] > {
1287  static const bool value = is_uq_pce<T>::value;
1288  };
1289 
1290  // Utility function to see if a PCE is really a constant
1291  template <typename Storage>
1292  KOKKOS_INLINE_FUNCTION
1293  bool is_constant(const Sacado::UQ::PCE<Storage>& x)
1294  {
1295  typedef typename Storage::ordinal_type ordinal_type;
1296  typedef typename Storage::value_type value_type;
1297 
1298  // All size-1 expansions are constants
1299  const ordinal_type sz = x.size();
1300  if (sz == 1) return true;
1301 
1302  // Maybe use a tolerance????
1303  const value_type zero = 0;
1304  for (ordinal_type i=1; i<sz; ++i)
1305  if (x.fastAccessCoeff(i) != zero) return false;
1306 
1307  return true;
1308  }
1309 
1310 } // namespace Sacado
1311 
1312 #include "Sacado_UQ_PCE_Traits.hpp"
1313 #include "Sacado_UQ_PCE_Imp.hpp"
1314 
1315 #endif // HAVE_STOKHOS_SACADO
1316 
1317 #endif // SACADO_PCE_ORTHOGPOLY_HPP
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > fabs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > tan(const PCE< Storage > &a)
Stokhos::StandardStorage< int, double > storage_type
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
atanh(expr.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION PCE< Storage > tanh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cbrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION bool operator!=(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > acos(const PCE< Storage > &a)
atan2(expr1.val(), expr2.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
asinh(expr.val())
KOKKOS_INLINE_FUNCTION bool operator>(const PCE< Storage > &a, const PCE< Storage > &b)
std::istream & operator>>(std::istream &is, PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator/(const PCE< Storage > &a, const PCE< Storage > &b)
void CG_divide(const PCE< Storage > &a, const PCE< Storage > &b, PCE< Storage > &c)
KOKKOS_INLINE_FUNCTION PCE< Storage > ceil(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator-(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION bool operator>=(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > cosh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
KOKKOS_INLINE_FUNCTION bool operator==(const PCE< Storage > &a, const PCE< Storage > &b)
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)
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
expr val()
acosh(expr.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator+(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator*(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
int n
KOKKOS_INLINE_FUNCTION PCE< Storage > asin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cos(const PCE< Storage > &a)