Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Lapack_decl.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //           Amesos2: Templated Direct Sparse Solver Package 
00006 //                  Copyright 2011 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ***********************************************************************
00041 //
00042 // @HEADER
00043 
00044 
00054 #ifndef AMESOS2_LAPACK_DECL_HPP
00055 #define AMESOS2_LAPACK_DECL_HPP
00056 
00057 #include <Teuchos_ScalarTraits.hpp>
00058 #include <Teuchos_SerialDenseSolver.hpp>
00059 #include <Teuchos_SerialDenseMatrix.hpp>
00060 
00061 #include "Amesos2_SolverTraits.hpp"
00062 #include "Amesos2_SolverCore.hpp"
00063 
00064 
00065 namespace Amesos2 {
00066 
00067 
00078   template <class Matrix,
00079       class Vector>
00080   class Lapack : public SolverCore<Amesos2::Lapack, Matrix, Vector> 
00081   {
00082     friend class SolverCore<Amesos2::Lapack,Matrix,Vector>; // Give our base access
00083                                                             // to our private
00084                                                             // implementation funcs
00085   public:
00086 
00088     static const char* name;  // declaration. Initialization outside.
00089 
00090     typedef Lapack<Matrix,Vector>                                                type;
00091     typedef SolverCore<Amesos2::Lapack,Matrix,Vector>                      super_type;
00092 
00093     // Since typedef's are not inheritted, go grab them
00094     typedef typename super_type::scalar_type                              scalar_type;
00095     typedef typename super_type::local_ordinal_type                local_ordinal_type;
00096     typedef typename super_type::global_ordinal_type              global_ordinal_type;
00097     typedef typename super_type::global_size_type                    global_size_type;
00098 
00099     typedef typename Teuchos::ScalarTraits<scalar_type>::magnitudeType magnitude_type;
00100 
00101 
00102 
00104 
00105 
00112     Lapack(Teuchos::RCP<const Matrix> A,
00113      Teuchos::RCP<Vector>       X,
00114      Teuchos::RCP<const Vector> B);
00115     
00116 
00118     ~Lapack( );
00119 
00121 
00122   private:
00123   
00127     int preOrdering_impl();
00128 
00129 
00133     int symbolicFactorization_impl();
00134 
00135 
00141     int numericFactorization_impl();
00142 
00143 
00154     int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> >       X,
00155        const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
00156 
00157 
00161     bool matrixShapeOK_impl() const;
00162 
00163 
00172     void setParameters_impl(const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
00173 
00174   
00179     Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
00180 
00181 
00190     bool loadA_impl(EPhase current_phase);
00191 
00192 
00193     // We keep some `temporary' storage for when we retrive values
00194     // from the input matrix
00195     //
00196     // NOTE:: It seems that the Teuchos::LAPACK wrappers only really
00197     // work for the OrdinalType=int case, so that's what we'll work
00198     // with, but ideally we should just be able to give
00199     // global_ordinal_type.
00200 
00202     Teuchos::Array<scalar_type> nzvals_;
00204     // Teuchos::Array<global_ordinal_type> rowind_;
00205     Teuchos::Array<int> rowind_;
00207     // Teuchos::Array<global_size_type> colptr_;
00208     Teuchos::Array<int> colptr_;
00210     mutable Teuchos::Array<scalar_type> rhsvals_;
00211 
00213     // Teuchos::SerialDenseMatrix<global_ordinal_type,scalar_type> lu_;
00214     Teuchos::SerialDenseMatrix<int,scalar_type> lu_;
00215 
00217     // Teuchos::SerialDenseSolver<global_ordinal_type,scalar_type> solver_;
00218     mutable Teuchos::SerialDenseSolver<int,scalar_type> solver_;
00219 
00220   };                              // End class Lapack
00221 
00222   
00223   // Specialize the solver_traits struct for Lapack.
00224   //
00225   // Specializations of Teuchos::LAPACK only exist for real and
00226   // complex float and double types.
00227   //
00228   // TODO: Reinstate the complex support once the bug in
00229   // Teuchos::SerialDenseSolver has been fixed
00230   template <>
00231   struct solver_traits<Lapack> {
00232 // #ifdef HAVE_TEUCHOS_COMPLEX
00233 //     typedef Meta::make_list4<float,
00234 //           double,
00235 //           std::complex<float>,
00236 //           std::complex<double> >supported_scalars;
00237 // #else
00238     typedef Meta::make_list2<float, double> supported_scalars;
00239 // #endif
00240 };
00241   
00242 } // end namespace Amesos2
00243 
00244 #endif  // AMESOS2_NEWSOLVER_DECL_HPP