NOX_TSF_Vector.H
Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 
00004 //@HEADER
00005 // ************************************************************************
00006 // 
00007 //            NOX: An Object-Oriented Nonlinear Solver Package
00008 //                 Copyright (2002) Sandia Corporation
00009 // 
00010 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00011 // license for use of this work by or on behalf of the U.S. Government.
00012 // 
00013 // This library is free software; you can redistribute it and/or modify
00014 // it under the terms of the GNU Lesser General Public License as
00015 // published by the Free Software Foundation; either version 2.1 of the
00016 // License, or (at your option) any later version.
00017 //  
00018 // This library is distributed in the hope that it will be useful, but
00019 // WITHOUT ANY WARRANTY; without even the implied warranty of
00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021 // Lesser General Public License for more details.
00022 //                                                                                 
00023 // You should have received a copy of the GNU Lesser General Public
00024 // License along with this library; if not, write to the Free Software
00025 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00026 // USA                                                                                
00027 // Questions? Contact Tammy Kolda (tgkolda@sandia.gov) or Roger Pawlowski
00028 // (rppawlo@sandia.gov), Sandia National Laboratories.
00029 // 
00030 // ************************************************************************
00031 //@HEADER
00032 
00033 /*! \file NOX_TSF_Vector.H - Header file for NOX::TSF::Vector. */
00034 
00035 #ifndef NOX_TSF_VECTOR_H
00036 #define NOX_TSF_VECTOR_H
00037 
00038 #include "NOX_Abstract_Vector.H" // base class
00039 #include "NOX_Common.H" // for #include<vector> 
00040 #include "TSFVectorDecl.hpp" // definitions for TSFExtended Vectors
00041 #include "TSFVectorSpaceDecl.hpp"
00042 
00043 namespace NOX 
00044 {
00045 
00046 //! NOX BLAS/TSF support
00047 namespace TSF 
00048 {
00049 using Teuchos::RCP;
00050   
00051 /** Implementation of the NOX::Abstract::Vector interface for 
00052  * TSFExtended::Vector<double> (using TSFExtended handle to TSFCore).
00053  *
00054  * @author Jill Reese and Kevin Long
00055  */
00056 class Vector : public NOX::Abstract::Vector 
00057 {
00058 
00059 public: 
00060 
00061   //! Copy constructor 
00062   Vector(const NOX::TSF::Vector& source, 
00063     NOX::CopyType type = DeepCopy);
00064 
00065   //! Copy constructor
00066   Vector(const TSFExtended::Vector<double>& source, 
00067     NOX::CopyType type = DeepCopy);
00068 
00069   //! Copy constructor when user requests specific precision  
00070   Vector(const NOX::TSF::Vector& source, 
00071     int numdigits, 
00072     NOX::CopyType type = DeepCopy);
00073 
00074   //! Copy constructor when user requests specific precision 
00075   Vector(const TSFExtended::Vector<double>& source, 
00076     int numdigits,
00077     NOX::CopyType type = DeepCopy);
00078 
00079   /* There's no need to write an explicit dtor for this class, because
00080    * the TSFExtended vector cleans up its own memory. I've commented out 
00081    * this method for now, but it should probably just be deleted. 
00082    * - KL 12 July 2004 */ 
00083   ////! Destruct Vector.
00084   //~Vector();
00085 
00086   /** Access to a writable reference to the underlying TSF vector*/
00087   TSFExtended::Vector<double>& getTSFVector();
00088 
00089   /** Access to a read-only reference to the underlying TSF vector*/
00090   const TSFExtended::Vector<double>& getTSFVector() const;
00091 
00092   /** Access to the vector precision expected by user*/
00093   int getPrecision() const;
00094 
00095   //@{ \name Initialization methods.
00096 
00097   /** Initialize all elements to a constant */
00098   NOX::Abstract::Vector& init(double value);
00099 
00100   /** Assignment operator */
00101   NOX::Abstract::Vector& operator=(const NOX::TSF::Vector& y);
00102   /** Assignment operator */
00103   NOX::Abstract::Vector& operator=(const NOX::Abstract::Vector& y);
00104 
00105   /* Element access should not be implemented in this class; it should
00106    * be done through the LoadableVector and AccessibleVector 
00107    * interfaces of TSFExtended.
00108    * -KL 12 July 2004  */
00109   // Store value in the i-th element of a vector 
00110   //void setElement(int i, const double& value);
00111 
00112   // Return the i-th element (const version).
00113   //const double& getElement(int i) const;
00114   
00115   /** Element-wise absolute value */
00116   NOX::Abstract::Vector& abs(const NOX::TSF::Vector& y);
00117   /** Element-wise absolute value */
00118   NOX::Abstract::Vector& abs(const NOX::Abstract::Vector& y);
00119   
00120   /** Element-wise reciprocal */
00121   NOX::Abstract::Vector& reciprocal(const NOX::TSF::Vector& y);
00122   /** Element-wise reciprocal */
00123   NOX::Abstract::Vector& reciprocal(const NOX::Abstract::Vector& y);
00124   
00125   //@}
00126   
00127   //@{ \name Update methods.
00128   
00129   // derived
00130   NOX::Abstract::Vector& scale(double gamma);
00131   
00132   // derived
00133   NOX::Abstract::Vector& scale(const NOX::TSF::Vector& a);
00134   NOX::Abstract::Vector& scale(const NOX::Abstract::Vector& a);
00135   
00136   // derived
00137   NOX::Abstract::Vector& update(double alpha, const NOX::TSF::Vector& a, double gamma = 0.0);
00138   NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a, double gamma = 0.0);
00139   
00140   // derived
00141   NOX::Abstract::Vector& update(double alpha, const NOX::TSF::Vector& a, 
00142     double beta, const NOX::TSF::Vector& b,
00143     double gamma = 0.0);
00144   NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a, 
00145     double beta, const NOX::Abstract::Vector& b,
00146     double gamma = 0.0);
00147   
00148   //@}
00149   
00150   //@{ \name Creating new Vectors. 
00151   
00152   // derived
00153 #ifdef TRILINOS_6
00154   NOX::Abstract::Vector* clone(NOX::CopyType type = NOX::DeepCopy) const;
00155 #else
00156   RCP<NOX::Abstract::Vector> clone(NOX::CopyType type = NOX::DeepCopy) const ;
00157 #endif
00158   
00159   //@}
00160   
00161   //@{ \name Norms.
00162   
00163   // derived
00164   double norm(NOX::Abstract::Vector::NormType type = NOX::Abstract::Vector::TwoNorm) const;
00165   
00166   // derived
00167   double norm(const NOX::TSF::Vector& weights) const;
00168   double norm(const NOX::Abstract::Vector& weights) const;
00169   
00170   //@}
00171   
00172   //@{ \name Dot products
00173   
00174   // derived
00175   double dot(const NOX::TSF::Vector& y) const;
00176   double dot(const NOX::Abstract::Vector& y) const;
00177   double innerProduct(const NOX::Abstract::Vector& y) const;
00178   
00179   //@}
00180   
00181   // derived
00182   //! The length of a TSFExtended vector is known only by the vector space it belongs to
00183   //! We query the vector space and ask its dimension  
00184   int length() const;
00185 
00186   //! Prints out the vector to the specified stream. 
00187   /*! 
00188     For example, a vector would appear as
00189     \f[ \left[ \; 0.1 \; 2.34 \; 5 \; \right] \f] 
00190     It will be all on one line, with a single space between each entry, bracketed on either side.
00191   */
00192   ostream& leftshift(std::ostream& stream) const;
00193 
00194   // derived
00195   void print() const;
00196 
00197 private:
00198 
00199   /** user-specified precision for printing vectors */
00200   int precision;
00201 
00202   /** The TSF vector owned by this object. */
00203   TSFExtended::Vector<double> x;
00204 };
00205 
00206 } // namespace TSF
00207 } // namespace NOX
00208 
00209 //! Function for printing
00210 namespace std{
00211 ostream& operator<<(std::ostream& stream, const NOX::TSF::Vector& v);
00212 }
00213 
00214 #endif

Site Contact