ShyLU  Version of the Day
shylu_directsolver_interface_def.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // ShyLU: Hybrid preconditioner package
5 // Copyright 2012 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
49 #ifndef SHYLU_DIRECTSOLVER_INTERFACE_DEF_HPP
50 #define SHYLU_DIRECTSOLVER_INTERFACE_DEF_HPP
51 
52 #include "ShyLUCore_config.h"
54 
55 #include <Teuchos_XMLParameterListHelpers.hpp>
56 
57 
58 namespace ShyLU{
59 
60  template<class Matrix, class Vector>
62  {}
63 
64  template<class Matrix, class Vector>
65  DirectSolverInterface<Matrix, Vector>::DirectSolverInterface(Matrix *inA, Teuchos::ParameterList *inpList)
66  {
67  A=inA;
68  pList = inpList;
69  }
70 
71  template<class Matrix, class Vector>
73  { }
74 
75  template <class Matrix, class Vector>
76  int
77  DirectSolverInterface<Matrix, Vector>::init_matrix(Matrix *inA, Teuchos::ParameterList *inpList)
78  {
79  A=inA;
80  pList = inpList;
81  return 0;
82  }
83 
84 
85 
86 
87  template <class Matrix, class Vector>
88  int
90  {
91  cout << "**Error**: Amesos is only supported for Epetra Matrices \n";
92  exit(1);
93  }
94 
95 
96  //Note: come back and update
97  template <>
98  int
100  {
101 
102  Teuchos::ParameterList subList = pList->sublist("Amesos Input");
103  string solvertype = Teuchos::getParameter<string>(subList, "Solver");
104  Teuchos::ParameterList subsubList = subList.sublist(solvertype + " Input");
105 
106  problem_amesos.SetOperator(A);
107  //future reference
108  //setLHS(x)
109  //setRHS(B)
110 
111  Amesos Factory;
112  solver_amesos = Factory.Create(solvertype, problem_amesos);
113  assert (solver_amesos != 0);
114  solver_amesos->SetParameters(subsubList);
115  //Add error checking
116  solver_amesos->SymbolicFactorization();
117  solver_amesos->NumericFactorization();
118 
119  return 0;
120  }//end factorAmesos
121 
122 #ifdef HAVE_SHYLUCORE_AMESOS2
123  template <class Matrix, class Vector>
125  {
126  //#pragma message("solve amesos2 compiled")
127  //cout << "odd call";
128  Teuchos::ParameterList subList = pList->sublist("Amesos2 Input");
129  string solvertype = Teuchos::getParameter<string>(subList, "Solver");
130  Teuchos::ParameterList subsubList = subList.sublist(solvertype + " Input");
131  solver_amesos2 = Amesos2::create<Matrix, Vector>
132  (solvertype, Teuchos::rcp(A,false) ); //right now only use default
133  solver_amesos2->symbolicFactorization().numericFactorization();
134 
135  return 0;
136  }//end factor_amesos2
137 #endif
138 
139 
140  template <class Matrix, class Vector>
142  {
143  #ifdef HAVE_SHYLUCORE_AMESOS2
144  return factorAmesos2();
145  #else
146  return 1;
147  #endif
148  }//end factor()
149 
150 
151  template < >
152  int
154  {
155  string solverpackage = Teuchos::getParameter<string>(*pList,"Direct Solver Package");
156  int returnvalue = 1;
157  if(solverpackage.compare("Amesos")==0)
158  {
159  returnvalue = factorAmesos();
160  }
161  else if(solverpackage.compare("Amesos2")==0)
162  {
163 #ifdef HAVE_SHYLUCORE_AMESOS2
164  returnvalue = factorAmesos2();
165 #else
166  cout << "Amesos2 is not installed \n";
167  exit(1);
168 #endif
169  }
170  else
171  {
172  cout << "No Direct Solver Package Found";
173  }
174  return returnvalue;
175  }//end factor<epetra>
176 
177 
178 
179 
180 
181 
182 template <class Matrix, class Vector>
183 int
185 {
186  cout << "**Error**: Amesos is only supported for Epetra Matrices \n";
187  exit(1);
188 }
189 template <>
190 int
191 DirectSolverInterface<Epetra_CrsMatrix, Epetra_MultiVector>::solveAmesos(Epetra_MultiVector *b, Epetra_MultiVector *x)
192 {
193 
194  Teuchos::ParameterList subList = pList->sublist("Amesos Input");
195  string solvertype = Teuchos::getParameter<string>(subList, "Solver");
196  Teuchos::ParameterList subsubList = subList.sublist(solvertype + " Input");
197 
198  //Epetra_LinearProblem Problem(A, x, b);
199  //Amesos Factory;
200  // Amesos_BaseSolver* Solver = Factory.Create(solvertype, Problem);
201  //assert (Solver != 0);
202  problem_amesos.SetRHS(x);
203  problem_amesos.SetLHS(b);
204 
205  //solver_amesos->SetParameters(subsubList);
206  //Add error checking
207  //Solver->SymbolicFactorization();
208  //Solver->NumericFactorization();
209  solver_amesos->Solve();
210 
211  return 0;
212 }
213 template <class Matrix, class Vector>
214 int
216 {
217 #ifdef HAVE_SHYLUCORE_AMESOS2
218  return solveAmesos2(b, x);
219 #else
220  return 1;
221 #endif
222 }
223 
224 template < >
225 int
226 DirectSolverInterface<Epetra_CrsMatrix, Epetra_MultiVector>::solve(Epetra_MultiVector*b ,Epetra_MultiVector* x)
227 {
228  string solverpackage = Teuchos::getParameter<string>(*pList,"Direct Solver Package");
229  int returnvalue = 1;
230  if(solverpackage.compare("Amesos")==0)
231  {
232  returnvalue = solveAmesos(b,x);
233  }
234  else if(solverpackage.compare("Amesos2")==0)
235  {
236 #ifdef HAVE_SHYLUCORE_AMESOS2
237  returnvalue = solveAmesos2(b,x);
238 #else
239  cout << "Amesos2 is not installed \n";
240  exit(1);
241 #endif
242  }
243  else
244  {
245  cout << "No Direct Solver Package Found";
246  }
247  return returnvalue;
248 }
249 #ifdef HAVE_SHYLUCORE_AMESOS2
250 template <class Matrix, class Vector>
252 {
253  //#pragma message("solve amesos2 compiled")
254  //cout << "odd call";
255  Teuchos::ParameterList subList = pList->sublist("Amesos2 Input");
256  string solvertype = Teuchos::getParameter<string>(subList, "Solver");
257  Teuchos::ParameterList subsubList = subList.sublist(solvertype + " Input");
258  solver_amesos2->solve(x, b);
259 
260  return 0;
261 }
262 #endif
263 
264 
265 
266 
267 }// end namespace
268 
269 #endif // end header if
DirectSolverInterface class templated on Epetra/Tpetra Matrix and Vector.
DirectSolverInterface()
Main constructor of class.
Eperta/Tpetra templated interface for call Amesos and Amesos2.