Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
46 #include "Stokhos_BasisFactory.hpp"
51 //#include "Stokhos_DerivOrthogPolyExpansion.hpp"
55 
56 template <typename ordinal_type, typename value_type>
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");
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
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");
84  tp_type != "Full" && tp_type != "Linear",
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 =
102 
103  else if (exp_type == "Quadrature") {
104  Teuchos::ParameterList& quadParams = sgParams.sublist("Quadrature");
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 =
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
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");
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 =
173  }
174 
175  else
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 }
static Teuchos::RCP< const psop_type > create(Teuchos::ParameterList &sgParams)
Generate pseudospectral operator object.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
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)
An operator interface for building pseudo-spectral approximations.
RCP< ParameterList > sublist(const RCP< ParameterList > &paramList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Orthogonal polynomial expansions limited to algebraic operations.
static Teuchos::RCP< Stokhos::OrthogPolyExpansion< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate expansion.
Abstract base class for multivariate orthogonal polynomials.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Abstract base class for quadrature methods.
static Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate multivariate basis.
static Teuchos::RCP< const Stokhos::Quadrature< ordinal_type, value_type > > create(Teuchos::ParameterList &sgParams)
Generate quadrature object.
Orthogonal polynomial expansions based on numerical quadrature.
Orthogonal polynomial expansions based on numerical quadrature.