Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_PCE_OrthogPolyImp.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 #include "Sacado_DynamicArrayTraits.hpp"
43 #include "Teuchos_TimeMonitor.hpp"
45 
46 namespace Sacado {
47 namespace PCE {
48 
49 template <typename T, typename Storage>
51 OrthogPoly() :
52  expansion_(),
54 {
55  const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion<int,T>);
56  expansion_ = const_expansion_;
57 }
58 
59 template <typename T, typename Storage>
62  expansion_(),
63  th(new Stokhos::OrthogPolyApprox<int,value_type,Storage>(Teuchos::null, 1, &x))
64 {
65  const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion<int,T>);
66  expansion_ = const_expansion_;
67 }
68 
69 template <typename T, typename Storage>
71 OrthogPoly(const Teuchos::RCP<expansion_type>& expansion) :
72  expansion_(expansion),
73  th(new Stokhos::OrthogPolyApprox<int,value_type,Storage>(expansion_->getBasis()))
74 {
75  const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion<int,T>);
76 }
77 
78 template <typename T, typename Storage>
80 OrthogPoly(const Teuchos::RCP<expansion_type>& expansion,
81  ordinal_type sz) :
82  expansion_(expansion),
83  th(new Stokhos::OrthogPolyApprox<int,value_type,Storage>(expansion_->getBasis(), sz))
84 {
85  const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion<int,T>);
86 }
87 
88 template <typename T, typename Storage>
91  expansion_(x.expansion_),
92  th(x.th)
93 {
94  const_expansion_ = Teuchos::rcp(new Stokhos::ConstantOrthogPolyExpansion<int,T>);
95 }
96 
97 template <typename T, typename Storage>
100 {
101 }
102 
103 template <typename T, typename Storage>
104 void
106 reset(const Teuchos::RCP<expansion_type>& expansion)
107 {
108  expansion_ = expansion;
109  th->reset(expansion_->getBasis());
110 }
111 
112 template <typename T, typename Storage>
113 void
115 reset(const Teuchos::RCP<expansion_type>& expansion, ordinal_type sz)
116 {
117  expansion_ = expansion;
118  th->reset(expansion_->getBasis(), sz);
119 }
120 
121 template <typename T, typename Storage>
124 evaluate(const Teuchos::Array<typename OrthogPoly<T,Storage>::value_type>& point) const
125 {
126  return th->evaluate(point);
127 }
128 
129 template <typename T, typename Storage>
132 evaluate(
133  const Teuchos::Array<typename OrthogPoly<T,Storage>::value_type>& point,
134  const Teuchos::Array<typename OrthogPoly<T,Storage>::value_type>& bvals) const
135 {
136  return th->evaluate(point, bvals);
137 }
138 
139 template <typename T, typename Storage>
140 bool
142 isEqualTo(const OrthogPoly& x) const {
143  typedef IsEqual<value_type> IE;
144  if (x.size() != this->size()) return false;
145  // Allow expansions to be different if their size is 1 and one
146  // of them is a constant expansion
147  if (expansion_ != x.expansion_) {
148  if (x.size() != 1)
149  return false;
150  if ((expansion_ != const_expansion_) &&
151  (x.expansion_ != x.const_expansion_))
152  return false;
153  }
154  bool eq = true;
155  for (int i=0; i<this->size(); i++)
156  eq = eq && IE::eval(x.coeff(i), this->coeff(i));
157  return eq;
158 }
159 
160 template <typename T, typename Storage>
164 {
165  th.makeOwnCopy();
166  *th = v;
167  return *this;
168 }
169 
170 template <typename T, typename Storage>
174 {
175  expansion_ = x.expansion_;
176  th = x.th;
177  return *this;
178 }
179 
180 template <typename T, typename Storage>
183 operator+() const
184 {
185  return *this;
186 }
187 
188 template <typename T, typename Storage>
191 operator-() const
192 {
193  OrthogPoly<T,Storage> x(expansion_);
194  expansion_->unaryMinus(*(x.th), *th);
195  return x;
196 }
197 
198 template <typename T, typename Storage>
202 {
203  th.makeOwnCopy();
204  expansion_->plusEqual(*th, v);
205  return *this;
206 }
207 
208 template <typename T, typename Storage>
212 {
213  th.makeOwnCopy();
214  expansion_->minusEqual(*th, v);
215  return *this;
216 }
217 
218 template <typename T, typename Storage>
222 {
223  th.makeOwnCopy();
224  expansion_->timesEqual(*th, v);
225  return *this;
226 }
227 
228 template <typename T, typename Storage>
232 {
233  th.makeOwnCopy();
234  expansion_->divideEqual(*th, v);
235  return *this;
236 }
237 
238 template <typename T, typename Storage>
242 {
243  th.makeOwnCopy();
244  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = expansion_;
245  if (x.size() > size()) {
246  e = x.expansion();
247  reset(e, size());
248  }
249  e->plusEqual(*th, *x.th);
250  return *this;
251 }
252 
253 template <typename T, typename Storage>
257 {
258  th.makeOwnCopy();
259  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = expansion_;
260  if (x.size() > size()) {
261  e = x.expansion();
262  reset(e, size());
263  }
264  e->minusEqual(*th, *x.th);
265  return *this;
266 }
267 
268 template <typename T, typename Storage>
272 {
273  th.makeOwnCopy();
274  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = expansion_;
275  if (x.size() > size()) {
276  e = x.expansion();
277  reset(e, size());
278  }
279  e->timesEqual(*th, *x.th);
280  return *this;
281 }
282 
283 template <typename T, typename Storage>
287 {
288  th.makeOwnCopy();
289  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = expansion_;
290  if (x.size() > size()) {
291  e = x.expansion();
292  reset(e, size());
293  }
294  e->divideEqual(*th, *x.th);
295  return *this;
296 }
297 
298 template <typename T, typename Storage>
301  const OrthogPoly<T,Storage>& b)
302 {
303  // Get expansion
305  ordinal_type da = a.size();
306  ordinal_type db = b.size();
307  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = a.expansion();
308  if (da == db || da > 1)
309  e = a.expansion();
310  else
311  e = b.expansion();
312 
313  OrthogPoly<T,Storage> c(e, 0);
314  e->plus(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(),
315  b.getOrthogPolyApprox());
316 
317  return c;
318 }
319 
320 template <typename T, typename Storage>
321 OrthogPoly<T,Storage>
323  const OrthogPoly<T,Storage>& b)
324 {
325  OrthogPoly<T,Storage> c(b.expansion(), 0);
326  b.expansion()->plus(c.getOrthogPolyApprox(), a, b.getOrthogPolyApprox());
327  return c;
328 }
329 
330 template <typename T, typename Storage>
331 OrthogPoly<T,Storage>
333  const typename OrthogPoly<T,Storage>::value_type& b)
334 {
335  OrthogPoly<T,Storage> c(a.expansion(), 0);
336  a.expansion()->plus(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(), b);
337  return c;
338 }
339 
340 template <typename T, typename Storage>
341 OrthogPoly<T,Storage>
343  const OrthogPoly<T,Storage>& b)
344 {
345  // Get expansion
347  ordinal_type da = a.size();
348  ordinal_type db = b.size();
349  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = a.expansion();
350  if (da == db || da > 1)
351  e = a.expansion();
352  else
353  e = b.expansion();
354 
355  OrthogPoly<T,Storage> c(e, 0);
356  e->minus(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(),
357  b.getOrthogPolyApprox());
358 
359  return c;
360 }
361 
362 template <typename T, typename Storage>
363 OrthogPoly<T,Storage>
365  const OrthogPoly<T,Storage>& b)
366 {
367  OrthogPoly<T,Storage> c(b.expansion(), 0);
368  b.expansion()->minus(c.getOrthogPolyApprox(), a, b.getOrthogPolyApprox());
369  return c;
370 }
371 
372 template <typename T, typename Storage>
373 OrthogPoly<T,Storage>
375  const typename OrthogPoly<T,Storage>::value_type& b)
376 {
377  OrthogPoly<T,Storage> c(a.expansion(), 0);
378  a.expansion()->minus(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(), b);
379  return c;
380 }
381 
382 template <typename T, typename Storage>
383 OrthogPoly<T,Storage>
385  const OrthogPoly<T,Storage>& b)
386 {
387  // Get expansion
389  ordinal_type da = a.size();
390  ordinal_type db = b.size();
391  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = a.expansion();
392  if (da == db || da > 1)
393  e = a.expansion();
394  else
395  e = b.expansion();
396 
397  OrthogPoly<T,Storage> c(e, 0);
398  e->times(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(),
399  b.getOrthogPolyApprox());
400 
401  return c;
402 }
403 
404 template <typename T, typename Storage>
405 OrthogPoly<T,Storage>
407  const OrthogPoly<T,Storage>& b)
408 {
409  OrthogPoly<T,Storage> c(b.expansion(), 0);
410  b.expansion()->times(c.getOrthogPolyApprox(), a, b.getOrthogPolyApprox());
411  return c;
412 }
413 
414 template <typename T, typename Storage>
415 OrthogPoly<T,Storage>
417  const typename OrthogPoly<T,Storage>::value_type& b)
418 {
419  OrthogPoly<T,Storage> c(a.expansion(), 0);
420  a.expansion()->times(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(), b);
421  return c;
422 }
423 
424 template <typename T, typename Storage>
425 OrthogPoly<T,Storage>
427  const OrthogPoly<T,Storage>& b)
428 {
429  // Get expansion
431  ordinal_type da = a.size();
432  ordinal_type db = b.size();
433  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = a.expansion();
434  if (da == db || da > 1)
435  e = a.expansion();
436  else
437  e = b.expansion();
438 
439  OrthogPoly<T,Storage> c(e, 0);
440  e->divide(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(),
441  b.getOrthogPolyApprox());
442 
443  return c;
444 }
445 
446 template <typename T, typename Storage>
447 OrthogPoly<T,Storage>
449  const OrthogPoly<T,Storage>& b)
450 {
451  OrthogPoly<T,Storage> c(b.expansion(), 0);
452  b.expansion()->divide(c.getOrthogPolyApprox(), a, b.getOrthogPolyApprox());
453  return c;
454 }
455 
456 template <typename T, typename Storage>
457 OrthogPoly<T,Storage>
459  const typename OrthogPoly<T,Storage>::value_type& b)
460 {
461  OrthogPoly<T,Storage> c(a.expansion(), 0);
462  a.expansion()->divide(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(), b);
463  return c;
464 }
465 
466 template <typename T, typename Storage>
467 OrthogPoly<T,Storage>
469 {
470  OrthogPoly<T,Storage> c(a.expansion(), 0);
471  a.expansion()->exp(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
472  return c;
473 }
474 
475 template <typename T, typename Storage>
476 OrthogPoly<T,Storage>
478 {
479  TEUCHOS_FUNC_TIME_MONITOR("LOG");
480  OrthogPoly<T,Storage> c(a.expansion(), 0);
481  {
482  TEUCHOS_FUNC_TIME_MONITOR("OPA LOG");
483  a.expansion()->log(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
484  }
485 
487  return d;
488 }
489 
490 template <typename T, typename Storage>
491 void
493 {
494  OrthogPoly<T,Storage> d(a.expansion(), 0);
495  a.expansion()->log(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
496 }
497 
498 template <typename T, typename Storage>
499 OrthogPoly<T,Storage>
501 {
502  OrthogPoly<T,Storage> c(a.expansion(), 0);
503  a.expansion()->log10(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
504  return c;
505 }
506 
507 template <typename T, typename Storage>
508 OrthogPoly<T,Storage>
510 {
511  OrthogPoly<T,Storage> c(a.expansion(), 0);
512  a.expansion()->sqrt(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
513  return c;
514 }
515 
516 template <typename T, typename Storage>
517 OrthogPoly<T,Storage>
519 {
520  OrthogPoly<T,Storage> c(a.expansion(), 0);
521  a.expansion()->cbrt(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
522  return c;
523 }
524 
525 template <typename T, typename Storage>
526 OrthogPoly<T,Storage>
528  const OrthogPoly<T,Storage>& b)
529 {
530  // Get expansion
532  ordinal_type da = a.size();
533  ordinal_type db = b.size();
534  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = a.expansion();
535  if (da == db || da > 1)
536  e = a.expansion();
537  else
538  e = b.expansion();
539 
540  OrthogPoly<T,Storage> c(e, 0);
541  e->pow(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(),
542  b.getOrthogPolyApprox());
543 
544  return c;
545 }
546 
547 template <typename T, typename Storage>
548 OrthogPoly<T,Storage>
549 pow(const T& a,
550  const OrthogPoly<T,Storage>& b)
551 {
552  OrthogPoly<T,Storage> c(b.expansion(), 0);
553  b.expansion()->pow(c.getOrthogPolyApprox(), a, b.getOrthogPolyApprox());
554  return c;
555 }
556 
557 template <typename T, typename Storage>
558 OrthogPoly<T,Storage>
560  const T& b)
561 {
562  OrthogPoly<T,Storage> c(a.expansion(), 0);
563  a.expansion()->pow(c.getOrthogPolyApprox(),a.getOrthogPolyApprox(), b);
564  return c;
565 }
566 
567 template <typename T, typename Storage>
568 OrthogPoly<T,Storage>
570 {
571  OrthogPoly<T,Storage> c(a.expansion(), 0);
572  a.expansion()->sin(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
573  return c;
574 }
575 
576 template <typename T, typename Storage>
577 OrthogPoly<T,Storage>
579 {
580  OrthogPoly<T,Storage> c(a.expansion(), 0);
581  a.expansion()->cos(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
582  return c;
583 }
584 
585 template <typename T, typename Storage>
586 OrthogPoly<T,Storage>
588 {
589  OrthogPoly<T,Storage> c(a.expansion(), 0);
590  a.expansion()->tan(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
591  return c;
592 }
593 
594 template <typename T, typename Storage>
595 OrthogPoly<T,Storage>
597 {
598  OrthogPoly<T,Storage> c(a.expansion(), 0);
599  a.expansion()->sinh(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
600  return c;
601 }
602 
603 template <typename T, typename Storage>
604 OrthogPoly<T,Storage>
606 {
607  OrthogPoly<T,Storage> c(a.expansion(), 0);
608  a.expansion()->cosh(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
609  return c;
610 }
611 
612 template <typename T, typename Storage>
613 OrthogPoly<T,Storage>
615 {
616  OrthogPoly<T,Storage> c(a.expansion(), 0);
617  a.expansion()->tanh(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
618  return c;
619 }
620 
621 template <typename T, typename Storage>
622 OrthogPoly<T,Storage>
624 {
625  OrthogPoly<T,Storage> c(a.expansion(), 0);
626  a.expansion()->acos(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
627  return c;
628 }
629 
630 template <typename T, typename Storage>
631 OrthogPoly<T,Storage>
633 {
634  OrthogPoly<T,Storage> c(a.expansion(), 0);
635  a.expansion()->asin(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
636  return c;
637 }
638 
639 template <typename T, typename Storage>
640 OrthogPoly<T,Storage>
642 {
643  OrthogPoly<T,Storage> c(a.expansion(), 0);
644  a.expansion()->atan(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
645  return c;
646 }
647 
648 template <typename T, typename Storage>
649 OrthogPoly<T,Storage>
651 {
652  OrthogPoly<T,Storage> c(a.expansion(), 0);
653  a.expansion()->acosh(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
654  return c;
655 }
656 
657 template <typename T, typename Storage>
658 OrthogPoly<T,Storage>
660 {
661  OrthogPoly<T,Storage> c(a.expansion(), 0);
662  a.expansion()->asinh(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
663  return c;
664 }
665 
666 template <typename T, typename Storage>
667 OrthogPoly<T,Storage>
669 {
670  OrthogPoly<T,Storage> c(a.expansion(), 0);
671  a.expansion()->atanh(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
672  return c;
673 }
674 
675 template <typename T, typename Storage>
676 OrthogPoly<T,Storage>
678 {
679  OrthogPoly<T,Storage> c(a.expansion(), 0);
680  a.expansion()->fabs(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
681  return c;
682 }
683 
684 template <typename T, typename Storage>
685 OrthogPoly<T,Storage>
687 {
688  OrthogPoly<T,Storage> c(a.expansion(), 0);
689  a.expansion()->abs(c.getOrthogPolyApprox(), a.getOrthogPolyApprox());
690  return c;
691 }
692 
693 template <typename T, typename Storage>
694 OrthogPoly<T,Storage>
696  const OrthogPoly<T,Storage>& b)
697 {
698  // Get expansion
700  ordinal_type da = a.size();
701  ordinal_type db = b.size();
702  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = a.expansion();
703  if (da == db || da > 1)
704  e = a.expansion();
705  else
706  e = b.expansion();
707 
708  OrthogPoly<T,Storage> c(e, 0);
709  e->max(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(),
710  b.getOrthogPolyApprox());
711 
712  return c;
713 }
714 
715 template <typename T, typename Storage>
716 OrthogPoly<T,Storage>
718  const OrthogPoly<T,Storage>& b)
719 {
720  OrthogPoly<T,Storage> c(b.expansion(), 0);
721  b.expansion()->max(c.getOrthogPolyApprox(), a, b.getOrthogPolyApprox());
722  return c;
723 }
724 
725 template <typename T, typename Storage>
726 OrthogPoly<T,Storage>
728  const typename OrthogPoly<T,Storage>::value_type& b)
729 {
730  OrthogPoly<T,Storage> c(a.expansion(), 0);
731  a.expansion()->max(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(), b);
732  return c;
733 }
734 
735 template <typename T, typename Storage>
736 OrthogPoly<T,Storage>
738  const OrthogPoly<T,Storage>& b)
739 {
740  // Get expansion
742  ordinal_type da = a.size();
743  ordinal_type db = b.size();
744  Teuchos::RCP<typename OrthogPoly<T,Storage>::expansion_type> e = a.expansion();
745  if (da == db || da > 1)
746  e = a.expansion();
747  else
748  e = b.expansion();
749 
750  OrthogPoly<T,Storage> c(e, 0);
751  e->min(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(),
752  b.getOrthogPolyApprox());
753 
754  return c;
755 }
756 
757 template <typename T, typename Storage>
758 OrthogPoly<T,Storage>
760  const OrthogPoly<T,Storage>& b)
761 {
762  OrthogPoly<T,Storage> c(b.expansion(), 0);
763  b.expansion()->min(c.getOrthogPolyApprox(), a, b.getOrthogPolyApprox());
764  return c;
765 }
766 
767 template <typename T, typename Storage>
768 OrthogPoly<T,Storage>
770  const typename OrthogPoly<T,Storage>::value_type& b)
771 {
772  OrthogPoly<T,Storage> c(a.expansion(), 0);
773  a.expansion()->min(c.getOrthogPolyApprox(), a.getOrthogPolyApprox(), b);
774  return c;
775 }
776 
777 template <typename T, typename Storage>
778 bool
780  const OrthogPoly<T,Storage>& b)
781 {
782  int n = std::max(a.size(), b.size());
783  for (int i=0; i<n; i++)
784  if (a.coeff(i) != b.coeff(i))
785  return false;
786  return true;
787 }
788 
789 template <typename T, typename Storage>
790 bool
792  const OrthogPoly<T,Storage>& b)
793 {
794  if (a != b.coeff(0))
795  return false;
796  for (int i=1; i<b.size(); i++)
797  if (b.coeff(i) != T(0.0))
798  return false;
799  return true;
800 }
801 
802 template <typename T, typename Storage>
803 bool
805  const typename OrthogPoly<T,Storage>::value_type& b)
806 {
807  if (a.coeff(0) != b)
808  return false;
809  for (int i=1; i<a.size(); i++)
810  if (a.coeff(i) != T(0.0))
811  return false;
812  return true;
813 }
814 
815 template <typename T, typename Storage>
816 bool
818  const OrthogPoly<T,Storage>& b)
819 {
820  return !(a == b);
821 }
822 
823 template <typename T, typename Storage>
824 bool
826  const OrthogPoly<T,Storage>& b)
827 {
828  return !(a == b);
829 }
830 
831 template <typename T, typename Storage>
832 bool
834  const typename OrthogPoly<T,Storage>::value_type& b)
835 {
836  return !(a == b);
837 }
838 
839 template <typename T, typename Storage>
840 bool
841 operator<=(const OrthogPoly<T,Storage>& a,
842  const OrthogPoly<T,Storage>& b)
843 {
844  return a.two_norm() <= b.two_norm();
845 }
846 
847 template <typename T, typename Storage>
848 bool
850  const OrthogPoly<T,Storage>& b)
851 {
852  return a <= b.two_norm();
853 }
854 
855 template <typename T, typename Storage>
856 bool
857 operator<=(const OrthogPoly<T,Storage>& a,
858  const typename OrthogPoly<T,Storage>::value_type& b)
859 {
860  return a.two_norm() <= b;
861 }
862 
863 template <typename T, typename Storage>
864 bool
866  const OrthogPoly<T,Storage>& b)
867 {
868  return a.two_norm() >= b.two_norm();
869 }
870 
871 template <typename T, typename Storage>
872 bool
874  const OrthogPoly<T,Storage>& b)
875 {
876  return a >= b.two_norm();
877 }
878 
879 template <typename T, typename Storage>
880 bool
882  const typename OrthogPoly<T,Storage>::value_type& b)
883 {
884  return a.two_norm() >= b;
885 }
886 
887 template <typename T, typename Storage>
888 bool
889 operator<(const OrthogPoly<T,Storage>& a,
890  const OrthogPoly<T,Storage>& b)
891 {
892  return a.two_norm() < b.two_norm();
893 }
894 
895 template <typename T, typename Storage>
896 bool
898  const OrthogPoly<T,Storage>& b)
899 {
900  return a < b.two_norm();
901 }
902 
903 template <typename T, typename Storage>
904 bool
905 operator<(const OrthogPoly<T,Storage>& a,
906  const typename OrthogPoly<T,Storage>::value_type& b)
907 {
908  return a.two_norm() < b;
909 }
910 
911 template <typename T, typename Storage>
912 bool
914  const OrthogPoly<T,Storage>& b)
915 {
916  return a.two_norm() > b.two_norm();
917 }
918 
919 template <typename T, typename Storage>
920 bool
922  const OrthogPoly<T,Storage>& b)
923 {
924  return a > b.two_norm();
925 }
926 
927 template <typename T, typename Storage>
928 bool
930  const typename OrthogPoly<T,Storage>::value_type& b)
931 {
932  return a.two_norm() > b;
933 }
934 
935 template <typename T, typename Storage>
937  bool is_zero = true;
938  for (int i=0; i<x.size(); i++)
939  is_zero = is_zero && (x.coeff(i) == 0.0);
940  return !is_zero;
941 }
942 
943 template <typename T, typename Storage>
944 inline bool
946 {
947  return toBool(x1) && toBool(x2);
948 }
949 
950 template <typename T, typename Storage>
951 inline bool
953  const OrthogPoly<T,Storage>& x2)
954 {
955  return a && toBool(x2);
956 }
957 
958 template <typename T, typename Storage>
959 inline bool
961  const typename OrthogPoly<T,Storage>::value_type& b)
962 {
963  return toBool(x1) && b;
964 }
965 
966 template <typename T, typename Storage>
967 inline bool
969 {
970  return toBool(x1) || toBool(x2);
971 }
972 
973 template <typename T, typename Storage>
974 inline bool
976  const OrthogPoly<T,Storage>& x2)
977 {
978  return a || toBool(x2);
979 }
980 
981 template <typename T, typename Storage>
982 inline bool
984  const typename OrthogPoly<T,Storage>::value_type& b)
985 {
986  return toBool(x1) || b;
987 }
988 
989 template <typename T, typename Storage>
990 std::ostream&
991 operator << (std::ostream& os, const OrthogPoly<T,Storage>& a)
992 {
994 
995  os << "[ ";
996 
997  for (ordinal_type i=0; i<a.size(); i++) {
998  os << a.coeff(i) << " ";
999  }
1000 
1001  os << "]\n";
1002  return os;
1003 }
1004 
1005 template <typename T, typename Storage>
1006 std::istream&
1008 {
1010 
1011  // Read in the opening "["
1012  char bracket;
1013  is >> bracket;
1014 
1015  for (ordinal_type i=0; i<a.size(); i++) {
1016  is >> a.fastAccessCoeff(i);
1017  }
1018 
1019  // Read in the closing "]"
1020 
1021  is >> bracket;
1022  return is;
1023 }
1024 
1025 } // namespace PCE
1026 } // namespace Sacado
OrthogPoly< T, Storage > exp(const OrthogPoly< T, Storage > &a)
bool operator||(const OrthogPoly< T, Storage > &x1, const OrthogPoly< T, Storage > &x2)
OrthogPoly< T, Storage > log(const OrthogPoly< T, Storage > &a)
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)
OrthogPoly< T, Storage > operator+(const OrthogPoly< T, Storage > &a, const typename OrthogPoly< T, Storage >::value_type &b)
bool operator!=(const OrthogPoly< T, Storage > &a, const OrthogPoly< T, Storage > &b)
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)
Orthogonal polynomial expansion class for constant (size 1) expansions.
OrthogPoly< T, Storage > log10(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > max(const OrthogPoly< T, Storage > &a, const typename OrthogPoly< T, Storage >::value_type &b)
OrthogPoly< T, Storage > abs(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > fabs(const OrthogPoly< T, Storage > &a)
OrthogPoly< T, Storage > operator-(const OrthogPoly< T, Storage > &a, const typename OrthogPoly< T, Storage >::value_type &b)
Class to store coefficients of a projection onto an orthogonal polynomial basis.
OrthogPoly< T, Storage > asinh(const OrthogPoly< T, Storage > &a)
bool operator&&(const OrthogPoly< T, Storage > &x1, const OrthogPoly< T, Storage > &x2)
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)
bool toBool(const OrthogPoly< T, Storage > &x)