|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) 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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef ALAP_DIRECT_SPARSE_SOLVER_MA28_H 00030 #define ALAP_DIRECT_SPARSE_SOLVER_MA28_H 00031 00032 #include <valarray> 00033 #include <vector> 00034 #include <string> 00035 00036 #include "AbstractLinAlgPack_DirectSparseSolverImp.hpp" 00037 #include "AbstractLinAlgPack_MA28Solver.hpp" 00038 #include "DenseLinAlgPack_DVectorClass.hpp" 00039 #include "DenseLinAlgPack_IVector.hpp" 00040 #include "Teuchos_StandardMemberCompositionMacros.hpp" 00041 00042 namespace AbstractLinAlgPack { 00043 00048 class DirectSparseSolverMA28 : public DirectSparseSolverImp { 00049 public: 00050 00053 00055 enum EScalingMethod { NO_SCALING, INITIAL_SCALING, SUCCESSIVE_SCALING }; 00056 00058 00061 00063 STANDARD_MEMBER_COMPOSITION_MEMBERS( value_type, u ); 00064 00066 STANDARD_MEMBER_COMPOSITION_MEMBERS( bool, grow ); 00067 00069 STANDARD_MEMBER_COMPOSITION_MEMBERS( value_type, tol ); 00070 00072 STANDARD_MEMBER_COMPOSITION_MEMBERS( index_type, nsrch ); 00073 00075 STANDARD_MEMBER_COMPOSITION_MEMBERS( bool, lbig ); 00076 00078 STANDARD_MEMBER_COMPOSITION_MEMBERS( bool, print_ma28_outputs ); 00079 00081 STANDARD_MEMBER_COMPOSITION_MEMBERS( std::string, output_file_name ); 00082 00084 00087 00089 DirectSparseSolverMA28( 00090 value_type estimated_fillin_ratio = 10.0 00091 ,value_type u = 0.1 00092 ,bool grow = false 00093 ,value_type tol = 0.0 00094 ,index_type nsrch = 4 00095 ,bool lbig = false 00096 ,bool print_ma28_outputs = false 00097 ,const std::string& output_file_name = "" 00098 ); 00099 00101 00104 00106 const basis_matrix_factory_ptr_t basis_matrix_factory() const; 00108 void estimated_fillin_ratio( value_type estimated_fillin_ratio ); 00109 00111 00112 protected: 00113 00116 00119 class BasisMatrixMA28 : public BasisMatrixImp { 00120 public: 00121 00124 00126 Teuchos::RCP<BasisMatrixImp> create_matrix() const; 00128 void V_InvMtV( 00129 VectorMutable* v_lhs, BLAS_Cpp::Transp trans_rhs1 00130 ,const Vector& v_rhs2) const ; 00131 00133 00134 }; // end class BasisMatrixMA28 00135 00138 class FactorizationStructureMA28 : public FactorizationStructure { 00139 public: 00141 friend class DirectSparseSolverMA28; 00143 friend class BasisMatrixMA28; 00144 private: 00145 // ///////////////////////////////////////// 00146 // Private types 00147 typedef Teuchos::RCP<MatrixScaling_Strategy> matrix_scaling_ptr_t; 00148 // ///////////////////////////////////////// 00149 // Private data members 00150 mutable MA28_Cpp::MA28Solver ma28_; // Management of common block data 00151 // Keep a memory of the size of the system to check for consistent usage. 00152 index_type m_; // number of rows (keep for checks on consistancy) 00153 index_type n_; // number of columns ("") 00154 index_type max_n_; // max(m_,n_) 00155 index_type nz_; // numner of non-zero elements in unfactorized matrix ("") 00156 index_type licn_; // size of icn_ and a_ (default = 3 * nz_) 00157 index_type lirn_; // size of irn_ (default = 3 * nz_) 00158 // Control parameters 00159 value_type u_; // fill-in vs. stability ratio (default = 0.1) 00160 EScalingMethod scaling_; // Scaling method 00161 // Matrix scaling 00162 matrix_scaling_ptr_t matrix_scaling_; 00163 // Memory for factorization structure 00164 std::valarray<index_type> ivect_; 00165 std::valarray<index_type> jvect_; 00166 std::valarray<index_type> icn_; 00167 std::valarray<index_type> ikeep_; 00168 // Basis matrix selection 00169 IVector row_perm_; 00170 IVector col_perm_; 00171 index_type rank_; 00172 // ///////////////////////////////////////// 00173 // Private member functions 00175 FactorizationStructureMA28(); 00176 }; // end class FactorizationStructureMA28 00177 00180 class FactorizationNonzerosMA28 : public FactorizationNonzeros { 00181 public: 00183 friend class DirectSparseSolverMA28; 00185 friend class BasisMatrixMA28; 00186 private: 00187 std::valarray<value_type> a_; // holds the non-zeros of the factorized matrix 'a' 00188 }; // end class FactorizationNonzerosMA28 00189 00191 00194 00196 const Teuchos::RCP<FactorizationStructure> create_fact_struc() const; 00198 const Teuchos::RCP<FactorizationNonzeros> create_fact_nonzeros() const; 00200 void imp_analyze_and_factor( 00201 const AbstractLinAlgPack::MatrixConvertToSparse &A 00202 ,FactorizationStructure *fact_struc 00203 ,FactorizationNonzeros *fact_nonzeros 00204 ,DenseLinAlgPack::IVector *row_perm 00205 ,DenseLinAlgPack::IVector *col_perm 00206 ,size_type *rank 00207 ,std::ostream *out 00208 ); 00210 void imp_factor( 00211 const AbstractLinAlgPack::MatrixConvertToSparse &A 00212 ,const FactorizationStructure &fact_struc 00213 ,FactorizationNonzeros *fact_nonzeros 00214 ,std::ostream *out 00215 ); 00216 00218 00219 private: 00220 00221 // ///////////////////////////////// 00222 // Private types 00223 00225 enum E_IFlag { 00226 SLOW_ITER_CONV = -17, 00227 MAXIT_REACHED = -16, 00228 MA28BD_CALLED_WITH_DROPPED = -15, 00229 DUPLICATE_ELEMENTS = -14, 00230 NEW_NONZERO_ELEMENT = -13, 00231 N_OUT_OF_RANGE = -11, 00232 NZ_LE_ZERO = -10, 00233 LICN_LE_NZ = -9, 00234 LIRN_LE_NZ = -8, 00235 ERROR_DURRING_BLOCK_TRI = -7, 00236 LICN_AND_LIRN_TOO_SMALL = -6, 00237 LICN_TOO_SMALL = -5, 00238 LICN_FAR_TOO_SMALL = -4, 00239 LIRN_TOO_SMALL = -3, 00240 NUMERICALLY_SINGULAR = -2, 00241 STRUCTURALLY_SINGULAR = -1, 00242 SUCCESSFUL_DECOMP_ON_STRUCT_SINGULAR = 1, 00243 SUCCESSFUL_DECOMP_ON_NUMER_SINGULAR = 2 00244 }; 00245 00246 // ///////////////////////////////// 00247 // Private data members 00248 00249 value_type estimated_fillin_ratio_; 00250 Teuchos::RCP<std::ostream> output_file_; 00251 int file_output_num_; 00252 00253 // //////////////////////////////// 00254 // Private member functions 00255 00256 // Set MA28 control parameters 00257 void set_ma28_parameters( FactorizationStructureMA28* fs ); 00258 00259 // Print MA28 return parameters 00260 void print_ma28_outputs( 00261 bool ma28ad_bd 00262 ,index_type iflag 00263 ,const FactorizationStructureMA28 &fs 00264 ,const value_type w[] 00265 ,std::ostream *out 00266 ); 00267 00268 // Throw an exception for an iflag error 00269 void ThrowIFlagException(index_type iflag); 00270 00271 }; // end class DirectSparseSolverMA28 00272 00273 // //////////////////////////////////////// 00274 // Inline members 00275 00276 } // end namespace AbstractLinAlgPack 00277 00278 #endif // ALAP_DIRECT_SPARSE_SOLVER_MA28_H
1.7.4