NOX_Playa_Vector.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 /*! \file NOX_Playa_Vector.H - Header file for NOX::NOXPlaya::Vector. */
00051 
00052 #ifndef NOX_Playa_VECTOR_H
00053 #define NOX_Playa_VECTOR_H
00054 
00055 #include <iostream>
00056 #include "NOX_Abstract_Vector.H" // base class
00057 #include "NOX_Common.H" // for #include<vector> 
00058 #include "PlayaVectorDecl.hpp" // definitions for Playa Vectors
00059 #include "PlayaVectorSpaceDecl.hpp"
00060 
00061 
00062 namespace NOX 
00063 {
00064 
00065 
00066 namespace NOXPlaya 
00067 {
00068 using Teuchos::RCP;
00069   
00070 /** Implementation of the NOX::Abstract::Vector interface for 
00071  * Playa::Vector<double> (using Playa handle to PlayaCore).
00072  *
00073  * @author Jill Reese and Kevin Long
00074  */
00075 class Vector : public NOX::Abstract::Vector 
00076 {
00077 
00078 public: 
00079 
00080   //! Copy constructor 
00081   Vector(const NOX::NOXPlaya::Vector& source, 
00082     NOX::CopyType type = DeepCopy);
00083 
00084   //! Copy constructor
00085   Vector(const Playa::Vector<double>& source, 
00086     NOX::CopyType type = DeepCopy);
00087 
00088   //! Copy constructor when user requests specific precision  
00089   Vector(const NOX::NOXPlaya::Vector& source, 
00090     int numdigits, 
00091     NOX::CopyType type = DeepCopy);
00092 
00093   //! Copy constructor when user requests specific precision 
00094   Vector(const Playa::Vector<double>& source, 
00095     int numdigits,
00096     NOX::CopyType type = DeepCopy);
00097 
00098   /* There's no need to write an explicit dtor for this class, because
00099    * the Playa vector cleans up its own memory. I've commented out 
00100    * this method for now, but it should probably just be deleted. 
00101    * - KL 12 July 2004 */ 
00102   ////! Destruct Vector.
00103   //~Vector();
00104 
00105   /** Access to a writable reference to the underlying Playa vector*/
00106   Playa::Vector<double>& getPlayaVector();
00107 
00108   /** Access to a read-only reference to the underlying Playa vector*/
00109   const Playa::Vector<double>& getPlayaVector() const;
00110 
00111   /** Access to the vector precision expected by user*/
00112   int getPrecision() const;
00113 
00114   //@{ \name Initialization methods.
00115 
00116   /** Initialize all elements to a constant */
00117   NOX::Abstract::Vector& init(double value);
00118 
00119   /** Assignment operator */
00120   NOX::Abstract::Vector& operator=(const NOX::NOXPlaya::Vector& y);
00121   /** Assignment operator */
00122   NOX::Abstract::Vector& operator=(const NOX::Abstract::Vector& y);
00123 
00124   /* Element access should not be implemented in this class; it should
00125    * be done through the LoadableVector and AccessibleVector 
00126    * interfaces of Playa.
00127    * -KL 12 July 2004  */
00128   // Store value in the i-th element of a vector 
00129   //void setElement(int i, const double& value);
00130 
00131   // Return the i-th element (const version).
00132   //const double& getElement(int i) const;
00133   
00134   /** Element-wise absolute value */
00135   NOX::Abstract::Vector& abs(const NOX::NOXPlaya::Vector& y);
00136   /** Element-wise absolute value */
00137   NOX::Abstract::Vector& abs(const NOX::Abstract::Vector& y);
00138   
00139   /** Element-wise reciprocal */
00140   NOX::Abstract::Vector& reciprocal(const NOX::NOXPlaya::Vector& y);
00141   /** Element-wise reciprocal */
00142   NOX::Abstract::Vector& reciprocal(const NOX::Abstract::Vector& y);
00143   
00144   //@}
00145   
00146   //@{ \name Update methods.
00147   
00148   // derived
00149   NOX::Abstract::Vector& scale(double gamma);
00150   
00151   // derived
00152   NOX::Abstract::Vector& scale(const NOX::NOXPlaya::Vector& a);
00153   NOX::Abstract::Vector& scale(const NOX::Abstract::Vector& a);
00154   
00155   // derived
00156   NOX::Abstract::Vector& update(double alpha, const NOX::NOXPlaya::Vector& a, double gamma = 0.0);
00157   NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a, double gamma = 0.0);
00158   
00159   // derived
00160   NOX::Abstract::Vector& update(double alpha, const NOX::NOXPlaya::Vector& a, 
00161     double beta, const NOX::NOXPlaya::Vector& b,
00162     double gamma = 0.0);
00163   NOX::Abstract::Vector& update(double alpha, const NOX::Abstract::Vector& a, 
00164     double beta, const NOX::Abstract::Vector& b,
00165     double gamma = 0.0);
00166   
00167   //@}
00168   
00169   //@{ \name Creating new Vectors. 
00170   
00171   // derived
00172 #ifdef TRILINOS_6
00173   NOX::Abstract::Vector* clone(NOX::CopyType type = NOX::DeepCopy) const;
00174 #else
00175   RCP<NOX::Abstract::Vector> clone(NOX::CopyType type = NOX::DeepCopy) const ;
00176 #endif
00177   
00178   //@}
00179   
00180   //@{ \name Norms.
00181   
00182   // derived
00183   double norm(NOX::Abstract::Vector::NormType type = NOX::Abstract::Vector::TwoNorm) const;
00184   
00185   // derived
00186   double norm(const NOX::NOXPlaya::Vector& weights) const;
00187   double norm(const NOX::Abstract::Vector& weights) const;
00188   
00189   //@}
00190   
00191   //@{ \name Dot products
00192   
00193   // derived
00194   double dot(const NOX::NOXPlaya::Vector& y) const;
00195   double dot(const NOX::Abstract::Vector& y) const;
00196   double innerProduct(const NOX::Abstract::Vector& y) const;
00197   
00198   //@}
00199   
00200   // derived
00201   //! The length of a Playa vector is known only by the vector space it belongs to
00202   //! We query the vector space and ask its dimension  
00203   NOX::size_type length() const;
00204 
00205   //! Prints out the vector to the specified stream. 
00206   /*! 
00207     For example, a vector would appear as
00208     \f[ \left[ \; 0.1 \; 2.34 \; 5 \; \right] \f] 
00209     It will be all on one line, with a single space between each entry, bracketed on either side.
00210   */
00211   std::ostream& leftshift(std::ostream& stream) const;
00212 
00213   // derived
00214   void print() const;
00215 
00216 private:
00217 
00218   /** user-specified precision for printing vectors */
00219   int precision;
00220 
00221   /** The Playa vector owned by this object. */
00222   Playa::Vector<double> x;
00223 };
00224 
00225 } // namespace Playa
00226 } // namespace NOX
00227 
00228 
00229 namespace std{
00230 //! Function for printing
00231 ostream& operator<<(std::ostream& stream, const NOX::NOXPlaya::Vector& v);
00232 }
00233 
00234 #endif

Site Contact