fei_Solver.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include <fei_macros.hpp>
00010 
00011 #include <fei_Solver.hpp>
00012 
00013 #include <fei_Matrix_Impl.hpp>
00014 #include <fei_MatrixReducer.hpp>
00015 #include <snl_fei_LinearSystem_FEData.hpp>
00016 #include <fei_ParameterSet.hpp>
00017 #include <fei_utils.hpp>
00018 
00019 #undef fei_file
00020 #define fei_file "fei_Solver.cpp"
00021 #include <fei_ErrMacros.hpp>
00022 
00023 //----------------------------------------------------------------------------
00024 int fei_Solver_solve(fei::LinearSystem* linearSystem,
00025          fei::Matrix* preconditioningMatrix,
00026          int numParams,
00027          const char* const* solverParams,
00028          int& iterationsTaken,
00029          int& status)
00030 {
00031   fei::SharedPtr<fei::Matrix> matrix = linearSystem->getMatrix();
00032   fei::Matrix_Impl<LinearSystemCore>* lscmatrix =
00033     dynamic_cast<fei::Matrix_Impl<LinearSystemCore>*>(matrix.get());
00034 
00035   fei::MatrixReducer* matred = dynamic_cast<fei::MatrixReducer*>(matrix.get());
00036   if (matred != NULL) {
00037     lscmatrix = dynamic_cast<fei::Matrix_Impl<LinearSystemCore>*>(matred->getTargetMatrix().get());
00038   }
00039 
00040   if (lscmatrix != NULL) {
00041     fei::SharedPtr<LinearSystemCore> linSysCore = lscmatrix->getMatrix();
00042 
00043     char** params = const_cast<char**>(solverParams);
00044     CHK_ERR( linSysCore->parameters(numParams, params) );
00045 
00046     CHK_ERR( linSysCore->launchSolver(status, iterationsTaken) );
00047 
00048     return(0);
00049   }
00050 
00051   snl_fei::LinearSystem_FEData* fedlinsys =
00052     dynamic_cast<snl_fei::LinearSystem_FEData*>(linearSystem);
00053   if (fedlinsys != NULL) {
00054     fei::SharedPtr<FiniteElementData> fedata = fedlinsys->getFiniteElementData();
00055 
00056     CHK_ERR( fedata->launchSolver(status, iterationsTaken) );
00057 
00058     return(0);
00059   }
00060 
00061   ERReturn(-1);
00062 }
00063 
00064 //----------------------------------------------------------------------------
00065 int fei::Solver::solve(fei::LinearSystem* linearSystem,
00066          fei::Matrix* preconditioningMatrix,
00067          const fei::ParameterSet& parameterSet,
00068          int& iterationsTaken,
00069          int& status)
00070 {
00071   int numParams = 0;
00072   const char** paramStrings = NULL;
00073   std::vector<std::string> stdstrings;
00074   fei::utils::convert_ParameterSet_to_strings(&parameterSet, stdstrings);
00075   fei::utils::strings_to_char_ptrs(stdstrings, numParams, paramStrings);
00076 
00077   int err = fei_Solver_solve(linearSystem, preconditioningMatrix,
00078       numParams, paramStrings,
00079       iterationsTaken, status);
00080 
00081   delete [] paramStrings;
00082 
00083   return(err);
00084 }
00085 

Generated on Wed May 12 21:30:41 2010 for FEI by  doxygen 1.4.7