NOX_Playa_Group.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                 Playa: Programmable Linear Algebra
00005 //                 Copyright 2012 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 
00043 // $Id$ 
00044 // $Source$ 
00045 
00046 
00047 //   
00048 
00049 
00050 #ifndef NOX_Playa_GROUP_H
00051 #define NOX_Playa_GROUP_H
00052 
00053 #include "NOX_Abstract_Group.H" // base class
00054 #include "Teuchos_ParameterList.hpp"  // base class
00055 
00056 #include "NOX_Common.H"             // class data element (string)
00057 #include "NOX_Playa_Vector.hpp"     // class data element
00058 #include "Teuchos_RCP.hpp"
00059 #include "PlayaVectorType.hpp"
00060 #include "PlayaVectorSpaceDecl.hpp"
00061 #include "PlayaLinearSolverDecl.hpp"
00062 #include "PlayaLinearOperatorDecl.hpp"
00063 #include "PlayaNonlinearOperator.hpp" // nonlinear operator
00064 
00065 // Forward declares
00066 namespace Teuchos 
00067 {
00068 namespace Parameter 
00069 {
00070 class List;
00071 }
00072 }
00073 
00074 namespace NOX {
00075 namespace NOXPlaya {
00076 
00077 using Teuchos::rcp;
00078 using Teuchos::rcp_dynamic_cast;
00079 
00080 class Group : public virtual NOX::Abstract::Group
00081 {
00082 
00083 public:
00084 
00085   /*! \brief Constructor.
00086    *
00087    * Construct a group given an initial condition, the nonlinear operator that 
00088    * describes the problem to be solved, and the linear solver
00089    */
00090   Group(const Playa::Vector<double>& initcond, 
00091     const Playa::NonlinearOperator<double>& nonlinOp,
00092     const Playa::LinearSolver<double>& solver);
00093 
00094   /*! \brief Constructor.
00095    *
00096    * Construct a group given an initial condition and the nonlinear operator that 
00097    * describes the problem to be solved.
00098    */
00099   Group(const Playa::NonlinearOperator<double>& nonlinOp,
00100     const Playa::LinearSolver<double>& solver);
00101 
00102   /*! \brief Constructor.
00103    *
00104    * Construct a group given an initial condition, the nonlinear operator that 
00105    * describes the problem to be solved, the linear solver, and user-specified precision.
00106    */
00107   Group(const Playa::Vector<double>& initcond, 
00108     const Playa::NonlinearOperator<double>& nonlinOp,
00109     const Playa::LinearSolver<double>& solver,
00110     int numdigits);
00111 
00112   /*! \brief Constructor.
00113    *
00114    * Construct a group given an initial condition, the nonlinear operator that 
00115    * describes the problem to be solved, and user-specified precision.
00116    */
00117   Group(const Playa::NonlinearOperator<double>& nonlinOp,
00118     const Playa::LinearSolver<double>& solver,
00119     int numdigits);
00120 
00121 
00122 
00123 
00124   /*! \brief Copy constructor
00125    *
00126    * Construct a new group given an existing group to copy from.
00127    */
00128   Group(const NOX::NOXPlaya::Group& source, NOX::CopyType type = DeepCopy);
00129 
00130   //! Destructor.
00131   ~Group();
00132 
00133 
00134   NOX::Abstract::Group& operator=(const NOX::Abstract::Group& source);
00135   //! See above.
00136   NOX::Abstract::Group& operator=(const NOX::NOXPlaya::Group& source);
00137 
00138   /** @name "Compute" functions. */
00139   //@{
00140 
00141   void setX(const NOX::Abstract::Vector& y);
00142   //! See above
00143   void setX(const NOX::NOXPlaya::Vector& y);
00144 
00145   void computeX(const NOX::Abstract::Group& grp, 
00146     const NOX::Abstract::Vector& d, 
00147     double step);
00148   //! See above.
00149   void computeX(const NOX::NOXPlaya::Group& grp, 
00150     const NOX::NOXPlaya::Vector& d, 
00151     double step);
00152 
00153   NOX::Abstract::Group::ReturnType computeF();
00154 
00155   NOX::Abstract::Group::ReturnType computeJacobian();
00156 
00157   NOX::Abstract::Group::ReturnType computeGradient();
00158 
00159   NOX::Abstract::Group::ReturnType computeNewton(Teuchos::ParameterList& params);
00160 
00161   //@}
00162 
00163   /** @name Jacobian operations.
00164    *
00165    * Operations using the Jacobian matrix. These may not be defined in
00166    * matrix-free scenarios. */
00167 
00168   //@{
00169   
00170   NOX::Abstract::Group::ReturnType 
00171   applyJacobian(const NOX::NOXPlaya::Vector& input, 
00172     NOX::NOXPlaya::Vector& result) const;
00173 
00174   //! See above
00175   NOX::Abstract::Group::ReturnType 
00176   applyJacobian(const NOX::Abstract::Vector& input, 
00177     NOX::Abstract::Vector& result) const;
00178 
00179   NOX::Abstract::Group::ReturnType 
00180   applyJacobianTranspose(const NOX::NOXPlaya::Vector& input, 
00181     NOX::NOXPlaya::Vector& result) const;
00182 
00183   //! See above
00184   NOX::Abstract::Group::ReturnType 
00185   applyJacobianTranspose(const NOX::Abstract::Vector& input, 
00186     NOX::Abstract::Vector& result) const;
00187 
00188   NOX::Abstract::Group::ReturnType 
00189   applyJacobianInverse(Teuchos::ParameterList& params, 
00190     const NOX::NOXPlaya::Vector& input, 
00191     NOX::NOXPlaya::Vector& result) const;
00192 
00193   NOX::Abstract::Group::ReturnType 
00194   applyJacobianInverse(Teuchos::ParameterList& params, 
00195     const NOX::Abstract::Vector& input, 
00196     NOX::Abstract::Vector& result) const;
00197   
00198   //@}
00199 
00200   /** @name "Is" functions
00201    *
00202    * Checks to see if various objects have been computed. Returns true
00203    * if the corresponding "compute" function has been called since the
00204    * last update to the solution vector (via instantiation or
00205    * computeX). */
00206   //@{
00207 
00208   bool isF() const;
00209   bool isJacobian() const;
00210   bool isGradient() const;
00211   bool isNewton() const;
00212 
00213   //@}
00214 
00215   /** @name "Get" functions 
00216    *
00217    * Note that these function do not check whether or not the vectors
00218    * are valid. Must use the "Is" functions for that purpose. */
00219   //@{
00220 
00221   const NOX::Abstract::Vector& getX() const;
00222 
00223   const NOX::Abstract::Vector& getF() const;
00224   
00225   double getNormF() const;
00226 
00227   const NOX::Abstract::Vector& getGradient() const;
00228 
00229   const NOX::Abstract::Vector& getNewton() const;
00230 
00231   //! Return RCP to solution vector.  
00232   virtual Teuchos::RCP< const NOX::Abstract::Vector > getXPtr() const 
00233     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(xVector);}
00234 
00235   //! Return RCP to F(x)
00236   virtual Teuchos::RCP< const NOX::Abstract::Vector > getFPtr() const 
00237     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(fVector);}
00238 
00239 
00240 
00241   //! Return RCP to gradient.
00242   virtual Teuchos::RCP< const NOX::Abstract::Vector > getGradientPtr() const
00243     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(gradientVector);}
00244 
00245   //! Return RCP to Newton direction.
00246   virtual Teuchos::RCP< const NOX::Abstract::Vector > getNewtonPtr() const 
00247     {return rcp_dynamic_cast<const NOX::Abstract::Vector>(newtonVector);}
00248   //@}
00249 
00250 #ifdef TRILINOS_6
00251   virtual NOX::Abstract::Group* clone(NOX::CopyType type = NOX::DeepCopy) const;
00252 #else
00253   virtual RCP<NOX::Abstract::Group> clone(NOX::CopyType type = NOX::DeepCopy) const;
00254 #endif
00255 
00256   //! Print out the group
00257   void print() const;
00258 
00259 protected:
00260 
00261   //! resets all isValid flags to false
00262   void resetIsValid();
00263 
00264 protected:
00265 
00266   //! user-specified precision
00267   int precision; 
00268       
00269   /** @name Vectors */
00270   //@{
00271   //! Solution vector.
00272   RCP<NOX::NOXPlaya::Vector> xVector;
00273   //! Right-hand-side vector (function evaluation).
00274   RCP<NOX::NOXPlaya::Vector> fVector;
00275   //! Newton direction vector.
00276   RCP<NOX::NOXPlaya::Vector> newtonVector;
00277   //! Gradient vector (steepest descent vector).
00278   RCP<NOX::NOXPlaya::Vector> gradientVector;
00279   //@}
00280 
00281   //! Linear solver that will be used to solve J*step = resid
00282   mutable Playa::LinearSolver<double> solver;
00283 
00284   //! Linear solver that will be used to solve J*step = resid
00285   Playa::LinearOperator<double> jacobian;
00286 
00287 
00288   //! Problem interface: reference to nonlinear operator passed to group
00289   Playa::NonlinearOperator<double> nonlinearOp;
00290 
00291   /** @name IsValid flags 
00292    *  
00293    * True if the current solution is up-to-date with respect to the
00294    * currect xVector. */
00295   //@{
00296   bool isValidF;
00297   bool isValidJacobian;
00298   bool isValidGradient;
00299   bool isValidNewton;
00300   //@}
00301   
00302   //! Norm of F
00303   double normF;
00304 
00305 };
00306 
00307 } // namespace Playa
00308 } // namespace NOX
00309 
00310 
00311 #endif

Site Contact