Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_PCE_OrthogPoly.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_PCE_ORTHOGPOLY_HPP
43 #define SACADO_PCE_ORTHOGPOLY_HPP
44 
45 #include "Stokhos_ConfigDefs.h"
46 
47 #ifdef HAVE_STOKHOS_SACADO
48 
49 #include "Teuchos_RCP.hpp"
50 
51 #include "Sacado_Traits.hpp"
52 #include "Sacado_Handle.hpp"
53 #include "Sacado_mpl_apply.hpp"
54 
57 
58 #include <cmath>
59 #include <algorithm> // for std::min and std::max
60 #include <ostream> // for std::ostream
61 
62 namespace Sacado {
63 
65  namespace PCE {
66 
68 
72  template <typename T, typename Storage >
73  class OrthogPoly {
74  public:
75 
77  typedef T value_type;
78 
80  typedef typename ScalarType<T>::type scalar_type;
81 
83  typedef int ordinal_type;
84 
86  typedef Storage storage_type;
87 
90 
93 
96 
97  typedef typename approx_type::pointer pointer;
98  typedef typename approx_type::const_pointer const_pointer;
99  typedef typename approx_type::reference reference;
100  typedef typename approx_type::const_reference const_reference;
101 
103  template <typename S>
104  struct apply {
105  typedef typename Sacado::mpl::apply<Storage,ordinal_type,S>::type storage_type;
106  typedef OrthogPoly<S,storage_type> type;
107  };
108 
110 
113  OrthogPoly();
114 
116 
119  OrthogPoly(const value_type& x);
120 
122 
125  OrthogPoly(const Teuchos::RCP<expansion_type>& expansion);
126 
128 
131  OrthogPoly(const Teuchos::RCP<expansion_type>& expansion,
132  ordinal_type sz);
133 
135  OrthogPoly(const OrthogPoly& x);
136 
138  ~OrthogPoly();
139 
141  void init(const T& v) { th->init(v); }
142 
144  void init(const T* v) { th->init(v); }
145 
147  template <typename S>
148  void init(const OrthogPoly<T,S>& v) { th->init(v.getOrthogPolyApprox()); }
149 
151  void load(T* v) { th->load(v); }
152 
154  template <typename S>
155  void load(OrthogPoly<T,S>& v) { th->load(v.getOrthogPolyApprox()); }
156 
158 
161  void reset(const Teuchos::RCP<expansion_type>& expansion);
162 
164 
167  void reset(const Teuchos::RCP<expansion_type>& expansion,
168  ordinal_type sz);
169 
171 
180  void copyForWrite() { th.makeOwnCopy(); }
181 
183  value_type evaluate(const Teuchos::Array<value_type>& point) const;
184 
186  value_type evaluate(const Teuchos::Array<value_type>& point,
187  const Teuchos::Array<value_type>& bvals) const;
188 
190  value_type mean() const {return th->mean(); }
191 
193  value_type standard_deviation() const { return th->standard_deviation(); }
194 
196  value_type two_norm() const { return th->two_norm(); }
197 
199  value_type two_norm_squared() const { return th->two_norm_squared(); }
200 
202  value_type inner_product(const OrthogPoly& b) const {
203  return th->inner_product(b.getOrthogPolyApprox()); }
204 
206  std::ostream& print(std::ostream& os) const { return th->print(os); }
207 
209  bool isEqualTo(const OrthogPoly& x) const;
210 
215 
217  OrthogPoly<T,Storage>& operator=(const value_type& val);
218 
220  OrthogPoly<T,Storage>& operator=(const OrthogPoly<T,Storage>& x);
221 
223 
228 
230  Teuchos::RCP<const basis_type> basis() const { return th->basis(); }
231 
233  Teuchos::RCP<expansion_type> expansion() const { return expansion_; }
234 
236 
241 
243  const_reference val() const { return (*th)[0]; }
244 
246  reference val() { return (*th)[0]; }
247 
249 
254 
256  ordinal_type size() const { return th->size();}
257 
259  bool hasFastAccess(ordinal_type sz) const { return th->size()>=sz;}
260 
262  const_pointer coeff() const { return th->coeff();}
263 
265  pointer coeff() { return th->coeff();}
266 
268  value_type coeff(ordinal_type i) const {
269  value_type tmp= i<th->size() ? (*th)[i]:value_type(0.); return tmp;}
270 
272  reference fastAccessCoeff(ordinal_type i) { return (*th)[i];}
273 
275  value_type fastAccessCoeff(ordinal_type i) const { return (*th)[i];}
276 
278  reference term(ordinal_type dimension, ordinal_type order) {
279  return th->term(dimension, order); }
280 
282  const_reference term(ordinal_type dimension, ordinal_type order) const {
283  return th->term(dimension, order); }
284 
286  Teuchos::Array<ordinal_type> order(ordinal_type term) const {
287  return th->order(term); }
288 
290 
295 
297  OrthogPoly<T,Storage> operator + () const;
298 
300  OrthogPoly<T,Storage> operator - () const;
301 
303  OrthogPoly<T,Storage>& operator += (const value_type& x);
304 
306  OrthogPoly<T,Storage>& operator -= (const value_type& x);
307 
309  OrthogPoly<T,Storage>& operator *= (const value_type& x);
310 
312  OrthogPoly<T,Storage>& operator /= (const value_type& x);
313 
315  OrthogPoly<T,Storage>& operator += (const OrthogPoly<T,Storage>& x);
316 
318  OrthogPoly<T,Storage>& operator -= (const OrthogPoly<T,Storage>& x);
319 
321  OrthogPoly<T,Storage>& operator *= (const OrthogPoly<T,Storage>& x);
322 
324  OrthogPoly<T,Storage>& operator /= (const OrthogPoly<T,Storage>& x);
325 
327 
329  const approx_type& getOrthogPolyApprox() const { return *th; }
330 
332  approx_type& getOrthogPolyApprox() { return *th; }
333 
334  protected:
335 
337  Teuchos::RCP<expansion_type> expansion_;
338 
340  static Teuchos::RCP<expansion_type> const_expansion_;
341 
342  Sacado::Handle< Stokhos::OrthogPolyApprox<int,value_type,Storage> > th;
343 
344  }; // class Hermite
345 
346  // Operations
347  template <typename T, typename Storage> OrthogPoly<T,Storage>
348  operator+(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
349 
350  template <typename T, typename Storage> OrthogPoly<T,Storage>
351  operator+(const typename OrthogPoly<T,Storage>::value_type& a,
352  const OrthogPoly<T,Storage>& b);
353 
354  template <typename T, typename Storage> OrthogPoly<T,Storage>
355  operator+(const OrthogPoly<T,Storage>& a,
356  const typename OrthogPoly<T,Storage>::value_type& b);
357 
358  template <typename T, typename Storage> OrthogPoly<T,Storage>
359  operator-(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
360 
361  template <typename T, typename Storage> OrthogPoly<T,Storage>
362  operator-(const typename OrthogPoly<T,Storage>::value_type& a,
363  const OrthogPoly<T,Storage>& b);
364 
365  template <typename T, typename Storage> OrthogPoly<T,Storage>
366  operator-(const OrthogPoly<T,Storage>& a,
367  const typename OrthogPoly<T,Storage>::value_type& b);
368 
369  template <typename T, typename Storage> OrthogPoly<T,Storage>
370  operator*(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
371 
372  template <typename T, typename Storage> OrthogPoly<T,Storage>
373  operator*(const typename OrthogPoly<T,Storage>::value_type& a,
374  const OrthogPoly<T,Storage>& b);
375 
376  template <typename T, typename Storage> OrthogPoly<T,Storage>
377  operator*(const OrthogPoly<T,Storage>& a,
378  const typename OrthogPoly<T,Storage>::value_type& b);
379 
380  template <typename T, typename Storage> OrthogPoly<T,Storage>
381  operator/(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
382 
383  template <typename T, typename Storage> OrthogPoly<T,Storage>
384  operator/(const typename OrthogPoly<T,Storage>::value_type& a,
385  const OrthogPoly<T,Storage>& b);
386 
387  template <typename T, typename Storage> OrthogPoly<T,Storage>
388  operator/(const OrthogPoly<T,Storage>& a,
389  const typename OrthogPoly<T,Storage>::value_type& b);
390 
391  template <typename T, typename Storage> OrthogPoly<T,Storage>
392  exp(const OrthogPoly<T,Storage>& a);
393 
394  template <typename T, typename Storage> OrthogPoly<T,Storage>
395  log(const OrthogPoly<T,Storage>& a);
396 
397  template <typename T, typename Storage> void
398  log(OrthogPoly<T,Storage>& c, const OrthogPoly<T,Storage>& a);
399 
400  template <typename T, typename Storage> OrthogPoly<T,Storage>
401  log10(const OrthogPoly<T,Storage>& a);
402 
403  template <typename T, typename Storage> OrthogPoly<T,Storage>
404  sqrt(const OrthogPoly<T,Storage>& a);
405 
406  template <typename T, typename Storage> OrthogPoly<T,Storage>
407  cbrt(const OrthogPoly<T,Storage>& a);
408 
409  template <typename T, typename Storage> OrthogPoly<T,Storage>
410  pow(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
411 
412  template <typename T, typename Storage> OrthogPoly<T,Storage>
413  pow(const T& a,
414  const OrthogPoly<T,Storage>& b);
415 
416  template <typename T, typename Storage> OrthogPoly<T,Storage>
417  pow(const OrthogPoly<T,Storage>& a,
418  const T& b);
419 
420  template <typename T, typename Storage> OrthogPoly<T,Storage>
421  cos(const OrthogPoly<T,Storage>& a);
422 
423  template <typename T, typename Storage> OrthogPoly<T,Storage>
424  sin(const OrthogPoly<T,Storage>& a);
425 
426  template <typename T, typename Storage> OrthogPoly<T,Storage>
427  tan(const OrthogPoly<T,Storage>& a);
428 
429  template <typename T, typename Storage> OrthogPoly<T,Storage>
430  cosh(const OrthogPoly<T,Storage>& a);
431 
432  template <typename T, typename Storage> OrthogPoly<T,Storage>
433  sinh(const OrthogPoly<T,Storage>& a);
434 
435  template <typename T, typename Storage> OrthogPoly<T,Storage>
436  tanh(const OrthogPoly<T,Storage>& a);
437 
438  template <typename T, typename Storage> OrthogPoly<T,Storage>
439  acos(const OrthogPoly<T,Storage>& a);
440 
441  template <typename T, typename Storage> OrthogPoly<T,Storage>
442  asin(const OrthogPoly<T,Storage>& a);
443 
444  template <typename T, typename Storage> OrthogPoly<T,Storage>
445  atan(const OrthogPoly<T,Storage>& a);
446 
447  template <typename T, typename Storage> OrthogPoly<T,Storage>
448  atan2(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
449 
450  template <typename T, typename Storage> OrthogPoly<T,Storage>
451  atan2(const typename OrthogPoly<T,Storage>::value_type& a,
452  const OrthogPoly<T,Storage>& b);
453 
454  template <typename T, typename Storage> OrthogPoly<T,Storage>
455  atan2(const OrthogPoly<T,Storage>& a,
456  const typename OrthogPoly<T,Storage>::value_type& b);
457 
458  template <typename T, typename Storage> OrthogPoly<T,Storage>
459  acosh(const OrthogPoly<T,Storage>& a);
460 
461  template <typename T, typename Storage> OrthogPoly<T,Storage>
462  asinh(const OrthogPoly<T,Storage>& a);
463 
464  template <typename T, typename Storage> OrthogPoly<T,Storage>
465  atanh(const OrthogPoly<T,Storage>& a);
466 
467  template <typename T, typename Storage> OrthogPoly<T,Storage>
468  abs(const OrthogPoly<T,Storage>& a);
469 
470  template <typename T, typename Storage> OrthogPoly<T,Storage>
471  fabs(const OrthogPoly<T,Storage>& a);
472 
473  template <typename T, typename Storage> OrthogPoly<T,Storage>
474  max(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
475 
476  template <typename T, typename Storage> OrthogPoly<T,Storage>
477  max(const typename OrthogPoly<T,Storage>::value_type& a,
478  const OrthogPoly<T,Storage>& b);
479 
480  template <typename T, typename Storage> OrthogPoly<T,Storage>
481  max(const OrthogPoly<T,Storage>& a,
482  const typename OrthogPoly<T,Storage>::value_type& b);
483 
484  template <typename T, typename Storage> OrthogPoly<T,Storage>
485  min(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
486 
487  template <typename T, typename Storage> OrthogPoly<T,Storage>
488  min(const typename OrthogPoly<T,Storage>::value_type& a,
489  const OrthogPoly<T,Storage>& b);
490 
491  template <typename T, typename Storage> OrthogPoly<T,Storage>
492  min(const OrthogPoly<T,Storage>& a,
493  const typename OrthogPoly<T,Storage>::value_type& b);
494 
495  template <typename T, typename Storage> bool
496  operator==(const OrthogPoly<T,Storage>& a,
497  const OrthogPoly<T,Storage>& b);
498 
499  template <typename T, typename Storage> bool
501  const OrthogPoly<T,Storage>& b);
502 
503  template <typename T, typename Storage> bool
504  operator==(const OrthogPoly<T,Storage>& a,
505  const typename OrthogPoly<T,Storage>::value_type& b);
506 
507  template <typename T, typename Storage> bool
508  operator!=(const OrthogPoly<T,Storage>& a,
509  const OrthogPoly<T,Storage>& b);
510 
511  template <typename T, typename Storage> bool
513  const OrthogPoly<T,Storage>& b);
514 
515  template <typename T, typename Storage> bool
516  operator!=(const OrthogPoly<T,Storage>& a,
517  const typename OrthogPoly<T,Storage>::value_type& b);
518 
519  template <typename T, typename Storage> bool
520  operator<=(const OrthogPoly<T,Storage>& a,
521  const OrthogPoly<T,Storage>& b);
522 
523  template <typename T, typename Storage> bool
525  const OrthogPoly<T,Storage>& b);
526 
527  template <typename T, typename Storage> bool
528  operator<=(const OrthogPoly<T,Storage>& a,
529  const typename OrthogPoly<T,Storage>::value_type& b);
530 
531  template <typename T, typename Storage> bool
532  operator>=(const OrthogPoly<T,Storage>& a,
533  const OrthogPoly<T,Storage>& b);
534 
535  template <typename T, typename Storage> bool
537  const OrthogPoly<T,Storage>& b);
538 
539  template <typename T, typename Storage> bool
540  operator>=(const OrthogPoly<T,Storage>& a,
541  const typename OrthogPoly<T,Storage>::value_type& b);
542 
543  template <typename T, typename Storage> bool
544  operator<(const OrthogPoly<T,Storage>& a,
545  const OrthogPoly<T,Storage>& b);
546 
547  template <typename T, typename Storage> bool
549  const OrthogPoly<T,Storage>& b);
550 
551  template <typename T, typename Storage> bool
552  operator<(const OrthogPoly<T,Storage>& a,
553  const typename OrthogPoly<T,Storage>::value_type& b);
554 
555  template <typename T, typename Storage> bool
556  operator>(const OrthogPoly<T,Storage>& a,
557  const OrthogPoly<T,Storage>& b);
558 
559  template <typename T, typename Storage> bool
561  const OrthogPoly<T,Storage>& b);
562 
563  template <typename T, typename Storage> bool
564  operator>(const OrthogPoly<T,Storage>& a,
565  const typename OrthogPoly<T,Storage>::value_type& b);
566 
567  template <typename T, typename Storage> std::ostream&
568  operator << (std::ostream& os, const OrthogPoly<T,Storage>& a);
569 
570  template <typename T, typename Storage> std::istream&
571  operator >> (std::istream& os, OrthogPoly<T,Storage>& a);
572 
573  } // namespace PCE
574 
575 } // namespace Sacado
576 
579 
580 #endif // HAVE_STOKHOS_SACADO
581 
582 #endif // SACADO_PCE_ORTHOGPOLY_HPP
OrthogPoly< T, Storage > exp(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > log(const OrthogPoly< T, Storage > &a)
Stokhos::StandardStorage< int, double > storage_type
OrthogPoly< T, Storage > sin(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > sqrt(const OrthogPoly< T, Storage > &a)
bool operator>=(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > operator-(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
expr val()
OrthogPoly< T, Storage > pow(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > atan(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > cbrt(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > acos(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > atanh(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > cosh(const OrthogPoly< T, Storage > &a)
std::istream & operator>>(std::istream &is, OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > sinh(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > tan(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > asin(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > operator+(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > operator/(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > max(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
Stokhos::LegendreBasis< int, double > basis_type
Abstract base class for orthogonal polynomial-based expansions.
bool operator!=(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
Abstract base class for multivariate orthogonal polynomials.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
OrthogPoly< T, Storage > cos(const OrthogPoly< T, Storage > &a)
bool operator==(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > acosh(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > min(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > log10(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > abs(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > fabs(const OrthogPoly< T, Storage > &a)
Class to store coefficients of a projection onto an orthogonal polynomial basis.
OrthogPoly< T, Storage > asinh(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > tanh(const OrthogPoly< T, Storage > &a)
bool operator>(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > operator*(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)