Stratimikos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Stratimikos_DefaultLinearSolverBuilder.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Stratimikos: Thyra-based strategies for linear solvers
00005 //                Copyright (2006) 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 // 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef STRATIMIKOS_DEFAULT_LINEAR_SOLVER_BUILDING_BASE
00043 #define STRATIMIKOS_DEFAULT_LINEAR_SOLVER_BUILDING_BASE
00044 
00045 #include "Stratimikos_ConfigDefs.hpp"
00046 #include "Thyra_LinearSolverBuilderBase.hpp"
00047 #include "Teuchos_AbstractFactory.hpp"
00048 #include "Teuchos_StandardMemberCompositionMacros.hpp"
00049 #include "Teuchos_StandardParameterEntryValidators.hpp"
00050 
00051 // Include these to make all of the helpful decls appear
00052 #include "Thyra_EpetraThyraWrappers.hpp"
00053 #include "Thyra_EpetraLinearOp.hpp"
00054 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
00055 #include "Thyra_LinearOpWithSolveBase.hpp"
00056 #include "Thyra_PreconditionerFactoryHelpers.hpp"
00057 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
00058 #include "Thyra_DefaultPreconditioner.hpp"
00059 #include "Thyra_MultiVectorStdOps.hpp"
00060 #include "Thyra_VectorStdOps.hpp"
00061 #include "Thyra_VectorBase.hpp"
00062 
00063 
00064 namespace Teuchos { class CommandLineProcessor; }
00065 
00066 
00067 namespace Stratimikos {
00068 
00069 
00071 using Teuchos::RCP;
00073 using Teuchos::Array;
00075 using Teuchos::AbstractFactory;
00077 using Teuchos::ParameterList;
00078 
00079 
00111 class DefaultLinearSolverBuilder
00112   : public Thyra::LinearSolverBuilderBase<double>
00113 {
00114 public:
00115 
00118 
00126   DefaultLinearSolverBuilder(
00127     const std::string    &paramsXmlFileName                = ""
00128     ,const std::string   &extraParamsXmlString             = ""
00129     ,const std::string   &paramsUsedXmlOutFileName         = ""
00130     ,const std::string   &paramsXmlFileNameOption          = "linear-solver-params-file"
00131     ,const std::string   &extraParamsXmlStringOption       = "extra-linear-solver-params"
00132     ,const std::string   &paramsUsedXmlOutFileNameOption   = "linear-solver-params-used-file"
00133     );
00134 
00136   ~DefaultLinearSolverBuilder();
00137   
00141   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileName);
00142     
00146   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlString);
00147 
00151   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileName);
00152 
00156   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsXmlFileNameOption);
00157 
00161   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,extraParamsXmlStringOption);
00162 
00166   STANDARD_MEMBER_COMPOSITION_MEMBERS(std::string,paramsUsedXmlOutFileNameOption);
00167 
00169   void setLinearSolveStrategyFactory(
00170     const RCP<const AbstractFactory<Thyra::LinearOpWithSolveFactoryBase<double> > >
00171     &solveStrategyFactory,
00172     const std::string &solveStrategyName,
00173     const bool makeDefault = false
00174     );
00175 
00177   void setDefaultLinearSolveStrategyFactoryName(
00178     const std::string &solveStrategyName);
00179 
00181   void setPreconditioningStrategyFactory(
00182     const RCP<const AbstractFactory<Thyra::PreconditionerFactoryBase<double> > >
00183     &precStrategyFactory,
00184     const std::string &precStrategyName,
00185     const bool makeDefault = false
00186     );
00187 
00189   void setDefaultPreconditioningStrategyFactoryName(
00190     const std::string &precStrategyName);
00191 
00208   void setupCLP( Teuchos::CommandLineProcessor *clp );
00209 
00228   void readParameters( std::ostream *out );
00229 
00245   void writeParamsFile(
00246     const Thyra::LinearOpWithSolveFactoryBase<double> &lowsFactory,
00247     const std::string &outputXmlFileName  = "" 
00248     ) const;
00249   
00253   std::string getLinearSolveStrategyName() const;
00254 
00258   std::string getPreconditionerStrategyName() const;
00259 
00261 
00264 
00266   void setParameterList(RCP<ParameterList> const& paramList);
00268   RCP<ParameterList> getNonconstParameterList();
00270   RCP<ParameterList> unsetParameterList();
00272   RCP<const ParameterList> getParameterList() const;
00274   RCP<const ParameterList> getValidParameters() const;
00275 
00277   
00280 
00282   RCP<Thyra::LinearOpWithSolveFactoryBase<double> >
00283   createLinearSolveStrategy(
00284     const std::string &linearSolveStrategyName
00285     ) const;
00287   RCP<Thyra::PreconditionerFactoryBase<double> >
00288   createPreconditioningStrategy(
00289     const std::string &preconditioningStrategyName
00290     ) const;
00291 
00293 
00294 private:
00295 
00296   // //////////////////////////////////////
00297   // Private types
00298 
00299   typedef RCP<const AbstractFactory<Thyra::LinearOpWithSolveFactoryBase<double> > >
00300   lowsf_fcty_t;
00301   typedef RCP<const AbstractFactory<Thyra::PreconditionerFactoryBase<double> > >
00302   pf_fcty_t;
00303 
00304   // //////////////////////////////////////
00305   // Private data members
00306   
00307   RCP<ParameterList> paramList_;
00308   Array<std::string> validLowsfNames_;
00309   Array<lowsf_fcty_t> lowsfArray_;
00310   std::string defaultLOWSF_;
00311   Array<std::string> validPfNames_; // Contains "None" as the 0th entry!
00312   Array<pf_fcty_t> pfArray_;
00313   std::string defaultPF_;
00314   bool enableDelayedSolverConstruction_;
00315   mutable RCP<const ParameterList> validParamList_;
00316   mutable RCP<const Teuchos::StringToIntegralParameterEntryValidator<int> > lowsfValidator_;
00317   mutable RCP<const Teuchos::StringToIntegralParameterEntryValidator<int> > pfValidator_;
00318 
00319   // //////////////////////////////////////
00320   // Private member functions
00321 
00322   void initializeDefaults();
00323   void justInTimeInitialize() const;
00324 
00325 };
00326 
00327 
00328 } // namespace Stratimikos
00329 
00330 
00331 #endif // STRATIMIKOS_DEFAULT_LINEAR_SOLVER_BUILDING_BASE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines