Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
53#include "Stokhos_RysBasis.hpp"
58
59template <typename ordinal_type, typename value_type>
60Teuchos::RCP<const Stokhos::OrthogPolyBasis<ordinal_type, value_type> >
62create(Teuchos::ParameterList& sgParams)
63{
64 Teuchos::ParameterList& basisParams = sgParams.sublist("Basis");
65
66 // Check if basis is already there
67 Teuchos::RCP< const OrthogPolyBasis<ordinal_type,value_type> > basis
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
75 Teuchos::Array< Teuchos::RCP<const OneDOrthogPolyBasis<ordinal_type,value_type> > > bases(dimension);
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 =
101 Teuchos::rcp(new TensorProductBasis<ordinal_type,value_type,TotalOrderLess<MultiIndex<ordinal_type> > >(bases, drop));
102 else if (ordering == "Lexicographical")
103 basis =
104 Teuchos::rcp(new TensorProductBasis<ordinal_type,value_type,LexographicLess<MultiIndex<ordinal_type> > >(bases, drop));
105 else
106 TEUCHOS_TEST_FOR_EXCEPTION(
107 true, Teuchos::Exceptions::InvalidParameter,
108 std::endl << "Invalid coefficient ordering " << ordering << std::endl);
109 }
110
111 else if (type == "Total Order") {
112 if (ordering == "Total")
113 basis =
114 Teuchos::rcp(new TotalOrderBasis<ordinal_type,value_type,TotalOrderLess<MultiIndex<ordinal_type> > >(bases, drop));
115 else if (ordering == "Lexicographical")
116 basis =
117 Teuchos::rcp(new TotalOrderBasis<ordinal_type,value_type,LexographicLess<MultiIndex<ordinal_type> > >(bases, drop));
118 else
119 TEUCHOS_TEST_FOR_EXCEPTION(
120 true, Teuchos::Exceptions::InvalidParameter,
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 =
129 Teuchos::rcp(new SmolyakBasis<ordinal_type,value_type,TotalOrderLess<MultiIndex<ordinal_type> > >(bases, index_set, drop));
130 else if (ordering == "Lexicographical")
131 basis =
132 Teuchos::rcp(new SmolyakBasis<ordinal_type,value_type,LexographicLess<MultiIndex<ordinal_type> > >(bases, index_set, drop));
133 else
134 TEUCHOS_TEST_FOR_EXCEPTION(
135 true, Teuchos::Exceptions::InvalidParameter,
136 std::endl << "Invalid coefficient ordering " << ordering << std::endl);
137 }
138
139 else
140 TEUCHOS_TEST_FOR_EXCEPTION(
141 true, Teuchos::Exceptions::InvalidParameter,
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
150template <typename ordinal_type, typename value_type>
151Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<ordinal_type, value_type> >
153create1DBasis(Teuchos::ParameterList& bp)
154{
155 Teuchos::RCP<OneDOrthogPolyBasis<ordinal_type,value_type> > basis;
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
169 TEUCHOS_TEST_FOR_EXCEPTION(
170 true, Teuchos::Exceptions::InvalidParameter,
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
193 TEUCHOS_TEST_FOR_EXCEPTION(
194 true, Teuchos::Exceptions::InvalidParameter,
195 std::endl << "Invalid basis type " << type << std::endl);
196
197 return basis;
198}
static Teuchos::RCP< const Stokhos::OneDOrthogPolyBasis< ordinal_type, value_type > > create1DBasis(Teuchos::ParameterList &params)
Generate 1-D basis.
static Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate basis.
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
Multivariate orthogonal polynomial basis generated from a total-order complete-polynomial tensor prod...
Legendre polynomial basis using Gauss-Patterson quadrature points.
Hermite polynomial basis.
Jacobi polynomial basis.
Legendre polynomial basis.
A comparison functor implementing a strict weak ordering based lexographic ordering.
A multidimensional index.
Rys polynomial basis.
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials.
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
An isotropic total order index set.
A comparison functor implementing a strict weak ordering based total-order ordering,...
GrowthPolicy
Enumerated type for determining Smolyak growth policies.