computation/interfaces/direct/SuperLU.hxx

00001 // Copyright (C) 2003-2009 Marc Duruflé
00002 //
00003 // This file is part of the linear-algebra library Seldon,
00004 // http://seldon.sourceforge.net/.
00005 //
00006 // Seldon is free software; you can redistribute it and/or modify it under the
00007 // terms of the GNU Lesser General Public License as published by the Free
00008 // Software Foundation; either version 2.1 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00018 
00019 
00020 #ifndef SELDON_FILE_SUPERLU_HXX
00021 
00022 extern "C"
00023 {
00024 #include "superlu_interface.h"
00025 }
00026 
00027 
00028 namespace Seldon
00029 {
00030 
00032   template<class T>
00033   class MatrixSuperLU_Base
00034   {
00035   protected :
00037     SuperMatrix L, U, B;
00038     SCformat *Lstore;  
00039     NCformat *Ustore;  
00040     SuperLUStat_t stat; 
00041     superlu_options_t options; 
00042 
00043     Vector<int> perm_r, perm_c;
00044 
00045     colperm_t permc_spec; 
00046     int n; 
00047     bool display_info; 
00048 
00049     int info_facto;
00050 
00051   public :
00052     MatrixSuperLU_Base();
00053     ~MatrixSuperLU_Base();
00054 
00055     template<class Prop, class Allocator>
00056     void GetLU(Matrix<double, Prop, ColSparse, Allocator>& Lmat,
00057                Matrix<double, Prop, ColSparse, Allocator>& Umat,
00058                bool permuted = true);
00059 
00060     template<class Prop, class Allocator>
00061     void GetLU(Matrix<double, Prop, RowSparse, Allocator>& Lmat,
00062                Matrix<double, Prop, RowSparse, Allocator>& Umat,
00063                bool permuted = true);
00064 
00065     const Vector<int>& GetRowPermutation() const;
00066     const Vector<int>& GetColPermutation() const;
00067 
00068     void SelectOrdering(colperm_t type);
00069     void SetPermutation(const IVect&);
00070 
00071     void Clear();
00072     void HideMessages();
00073     void ShowMessages();
00074 
00075     int GetInfoFactorization() const;
00076   };
00077 
00078 
00080   template<class T>
00081   class MatrixSuperLU : public MatrixSuperLU_Base<T>
00082   {
00083   };
00084 
00085 
00087   template<>
00088   class MatrixSuperLU<double> : public MatrixSuperLU_Base<double>
00089   {
00090   public:
00091     MatrixSuperLU() : MatrixSuperLU_Base<double>() {}
00092 
00093     template<class Prop, class Storage, class Allocator>
00094     void FactorizeMatrix(Matrix<double, Prop, Storage, Allocator> & mat,
00095                          bool keep_matrix = false);
00096 
00097     template<class Allocator2>
00098     void Solve(Vector<double, VectFull, Allocator2>& x);
00099 
00100     template<class TransStatus, class Allocator2>
00101     void Solve(const TransStatus& TransA,
00102                Vector<double, VectFull, Allocator2>& x);
00103   };
00104 
00105 
00107   template<>
00108   class MatrixSuperLU<complex<double> >
00109     : public MatrixSuperLU_Base<complex<double> >
00110   {
00111   public:
00112     MatrixSuperLU() : MatrixSuperLU_Base<complex<double> >() {}
00113 
00114     template<class Prop, class Storage, class Allocator>
00115     void FactorizeMatrix(Matrix<complex<double>, Prop,
00116                          Storage, Allocator> & mat,
00117                          bool keep_matrix = false);
00118 
00119     template<class Allocator2>
00120     void Solve(Vector<complex<double>, VectFull, Allocator2>& x);
00121 
00122     template<class TransStatus, class Allocator2>
00123     void Solve(const TransStatus& TransA,
00124                Vector<complex<double>, VectFull, Allocator2>& x);
00125 
00126   };
00127 
00128 }
00129 
00130 #define SELDON_FILE_SUPERLU_HXX
00131 #endif