Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_GrowthRules.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef STOKHOS_GROWTH_RULES
11 #define STOKHOS_GROWTH_RULES
12 
13 namespace Stokhos {
14 
16  template <typename value_type>
17  class GrowthRule {
18  public:
19 
22 
24  virtual ~GrowthRule() {}
25 
27  virtual value_type operator() (const value_type& x) const = 0;
28  };
29 
31  template <typename value_type>
32  class IdentityGrowthRule : public GrowthRule<value_type> {
33  public:
36 
38  virtual ~IdentityGrowthRule() {}
39 
41  virtual value_type operator() (const value_type& x) const { return x; }
42  };
43 
45  template <typename value_type>
46  class LinearGrowthRule : public GrowthRule<value_type> {
47  public:
50  const value_type& b_ = value_type(0)) :
51  a(a_), b(b_) {}
52 
54  virtual ~LinearGrowthRule() {}
55 
57  virtual value_type operator() (const value_type& x) const { return a*x+b; }
58 
59  protected:
60 
63 
66  };
67 
69 
75  template <typename value_type>
76  class EvenGrowthRule : public GrowthRule<value_type> {
77  public:
80 
82  virtual ~EvenGrowthRule() {}
83 
85  virtual value_type operator() (const value_type& x) const {
86  if (x % value_type(2) == value_type(1)) return x+value_type(1);
87  return x;
88  }
89 
90  };
91 
93  template <typename value_type>
94  class ClenshawCurtisExponentialGrowthRule : public GrowthRule<value_type> {
95  public:
98 
101 
103  virtual value_type operator() (const value_type& x) const {
104  if (x == value_type(0)) return value_type(0);
105  return std::pow(value_type(2),x-value_type(1));
106  }
107 
108  };
109 
111  template <typename value_type>
112  class GaussPattersonExponentialGrowthRule : public GrowthRule<value_type> {
113  public:
116 
119 
121  virtual value_type operator() (const value_type& x) const {
122  // Gauss-Patterson rules have precision 3*2*l-1, which is odd.
123  // Since discrete orthogonality requires integrating polynomials of
124  // order 2*p, setting p = 3*2*{l-1}-1 will yield the largest p such that
125  // 2*p <= 3*2^l-1
126  if (x == value_type(0)) return value_type(0);
127  return 3*std::pow(value_type(2),x-value_type(1))-value_type(1);
128  }
129 
130  };
131 
132 }
133 
134 #endif
A growth rule that is the identity.
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
LinearGrowthRule(const value_type &a_=value_type(1), const value_type &b_=value_type(0))
Constructor.
A linear growth rule.
virtual value_type operator()(const value_type &x) const =0
Evaluate growth rule.
An exponential growth rule for Gauss-Patterson.
Interface for abstract growth rules.
virtual ~IdentityGrowthRule()
Destructor.
virtual ~LinearGrowthRule()
Destructor.
virtual value_type operator()(const value_type &x) const
Evaluate growth rule.
virtual value_type operator()(const value_type &x) const
Evaluate growth rule.
virtual ~EvenGrowthRule()
Destructor.
virtual value_type operator()(const value_type &x) const
Evaluate growth rule.
virtual value_type operator()(const value_type &x) const
Evaluate growth rule.
virtual value_type operator()(const value_type &x) const
Evaluate growth rule.
virtual ~GrowthRule()
Destructor.
An exponential growth rule for Clenshaw-Curtis.
A growth rule that always makes the supplied order even.