|
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 #include "AbstractLinAlgPack_BasisSystemFactoryStd.hpp" 00030 #include "AbstractLinAlgPack_BasisSystemPermDirectSparse.hpp" 00031 #include "AbstractLinAlgPack_DirectSparseSolverDense.hpp" 00032 #include "Teuchos_TestForException.hpp" 00033 #include "OptionsFromStreamPack_OptionsFromStream.hpp" 00034 #include "OptionsFromStreamPack_StringToIntMap.hpp" 00035 #include "OptionsFromStreamPack_StringToBool.hpp" 00036 00037 #ifdef HAVE_MOOCHO_MA28 00038 #include "AbstractLinAlgPack_DirectSparseSolverMA28.hpp" 00039 #include "AbstractLinAlgPack_DirectSparseSolverMA28SetOptions.hpp" 00040 #endif 00041 00042 namespace AbstractLinAlgPack { 00043 00044 BasisSystemFactoryStd::BasisSystemFactoryStd() 00045 :direct_linear_solver_type_( 00046 #ifdef SPARSE_SOLVER_PACK_USE_MA48 00047 LA_MA48 // If we have MA48 use it as a first choice 00048 #else 00049 # ifdef HAVE_MOOCHO_MA28 00050 LA_MA28 // If we have MA28 use it as a second choice 00051 # else 00052 LA_DENSE // If we don't have any sparse solvers use dense 00053 # endif 00054 #endif 00055 ) 00056 {} 00057 00058 // Overridden from BasisSystemFactory 00059 00060 void BasisSystemFactoryStd::set_options( const options_ptr_t& options ) 00061 { 00062 options_ = options; 00063 } 00064 00065 const BasisSystemFactoryStd::options_ptr_t& 00066 BasisSystemFactoryStd::get_options() const 00067 { 00068 return options_; 00069 } 00070 00071 // Overridden from AbstractFactory 00072 00073 BasisSystemFactoryStd::obj_ptr_t 00074 BasisSystemFactoryStd::create() const 00075 { 00076 namespace mmp = MemMngPack;; 00077 00078 // Read in the options 00079 read_options(); 00080 00081 // Create the direct sparse solver 00082 Teuchos::RCP<DirectSparseSolver> direct_sparse_solver; 00083 switch(direct_linear_solver_type_) { 00084 case LA_DENSE: { 00085 Teuchos::RCP<DirectSparseSolverDense> 00086 dss_dense = Teuchos::rcp(new DirectSparseSolverDense()); 00087 direct_sparse_solver = dss_dense; 00088 break; 00089 } 00090 case LA_MA28: { 00091 #ifdef HAVE_MOOCHO_MA28 00092 Teuchos::RCP<DirectSparseSolverMA28> 00093 dss_ma28 = Teuchos::rcp(new DirectSparseSolverMA28()); 00094 if(options_.get()) { 00095 AbstractLinAlgPack::DirectSparseSolverMA28SetOptions 00096 opt_setter(dss_ma28.get()); 00097 opt_setter.set_options(*options_); 00098 } 00099 direct_sparse_solver = dss_ma28; 00100 #else 00101 TEST_FOR_EXCEPTION( 00102 true, std::logic_error 00103 ,"Error, HAVE_MOOCHO_MA28 is not defined and therefore MA28 is not supported!" ); 00104 #endif 00105 break; 00106 } 00107 case LA_MA48: { 00108 TEST_FOR_EXCEPTION( 00109 true, std::logic_error 00110 ,"Error, MA48 is not supported yet!" ); 00111 break; 00112 } 00113 case LA_SUPERLU: { 00114 #ifdef SPARSE_SOLVER_PACK_USE_SUPERLU 00115 Teuchos::RCP<DirectSparseSolverSuperLU> 00116 dss_slu = Teuchos::rcp(new DirectSparseSolverSuperLU()); 00117 // ToDo: Set options from stream! 00118 direct_sparse_solver = dss_slu; 00119 #else 00120 TEST_FOR_EXCEPTION( 00121 true, std::logic_error 00122 ,"Error, SPARSE_SOLVER_PACK_USE_SUPERLU is not defined and therefore SuperLU is not supported!" ); 00123 #endif 00124 break; 00125 } 00126 default: 00127 TEST_FOR_EXCEPT(true); // Should not be called? 00128 } 00129 00130 // Return the basis system 00131 return Teuchos::rcp(new BasisSystemPermDirectSparse(direct_sparse_solver)); 00132 00133 } 00134 00135 // private 00136 00137 void BasisSystemFactoryStd::read_options() const 00138 { 00139 namespace ofsp = OptionsFromStreamPack; 00140 using ofsp::OptionsFromStream; 00141 typedef OptionsFromStream::options_group_t options_group_t; 00142 using ofsp::StringToIntMap; 00143 using ofsp::StringToBool; 00144 00145 if(!options_.get()) 00146 return; 00147 00148 const std::string opt_grp_name = "BasisSystemFactoryStd"; 00149 const OptionsFromStream::options_group_t optgrp = options_->options_group( opt_grp_name ); 00150 if( OptionsFromStream::options_group_exists( optgrp ) ) { 00151 00152 const int num_opts = 1; 00153 enum EBasisSystemFactorStd { 00154 DIRECT_LINEAR_SOLVER 00155 }; 00156 const char* SBasisSystemFactorStd[num_opts] = { 00157 "direct_linear_solver" 00158 }; 00159 StringToIntMap map( opt_grp_name, num_opts, SBasisSystemFactorStd ); 00160 00161 options_group_t::const_iterator itr = optgrp.begin(); 00162 for( ; itr != optgrp.end(); ++itr ) { 00163 switch( (EBasisSystemFactorStd)map( ofsp::option_name(itr) ) ) { 00164 case DIRECT_LINEAR_SOLVER: 00165 { 00166 const std::string &linear_solver = ofsp::option_value(itr); 00167 if( linear_solver == "DENSE" ) { 00168 direct_linear_solver_type_ = LA_DENSE; 00169 } else if( linear_solver == "MA28" ) { 00170 #ifdef HAVE_MOOCHO_MA28 00171 direct_linear_solver_type_ = LA_MA28; 00172 #else 00173 TEST_FOR_EXCEPTION( 00174 true, std::logic_error 00175 ,"BasisSystemFactoryStd::read_options(...) : MA28 is not supported," 00176 " you must configure with --enable-moocho-ma28!" ); 00177 #endif 00178 } else if( linear_solver == "MA48" ) { 00179 #ifdef SPARSE_SOLVER_PACK_USE_MA48 00180 direct_linear_solver_type_ = LA_MA48; 00181 #else 00182 TEST_FOR_EXCEPTION( 00183 true, std::logic_error 00184 ,"BasisSystemFactoryStd::read_options(...) : MA48 is not supported," 00185 " must define SPARSE_SOLVER_PACK_USE_MA48!" ); 00186 #endif 00187 } else if( linear_solver == "SUPERLU" ) { 00188 #ifdef SPARSE_SOLVER_PACK_USE_SUPERLU 00189 direct_linear_solver_type_ = LA_SUPERLU; 00190 #else 00191 TEST_FOR_EXCEPTION( 00192 true, std::logic_error 00193 ,"BasisSystemFactoryStd::read_options(...) : SUPERLU is not supported," 00194 " must define SPARSE_SOLVER_PACK_USE_SUPERLU!" ); 00195 #endif 00196 } else { 00197 TEST_FOR_EXCEPTION( 00198 true, std::invalid_argument 00199 ,"BasisSystemFactoryStd::read_options(...) : " 00200 "Error, incorrect value for \"direct_linear_solver\" " 00201 "Only the options \'DENSE\', \'MA28\' and \'SUPERLU\' are avalible." ); 00202 } 00203 break; 00204 } 00205 default: 00206 TEST_FOR_EXCEPT(true); // this would be a local programming error only. 00207 } 00208 } 00209 } 00210 else { 00211 // Warning, options group was not found!!! 00212 } 00213 00214 } 00215 00216 } // end namespace AbstractLinAlgPack
1.7.4