Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Ifpack2_Details_OneLevelFactory_def.hpp
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack2: Tempated Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2009) 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 Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 */
00042 
00043 #ifndef IFPACK2_DETAILS_ONELEVELFACTORY_DEF_HPP
00044 #define IFPACK2_DETAILS_ONELEVELFACTORY_DEF_HPP
00045 
00046 #include "Ifpack2_Chebyshev.hpp"
00047 #include "Ifpack2_Details_DenseSolver.hpp"
00048 #include "Ifpack2_Diagonal.hpp"
00049 #include "Ifpack2_IdentitySolver.hpp"
00050 #include "Ifpack2_ILUT.hpp"
00051 #include "Ifpack2_Relaxation.hpp"
00052 #include "Ifpack2_RILUK.hpp"
00053 #include "Ifpack2_Krylov.hpp"
00054 #include "Ifpack2_BlockRelaxation.hpp"
00055 #include "Ifpack2_DenseContainer.hpp"
00056 
00057 #ifdef HAVE_IFPACK2_AMESOS2
00058 #  include "Ifpack2_Details_Amesos2Wrapper.hpp"
00059 #endif // HAVE_IFPACK2_AMESOS2
00060 
00061 namespace Ifpack2 {
00062 namespace Details {
00063 
00064 template<class MatrixType>
00065 Teuchos::RCP<typename OneLevelFactory<MatrixType>::prec_type>
00066 OneLevelFactory<MatrixType>::create (const std::string& precType,
00067                                      const Teuchos::RCP<const row_matrix_type>& matrix) const
00068 {
00069   using Teuchos::RCP;
00070   using Teuchos::rcp;
00071 
00072   RCP<prec_type> prec;
00073 
00074   // precTypeUpper is the upper-case version of precType.
00075   std::string precTypeUpper (precType);
00076   if (precTypeUpper.size () > 0) {
00077     std::locale locale;
00078     for (size_t k = 0; k < precTypeUpper.size (); ++k) {
00079       precTypeUpper[k] = std::toupper<char> (precTypeUpper[k], locale);
00080     }
00081   }
00082 
00083   if (precTypeUpper == "CHEBYSHEV") {
00084     // We have to distinguish Ifpack2::Chebyshev from its
00085     // implementation class Ifpack2::Details::Chebyshev.
00086     prec = rcp (new ::Ifpack2::Chebyshev<MatrixType> (matrix));
00087   }
00088   else if (precTypeUpper == "DENSE" || precTypeUpper == "LAPACK") {
00089     prec = rcp (new Details::DenseSolver<MatrixType> (matrix));
00090   }
00091   else if (precTypeUpper == "AMESOS2") {
00092 #ifdef HAVE_IFPACK2_AMESOS2
00093     prec = rcp (new Details::Amesos2Wrapper<MatrixType> (matrix));
00094 #else
00095     TEUCHOS_TEST_FOR_EXCEPTION(
00096       true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory: "
00097       "You may not ask for the preconditioner \"AMESOS2\" unless "
00098       "you have built Trilinos with the Amesos2 package enabled.");
00099 #endif // HAVE_IFPACK2_AMESOS2
00100   }
00101   else if (precTypeUpper == "DIAGONAL") {
00102     prec = rcp (new Diagonal<MatrixType> (matrix));
00103   }
00104   else if (precTypeUpper == "ILUT") {
00105     prec = rcp (new ILUT<MatrixType> (matrix));
00106   }
00107   else if (precTypeUpper == "RELAXATION") {
00108     prec = rcp (new Relaxation<MatrixType> (matrix));
00109   }
00110   else if (precTypeUpper == "RILUK") {
00111     prec = rcp (new RILUK<MatrixType> (matrix));
00112   }
00113   else if (precTypeUpper == "KRYLOV") {
00114     prec = rcp (new Krylov<MatrixType> (matrix));
00115   }
00116   else if (precTypeUpper == "BLOCK_RELAXATION" ||
00117            precTypeUpper == "BLOCK RELAXATION" ||
00118            precTypeUpper == "BLOCKRELAXATION" ) {
00119     // FIXME (mfh 22 May 2014) We would prefer to have the choice of
00120     // dense or sparse blocks (the "container type") be a run-time
00121     // decision.  This will require refactoring BlockRelaxation so
00122     // that the "container type" is not a template parameter.  For
00123     // now, we default to use dense blocks.
00124     typedef DenseContainer<MatrixType, scalar_type> container_type;
00125     prec = rcp (new BlockRelaxation<MatrixType, container_type> (matrix));
00126   }
00127   else if (precTypeUpper == "IDENTITY" || precTypeUpper == "IDENTITY_SOLVER") {
00128     prec = rcp (new IdentitySolver<MatrixType> (matrix));
00129   }
00130   else {
00131     TEUCHOS_TEST_FOR_EXCEPTION(
00132       true, std::invalid_argument, "Ifpack2::Details::OneLevelFactory::create: "
00133       "Invalid preconditioner type \"" << precType << "\".");
00134   }
00135 
00136   TEUCHOS_TEST_FOR_EXCEPTION(
00137     prec.is_null (), std::logic_error, "Ifpack2::Details::OneLevelFactory::"
00138     "create: Return value is null right before return.  This should never "
00139     "happen.  Please report this bug to the Ifpack2 developers.");
00140   return prec;
00141 }
00142 
00143 } // namespace Details
00144 } // namespace Ifpack2
00145 
00146 #define IFPACK2_DETAILS_ONELEVELFACTORY_INSTANT(S,LO,GO,N)              \
00147   template class Ifpack2::Details::OneLevelFactory< Tpetra::CrsMatrix<S, LO, GO, N> >;
00148 
00149 #endif // IFPACK2_DETAILS_ONELEVELFACTORY_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends