Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_ExpansionFactoryImp.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 "Teuchos_Assert.hpp"
45
51//#include "Stokhos_DerivOrthogPolyExpansion.hpp"
55
56template <typename ordinal_type, typename value_type>
57Teuchos::RCP<Stokhos::OrthogPolyExpansion<ordinal_type, value_type> >
59create(Teuchos::ParameterList& sgParams)
60{
61 // Check if expansion is already there
62 Teuchos::ParameterList& expParams = sgParams.sublist("Expansion");
63 Teuchos::RCP< Stokhos::OrthogPolyExpansion<ordinal_type,value_type> > expansion = expParams.template get< Teuchos::RCP< Stokhos::OrthogPolyExpansion<ordinal_type,value_type> > >("Stochastic Galerkin Expansion", Teuchos::null);
64 if (expansion != Teuchos::null)
65 return expansion;
66
67 // Get basis
68 Teuchos::ParameterList& basisParams = sgParams.sublist("Basis");
69 Teuchos::RCP< const Stokhos::OrthogPolyBasis<ordinal_type,value_type> > basis;
70 if (basisParams.template isType< Teuchos::RCP< const Stokhos::OrthogPolyBasis<ordinal_type,value_type> > >("Stochastic Galerkin Basis"))
71 basis = basisParams.template get< Teuchos::RCP<const Stokhos::OrthogPolyBasis<ordinal_type,value_type> > >("Stochastic Galerkin Basis");
72 else {
74 basisParams.set("Stochastic Galerkin Basis", basis);
75 }
76
77 // Get 3-tensor
78 Teuchos::RCP<const Stokhos::Sparse3Tensor<ordinal_type,value_type> > Cijk;
79 if (sgParams.template isType<Teuchos::RCP<const Stokhos::Sparse3Tensor<ordinal_type,value_type> > >("Triple Product Tensor"))
80 Cijk = sgParams.template get<Teuchos::RCP<const Stokhos::Sparse3Tensor<ordinal_type,value_type> > >("Triple Product Tensor");
81 else {
82 std::string tp_type = sgParams.get("Triple Product Size", "Full");
83 TEUCHOS_TEST_FOR_EXCEPTION(
84 tp_type != "Full" && tp_type != "Linear",
85 Teuchos::Exceptions::InvalidParameter,
86 std::endl << "Invalid triple product expansion type " << tp_type <<
87 std::endl);
88
89 if (tp_type == "Full")
90 Cijk = basis->computeTripleProductTensor();
91 else
92 Cijk = basis->computeLinearTripleProductTensor();
93
94 sgParams.set("Triple Product Tensor", Cijk);
95 }
96
97 // Create expansion
98 std::string exp_type = expParams.get("Type", "Algebraic");
99 if (exp_type == "Algebraic")
100 expansion =
101 Teuchos::rcp(new Stokhos::AlgebraicOrthogPolyExpansion<ordinal_type,value_type>(basis, Cijk, Teuchos::rcp(&expParams,false)));
102
103 else if (exp_type == "Quadrature") {
104 Teuchos::ParameterList& quadParams = sgParams.sublist("Quadrature");
105 Teuchos::RCP<const Stokhos::Quadrature<ordinal_type,value_type> > quad;
106 if (quadParams.template isType<Teuchos::RCP<const Stokhos::Quadrature<ordinal_type,value_type> > >("Stochastic Galerkin Quadrature"))
107 quad = quadParams.template get<Teuchos::RCP<const Stokhos::Quadrature<ordinal_type,value_type> > >("Stochastic Galerkin Quadrature");
108 else {
109 quad =
111 quadParams.set("Stochastic Galerkin Quadrature", quad);
112 }
113 expansion =
114 Teuchos::rcp(new Stokhos::QuadOrthogPolyExpansion<ordinal_type,value_type>(basis, Cijk, quad, Teuchos::rcp(&expParams,false)));
115 }
116
117 else if (exp_type == "For UQTK") {
118#ifdef HAVE_STOKHOS_FORUQTK
119 typename Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type,value_type>::EXPANSION_METHOD method =
120 expParams.get("ForUQTK Expansion Method",
121 Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type,value_type>::TAYLOR);
122 value_type rtol = expParams.get("ForUQTK Expansion Tolerance", 1e-12);
123 expansion =
124 Teuchos::rcp(new Stokhos::ForUQTKOrthogPolyExpansion<ordinal_type,value_type>(basis, Cijk, method, rtol));
125#else
126 TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
127 std::endl <<
128 "Error! Stokhos::ExpansionFactory::create(): " <<
129 "ForUQTK expansion requires ForUQTK!" << std::endl);
130#endif
131 }
132
133 /*
134 else if (exp_type == "Derivative") {
135 Teuchos::RCP<const Stokhos::DerivBasis<ordinal_type,value_type> > deriv_basis = Teuchos::rcp_dynamic_cast<const Stokhos::DerivBasis<ordinal_type,value_type> >(basis, true);
136 Teuchos::RCP<Teuchos::SerialDenseMatrix<ordinal_type,value_type> > Bij;
137 if (sgParams.template isType<Teuchos::RCP<const Teuchos::SerialDenseMatrix<ordinal_type,value_type> > >("Derivative Double Product Tensor"))
138 Bij = sgParams.template get<const Teuchos::RCP<Teuchos::SerialDenseMatrix<ordinal_type,value_type> > >("Derivative Double Product Tensor");
139 else {
140 Bij = deriv_basis->computeDerivDoubleProductTensor();
141 sgParams.set("Derivative Double Product Tensor", Bij);
142 }
143 Teuchos::RCP<const Stokhos::Dense3Tensor<ordinal_type,value_type> > Dijk;
144 if (sgParams.template isType<Teuchos::RCP<const Stokhos::Dense3Tensor<ordinal_type,value_type> > >("Derivative Triple Product Tensor"))
145 Dijk = sgParams.template get<Teuchos::RCP<const Stokhos::Dense3Tensor<ordinal_type,value_type> > >("Derivative Triple Product Tensor");
146 else {
147 Dijk = deriv_basis->computeDerivTripleProductTensor(Bij, Cijk);
148 sgParams.set("Derivative Triple Product Tensor", Dijk);
149 }
150 expansion =
151 Teuchos::rcp(new
152 Stokhos::DerivOrthogPolyExpansion<ordinal_type,value_type>(
153 deriv_basis, Bij, Cijk, Dijk));
154 }
155 */
156
157 else if (exp_type == "Pseudospectral") {
159 Teuchos::ParameterList& psopParams =
160 sgParams.sublist("Pseudospectral Operator");
161 Teuchos::RCP<const psop_type> psop;
162 if (psopParams.template isType<Teuchos::RCP<const psop_type> >(
163 "Stochastic Galerkin Pseudospectral Operator"))
164 psop = psopParams.template get<Teuchos::RCP<const psop_type> >(
165 "Stochastic Galerkin Pseudospectral Operator");
166 else {
167 psop =
169 psopParams.set("Stochastic Galerkin Pseudospectral Operator", psop);
170 }
171 expansion =
172 Teuchos::rcp(new Stokhos::PseudoSpectralOrthogPolyExpansion<ordinal_type,value_type>(basis, Cijk, psop, Teuchos::rcp(&expParams,false)));
173 }
174
175 else
176 TEUCHOS_TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
177 std::endl <<
178 "Error! Stokhos::ExpansionFactory::create(): " <<
179 "Invalid expansion type " << exp_type << std::endl);
180
181 expParams.set("Stochastic Galerkin Expansion", expansion);
182 return expansion;
183}
Orthogonal polynomial expansions limited to algebraic operations.
static Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate basis.
static Teuchos::RCP< Stokhos::OrthogPolyExpansion< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate expansion.
Abstract base class for multivariate orthogonal polynomials.
static Teuchos::RCP< const psop_type > create(Teuchos::ParameterList &sgParams)
Generate pseudospectral operator object.
An operator interface for building pseudo-spectral approximations.
Orthogonal polynomial expansions based on numerical quadrature.
Orthogonal polynomial expansions based on numerical quadrature.
static Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate quadrature object.
Abstract base class for quadrature methods.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.