NOX_Playa_Vector.hpp
Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 
00004 //@HEADER
00005 //   
00006 //@HEADER
00007 
00008 /*! \file NOX_Playa_Vector.H - Header file for NOX::NOXPlaya::Vector. */
00009 
00010 #ifndef NOX_Playa_VECTOR_H
00011 #define NOX_Playa_VECTOR_H
00012 
00013 #include "NOX_Abstract_Vector.H" // base class
00014 #include "NOX_Common.H" // for #include<vector> 
00015 #include "PlayaVectorDecl.hpp" // definitions for Playa Vectors
00016 #include "PlayaVectorSpaceDecl.hpp"
00017 
00018 namespace NOX 
00019 {
00020 
00021 
00022 namespace NOXPlaya 
00023 {
00024 using Teuchos::RCP;
00025   
00026 /** Implementation of the NOX::Abstract::Vector interface for 
00027  * Playa::Vector<double> (using Playa handle to PlayaCore).
00028  *
00029  * @author Jill Reese and Kevin Long
00030  */
00031 class Vector : public NOX::Abstract::Vector 
00032 {
00033 
00034 public: 
00035 
00036   //! Copy constructor 
00037   Vector(const NOX::NOXPlaya::Vector& source, 
00038     NOX::CopyType type = DeepCopy);
00039 
00040   //! Copy constructor
00041   Vector(const Playa::Vector<double>& source, 
00042     NOX::CopyType type = DeepCopy);
00043 
00044   //! Copy constructor when user requests specific precision  
00045   Vector(const NOX::NOXPlaya::Vector& source, 
00046     int numdigits, 
00047     NOX::CopyType type = DeepCopy);
00048 
00049   //! Copy constructor when user requests specific precision 
00050   Vector(const Playa::Vector<double>& source, 
00051     int numdigits,
00052     NOX::CopyType type = DeepCopy);
00053 
00054   /* There's no need to write an explicit dtor for this class, because
00055    * the Playa vector cleans up its own memory. I've commented out 
00056    * this method for now, but it should probably just be deleted. 
00057    * - KL 12 July 2004 */ 
00058   ////! Destruct Vector.
00059   //~Vector();
00060 
00061   /** Access to a writable reference to the underlying Playa vector*/
00062   Playa::Vector<double>& getPlayaVector();
00063 
00064   /** Access to a read-only reference to the underlying Playa vector*/
00065   const Playa::Vector<double>& getPlayaVector() const;
00066 
00067   /** Access to the vector precision expected by user*/
00068   int getPrecision() const;
00069 
00070   //@{ \name Initialization methods.
00071 
00072   /** Initialize all elements to a constant */
00073   NOX::Abstract::Vector& init(double value);
00074 
00075   /** Assignment operator */
00076   NOX::Abstract::Vector& operator=(const NOX::NOXPlaya::Vector& y);
00077   /** Assignment operator */
00078   NOX::Abstract::Vector& operator=(const NOX::Abstract::Vector& y);
00079 
00080   /* Element access should not be implemented in this class; it should
00081    * be done through the LoadableVector and AccessibleVector 
00082    * interfaces of Playa.
00083    * -KL 12 July 2004  */
00084   // Store value in the i-th element of a vector 
00085   //void setElement(int i, const double& value);
00086 
00087   // Return the i-th element (const version).
00088   //const double& getElement(int i) const;
00089   
00090   /** Element-wise absolute value */
00091   NOX::Abstract::Vector& abs(const NOX::NOXPlaya::Vector& y);
00092   /** Element-wise absolute value */
00093   NOX::Abstract::Vector& abs(const NOX::Abstract::Vector& y);
00094   
00095   /** Element-wise reciprocal */
00096   NOX::Abstract::Vector& reciprocal(const NOX::NOXPlaya::Vector& y);
00097   /** Element-wise reciprocal */
00098   NOX::Abstract::Vector& reciprocal(const NOX::Abstract::Vector& y);
00099   
00100   //@}
00101   
00102   //@{ \name Update methods.
00103   
00104   // derived
00105   NOX::Abstract::Vector& scale(double gamma);
00106   
00107   // derived
00108   NOX::Abstract::Vector& scale(const NOX::NOXPlaya::Vector& a);
00109   NOX::Abstract::Vector& scale(const NOX::Abstract::Vector& a);
00110   
00111   // derived
00112   NOX::Abstract::Vector& update(double alpha, const NOX::NOXPlaya::Vector& a, double gamma = 0.0);
00113   NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a, double gamma = 0.0);
00114   
00115   // derived
00116   NOX::Abstract::Vector& update(double alpha, const NOX::NOXPlaya::Vector& a, 
00117     double beta, const NOX::NOXPlaya::Vector& b,
00118     double gamma = 0.0);
00119   NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a, 
00120     double beta, const NOX::Abstract::Vector& b,
00121     double gamma = 0.0);
00122   
00123   //@}
00124   
00125   //@{ \name Creating new Vectors. 
00126   
00127   // derived
00128 #ifdef TRILINOS_6
00129   NOX::Abstract::Vector* clone(NOX::CopyType type = NOX::DeepCopy) const;
00130 #else
00131   RCP<NOX::Abstract::Vector> clone(NOX::CopyType type = NOX::DeepCopy) const ;
00132 #endif
00133   
00134   //@}
00135   
00136   //@{ \name Norms.
00137   
00138   // derived
00139   double norm(NOX::Abstract::Vector::NormType type = NOX::Abstract::Vector::TwoNorm) const;
00140   
00141   // derived
00142   double norm(const NOX::NOXPlaya::Vector& weights) const;
00143   double norm(const NOX::Abstract::Vector& weights) const;
00144   
00145   //@}
00146   
00147   //@{ \name Dot products
00148   
00149   // derived
00150   double dot(const NOX::NOXPlaya::Vector& y) const;
00151   double dot(const NOX::Abstract::Vector& y) const;
00152   double innerProduct(const NOX::Abstract::Vector& y) const;
00153   
00154   //@}
00155   
00156   // derived
00157   //! The length of a Playa vector is known only by the vector space it belongs to
00158   //! We query the vector space and ask its dimension  
00159   int length() const;
00160 
00161   //! Prints out the vector to the specified stream. 
00162   /*! 
00163     For example, a vector would appear as
00164     \f[ \left[ \; 0.1 \; 2.34 \; 5 \; \right] \f] 
00165     It will be all on one line, with a single space between each entry, bracketed on either side.
00166   */
00167   ostream& leftshift(std::ostream& stream) const;
00168 
00169   // derived
00170   void print() const;
00171 
00172 private:
00173 
00174   /** user-specified precision for printing vectors */
00175   int precision;
00176 
00177   /** The Playa vector owned by this object. */
00178   Playa::Vector<double> x;
00179 };
00180 
00181 } // namespace Playa
00182 } // namespace NOX
00183 
00184 
00185 namespace std{
00186 //! Function for printing
00187 ostream& operator<<(std::ostream& stream, const NOX::NOXPlaya::Vector& v);
00188 }
00189 
00190 #endif

Site Contact