PlayaLinearSolverDecl.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                 Playa: Programmable Linear Algebra
00005 //                 Copyright 2012 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 
00043 #ifndef PLAYA_LINEARSOLVERDECL_HPP
00044 #define PLAYA_LINEARSOLVERDECL_HPP
00045 
00046 #include "PlayaTabs.hpp"
00047 #include "PlayaHandle.hpp"
00048 #include "PlayaHandleable.hpp"
00049 #include "PlayaLinearSolverBaseDecl.hpp"
00050 #include "Teuchos_TimeMonitor.hpp"
00051 
00052 
00053 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00054 #include "PlayaLinearSolverBaseImpl.hpp"
00055 #include "PlayaLinearOperatorImpl.hpp"
00056 #endif
00057 
00058 inline static Teuchos::Time& solveTimer() 
00059 {
00060   static Teuchos::RCP<Teuchos::Time> rtn 
00061     = Teuchos::TimeMonitor::getNewTimer("linear solve"); 
00062   return *rtn;
00063 }
00064 
00065 namespace Playa
00066 {
00067 using namespace Teuchos;
00068 
00069   
00070 /**
00071  * \brief User-level linear solver object
00072  */
00073 template <class Scalar>
00074 class LinearSolver : public Playa::Handle<LinearSolverBase<Scalar> >
00075 {
00076 public:
00077   /** */
00078   LinearSolver() : Playa::Handle<LinearSolverBase<Scalar> >() {;}
00079   /** */
00080   LinearSolver( Playa::Handleable<LinearSolverBase<Scalar> >* rawPtr) 
00081     : Playa::Handle<LinearSolverBase<Scalar> >(rawPtr) {;}
00082   /** */
00083   LinearSolver(const RCP<LinearSolverBase<Scalar> >& smartPtr)
00084     : Playa::Handle<LinearSolverBase<Scalar> >(smartPtr) {;}
00085 
00086 
00087   /** Change the convergence tolerance. Default does nothing. */
00088   void updateTolerance(const double& tol) {this->ptr()->updateTolerance(tol);}
00089 
00090   /** Set a user-defined preconditioner */
00091   void setUserPrec(const LinearOperator<Scalar>& op,
00092     const LinearSolver<Scalar>& pSolver) ;
00093 
00094   /** Set a user-defined preconditioner */
00095   void setUserPrec(const PreconditionerFactory<Scalar>& pf);
00096 
00097 
00098   /** */
00099   SolverState<Scalar> solve(const LinearOperator<Scalar>& op,
00100     const Vector<Scalar>& rhs,
00101     Vector<Scalar>& soln) const ;
00102     
00103     
00104 
00105   /** */
00106   const ParameterList& parameters() const ;
00107 
00108   /** */
00109   ParameterList& parameters() ;
00110 };
00111 
00112   
00113 template <class Scalar> inline 
00114 SolverState<Scalar> LinearSolver<Scalar>
00115 ::solve(const LinearOperator<Scalar>& op,
00116   const Vector<Scalar>& rhs,
00117   Vector<Scalar>& soln) const
00118 {
00119   Tabs tab;
00120   TEUCHOS_TEST_FOR_EXCEPTION(this->ptr().get()==0, std::runtime_error,
00121     "null pointer in LinearSolver<Scalar>::solve()");
00122 
00123   TEUCHOS_TEST_FOR_EXCEPTION(rhs.ptr().get()==0, std::runtime_error,
00124     "null rhs pointer in LinearSolver<Scalar>::solve()");
00125 
00126   TEUCHOS_TEST_FOR_EXCEPTION(op.ptr().get()==0, std::runtime_error,
00127     "null op pointer in LinearSolver<Scalar>::solve()");
00128 
00129   TimeMonitor timer(solveTimer());
00130 
00131   PLAYA_MSG1(this->ptr()->verb() * (MPIComm::world().getRank()==0), 
00132     tab << "Solver(" << this->description() << ") starting solve");
00133 
00134   SolverState<Scalar> rtn = this->ptr()->solve(op, rhs, soln);
00135 
00136   PLAYA_MSG1(this->ptr()->verb() * (MPIComm::world().getRank()==0), 
00137     tab << "Solver(" << this->description() << ") done solve:");
00138   Tabs tab1;
00139   PLAYA_MSG2(this->ptr()->verb() * (MPIComm::world().getRank()==0), 
00140     tab << "state=" << rtn);
00141 
00142   return rtn;    
00143 }
00144 
00145 template <class Scalar> inline 
00146 const ParameterList& LinearSolver<Scalar>::parameters() const 
00147 {
00148   TEUCHOS_TEST_FOR_EXCEPTION(this->ptr().get()==0, std::runtime_error,
00149     "null pointer in LinearSolver<Scalar>::parameters()");
00150   return this->ptr()->parameters();
00151 }
00152 
00153 template <class Scalar> inline 
00154 ParameterList& LinearSolver<Scalar>::parameters() 
00155 {
00156   TEUCHOS_TEST_FOR_EXCEPTION(this->ptr().get()==0, std::runtime_error,
00157     "null pointer in LinearSolver<Scalar>::parameters()");
00158   return this->ptr()->parameters();
00159 }
00160 
00161   
00162 
00163   
00164 
00165 }
00166 
00167 #endif

Site Contact