PlayaILUKPreconditionerFactory.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 #ifndef PLAYA_ILUKPRECONDITIONERFACTORY_HPP
00043 #define PLAYA_ILUKPRECONDITIONERFACTORY_HPP
00044 
00045 #include "PlayaDefs.hpp"
00046 #include "PlayaPreconditionerFactoryBase.hpp"
00047 #include "PlayaLinearOperatorDecl.hpp"
00048 #include "Teuchos_ParameterList.hpp"
00049 #include "PlayaILUFactorizableOp.hpp"
00050 #include "PlayaLinearSolverBaseDecl.hpp"
00051 
00052 namespace Playa
00053 {
00054   using namespace Teuchos;
00055 
00056   /**
00057    * 
00058    */
00059   template <class Scalar>
00060   class ILUKPreconditionerFactory
00061     : public PreconditionerFactoryBase<Scalar>
00062   {
00063   public:
00064     /** Construct with a parameter list */
00065     ILUKPreconditionerFactory(const ParameterList& params)
00066       : fillLevels_(1),
00067         overlapFill_(0),
00068         relaxationValue_(0.0),
00069         relativeThreshold_(1.0),
00070         absoluteThreshold_(0.0),
00071         leftOrRight_(Right)
00072     {
00073       LinearSolverBase<Scalar>::template setParameter<int>(params, &fillLevels_, 
00074                                                   "Graph Fill");
00075 
00076       LinearSolverBase<Scalar>::template setParameter<int>(params, &overlapFill_, 
00077                                                   "Overlap");
00078 
00079       LinearSolverBase<Scalar>::template setParameter<double>(params, &relaxationValue_, 
00080                                                      "Relaxation");
00081 
00082       LinearSolverBase<Scalar>::template setParameter<double>(params, &absoluteThreshold_, 
00083                                                      "Absolute Threshold");
00084 
00085       LinearSolverBase<Scalar>::template setParameter<double>(params, &relativeThreshold_, 
00086                                                      "Relative Threshold");
00087 
00088       bool isLeft = false;
00089 
00090       LinearSolverBase<Scalar>::template setParameter<bool>(params, &isLeft, "Left");
00091 
00092       if (isLeft) leftOrRight_ = Left;
00093       
00094     }
00095 
00096 
00097     /** virtual dtor */
00098     virtual ~ILUKPreconditionerFactory(){;}
00099 
00100     
00101     /** */
00102     virtual Preconditioner <Scalar>
00103     createPreconditioner(const LinearOperator<Scalar>& A) const 
00104     {
00105       /* In order for ILU factorization to work, the operator A must
00106        * implement the ILUFactorizableOp interface. We cast A's pointer
00107        * to a ILUFactorizableOp ptr. If the cast fails, throw a spoke. */
00108       
00109       const ILUFactorizableOp<Scalar>* fop 
00110         = dynamic_cast<const ILUFactorizableOp<Scalar>*>(A.ptr().get());
00111 
00112       TEUCHOS_TEST_FOR_EXCEPTION(fop==0, std::runtime_error,
00113                          "ILUKPreconditionerFactory attempted to "
00114                          "create an ILU preconditioner for an operator type "
00115                          "that does not implement the ILUFactorizableOp "
00116                          "interface. The op is " << A.description());
00117 
00118       
00119       /* Now we can delegate the construction of the ILU factors to 
00120       * the factorizable op. */
00121       Preconditioner<Scalar> P;
00122       fop->getILUKPreconditioner(fillLevels_,
00123                                  overlapFill_,
00124                                  relaxationValue_,
00125                                  relativeThreshold_,
00126                                  absoluteThreshold_,
00127                                  leftOrRight_,
00128                                  P);
00129       /* Return the preconditioner */
00130       return P;
00131     }
00132 
00133     /* Handleable boilerplate */
00134     GET_RCP(PreconditionerFactoryBase<Scalar>);
00135   private:
00136 
00137     int fillLevels_;
00138     int overlapFill_;
00139     Scalar relaxationValue_;
00140     Scalar relativeThreshold_;
00141     Scalar absoluteThreshold_;
00142     LeftOrRight leftOrRight_;
00143   };
00144 
00145 
00146 }
00147 
00148 #endif

Site Contact