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