Thyra_LinearNonlinearSolver.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
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 THYRA_LINEAR_NONLINEAR_SOLVER_BASE_HPP
00030 #define THYRA_LINEAR_NONLINEAR_SOLVER_BASE_HPP
00031 
00032 #include "Thyra_NonlinearSolverBase.hpp"
00033 #include "Thyra_ModelEvaluatorHelpers.hpp"
00034 
00035 namespace Thyra {
00036 
00041 template <class Scalar>
00042 class LinearNonlinearSolver : public NonlinearSolverBase<Scalar> {
00043 public:
00044 
00047 
00049   void setModel(
00050     const Teuchos::RefCountPtr<const ModelEvaluator<Scalar> > &model
00051     );
00053   Teuchos::RefCountPtr<const ModelEvaluator<Scalar> > getModel() const;
00055   SolveStatus<Scalar> solve(
00056     VectorBase<Scalar>              *x
00057     ,const SolveCriteria<Scalar>    *solveCriteria
00058     ,VectorBase<Scalar>             *delta
00059     );
00061   Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> > get_nonconst_W();
00063   Teuchos::RefCountPtr<const LinearOpWithSolveBase<Scalar> > get_W() const;
00064 
00066 
00067 private:
00068 
00069   Teuchos::RefCountPtr<const ModelEvaluator<Scalar> >    model_;
00070   Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> >   J_;
00071 
00072 };
00073 
00074 // ////////////////////////
00075 // Defintions
00076 
00077 // Overridden from NonlinearSolverBase
00078 
00079 template <class Scalar>
00080 void LinearNonlinearSolver<Scalar>::setModel(
00081   const Teuchos::RefCountPtr<const ModelEvaluator<Scalar> > &model
00082   )
00083 {
00084   TEST_FOR_EXCEPT(model.get()==NULL);
00085   model_ = model;
00086   J_ = Teuchos::null;
00087 }
00088 
00089 template <class Scalar>
00090 Teuchos::RefCountPtr<const ModelEvaluator<Scalar> >
00091 LinearNonlinearSolver<Scalar>::getModel() const
00092 {
00093   return model_;
00094 }
00095 
00096 template <class Scalar>
00097 SolveStatus<Scalar> LinearNonlinearSolver<Scalar>::solve(
00098   VectorBase<Scalar>             *x
00099   ,const SolveCriteria<Scalar>   *solveCriteria
00100   ,VectorBase<Scalar>            *delta = NULL
00101   )
00102 {
00103   typedef Teuchos::ScalarTraits<Scalar> ST;
00104   TEST_FOR_EXCEPT(solveCriteria!=NULL); // ToDo: Pass to linear solver?
00105   // Compute the Jacobian and the residual at the input point!
00106   if(!J_.get())                               J_ = model_->create_W();
00107   Teuchos::RefCountPtr<VectorBase<Scalar> >   f = createMember(model_->get_f_space());
00108   eval_f_W( *model_, *x, ST::one(), &*f, &*J_ );
00109   // Solve the system: J*m_dx = f
00110   Teuchos::RefCountPtr<VectorBase<Scalar> > m_dx = createMember(model_->get_x_space());
00111   Thyra::solve( *J_, NOTRANS, *f, &*m_dx );
00112   // Set the solution: x = x - m_dx
00113   Vt_S( &*m_dx, Scalar(-ST::one()) );
00114   Vp_V( x, *m_dx );
00115   if (delta != NULL) assign( delta, *m_dx );
00116   // Return default status
00117   return SolveStatus<Scalar>();
00118 }
00119 
00120 template <class Scalar>
00121 Teuchos::RefCountPtr<LinearOpWithSolveBase<Scalar> >
00122 LinearNonlinearSolver<Scalar>::get_nonconst_W()
00123 {
00124   return J_;
00125 }
00126 
00127 template <class Scalar>
00128 Teuchos::RefCountPtr<const LinearOpWithSolveBase<Scalar> >
00129 LinearNonlinearSolver<Scalar>::get_W() const
00130 {
00131   return J_;
00132 }
00133 
00134 } // namespace Thyra
00135 
00136 #endif // THYRA_LINEAR_NONLINEAR_SOLVER_BASE_HPP

Generated on Thu Sep 18 12:33:02 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1