Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
63namespace 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 Teuchos::RCP<expansion_type> const_expansion_;
342
343 Sacado::Handle< Stokhos::OrthogPolyApprox<int,value_type,Storage> > th;
344
345 }; // class Hermite
346
347 // Operations
348 template <typename T, typename Storage> OrthogPoly<T,Storage>
349 operator+(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
350
351 template <typename T, typename Storage> OrthogPoly<T,Storage>
352 operator+(const typename OrthogPoly<T,Storage>::value_type& a,
353 const OrthogPoly<T,Storage>& b);
354
355 template <typename T, typename Storage> OrthogPoly<T,Storage>
356 operator+(const OrthogPoly<T,Storage>& a,
357 const typename OrthogPoly<T,Storage>::value_type& b);
358
359 template <typename T, typename Storage> OrthogPoly<T,Storage>
360 operator-(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
361
362 template <typename T, typename Storage> OrthogPoly<T,Storage>
363 operator-(const typename OrthogPoly<T,Storage>::value_type& a,
364 const OrthogPoly<T,Storage>& b);
365
366 template <typename T, typename Storage> OrthogPoly<T,Storage>
367 operator-(const OrthogPoly<T,Storage>& a,
368 const typename OrthogPoly<T,Storage>::value_type& b);
369
370 template <typename T, typename Storage> OrthogPoly<T,Storage>
371 operator*(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
372
373 template <typename T, typename Storage> OrthogPoly<T,Storage>
374 operator*(const typename OrthogPoly<T,Storage>::value_type& a,
375 const OrthogPoly<T,Storage>& b);
376
377 template <typename T, typename Storage> OrthogPoly<T,Storage>
378 operator*(const OrthogPoly<T,Storage>& a,
379 const typename OrthogPoly<T,Storage>::value_type& b);
380
381 template <typename T, typename Storage> OrthogPoly<T,Storage>
382 operator/(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
383
384 template <typename T, typename Storage> OrthogPoly<T,Storage>
385 operator/(const typename OrthogPoly<T,Storage>::value_type& a,
386 const OrthogPoly<T,Storage>& b);
387
388 template <typename T, typename Storage> OrthogPoly<T,Storage>
389 operator/(const OrthogPoly<T,Storage>& a,
390 const typename OrthogPoly<T,Storage>::value_type& b);
391
392 template <typename T, typename Storage> OrthogPoly<T,Storage>
393 exp(const OrthogPoly<T,Storage>& a);
394
395 template <typename T, typename Storage> OrthogPoly<T,Storage>
396 log(const OrthogPoly<T,Storage>& a);
397
398 template <typename T, typename Storage> void
399 log(OrthogPoly<T,Storage>& c, const OrthogPoly<T,Storage>& a);
400
401 template <typename T, typename Storage> OrthogPoly<T,Storage>
402 log10(const OrthogPoly<T,Storage>& a);
403
404 template <typename T, typename Storage> OrthogPoly<T,Storage>
405 sqrt(const OrthogPoly<T,Storage>& a);
406
407 template <typename T, typename Storage> OrthogPoly<T,Storage>
408 cbrt(const OrthogPoly<T,Storage>& a);
409
410 template <typename T, typename Storage> OrthogPoly<T,Storage>
411 pow(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
412
413 template <typename T, typename Storage> OrthogPoly<T,Storage>
414 pow(const T& a,
415 const OrthogPoly<T,Storage>& b);
416
417 template <typename T, typename Storage> OrthogPoly<T,Storage>
418 pow(const OrthogPoly<T,Storage>& a,
419 const T& b);
420
421 template <typename T, typename Storage> OrthogPoly<T,Storage>
422 cos(const OrthogPoly<T,Storage>& a);
423
424 template <typename T, typename Storage> OrthogPoly<T,Storage>
425 sin(const OrthogPoly<T,Storage>& a);
426
427 template <typename T, typename Storage> OrthogPoly<T,Storage>
428 tan(const OrthogPoly<T,Storage>& a);
429
430 template <typename T, typename Storage> OrthogPoly<T,Storage>
431 cosh(const OrthogPoly<T,Storage>& a);
432
433 template <typename T, typename Storage> OrthogPoly<T,Storage>
434 sinh(const OrthogPoly<T,Storage>& a);
435
436 template <typename T, typename Storage> OrthogPoly<T,Storage>
437 tanh(const OrthogPoly<T,Storage>& a);
438
439 template <typename T, typename Storage> OrthogPoly<T,Storage>
440 acos(const OrthogPoly<T,Storage>& a);
441
442 template <typename T, typename Storage> OrthogPoly<T,Storage>
443 asin(const OrthogPoly<T,Storage>& a);
444
445 template <typename T, typename Storage> OrthogPoly<T,Storage>
446 atan(const OrthogPoly<T,Storage>& a);
447
448 template <typename T, typename Storage> OrthogPoly<T,Storage>
449 atan2(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
450
451 template <typename T, typename Storage> OrthogPoly<T,Storage>
452 atan2(const typename OrthogPoly<T,Storage>::value_type& a,
453 const OrthogPoly<T,Storage>& b);
454
455 template <typename T, typename Storage> OrthogPoly<T,Storage>
456 atan2(const OrthogPoly<T,Storage>& a,
457 const typename OrthogPoly<T,Storage>::value_type& b);
458
459 template <typename T, typename Storage> OrthogPoly<T,Storage>
460 acosh(const OrthogPoly<T,Storage>& a);
461
462 template <typename T, typename Storage> OrthogPoly<T,Storage>
463 asinh(const OrthogPoly<T,Storage>& a);
464
465 template <typename T, typename Storage> OrthogPoly<T,Storage>
466 atanh(const OrthogPoly<T,Storage>& a);
467
468 template <typename T, typename Storage> OrthogPoly<T,Storage>
469 abs(const OrthogPoly<T,Storage>& a);
470
471 template <typename T, typename Storage> OrthogPoly<T,Storage>
472 fabs(const OrthogPoly<T,Storage>& a);
473
474 template <typename T, typename Storage> OrthogPoly<T,Storage>
475 max(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
476
477 template <typename T, typename Storage> OrthogPoly<T,Storage>
478 max(const typename OrthogPoly<T,Storage>::value_type& a,
479 const OrthogPoly<T,Storage>& b);
480
481 template <typename T, typename Storage> OrthogPoly<T,Storage>
482 max(const OrthogPoly<T,Storage>& a,
483 const typename OrthogPoly<T,Storage>::value_type& b);
484
485 template <typename T, typename Storage> OrthogPoly<T,Storage>
486 min(const OrthogPoly<T,Storage>& a, const OrthogPoly<T,Storage>& b);
487
488 template <typename T, typename Storage> OrthogPoly<T,Storage>
489 min(const typename OrthogPoly<T,Storage>::value_type& a,
490 const OrthogPoly<T,Storage>& b);
491
492 template <typename T, typename Storage> OrthogPoly<T,Storage>
493 min(const OrthogPoly<T,Storage>& a,
494 const typename OrthogPoly<T,Storage>::value_type& b);
495
496 template <typename T, typename Storage> bool
497 operator==(const OrthogPoly<T,Storage>& a,
498 const OrthogPoly<T,Storage>& b);
499
500 template <typename T, typename Storage> bool
501 operator==(const typename OrthogPoly<T,Storage>::value_type& a,
502 const OrthogPoly<T,Storage>& b);
503
504 template <typename T, typename Storage> bool
505 operator==(const OrthogPoly<T,Storage>& a,
506 const typename OrthogPoly<T,Storage>::value_type& b);
507
508 template <typename T, typename Storage> bool
509 operator!=(const OrthogPoly<T,Storage>& a,
510 const OrthogPoly<T,Storage>& b);
511
512 template <typename T, typename Storage> bool
513 operator!=(const typename OrthogPoly<T,Storage>::value_type& a,
514 const OrthogPoly<T,Storage>& b);
515
516 template <typename T, typename Storage> bool
517 operator!=(const OrthogPoly<T,Storage>& a,
518 const typename OrthogPoly<T,Storage>::value_type& b);
519
520 template <typename T, typename Storage> bool
521 operator<=(const OrthogPoly<T,Storage>& a,
522 const OrthogPoly<T,Storage>& b);
523
524 template <typename T, typename Storage> bool
525 operator<=(const typename OrthogPoly<T,Storage>::value_type& a,
526 const OrthogPoly<T,Storage>& b);
527
528 template <typename T, typename Storage> bool
529 operator<=(const OrthogPoly<T,Storage>& a,
530 const typename OrthogPoly<T,Storage>::value_type& b);
531
532 template <typename T, typename Storage> bool
533 operator>=(const OrthogPoly<T,Storage>& a,
534 const OrthogPoly<T,Storage>& b);
535
536 template <typename T, typename Storage> bool
537 operator>=(const typename OrthogPoly<T,Storage>::value_type& a,
538 const OrthogPoly<T,Storage>& b);
539
540 template <typename T, typename Storage> bool
541 operator>=(const OrthogPoly<T,Storage>& a,
542 const typename OrthogPoly<T,Storage>::value_type& b);
543
544 template <typename T, typename Storage> bool
545 operator<(const OrthogPoly<T,Storage>& a,
546 const OrthogPoly<T,Storage>& b);
547
548 template <typename T, typename Storage> bool
549 operator<(const typename OrthogPoly<T,Storage>::value_type& a,
550 const OrthogPoly<T,Storage>& b);
551
552 template <typename T, typename Storage> bool
553 operator<(const OrthogPoly<T,Storage>& a,
554 const typename OrthogPoly<T,Storage>::value_type& b);
555
556 template <typename T, typename Storage> bool
557 operator>(const OrthogPoly<T,Storage>& a,
558 const OrthogPoly<T,Storage>& b);
559
560 template <typename T, typename Storage> bool
561 operator>(const typename OrthogPoly<T,Storage>::value_type& a,
562 const OrthogPoly<T,Storage>& b);
563
564 template <typename T, typename Storage> bool
565 operator>(const OrthogPoly<T,Storage>& a,
566 const typename OrthogPoly<T,Storage>::value_type& b);
567
568 template <typename T, typename Storage> std::ostream&
569 operator << (std::ostream& os, const OrthogPoly<T,Storage>& a);
570
571 template <typename T, typename Storage> std::istream&
572 operator >> (std::istream& os, OrthogPoly<T,Storage>& a);
573
574 } // namespace PCE
575
576} // namespace Sacado
577
580
581#endif // HAVE_STOKHOS_SACADO
582
583#endif // SACADO_PCE_ORTHOGPOLY_HPP
asinh(expr.val())
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j) - expr2.val(j)
acosh(expr.val())
atan2(expr1.val(), expr2.val())
expr val()
atanh(expr.val())
Stokhos::StandardStorage< int, double > storage_type
Class to store coefficients of a projection onto an orthogonal polynomial basis.
Abstract base class for multivariate orthogonal polynomials.
Abstract base class for orthogonal polynomial-based expansions.
Stokhos::LegendreBasis< int, double > basis_type
std::istream & operator>>(std::istream &is, 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 > operator/(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
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)
bool operator==(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
bool operator<=(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
std::ostream & operator<<(std::ostream &os, const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > min(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
OrthogPoly< T, Storage > max(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
bool 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 > operator*(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
bool operator>(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > tan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > tanh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cos(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cosh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > acos(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cbrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > fabs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > asin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)