TSFSolverState.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 /* ***********************************************************************
00003 // 
00004 //           TSFExtended: Trilinos Solver Framework Extended
00005 //                 Copyright (2004) 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 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // **********************************************************************/
00027  /* @HEADER@ */
00028 
00029 #ifndef TSFSOLVERSTATE_HPP
00030 #define TSFSOLVERSTATE_HPP
00031 
00032 #include "SundanceDefs.hpp"
00033 #include "TSFVectorDecl.hpp"
00034 #include "TSFLinearOperatorDecl.hpp"
00035 #include "Teuchos_ParameterList.hpp"
00036 
00037 namespace TSFExtended
00038 {
00039 using namespace Teuchos;
00040 
00041 /** 
00042  *
00043  */
00044 enum SolverStatusCode {SolveCrashed, SolveFailedToConverge, SolveConverged};
00045 
00046 
00047 /**
00048  *
00049  */
00050 template <class Scalar>
00051 class SolverState
00052 {
00053 public:
00054   /** */
00055   SolverState(SolverStatusCode finalState, const std::string& msg, 
00056     int finalIters, const Scalar& finalResid)
00057     : finalState_(finalState),
00058       finalResid_(finalResid),
00059       finalIters_(finalIters),
00060       msg_(msg)
00061     {;}
00062 
00063   /** */
00064   SolverState() {;}
00065 
00066   /** */
00067   const Scalar& finalResid() const {return finalResid_;}
00068 
00069   /** */
00070   int finalIters() const {return finalIters_;}
00071 
00072   /** */
00073   const SolverStatusCode& finalState() const {return finalState_;}
00074 
00075   /** */
00076   const std::string& finalMsg() const {return msg_;}
00077 
00078   /** */
00079   std::string stateDescription() const 
00080     {
00081       switch (finalState_)
00082       {
00083         case SolveCrashed:
00084           return "Crashed";
00085         case SolveFailedToConverge:
00086           return "Failed to converge";
00087         case SolveConverged:
00088           return "Converged";
00089       }
00090       return "Crashed";
00091     }
00092 
00093 private:
00094     
00095   SolverStatusCode finalState_;
00096 
00097   Scalar finalResid_;
00098 
00099   int finalIters_;
00100 
00101   std::string msg_;
00102 };
00103 
00104 
00105 template <class Scalar> inline
00106 std::ostream& operator<<(std::ostream& os, 
00107   const TSFExtended::SolverState<Scalar>& state)
00108 {
00109   os << "Solver final state: " << state.stateDescription() << std::endl;
00110   os << "message: " << state.finalMsg() << std::endl;
00111   os << "iters taken: " << state.finalIters() << std::endl;
00112   os << "final residual: " << state.finalResid() << std::endl;
00113   return os;
00114 }
00115 
00116 }
00117 
00118 
00119 #endif

Site Contact