PlayaICCPreconditionerFactory.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_ICCPRECONDITIONERFACTORY_HPP
00043 #define PLAYA_ICCPRECONDITIONERFACTORY_HPP
00044 
00045 #include "PlayaDefs.hpp"
00046 #include "PlayaPreconditionerFactoryBase.hpp"
00047 #include "PlayaLinearOperatorDecl.hpp"
00048 #include "Teuchos_ParameterList.hpp"
00049 #include "PlayaICCFactorizableOp.hpp"
00050 #include "PlayaLinearSolverBaseDecl.hpp"
00051 
00052 namespace Playa
00053 {
00054   using namespace Teuchos;
00055 
00056   /**
00057    * 
00058    */
00059   template <class Scalar>
00060   class ICCPreconditionerFactory
00061     : public PreconditionerFactoryBase<Scalar>
00062   {
00063   public:
00064     /** Magnitude type */
00065     typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00066     /** Construct with a parameter list */
00067     //const ParameterList& params inside
00068     ICCPreconditionerFactory():
00069       fillLevels_(1),
00070         overlapFill_(0),
00071   dropTolerance_(1.0e-4),
00072         relaxationValue_(0.0),
00073         relativeThreshold_(1.0),
00074         absoluteThreshold_(0.0){;}
00075         
00076     ICCPreconditionerFactory(int fillLevels, 
00077            int overlapFill, 
00078            ScalarMag dropTolerance,
00079            ScalarMag relaxationValue, 
00080            ScalarMag relativeThreshold, 
00081            ScalarMag absoluteThreshold)
00082     {
00083       fillLevels_=fillLevels;
00084       overlapFill_=overlapFill;
00085   dropTolerance_ = dropTolerance;
00086       relaxationValue_=relaxationValue;
00087       relativeThreshold_=relativeThreshold;
00088       absoluteThreshold_=absoluteThreshold;
00089     }
00090 
00091     /** virtual dtor */
00092     virtual ~ICCPreconditionerFactory(){;}
00093 
00094     
00095     /** */
00096     virtual Preconditioner <Scalar>
00097     createPreconditioner(const LinearOperator<Scalar>& A) const 
00098     {
00099       /* In order for ICC factorization to work, the operator A must
00100        * implement the ICCFactorizableOp interface. We cast A's pointer
00101        * to a ICCFactorizableOp ptr. If the cast fails, throw a spoke. */
00102       
00103       const ICCFactorizableOp<Scalar>* fop 
00104         = dynamic_cast<const ICCFactorizableOp<Scalar>*>(A.ptr().get());
00105 
00106       TEUCHOS_TEST_FOR_EXCEPTION(fop==0, std::runtime_error,
00107                          "ICCPreconditionerFactory attempted to "
00108                          "create an ICC preconditioner for an operator type "
00109                          "that does not implement the ICCFactorizableOp "
00110                          "interface. The op is " << A.description());
00111 
00112       
00113       /* Now we can delegate the construction of the ICC factors to 
00114       * the factorizable op. */
00115       Preconditioner<Scalar> P;
00116       fop->getICCPreconditioner(fillLevels_,
00117         overlapFill_,
00118         dropTolerance_,
00119         relaxationValue_,
00120         relativeThreshold_,
00121         absoluteThreshold_,
00122         P);
00123       /* Return the preconditioner */
00124       return P;
00125     }
00126 
00127     /* Handleable boilerplate */
00128     GET_RCP(PreconditionerFactoryBase<Scalar>);
00129   private:
00130 
00131     int fillLevels_;
00132     int overlapFill_;
00133     ScalarMag dropTolerance_;
00134     ScalarMag relaxationValue_;
00135     ScalarMag relativeThreshold_;
00136     ScalarMag absoluteThreshold_;
00137   };
00138 
00139 
00140 }
00141 
00142 #endif

Site Contact