TSFLinearSolverDecl.hpp
Go to the documentation of this file.
00001 /* ***********************************************************************
00002 // 
00003 //           TSFExtended: Trilinos Solver Framework Extended
00004 //                 Copyright (2004) Sandia Corporation
00005 // 
00006 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00007 // license for use of this work by or on behalf of the U.S. Government.
00008 // 
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Lesser General Public License as
00011 // published by the Free Software Foundation; either version 2.1 of the
00012 // License, or (at your option) any later version.
00013 //  
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //  
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022 // USA
00023 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00024 // 
00025 // **********************************************************************/
00026 
00027 #ifndef TSFLINEARSOLVERDECL_HPP
00028 #define TSFLINEARSOLVERDECL_HPP
00029 
00030 #include "SundanceTabs.hpp"
00031 #include "SundanceHandle.hpp"
00032 #include "SundanceHandleable.hpp"
00033 #include "TSFLinearSolverBaseDecl.hpp"
00034 #include "Teuchos_TimeMonitor.hpp"
00035 
00036 
00037 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00038 #include "TSFLinearSolverBaseImpl.hpp"
00039 #include "TSFLinearOperatorImpl.hpp"
00040 #endif
00041 
00042 inline static Teuchos::Time& solveTimer() 
00043 {
00044   static Teuchos::RCP<Teuchos::Time> rtn 
00045     = Teuchos::TimeMonitor::getNewTimer("linear solve"); 
00046   return *rtn;
00047 }
00048 
00049 namespace TSFExtended
00050 {
00051 using namespace Teuchos;
00052 using namespace Sundance;
00053   
00054 /**
00055  *
00056  */
00057 template <class Scalar>
00058 class LinearSolver : public Sundance::Handle<LinearSolverBase<Scalar> >
00059 {
00060 public:
00061   /** */
00062   LinearSolver() : Sundance::Handle<LinearSolverBase<Scalar> >() {;}
00063   /** */
00064   LinearSolver( Sundance::Handleable<LinearSolverBase<Scalar> >* rawPtr) 
00065     : Sundance::Handle<LinearSolverBase<Scalar> >(rawPtr) {;}
00066   /** */
00067   LinearSolver(const RCP<LinearSolverBase<Scalar> >& smartPtr)
00068     : Sundance::Handle<LinearSolverBase<Scalar> >(smartPtr) {;}
00069 
00070 
00071   /** Change the convergence tolerance. Default does nothing. */
00072   void updateTolerance(const double& tol) {this->ptr()->updateTolerance(tol);}
00073 
00074   /** Set a user-defined preconditioner */
00075   void setUserPrec(const LinearOperator<Scalar>& op,
00076     const LinearSolver<Scalar>& pSolver) ;
00077 
00078   /** Set a user-defined preconditioner */
00079   void setUserPrec(const PreconditionerFactory<Scalar>& pf);
00080 
00081 
00082   /** */
00083   SolverState<Scalar> solve(const LinearOperator<Scalar>& op,
00084     const Vector<Scalar>& rhs,
00085     Vector<Scalar>& soln) const ;
00086     
00087     
00088 
00089   /** */
00090   const ParameterList& parameters() const ;
00091 
00092   /** */
00093   ParameterList& parameters() ;
00094 };
00095 
00096   
00097 template <class Scalar> inline 
00098 SolverState<Scalar> LinearSolver<Scalar>
00099 ::solve(const LinearOperator<Scalar>& op,
00100   const Vector<Scalar>& rhs,
00101   Vector<Scalar>& soln) const
00102 {
00103   Tabs tab;
00104   TEST_FOR_EXCEPTION(this->ptr().get()==0, std::runtime_error,
00105     "null pointer in LinearSolver<Scalar>::solve()");
00106 
00107   TEST_FOR_EXCEPTION(rhs.ptr().get()==0, std::runtime_error,
00108     "null rhs pointer in LinearSolver<Scalar>::solve()");
00109 
00110   TEST_FOR_EXCEPTION(op.ptr().get()==0, std::runtime_error,
00111     "null op pointer in LinearSolver<Scalar>::solve()");
00112 
00113   TimeMonitor timer(solveTimer());
00114 
00115   SUNDANCE_MSG1(this->ptr()->verb(), 
00116     tab << "Solver(" << this->description() << ") starting solve");
00117 
00118   SolverState<Scalar> rtn = this->ptr()->solve(op, rhs, soln);
00119 
00120   SUNDANCE_MSG1(this->ptr()->verb(), 
00121     tab << "Solver(" << this->description() << ") done solve:");
00122   Tabs tab1;
00123   SUNDANCE_MSG2(this->ptr()->verb(), 
00124     tab << "state=" << rtn);
00125 
00126   return rtn;    
00127 }
00128 
00129 template <class Scalar> inline 
00130 const ParameterList& LinearSolver<Scalar>::parameters() const 
00131 {
00132   TEST_FOR_EXCEPTION(this->ptr().get()==0, std::runtime_error,
00133     "null pointer in LinearSolver<Scalar>::parameters()");
00134   return this->ptr()->parameters();
00135 }
00136 
00137 template <class Scalar> inline 
00138 ParameterList& LinearSolver<Scalar>::parameters() 
00139 {
00140   TEST_FOR_EXCEPTION(this->ptr().get()==0, std::runtime_error,
00141     "null pointer in LinearSolver<Scalar>::parameters()");
00142   return this->ptr()->parameters();
00143 }
00144 
00145   
00146 
00147   
00148 
00149 }
00150 
00151 #endif

Site Contact