Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_BasisFactoryImp.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Stokhos Package
7 // Copyright (2009) Sandia Corporation
8 //
9 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10 // license for use of this work by or on behalf of the U.S. Government.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
40 //
41 // ***********************************************************************
42 // @HEADER
43 
44 #include <sstream>
45 #include "Teuchos_Assert.hpp"
46 #include "Teuchos_Array.hpp"
47 
51 #include "Stokhos_HermiteBasis.hpp"
52 #include "Stokhos_JacobiBasis.hpp"
53 #include "Stokhos_RysBasis.hpp"
57 #include "Stokhos_SmolyakBasis.hpp"
58 
59 template <typename ordinal_type, typename value_type>
63 {
64  Teuchos::ParameterList& basisParams = sgParams.sublist("Basis");
65 
66  // Check if basis is already there
68  = basisParams.template get< Teuchos::RCP< const OrthogPolyBasis<ordinal_type,value_type> > >("Stochastic Galerkin Basis", Teuchos::null);
69  if (basis != Teuchos::null)
70  return basis;
71 
72  ordinal_type dimension = basisParams.get("Dimension", 1);
73  bool isotropic = basisParams.get("Isotropic", false);
74 
76  for (ordinal_type i=0; i<dimension; i++) {
77  if (isotropic)
78  bases[i] = create1DBasis(basisParams);
79  else {
80  std::ostringstream ss;
81  ss << "Basis " << i;
82  Teuchos::ParameterList& bp = basisParams.sublist(ss.str());
83  bases[i] = create1DBasis(bp);
84  }
85  }
86 
87  std::string type = basisParams.get("Multivariate Type", "Complete");
88  value_type drop = basisParams.get("Cijk Drop Tolerance", 1e-12);
89  std::string ordering = basisParams.get("Coefficient Ordering", "Total");
90 
91  if (type == "Complete") {
92  bool use_old = basisParams.get("Use Old Cijk Algorithm", false);
93  basis =
95  bases, drop, use_old));
96  }
97 
98  else if (type == "Tensor Product") {
99  if (ordering == "Total")
100  basis =
102  else if (ordering == "Lexicographical")
103  basis =
105  else
108  std::endl << "Invalid coefficient ordering " << ordering << std::endl);
109  }
110 
111  else if (type == "Total Order") {
112  if (ordering == "Total")
113  basis =
115  else if (ordering == "Lexicographical")
116  basis =
118  else
121  std::endl << "Invalid coefficient ordering " << ordering << std::endl);
122  }
123 
124  else if (type == "Smolyak") {
125  ordinal_type order = basisParams.template get<ordinal_type>("Order");
126  TotalOrderIndexSet<ordinal_type> index_set(dimension, order);
127  if (ordering == "Total")
128  basis =
130  else if (ordering == "Lexicographical")
131  basis =
133  else
136  std::endl << "Invalid coefficient ordering " << ordering << std::endl);
137  }
138 
139  else
142  std::endl << "Invalid multivariate basis type " << type << std::endl);
143 
144 
145  basisParams.set("Stochastic Galerkin Basis", basis);
146 
147  return basis;
148 }
149 
150 template <typename ordinal_type, typename value_type>
154 {
156 
157  std::string type = bp.get("Type","Legendre");
158  ordinal_type order = bp.get("Order", 3);
159  bool normalize = bp.get("Normalize", false);
160  bool isotropic = bp.get("Isotropic", false);
161 
162  std::string growth_string = bp.get("Growth Policy", "Slow");
163  GrowthPolicy growth;
164  if (growth_string == "Slow")
165  growth = SLOW_GROWTH;
166  else if (growth_string == "Moderate")
167  growth = MODERATE_GROWTH;
168  else
171  std::endl << "Invalid growth policy " << growth_string << std::endl);
172 
173  if (type == "Legendre")
174  basis = Teuchos::rcp(new LegendreBasis<ordinal_type,value_type>(order, normalize, growth));
175  else if (type == "Clenshaw-Curtis") {
176  basis = Teuchos::rcp(new ClenshawCurtisLegendreBasis<ordinal_type,value_type>(order, normalize, isotropic));
177  }
178  else if (type == "Gauss-Patterson") {
179  basis = Teuchos::rcp(new GaussPattersonLegendreBasis<ordinal_type,value_type>(order, normalize, isotropic));
180  }
181  else if (type == "Hermite")
182  basis = Teuchos::rcp(new HermiteBasis<ordinal_type,value_type>(order, normalize, growth));
183  else if (type == "Jacobi") {
184  value_type alpha = bp.get<value_type>("Jacobi Alpha");
185  value_type beta = bp.get<value_type>("Jacobi Beta");
186  basis = Teuchos::rcp(new JacobiBasis<ordinal_type,value_type>(order, alpha, beta, normalize, growth));
187  }
188  else if (type == "Rys") {
189  value_type cut = bp.get("Weight Cut", 1.0);
190  basis = Teuchos::rcp(new RysBasis<ordinal_type,value_type>(order, cut, normalize, growth));
191  }
192  else
195  std::endl << "Invalid basis type " << type << std::endl);
196 
197  return basis;
198 }
Hermite polynomial basis.
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
GrowthPolicy
Enumerated type for determining Smolyak growth policies.
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
A comparison functor implementing a strict weak ordering based total-order ordering, recursive on the dimension.
Legendre polynomial basis using Gauss-Patterson quadrature points.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Rys polynomial basis.
Jacobi polynomial basis.
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials...
Legendre polynomial basis.
An isotropic total order index set.
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
static Teuchos::RCP< const Stokhos::OneDOrthogPolyBasis< ordinal_type, value_type > > create1DBasis(Teuchos::ParameterList &params)
Generate 1-D basis.
A comparison functor implementing a strict weak ordering based lexographic ordering.
static Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate basis.