00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00076
00077
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);
00105
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
00110 Teuchos::RefCountPtr<VectorBase<Scalar> > m_dx = createMember(model_->get_x_space());
00111 Thyra::solve( *J_, NOTRANS, *f, &*m_dx );
00112
00113 Vt_S( &*m_dx, Scalar(-ST::one()) );
00114 Vp_V( x, *m_dx );
00115 if (delta != NULL) assign( delta, *m_dx );
00116
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 }
00135
00136 #endif // THYRA_LINEAR_NONLINEAR_SOLVER_BASE_HPP