NOX_Playa_Group.hpp
Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 
00004 //@HEADER
00005 //   
00006 //@HEADER
00007 
00008 #ifndef NOX_Playa_GROUP_H
00009 #define NOX_Playa_GROUP_H
00010 
00011 #include "NOX_Abstract_Group.H" // base class
00012 #include "Teuchos_ParameterList.hpp"  // base class
00013 
00014 #include "NOX_Common.H"             // class data element (string)
00015 #include "NOX_Playa_Vector.hpp"     // class data element
00016 #include "Teuchos_RCP.hpp"
00017 #include "PlayaVectorType.hpp"
00018 #include "PlayaVectorSpaceDecl.hpp"
00019 #include "PlayaLinearSolverDecl.hpp"
00020 #include "PlayaLinearOperatorDecl.hpp"
00021 #include "PlayaNonlinearOperator.hpp" // nonlinear operator
00022 
00023 // Forward declares
00024 namespace Teuchos 
00025 {
00026 namespace Parameter 
00027 {
00028 class List;
00029 }
00030 }
00031 
00032 namespace NOX {
00033 namespace NOXPlaya {
00034 
00035 using Teuchos::rcp;
00036 using Teuchos::rcp_dynamic_cast;
00037 
00038 class Group : public virtual NOX::Abstract::Group
00039 {
00040 
00041 public:
00042 
00043   /*! \brief Constructor.
00044    *
00045    * Construct a group given an initial condition, the nonlinear operator that 
00046    * describes the problem to be solved, and the linear solver
00047    */
00048   Group(const Playa::Vector<double>& initcond, 
00049     const Playa::NonlinearOperator<double>& nonlinOp,
00050     const Playa::LinearSolver<double>& solver);
00051 
00052   /*! \brief Constructor.
00053    *
00054    * Construct a group given an initial condition and the nonlinear operator that 
00055    * describes the problem to be solved.
00056    */
00057   Group(const Playa::NonlinearOperator<double>& nonlinOp,
00058     const Playa::LinearSolver<double>& solver);
00059 
00060   /*! \brief Constructor.
00061    *
00062    * Construct a group given an initial condition, the nonlinear operator that 
00063    * describes the problem to be solved, the linear solver, and user-specified precision.
00064    */
00065   Group(const Playa::Vector<double>& initcond, 
00066     const Playa::NonlinearOperator<double>& nonlinOp,
00067     const Playa::LinearSolver<double>& solver,
00068     int numdigits);
00069 
00070   /*! \brief Constructor.
00071    *
00072    * Construct a group given an initial condition, the nonlinear operator that 
00073    * describes the problem to be solved, and user-specified precision.
00074    */
00075   Group(const Playa::NonlinearOperator<double>& nonlinOp,
00076     const Playa::LinearSolver<double>& solver,
00077     int numdigits);
00078 
00079 
00080 
00081 
00082   /*! \brief Copy constructor
00083    *
00084    * Construct a new group given an existing group to copy from.
00085    */
00086   Group(const NOX::NOXPlaya::Group& source, NOX::CopyType type = DeepCopy);
00087 
00088   //! Destructor.
00089   ~Group();
00090 
00091 
00092   NOX::Abstract::Group& operator=(const NOX::Abstract::Group& source);
00093   //! See above.
00094   NOX::Abstract::Group& operator=(const NOX::NOXPlaya::Group& source);
00095 
00096   /** @name "Compute" functions. */
00097   //@{
00098 
00099   void setX(const NOX::Abstract::Vector& y);
00100   //! See above
00101   void setX(const NOX::NOXPlaya::Vector& y);
00102 
00103   void computeX(const NOX::Abstract::Group& grp, 
00104     const NOX::Abstract::Vector& d, 
00105     double step);
00106   //! See above.
00107   void computeX(const NOX::NOXPlaya::Group& grp, 
00108     const NOX::NOXPlaya::Vector& d, 
00109     double step);
00110 
00111   NOX::Abstract::Group::ReturnType computeF();
00112 
00113   NOX::Abstract::Group::ReturnType computeJacobian();
00114 
00115   NOX::Abstract::Group::ReturnType computeGradient();
00116 
00117   NOX::Abstract::Group::ReturnType computeNewton(Teuchos::ParameterList& params);
00118 
00119   //@}
00120 
00121   /** @name Jacobian operations.
00122    *
00123    * Operations using the Jacobian matrix. These may not be defined in
00124    * matrix-free scenarios. */
00125 
00126   //@{
00127   
00128   NOX::Abstract::Group::ReturnType 
00129   applyJacobian(const NOX::NOXPlaya::Vector& input, 
00130     NOX::NOXPlaya::Vector& result) const;
00131 
00132   //! See above
00133   NOX::Abstract::Group::ReturnType 
00134   applyJacobian(const NOX::Abstract::Vector& input, 
00135     NOX::Abstract::Vector& result) const;
00136 
00137   NOX::Abstract::Group::ReturnType 
00138   applyJacobianTranspose(const NOX::NOXPlaya::Vector& input, 
00139     NOX::NOXPlaya::Vector& result) const;
00140 
00141   //! See above
00142   NOX::Abstract::Group::ReturnType 
00143   applyJacobianTranspose(const NOX::Abstract::Vector& input, 
00144     NOX::Abstract::Vector& result) const;
00145 
00146   NOX::Abstract::Group::ReturnType 
00147   applyJacobianInverse(Teuchos::ParameterList& params, 
00148     const NOX::NOXPlaya::Vector& input, 
00149     NOX::NOXPlaya::Vector& result) const;
00150 
00151   NOX::Abstract::Group::ReturnType 
00152   applyJacobianInverse(Teuchos::ParameterList& params, 
00153     const NOX::Abstract::Vector& input, 
00154     NOX::Abstract::Vector& result) const;
00155   
00156   //@}
00157 
00158   /** @name "Is" functions
00159    *
00160    * Checks to see if various objects have been computed. Returns true
00161    * if the corresponding "compute" function has been called since the
00162    * last update to the solution vector (via instantiation or
00163    * computeX). */
00164   //@{
00165 
00166   bool isF() const;
00167   bool isJacobian() const;
00168   bool isGradient() const;
00169   bool isNewton() const;
00170 
00171   //@}
00172 
00173   /** @name "Get" functions 
00174    *
00175    * Note that these function do not check whether or not the vectors
00176    * are valid. Must use the "Is" functions for that purpose. */
00177   //@{
00178 
00179   const NOX::Abstract::Vector& getX() const;
00180 
00181   const NOX::Abstract::Vector& getF() const;
00182   
00183   double getNormF() const;
00184 
00185   const NOX::Abstract::Vector& getGradient() const;
00186 
00187   const NOX::Abstract::Vector& getNewton() const;
00188 
00189   //! Return RCP to solution vector.  
00190   virtual Teuchos::RCP< const NOX::Abstract::Vector > getXPtr() const 
00191     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(xVector);}
00192 
00193   //! Return RCP to F(x)
00194   virtual Teuchos::RCP< const NOX::Abstract::Vector > getFPtr() const 
00195     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(fVector);}
00196 
00197 
00198 
00199   //! Return RCP to gradient.
00200   virtual Teuchos::RCP< const NOX::Abstract::Vector > getGradientPtr() const
00201     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(gradientVector);}
00202 
00203   //! Return RCP to Newton direction.
00204   virtual Teuchos::RCP< const NOX::Abstract::Vector > getNewtonPtr() const 
00205     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(newtonVector);}
00206   //@}
00207 
00208 #ifdef TRILINOS_6
00209   virtual NOX::Abstract::Group* clone(NOX::CopyType type = NOX::DeepCopy) const;
00210 #else
00211   virtual RCP<NOX::Abstract::Group> clone(NOX::CopyType type = NOX::DeepCopy) const;
00212 #endif
00213 
00214   //! Print out the group
00215   void print() const;
00216 
00217 protected:
00218 
00219   //! resets all isValid flags to false
00220   void resetIsValid();
00221 
00222 protected:
00223 
00224   //! user-specified precision
00225   int precision; 
00226       
00227   /** @name Vectors */
00228   //@{
00229   //! Solution vector.
00230   RCP<NOX::NOXPlaya::Vector> xVector;
00231   //! Right-hand-side vector (function evaluation).
00232   RCP<NOX::NOXPlaya::Vector> fVector;
00233   //! Newton direction vector.
00234   RCP<NOX::NOXPlaya::Vector> newtonVector;
00235   //! Gradient vector (steepest descent vector).
00236   RCP<NOX::NOXPlaya::Vector> gradientVector;
00237   //@}
00238 
00239   //! Linear solver that will be used to solve J*step = resid
00240   mutable Playa::LinearSolver<double> solver;
00241 
00242   //! Linear solver that will be used to solve J*step = resid
00243   Playa::LinearOperator<double> jacobian;
00244 
00245 
00246   //! Problem interface: reference to nonlinear operator passed to group
00247   Playa::NonlinearOperator<double> nonlinearOp;
00248 
00249   /** @name IsValid flags 
00250    *  
00251    * True if the current solution is up-to-date with respect to the
00252    * currect xVector. */
00253   //@{
00254   bool isValidF;
00255   bool isValidJacobian;
00256   bool isValidGradient;
00257   bool isValidNewton;
00258   //@}
00259   
00260   //! Norm of F
00261   double normF;
00262 
00263 };
00264 
00265 } // namespace Playa
00266 } // namespace NOX
00267 
00268 
00269 #endif

Site Contact