FEApp_SourceFunctionFactoryImpl.hpp

Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 #include <sstream>
00032 #include "Teuchos_TestForException.hpp"
00033 #include "FEApp_QuadraticSourceFunction.hpp"
00034 #include "FEApp_CubicSourceFunction.hpp"
00035 #include "FEApp_ExponentialSourceFunction.hpp"
00036 #include "FEApp_MultiVariateExponentialSourceFunction.hpp"
00037 
00038 template <typename EvalT>
00039 FEApp::SourceFunctionFactory<EvalT>::SourceFunctionFactory(
00040       const Teuchos::RCP<Teuchos::ParameterList>& funcParams_,
00041       const Teuchos::RCP<ParamLib>& paramLib_) :
00042   funcParams(funcParams_), paramLib(paramLib_)
00043 {
00044 }
00045 
00046 template <typename EvalT>
00047 Teuchos::RCP< FEApp::AbstractSourceFunction<EvalT> >
00048 FEApp::SourceFunctionFactory<EvalT>::create()
00049 {
00050   Teuchos::RCP< FEApp::AbstractSourceFunction<EvalT> > strategy;
00051 
00052   std::string& method = funcParams->get("Name", "Quadratic");
00053   if (method == "Quadratic") {
00054     double factor = funcParams->get("Nonlinear Factor", 1.0);
00055     strategy = 
00056       Teuchos::rcp(new FEApp::QuadraticSourceFunction<EvalT>(factor,
00057                                                              paramLib));
00058   }
00059   else if (method == "Cubic") {
00060     double factor = funcParams->get("Nonlinear Factor", 1.0);
00061     strategy = 
00062       Teuchos::rcp(new FEApp::CubicSourceFunction<EvalT>(factor,
00063                                                          paramLib));
00064   }
00065   else if (method == "Exponential") {
00066     double factor = funcParams->get("Nonlinear Factor", 1.0);
00067     strategy = 
00068       Teuchos::rcp(new FEApp::ExponentialSourceFunction<EvalT>(factor,
00069                                                                paramLib));
00070   }
00071   else if (method == "Multi-Variate Exponential") {
00072     unsigned int numdims = funcParams->template get<unsigned int>("Nonlinear Factor Dimensions", 1);
00073     std::vector<ScalarT> factor(numdims);
00074     for (unsigned int i=0; i<numdims; i++) {
00075       std::stringstream ss;
00076       ss << "Nonlinear Factor " << i;
00077       factor[i] = funcParams->get(ss.str(), 1.0);
00078     }
00079     strategy = 
00080       Teuchos::rcp(new FEApp::MultiVariateExponentialSourceFunction<EvalT>(factor,
00081                                                                            paramLib));
00082   }
00083   else {
00084     TEST_FOR_EXCEPTION(true, Teuchos::Exceptions::InvalidParameter,
00085                        std::endl << 
00086                        "Error!  Unknown source function " << method << 
00087                        "!" << std::endl << "Supplied parameter list is " << 
00088                        std::endl << *funcParams);
00089   }
00090 
00091   return strategy;
00092 }

Generated on Wed May 12 21:39:33 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7