AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AbstractLinAlgPack_BasisSystemFactoryStd.cpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "AbstractLinAlgPack_BasisSystemFactoryStd.hpp"
43 #include "AbstractLinAlgPack_BasisSystemPermDirectSparse.hpp"
44 #include "AbstractLinAlgPack_DirectSparseSolverDense.hpp"
45 #include "Teuchos_Assert.hpp"
46 #include "OptionsFromStreamPack_OptionsFromStream.hpp"
47 #include "OptionsFromStreamPack_StringToIntMap.hpp"
48 #include "OptionsFromStreamPack_StringToBool.hpp"
49 
50 #ifdef HAVE_MOOCHO_MA28
51 #include "AbstractLinAlgPack_DirectSparseSolverMA28.hpp"
52 #include "AbstractLinAlgPack_DirectSparseSolverMA28SetOptions.hpp"
53 #endif
54 
55 namespace AbstractLinAlgPack {
56 
58  :direct_linear_solver_type_(
59 #ifdef SPARSE_SOLVER_PACK_USE_MA48
60  LA_MA48 // If we have MA48 use it as a first choice
61 #else
62 # ifdef HAVE_MOOCHO_MA28
63  LA_MA28 // If we have MA28 use it as a second choice
64 # else
65  LA_DENSE // If we don't have any sparse solvers use dense
66 # endif
67 #endif
68  )
69 {}
70 
71 // Overridden from BasisSystemFactory
72 
74 {
75  options_ = options;
76 }
77 
80 {
81  return options_;
82 }
83 
84 // Overridden from AbstractFactory
85 
86 BasisSystemFactoryStd::obj_ptr_t
88 {
89  namespace mmp = MemMngPack;;
90 
91  // Read in the options
92  read_options();
93 
94  // Create the direct sparse solver
95  Teuchos::RCP<DirectSparseSolver> direct_sparse_solver;
96  switch(direct_linear_solver_type_) {
97  case LA_DENSE: {
99  dss_dense = Teuchos::rcp(new DirectSparseSolverDense());
100  direct_sparse_solver = dss_dense;
101  break;
102  }
103  case LA_MA28: {
104 #ifdef HAVE_MOOCHO_MA28
106  dss_ma28 = Teuchos::rcp(new DirectSparseSolverMA28());
107  if(options_.get()) {
109  opt_setter(dss_ma28.get());
110  opt_setter.set_options(*options_);
111  }
112  direct_sparse_solver = dss_ma28;
113 #else
115  true, std::logic_error
116  ,"Error, HAVE_MOOCHO_MA28 is not defined and therefore MA28 is not supported!" );
117 #endif
118  break;
119  }
120  case LA_MA48: {
122  true, std::logic_error
123  ,"Error, MA48 is not supported yet!" );
124  break;
125  }
126  case LA_SUPERLU: {
127 #ifdef SPARSE_SOLVER_PACK_USE_SUPERLU
129  dss_slu = Teuchos::rcp(new DirectSparseSolverSuperLU());
130  // ToDo: Set options from stream!
131  direct_sparse_solver = dss_slu;
132 #else
134  true, std::logic_error
135  ,"Error, SPARSE_SOLVER_PACK_USE_SUPERLU is not defined and therefore SuperLU is not supported!" );
136 #endif
137  break;
138  }
139  default:
140  TEUCHOS_TEST_FOR_EXCEPT(true); // Should not be called?
141  }
142 
143  // Return the basis system
144  return Teuchos::rcp(new BasisSystemPermDirectSparse(direct_sparse_solver));
145 
146 }
147 
148 // private
149 
150 void BasisSystemFactoryStd::read_options() const
151 {
152  namespace ofsp = OptionsFromStreamPack;
153  using ofsp::OptionsFromStream;
154  typedef OptionsFromStream::options_group_t options_group_t;
155  using ofsp::StringToIntMap;
156  using ofsp::StringToBool;
157 
158  if(!options_.get())
159  return;
160 
161  const std::string opt_grp_name = "BasisSystemFactoryStd";
162  const OptionsFromStream::options_group_t optgrp = options_->options_group( opt_grp_name );
163  if( OptionsFromStream::options_group_exists( optgrp ) ) {
164 
165  const int num_opts = 1;
166  enum EBasisSystemFactorStd {
167  DIRECT_LINEAR_SOLVER
168  };
169  const char* SBasisSystemFactorStd[num_opts] = {
170  "direct_linear_solver"
171  };
172  StringToIntMap map( opt_grp_name, num_opts, SBasisSystemFactorStd );
173 
174  options_group_t::const_iterator itr = optgrp.begin();
175  for( ; itr != optgrp.end(); ++itr ) {
176  switch( (EBasisSystemFactorStd)map( ofsp::option_name(itr) ) ) {
177  case DIRECT_LINEAR_SOLVER:
178  {
179  const std::string &linear_solver = ofsp::option_value(itr);
180  if( linear_solver == "DENSE" ) {
181  direct_linear_solver_type_ = LA_DENSE;
182  } else if( linear_solver == "MA28" ) {
183 #ifdef HAVE_MOOCHO_MA28
184  direct_linear_solver_type_ = LA_MA28;
185 #else
187  true, std::logic_error
188  ,"BasisSystemFactoryStd::read_options(...) : MA28 is not supported,"
189  " you must configure with --enable-moocho-ma28!" );
190 #endif
191  } else if( linear_solver == "MA48" ) {
192 #ifdef SPARSE_SOLVER_PACK_USE_MA48
193  direct_linear_solver_type_ = LA_MA48;
194 #else
196  true, std::logic_error
197  ,"BasisSystemFactoryStd::read_options(...) : MA48 is not supported,"
198  " must define SPARSE_SOLVER_PACK_USE_MA48!" );
199 #endif
200  } else if( linear_solver == "SUPERLU" ) {
201 #ifdef SPARSE_SOLVER_PACK_USE_SUPERLU
202  direct_linear_solver_type_ = LA_SUPERLU;
203 #else
205  true, std::logic_error
206  ,"BasisSystemFactoryStd::read_options(...) : SUPERLU is not supported,"
207  " must define SPARSE_SOLVER_PACK_USE_SUPERLU!" );
208 #endif
209  } else {
211  true, std::invalid_argument
212  ,"BasisSystemFactoryStd::read_options(...) : "
213  "Error, incorrect value for \"direct_linear_solver\" "
214  "Only the options \'DENSE\', \'MA28\' and \'SUPERLU\' are avalible." );
215  }
216  break;
217  }
218  default:
219  TEUCHOS_TEST_FOR_EXCEPT(true); // this would be a local programming error only.
220  }
221  }
222  }
223  else {
224  // Warning, options group was not found!!!
225  }
226 
227 }
228 
229 } // end namespace AbstractLinAlgPack
Concreate sparse solver subclass that uses MA28.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void set_options(const OptionsFromStream &options)
T * get() const
Concreate sparse solver subclass that uses the dense LAPACK routines.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Permutatble basis system subclass that uses a direct sparse solver.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Set options for DirectSparseSolverMA28 from OptionsFromStream object.