Teko Version of the Day
Teko_PreconditionerFactory.hpp
00001 /*
00002 // @HEADER
00003 // 
00004 // ***********************************************************************
00005 // 
00006 //      Teko: A package for block and physics based preconditioning
00007 //                  Copyright 2010 Sandia Corporation 
00008 //  
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 //  
00012 // Redistribution and use in source and binary forms, with or without
00013 // modification, are permitted provided that the following conditions are
00014 // met:
00015 //  
00016 // 1. Redistributions of source code must retain the above copyright
00017 // notice, this list of conditions and the following disclaimer.
00018 //  
00019 // 2. Redistributions in binary form must reproduce the above copyright
00020 // notice, this list of conditions and the following disclaimer in the
00021 // documentation and/or other materials provided with the distribution.
00022 //  
00023 // 3. Neither the name of the Corporation nor the names of the
00024 // contributors may be used to endorse or promote products derived from
00025 // this software without specific prior written permission. 
00026 //  
00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 //  
00039 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
00040 // 
00041 // ***********************************************************************
00042 // 
00043 // @HEADER
00044 
00045 */
00046 
00047 #ifndef __Teko_PreconditionerFactory_hpp__
00048 #define __Teko_PreconditionerFactory_hpp__
00049 
00050 #include "Teuchos_ParameterListAcceptor.hpp"
00051 
00052 // Thyra includes
00053 #include "Thyra_SolveSupportTypes.hpp"
00054 #include "Thyra_LinearOpSourceBase.hpp"
00055 #include "Thyra_PreconditionerFactoryBase.hpp"
00056 #include "Thyra_DefaultBlockedLinearOp.hpp"
00057 #include "Thyra_DefaultPreconditioner.hpp"
00058 
00059 // Teko includes
00060 #include "Teko_Utilities.hpp"
00061 #include "Teko_InverseLibrary.hpp"
00062 #include "Teko_CloneFactory.hpp"
00063 #include "Teko_PreconditionerState.hpp"
00064 #include "Teko_RequestHandler.hpp"
00065 #include "Teko_RequestHandlerContainer.hpp"
00066 
00067 namespace Teko {
00068 
00069 using Thyra::LinearOpBase;
00070 using Thyra::DefaultPreconditioner;
00071 
00082 class PreconditionerFactory 
00083    : public virtual Thyra::PreconditionerFactoryBase<double>, public RequestHandlerContainer
00084    {
00085 public:
00086 
00100    virtual LinearOp buildPreconditionerOperator(LinearOp & lo,PreconditionerState & state) const = 0;
00101 
00114    virtual Teuchos::RCP<PreconditionerState> buildPreconditionerState() const
00115    { return Teuchos::rcp(new PreconditionerState()); }
00116 
00118 
00119 
00132    virtual void initializeFromParameterList(const Teuchos::ParameterList & settings)
00133    { }
00134 
00149    virtual Teuchos::RCP<Teuchos::ParameterList> getRequestedParameters() const
00150    { return Teuchos::null; }
00151    
00165    virtual bool updateRequestedParameters(const Teuchos::ParameterList & pl)
00166    { return true; }
00167    
00169 
00171    void setInverseLibrary(const Teuchos::RCP<const InverseLibrary> & il);
00172 
00174    Teuchos::RCP<const InverseLibrary> getInverseLibrary() const;
00175 
00177 
00178  
00180    bool isCompatible(const Thyra::LinearOpSourceBase<double> &fwdOpSrc) const;
00181 
00183    Teuchos::RCP<Thyra::PreconditionerBase<double> > createPrec() const;
00184 
00195    void initializePrec(const Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > & fwdOpSrc,
00196                        const Teuchos::RCP<const Thyra::MultiVectorBase<double> > & solnVec,
00197                        Thyra::PreconditionerBase<double> * precOp,
00198                        const Thyra::ESupportSolveUse supportSolveUse) const;
00199 
00201    void initializePrec(const Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > & fwdOpSrc,
00202                        Thyra::PreconditionerBase<double> * precOp,
00203                        const Thyra::ESupportSolveUse supportSolveUse) const;
00204 
00206    void uninitializePrec(Thyra::PreconditionerBase<double> * prec, 
00207                          Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > * fwdOpSrc,
00208                          Thyra::ESupportSolveUse *supportSolveUse) const;
00210 
00212 
00213 
00215    void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & paramList); 
00216 
00218    Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList();
00219 
00221    Teuchos::RCP< Teuchos::ParameterList > unsetParameterList();
00223 
00225    void setRequestHandler(const Teuchos::RCP<RequestHandler> & rh)
00226    { callbackHandler_ = rh; }
00227 
00229    Teuchos::RCP<RequestHandler> getRequestHandler() const 
00230    { return callbackHandler_; }
00231 
00232 protected:
00234    Teuchos::RCP<Teuchos::ParameterList>          paramList_;
00235 
00237    Teuchos::RCP<RequestHandler> callbackHandler_;
00238 
00239 private:
00241    Teuchos::RCP<const InverseLibrary> inverseLibrary_;
00242 
00244    static void setOpRequestHandler(const RequestHandlerContainer & rhc,const LinearOp & op);
00245 
00246 public:
00247 
00262    static Teuchos::RCP<PreconditionerFactory> 
00263    buildPreconditionerFactory(const std::string & name, 
00264                               const Teuchos::ParameterList & settings,
00265                               const Teuchos::RCP<const InverseLibrary> & invLib=Teuchos::null);
00266 
00280    static void addPreconditionerFactory(const std::string & name,const Teuchos::RCP<Cloneable> & clone);
00281 
00284    static void getPreconditionerFactoryNames(std::vector<std::string> & names);
00285 
00286 private:
00287 
00289    static CloneFactory<PreconditionerFactory> precFactoryBuilder_;
00290 
00292    static void initializePrecFactoryBuilder();
00293 };
00294 
00295 } // end namespace Teko
00296 
00297 #endif
 All Classes Files Functions Variables