Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
58 
59 #include <cmath>
60 #include <algorithm> // for std::min and std::max
61 #include <ostream> // for std::ostream
62 
63 namespace Sacado {
64 
66  namespace PCE {
67 
69 
73  template <typename T, typename Storage >
74  class OrthogPoly {
75  public:
76 
78  typedef T value_type;
79 
81  typedef typename ScalarType<T>::type scalar_type;
82 
84  typedef int ordinal_type;
85 
87  typedef Storage storage_type;
88 
91 
94 
97 
98  typedef typename approx_type::pointer pointer;
99  typedef typename approx_type::const_pointer const_pointer;
100  typedef typename approx_type::reference reference;
101  typedef typename approx_type::const_reference const_reference;
102 
104  template <typename S>
105  struct apply {
106  typedef typename Sacado::mpl::apply<Storage,ordinal_type,S>::type storage_type;
107  typedef OrthogPoly<S,storage_type> type;
108  };
109 
111 
114  OrthogPoly();
115 
117 
120  OrthogPoly(const value_type& x);
121 
123 
126  OrthogPoly(const Teuchos::RCP<expansion_type>& expansion);
127 
129 
132  OrthogPoly(const Teuchos::RCP<expansion_type>& expansion,
133  ordinal_type sz);
134 
136  OrthogPoly(const OrthogPoly& x);
137 
139  ~OrthogPoly();
140 
142  void init(const T& v) { th->init(v); }
143 
145  void init(const T* v) { th->init(v); }
146 
148  template <typename S>
149  void init(const OrthogPoly<T,S>& v) { th->init(v.getOrthogPolyApprox()); }
150 
152  void load(T* v) { th->load(v); }
153 
155  template <typename S>
156  void load(OrthogPoly<T,S>& v) { th->load(v.getOrthogPolyApprox()); }
157 
159 
162  void reset(const Teuchos::RCP<expansion_type>& expansion);
163 
165 
168  void reset(const Teuchos::RCP<expansion_type>& expansion,
169  ordinal_type sz);
170 
172 
181  void copyForWrite() { th.makeOwnCopy(); }
182 
184  value_type evaluate(const Teuchos::Array<value_type>& point) const;
185 
187  value_type evaluate(const Teuchos::Array<value_type>& point,
188  const Teuchos::Array<value_type>& bvals) const;
189 
191  value_type mean() const {return th->mean(); }
192 
194  value_type standard_deviation() const { return th->standard_deviation(); }
195 
197  value_type two_norm() const { return th->two_norm(); }
198 
200  value_type two_norm_squared() const { return th->two_norm_squared(); }
201 
203  value_type inner_product(const OrthogPoly& b) const {
204  return th->inner_product(b.getOrthogPolyApprox()); }
205 
207  std::ostream& print(std::ostream& os) const { return th->print(os); }
208 
210  bool isEqualTo(const OrthogPoly& x) const;
211 
216 
218  OrthogPoly<T,Storage>& operator=(const value_type& val);
219 
221  OrthogPoly<T,Storage>& operator=(const OrthogPoly<T,Storage>& x);
222 
224 
229 
231  Teuchos::RCP<const basis_type> basis() const { return th->basis(); }
232 
234  Teuchos::RCP<expansion_type> expansion() const { return expansion_; }
235 
237 
242 
244  const_reference val() const { return (*th)[0]; }
245 
247  reference val() { return (*th)[0]; }
248 
250 
255 
257  ordinal_type size() const { return th->size();}
258 
260  bool hasFastAccess(ordinal_type sz) const { return th->size()>=sz;}
261 
263  const_pointer coeff() const { return th->coeff();}
264 
266  pointer coeff() { return th->coeff();}
267 
269  value_type coeff(ordinal_type i) const {
270  value_type tmp= i<th->size() ? (*th)[i]:value_type(0.); return tmp;}
271 
273  reference fastAccessCoeff(ordinal_type i) { return (*th)[i];}
274 
276  value_type fastAccessCoeff(ordinal_type i) const { return (*th)[i];}
277 
279  reference term(ordinal_type dimension, ordinal_type order) {
280  return th->term(dimension, order); }
281 
283  const_reference term(ordinal_type dimension, ordinal_type order) const {
284  return th->term(dimension, order); }
285 
287  Teuchos::Array<ordinal_type> order(ordinal_type term) const {
288  return th->order(term); }
289 
291 
296 
298  OrthogPoly<T,Storage> operator + () const;
299 
301  OrthogPoly<T,Storage> operator - () const;
302 
304  OrthogPoly<T,Storage>& operator += (const value_type& x);
305 
307  OrthogPoly<T,Storage>& operator -= (const value_type& x);
308 
310  OrthogPoly<T,Storage>& operator *= (const value_type& x);
311 
313  OrthogPoly<T,Storage>& operator /= (const value_type& x);
314 
316  OrthogPoly<T,Storage>& operator += (const OrthogPoly<T,Storage>& x);
317 
319  OrthogPoly<T,Storage>& operator -= (const OrthogPoly<T,Storage>& x);
320 
322  OrthogPoly<T,Storage>& operator *= (const OrthogPoly<T,Storage>& x);
323 
325  OrthogPoly<T,Storage>& operator /= (const OrthogPoly<T,Storage>& x);
326 
328 
330  const approx_type& getOrthogPolyApprox() const { return *th; }
331 
333  approx_type& getOrthogPolyApprox() { return *th; }
334 
335  protected:
336 
338  Teuchos::RCP<expansion_type> expansion_;
339 
341  static Teuchos::RCP<expansion_type> const_expansion_;
342 
343  Sacado::Handle< Stokhos::OrthogPolyApprox<int,value_type,Storage> > th;
344 
345  }; // class Hermite
346 
347  template <typename T, typename Storage>
349  OrthogPoly<T,Storage>::const_expansion_ =
351 
352  // Operations
353  template <typename T, typename Storage> OrthogPoly<T,Storage>
354  operator+(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
355 
356  template <typename T, typename Storage> OrthogPoly<T,Storage>
357  operator+(const typename OrthogPoly<T,Storage>::value_type& a,
358  const OrthogPoly<T,Storage>& b);
359 
360  template <typename T, typename Storage> OrthogPoly<T,Storage>
361  operator+(const OrthogPoly<T,Storage>& a,
362  const typename OrthogPoly<T,Storage>::value_type& b);
363 
364  template <typename T, typename Storage> OrthogPoly<T,Storage>
365  operator-(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
366 
367  template <typename T, typename Storage> OrthogPoly<T,Storage>
368  operator-(const typename OrthogPoly<T,Storage>::value_type& a,
369  const OrthogPoly<T,Storage>& b);
370 
371  template <typename T, typename Storage> OrthogPoly<T,Storage>
372  operator-(const OrthogPoly<T,Storage>& a,
373  const typename OrthogPoly<T,Storage>::value_type& b);
374 
375  template <typename T, typename Storage> OrthogPoly<T,Storage>
376  operator*(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
377 
378  template <typename T, typename Storage> OrthogPoly<T,Storage>
379  operator*(const typename OrthogPoly<T,Storage>::value_type& a,
380  const OrthogPoly<T,Storage>& b);
381 
382  template <typename T, typename Storage> OrthogPoly<T,Storage>
383  operator*(const OrthogPoly<T,Storage>& a,
384  const typename OrthogPoly<T,Storage>::value_type& b);
385 
386  template <typename T, typename Storage> OrthogPoly<T,Storage>
387  operator/(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
388 
389  template <typename T, typename Storage> OrthogPoly<T,Storage>
390  operator/(const typename OrthogPoly<T,Storage>::value_type& a,
391  const OrthogPoly<T,Storage>& b);
392 
393  template <typename T, typename Storage> OrthogPoly<T,Storage>
394  operator/(const OrthogPoly<T,Storage>& a,
395  const typename OrthogPoly<T,Storage>::value_type& b);
396 
397  template <typename T, typename Storage> OrthogPoly<T,Storage>
398  exp(const OrthogPoly<T,Storage>& a);
399 
400  template <typename T, typename Storage> OrthogPoly<T,Storage>
401  log(const OrthogPoly<T,Storage>& a);
402 
403  template <typename T, typename Storage> void
404  log(OrthogPoly<T,Storage>& c, const OrthogPoly<T,Storage>& a);
405 
406  template <typename T, typename Storage> OrthogPoly<T,Storage>
407  log10(const OrthogPoly<T,Storage>& a);
408 
409  template <typename T, typename Storage> OrthogPoly<T,Storage>
410  sqrt(const OrthogPoly<T,Storage>& a);
411 
412  template <typename T, typename Storage> OrthogPoly<T,Storage>
413  cbrt(const OrthogPoly<T,Storage>& a);
414 
415  template <typename T, typename Storage> OrthogPoly<T,Storage>
416  pow(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
417 
418  template <typename T, typename Storage> OrthogPoly<T,Storage>
419  pow(const T& a,
420  const OrthogPoly<T,Storage>& b);
421 
422  template <typename T, typename Storage> OrthogPoly<T,Storage>
423  pow(const OrthogPoly<T,Storage>& a,
424  const T& b);
425 
426  template <typename T, typename Storage> OrthogPoly<T,Storage>
427  cos(const OrthogPoly<T,Storage>& a);
428 
429  template <typename T, typename Storage> OrthogPoly<T,Storage>
430  sin(const OrthogPoly<T,Storage>& a);
431 
432  template <typename T, typename Storage> OrthogPoly<T,Storage>
433  tan(const OrthogPoly<T,Storage>& a);
434 
435  template <typename T, typename Storage> OrthogPoly<T,Storage>
436  cosh(const OrthogPoly<T,Storage>& a);
437 
438  template <typename T, typename Storage> OrthogPoly<T,Storage>
439  sinh(const OrthogPoly<T,Storage>& a);
440 
441  template <typename T, typename Storage> OrthogPoly<T,Storage>
442  tanh(const OrthogPoly<T,Storage>& a);
443 
444  template <typename T, typename Storage> OrthogPoly<T,Storage>
445  acos(const OrthogPoly<T,Storage>& a);
446 
447  template <typename T, typename Storage> OrthogPoly<T,Storage>
448  asin(const OrthogPoly<T,Storage>& a);
449 
450  template <typename T, typename Storage> OrthogPoly<T,Storage>
451  atan(const OrthogPoly<T,Storage>& a);
452 
453  template <typename T, typename Storage> OrthogPoly<T,Storage>
454  atan2(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
455 
456  template <typename T, typename Storage> OrthogPoly<T,Storage>
457  atan2(const typename OrthogPoly<T,Storage>::value_type& a,
458  const OrthogPoly<T,Storage>& b);
459 
460  template <typename T, typename Storage> OrthogPoly<T,Storage>
461  atan2(const OrthogPoly<T,Storage>& a,
462  const typename OrthogPoly<T,Storage>::value_type& b);
463 
464  template <typename T, typename Storage> OrthogPoly<T,Storage>
465  acosh(const OrthogPoly<T,Storage>& a);
466 
467  template <typename T, typename Storage> OrthogPoly<T,Storage>
468  asinh(const OrthogPoly<T,Storage>& a);
469 
470  template <typename T, typename Storage> OrthogPoly<T,Storage>
471  atanh(const OrthogPoly<T,Storage>& a);
472 
473  template <typename T, typename Storage> OrthogPoly<T,Storage>
474  abs(const OrthogPoly<T,Storage>& a);
475 
476  template <typename T, typename Storage> OrthogPoly<T,Storage>
477  fabs(const OrthogPoly<T,Storage>& a);
478 
479  template <typename T, typename Storage> OrthogPoly<T,Storage>
480  max(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
481 
482  template <typename T, typename Storage> OrthogPoly<T,Storage>
483  max(const typename OrthogPoly<T,Storage>::value_type& a,
484  const OrthogPoly<T,Storage>& b);
485 
486  template <typename T, typename Storage> OrthogPoly<T,Storage>
487  max(const OrthogPoly<T,Storage>& a,
488  const typename OrthogPoly<T,Storage>::value_type& b);
489 
490  template <typename T, typename Storage> OrthogPoly<T,Storage>
491  min(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
492 
493  template <typename T, typename Storage> OrthogPoly<T,Storage>
494  min(const typename OrthogPoly<T,Storage>::value_type& a,
495  const OrthogPoly<T,Storage>& b);
496 
497  template <typename T, typename Storage> OrthogPoly<T,Storage>
498  min(const OrthogPoly<T,Storage>& a,
499  const typename OrthogPoly<T,Storage>::value_type& b);
500 
501  template <typename T, typename Storage> bool
502  operator==(const OrthogPoly<T,Storage>& a,
503  const OrthogPoly<T,Storage>& b);
504 
505  template <typename T, typename Storage> bool
507  const OrthogPoly<T,Storage>& b);
508 
509  template <typename T, typename Storage> bool
510  operator==(const OrthogPoly<T,Storage>& a,
511  const typename OrthogPoly<T,Storage>::value_type& b);
512 
513  template <typename T, typename Storage> bool
514  operator!=(const OrthogPoly<T,Storage>& a,
515  const OrthogPoly<T,Storage>& b);
516 
517  template <typename T, typename Storage> bool
519  const OrthogPoly<T,Storage>& b);
520 
521  template <typename T, typename Storage> bool
522  operator!=(const OrthogPoly<T,Storage>& a,
523  const typename OrthogPoly<T,Storage>::value_type& b);
524 
525  template <typename T, typename Storage> bool
526  operator<=(const OrthogPoly<T,Storage>& a,
527  const OrthogPoly<T,Storage>& b);
528 
529  template <typename T, typename Storage> bool
531  const OrthogPoly<T,Storage>& b);
532 
533  template <typename T, typename Storage> bool
534  operator<=(const OrthogPoly<T,Storage>& a,
535  const typename OrthogPoly<T,Storage>::value_type& b);
536 
537  template <typename T, typename Storage> bool
538  operator>=(const OrthogPoly<T,Storage>& a,
539  const OrthogPoly<T,Storage>& b);
540 
541  template <typename T, typename Storage> bool
543  const OrthogPoly<T,Storage>& b);
544 
545  template <typename T, typename Storage> bool
546  operator>=(const OrthogPoly<T,Storage>& a,
547  const typename OrthogPoly<T,Storage>::value_type& b);
548 
549  template <typename T, typename Storage> bool
550  operator<(const OrthogPoly<T,Storage>& a,
551  const OrthogPoly<T,Storage>& b);
552 
553  template <typename T, typename Storage> bool
555  const OrthogPoly<T,Storage>& b);
556 
557  template <typename T, typename Storage> bool
558  operator<(const OrthogPoly<T,Storage>& a,
559  const typename OrthogPoly<T,Storage>::value_type& b);
560 
561  template <typename T, typename Storage> bool
562  operator>(const OrthogPoly<T,Storage>& a,
563  const OrthogPoly<T,Storage>& b);
564 
565  template <typename T, typename Storage> bool
567  const OrthogPoly<T,Storage>& b);
568 
569  template <typename T, typename Storage> bool
570  operator>(const OrthogPoly<T,Storage>& a,
571  const typename OrthogPoly<T,Storage>::value_type& b);
572 
573  template <typename T, typename Storage> std::ostream&
574  operator << (std::ostream& os, const OrthogPoly<T,Storage>& a);
575 
576  template <typename T, typename Storage> std::istream&
577  operator >> (std::istream& os, OrthogPoly<T,Storage>& a);
578 
579  } // namespace PCE
580 
581 } // namespace Sacado
582 
585 
586 #endif // HAVE_STOKHOS_SACADO
587 
588 #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)
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)
atan2(expr1.val(), expr2.val())
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
Orthogonal polynomial expansion class for constant (size 1) expansions.
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.
expr val()
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)