• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Meros_LinearSolveStrategy.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //              Meros: Segregated Preconditioning Package
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef MEROS_LINEAR_SOLVE_STRATEGY_H
00030 #define MEROS_LINEAR_SOLVE_STRATEGY_H
00031 
00032 #include "Thyra_LinearOpBase.hpp"
00033 #include "Thyra_VectorImpl.hpp" 
00034 #include "Thyra_VectorSpaceImpl.hpp" 
00035 #include "Thyra_LinearOperatorImpl.hpp"
00036 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
00037 #include "Thyra_LinearOpWithSolveBase.hpp"
00038 #include "Thyra_DefaultLinearOpSource.hpp"
00039 #include "Meros_Preconditioner.hpp"
00040 
00041 namespace Meros 
00042 {
00043   using namespace Teuchos;
00044   using namespace Thyra;
00045 
00049   template <class Scalar>
00050   class LinearSolveStrategy
00051   {
00052   public:
00054     LinearSolveStrategy() : lowsf_(), pf_() {;}
00055     
00057     LinearSolveStrategy(const RCP<LinearOpWithSolveFactoryBase<Scalar> >& lowsf)
00058       : lowsf_(lowsf), pf_(lowsf->getPreconditionerFactory()) {;}
00059     
00061     LinearSolveStrategy(Handleable<LinearOpWithSolveFactoryBase<Scalar> >* lowsf)
00062       : lowsf_(lowsf->getRcp()), pf_(lowsf_->getPreconditionerFactory()) {;}
00063 
00065     RCP<LinearOpWithSolveFactoryBase<Scalar> > getLOWSF() const
00066       {
00067         return lowsf_;
00068       }
00069 
00071     RCP<LinearOpWithSolveBase<Scalar> > getLOWS(const LinearOperator<Scalar>& op) const 
00072     {
00073       RCP<LinearOpWithSolveBase<Scalar> > rtn = lowsf_->createOp();
00074       RCP<const LinearOpSourceBase<Scalar> > src 
00075         = rcp(new DefaultLinearOpSource<Scalar>(op.ptr()));
00076 
00077       if (pf_.get() == 0)
00078         {
00079           LinearOpWithSolveBase<Scalar>* rtnPtr = rtn.get();
00080           lowsf_->initializeOp(src, rtnPtr);
00081         }
00082       else
00083         {
00084           Preconditioner<Scalar> p = pf_->createPrec();
00085           pf_->initializePrec(src, p.ptr().get());
00086           lowsf_->initializePreconditionedOp(src, p.ptr(), &*rtn);
00087         }
00088 
00089       return rtn;
00090     }
00091 
00093     RCP<LinearOpWithSolveBase<Scalar> > getLOWS(const ConstLinearOperator<Scalar>& op) const 
00094     {
00095       RCP<LinearOpWithSolveBase<Scalar> > rtn = lowsf_->createOp();
00096       RCP<const LinearOpSourceBase<Scalar> > src 
00097         = rcp(new DefaultLinearOpSource<Scalar>(op.constPtr()));
00098 
00099       if (pf_.get() == 0)
00100         {
00101           LinearOpWithSolveBase<Scalar>* rtnPtr = rtn.get();
00102           lowsf_->initializeOp(src, rtnPtr);
00103         }
00104       else
00105         {
00106           Preconditioner<Scalar> p = pf_->createPrec();
00107           pf_->initializePrec(src, p.ptr().get());
00108           lowsf_->initializePreconditionedOp(src, p.ptr(), &*rtn);
00109         }
00110 
00111       return rtn;
00112     }
00113 
00114   protected:
00115     RCP<LinearOpWithSolveFactoryBase<Scalar> > lowsf() {return lowsf_;}
00116     RCP<PreconditionerFactoryBase<Scalar> > pf() {return pf_;}
00117 
00118   private:
00119 
00120     RCP<LinearOpWithSolveFactoryBase<Scalar> > lowsf_;
00121     RCP<PreconditionerFactoryBase<Scalar> > pf_;
00122   };
00123 
00124 
00125 } // namespace Meros
00126 
00127 #endif // MEROS_PCD_OPERATOR_SOURCE_H