FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_Solver.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include <fei_macros.hpp>
10 
11 #include <fei_Solver.hpp>
12 
13 #include <fei_Matrix_Impl.hpp>
14 #include <fei_MatrixReducer.hpp>
15 #include <snl_fei_LinearSystem_FEData.hpp>
16 #include <fei_ParameterSet.hpp>
17 #include <fei_utils.hpp>
18 
19 #undef fei_file
20 #define fei_file "fei_Solver.cpp"
21 #include <fei_ErrMacros.hpp>
22 
23 //----------------------------------------------------------------------------
24 int fei_Solver_solve(fei::LinearSystem* linearSystem,
25  fei::Matrix* preconditioningMatrix,
26  int numParams,
27  const char* const* solverParams,
28  int& iterationsTaken,
29  int& status)
30 {
31  fei::SharedPtr<fei::Matrix> matrix = linearSystem->getMatrix();
33  dynamic_cast<fei::Matrix_Impl<LinearSystemCore>*>(matrix.get());
34 
35  fei::MatrixReducer* matred = dynamic_cast<fei::MatrixReducer*>(matrix.get());
36  if (matred != NULL) {
37  lscmatrix = dynamic_cast<fei::Matrix_Impl<LinearSystemCore>*>(matred->getTargetMatrix().get());
38  }
39 
40  if (lscmatrix != NULL) {
41  fei::SharedPtr<LinearSystemCore> linSysCore = lscmatrix->getMatrix();
42 
43  char** params = const_cast<char**>(solverParams);
44  CHK_ERR( linSysCore->parameters(numParams, params) );
45 
46  CHK_ERR( linSysCore->launchSolver(status, iterationsTaken) );
47 
48  return(0);
49  }
50 
51  snl_fei::LinearSystem_FEData* fedlinsys =
52  dynamic_cast<snl_fei::LinearSystem_FEData*>(linearSystem);
53  if (fedlinsys != NULL) {
55 
56  CHK_ERR( fedata->launchSolver(status, iterationsTaken) );
57 
58  return(0);
59  }
60 
61  ERReturn(-1);
62 }
63 
64 //----------------------------------------------------------------------------
66  fei::Matrix* preconditioningMatrix,
67  const fei::ParameterSet& parameterSet,
68  int& iterationsTaken,
69  int& status)
70 {
71  int numParams = 0;
72  const char** paramStrings = NULL;
73  std::vector<std::string> stdstrings;
74  fei::utils::convert_ParameterSet_to_strings(&parameterSet, stdstrings);
75  fei::utils::strings_to_char_ptrs(stdstrings, numParams, paramStrings);
76 
77  int err = fei_Solver_solve(linearSystem, preconditioningMatrix,
78  numParams, paramStrings,
79  iterationsTaken, status);
80 
81  delete [] paramStrings;
82 
83  return(err);
84 }
85 
void strings_to_char_ptrs(std::vector< std::string > &stdstrings, int &numStrings, const char **&charPtrs)
Definition: fei_utils.cpp:178
virtual fei::SharedPtr< fei::Matrix > getMatrix()
void convert_ParameterSet_to_strings(const fei::ParameterSet *paramset, std::vector< std::string > &paramStrings)
Definition: fei_utils.cpp:270
T * get() const
fei::SharedPtr< T > getMatrix()
virtual int launchSolver(int &solveStatus, int &iterations)=0
fei::SharedPtr< FiniteElementData > getFiniteElementData()
virtual int solve(fei::LinearSystem *linearSystem, fei::Matrix *preconditioningMatrix, const fei::ParameterSet &parameterSet, int &iterationsTaken, int &status)
Definition: fei_Solver.cpp:65
virtual int parameters(int numParams, const char *const *params)=0
virtual int launchSolver(int &solveStatus, int &iterations)=0