TSFILUKPreconditionerFactory.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 /* ***********************************************************************
00003 // 
00004 //           TSFExtended: Trilinos Solver Framework Extended
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 TSFILUKPRECONDITIONERFACTORY_HPP
00030 #define TSFILUKPRECONDITIONERFACTORY_HPP
00031 
00032 #include "SundanceDefs.hpp"
00033 #include "TSFPreconditionerFactoryBase.hpp"
00034 #include "TSFLinearOperatorDecl.hpp"
00035 #include "Teuchos_ParameterList.hpp"
00036 #include "TSFILUFactorizableOp.hpp"
00037 #include "TSFLinearSolverBaseDecl.hpp"
00038 
00039 namespace TSFExtended
00040 {
00041   using namespace Teuchos;
00042 
00043   /**
00044    * 
00045    */
00046   template <class Scalar>
00047   class ILUKPreconditionerFactory
00048     : public PreconditionerFactoryBase<Scalar>
00049   {
00050   public:
00051     /** Construct with a parameter list */
00052     ILUKPreconditionerFactory(const ParameterList& params)
00053       : fillLevels_(1),
00054         overlapFill_(0),
00055         relaxationValue_(0.0),
00056         relativeThreshold_(1.0),
00057         absoluteThreshold_(0.0),
00058         leftOrRight_(Right)
00059     {
00060       LinearSolverBase<Scalar>::template setParameter<int>(params, &fillLevels_, 
00061                                                   "Graph Fill");
00062 
00063       LinearSolverBase<Scalar>::template setParameter<int>(params, &overlapFill_, 
00064                                                   "Overlap");
00065 
00066       LinearSolverBase<Scalar>::template setParameter<double>(params, &relaxationValue_, 
00067                                                      "Relaxation");
00068 
00069       LinearSolverBase<Scalar>::template setParameter<double>(params, &absoluteThreshold_, 
00070                                                      "Absolute Threshold");
00071 
00072       LinearSolverBase<Scalar>::template setParameter<double>(params, &relativeThreshold_, 
00073                                                      "Relative Threshold");
00074 
00075       bool isLeft = false;
00076 
00077       LinearSolverBase<Scalar>::template setParameter<bool>(params, &isLeft, "Left");
00078 
00079       if (isLeft) leftOrRight_ = Left;
00080       
00081     }
00082 
00083 
00084     /** virtual dtor */
00085     virtual ~ILUKPreconditionerFactory(){;}
00086 
00087     
00088     /** */
00089     virtual Preconditioner <Scalar>
00090     createPreconditioner(const LinearOperator<Scalar>& A) const 
00091     {
00092       /* In order for ILU factorization to work, the operator A must
00093        * implement the ILUFactorizableOp interface. We cast A's pointer
00094        * to a ILUFactorizableOp ptr. If the cast fails, throw a spoke. */
00095       
00096       const ILUFactorizableOp<Scalar>* fop 
00097         = dynamic_cast<const ILUFactorizableOp<Scalar>*>(A.ptr().get());
00098 
00099       TEST_FOR_EXCEPTION(fop==0, std::runtime_error,
00100                          "ILUKPreconditionerFactory attempted to "
00101                          "create an ILU preconditioner for an operator type "
00102                          "that does not implement the ILUFactorizableOp "
00103                          "interface. The op is " << A.description());
00104 
00105       
00106       /* Now we can delegate the construction of the ILU factors to 
00107       * the factorizable op. */
00108       Preconditioner<Scalar> P;
00109       fop->getILUKPreconditioner(fillLevels_,
00110                                  overlapFill_,
00111                                  relaxationValue_,
00112                                  relativeThreshold_,
00113                                  absoluteThreshold_,
00114                                  leftOrRight_,
00115                                  P);
00116       /* Return the preconditioner */
00117       return P;
00118     }
00119 
00120     /* Handleable boilerplate */
00121     GET_RCP(PreconditionerFactoryBase<Scalar>);
00122   private:
00123 
00124     int fillLevels_;
00125     int overlapFill_;
00126     Scalar relaxationValue_;
00127     Scalar relativeThreshold_;
00128     Scalar absoluteThreshold_;
00129     LeftOrRight leftOrRight_;
00130   };
00131 
00132 
00133 }
00134 
00135 #endif

Site Contact