Thyra_VectorHandleOpsImpl.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_VECTOR_HANDLE_OPS_IMPL_HPP
00030 #define THYRA_VECTOR_HANDLE_OPS_IMPL_HPP
00031 
00032 #include "Thyra_ConfigDefs.hpp"
00033 #include "Thyra_VectorHandleOpsDecl.hpp"
00034 
00035 namespace Thyra
00036 {
00037   
00038   template <class Scalar> inline  
00039   void setToConstant(Vector<Scalar>& x, const Scalar& a)
00040   {
00041     put_scalar(a, x.ptr().get());
00042   }
00043 
00044   template <class Scalar> inline  
00045   void zeroOut(Vector<Scalar>& x)
00046   {
00047     setToConstant(x, Teuchos::ScalarTraits<Scalar>::zero());
00048   }
00049 
00050   THYRA_UNARY_VECTOR_OP(abs, absInto, abs, "absolute value")
00051     
00052   THYRA_UNARY_VECTOR_OP(reciprocal, reciprocalInto, reciprocal, "reciprocal")
00053 
00054   THYRA_UNARY_VECTOR_ROP_MAG(norm, norm, "natural norm")
00055     
00056   THYRA_UNARY_VECTOR_ROP_MAG(norm1, norm_1, "1-norm")
00057 
00058   THYRA_UNARY_VECTOR_ROP_MAG(norm2, norm_2, "2-norm")
00059 
00060   THYRA_UNARY_VECTOR_ROP_MAG(normInf, norm_inf, "inf-norm")
00061 
00062   THYRA_UNARY_VECTOR_ROP(sum, sum, "sum of the elements")
00063 
00064   THYRA_BINARY_VECTOR_ROP(inner, scalarProd, "Inner or scalar product")
00065 
00066   THYRA_UNARY_VECTOR_ROP_MAG(max, max, "max element")
00067 
00068   THYRA_UNARY_VECTOR_ROP_MAG(min, min, "min element")
00069 
00070   template <class Scalar> inline 
00071   Scalar maxloc(const Converter<Scalar, ConstVector<Scalar> >& x, Index& index) 
00072   {
00073     Scalar maxEl;
00074     Scalar* maxElP = &maxEl;
00075     int* indexP = &index;
00076     Thyra::max(*(toVector(x).constPtr()), maxElP, indexP); 
00077     return maxEl;
00078   }
00079 
00080   template <class Scalar> inline 
00081   Scalar minloc(const Converter<Scalar, ConstVector<Scalar> >& x, Index& index) 
00082   {
00083     Scalar minEl;
00084     Scalar* minElP = &minEl;
00085     int* indexP = &index;
00086     Thyra::min(*(toVector(x).constPtr()), minElP, indexP); 
00087     return minEl;
00088   }
00089 
00090   template <class Scalar> inline  
00091   Scalar minloc(const Converter<Scalar, ConstVector<Scalar> >& x, 
00092              const Scalar& bound, Index& index)
00093   {
00094     Scalar minEl;
00095     Scalar* minElP = &minEl;
00096     int* indexP = &index;
00097     Thyra::minGreaterThanBound(*(toVector(x).constPtr()), bound, minElP, indexP); 
00098     return minEl;
00099   }
00100 
00101   template <class Scalar> inline  
00102   Scalar maxloc(const Converter<Scalar, ConstVector<Scalar> >& x, 
00103              const Scalar& bound, Index& index)
00104   {
00105     Scalar maxEl;
00106     Scalar* maxElP = &maxEl;
00107     int* indexP = &index;
00108     Thyra::maxLessThanBound(*(toVector(x).constPtr()), bound, maxElP, indexP); 
00109     return maxEl;
00110   }
00111 
00112   template <class Scalar> inline  
00113   void dotStarInto(const Converter<Scalar, ConstVector<Scalar> >& x, 
00114                    const Converter<Scalar, ConstVector<Scalar> >& y,
00115                    Vector<Scalar>& result)
00116     {
00117       zeroOut(result);
00118       Thyra::ele_wise_prod(Teuchos::ScalarTraits<Scalar>::one(), 
00119                            *(toVector(x).constPtr()), *(toVector(y).constPtr()), 
00120                            result.ptr().get());
00121     }
00122 
00123   template <class Scalar> inline  
00124   Vector<Scalar> dotStar(const Converter<Scalar, ConstVector<Scalar> >& xIn, 
00125                          const Converter<Scalar, ConstVector<Scalar> >& y)
00126     {
00127       ConstVector<Scalar> x = toVector(xIn);
00128       Vector<Scalar> result = space(x).createMember();
00129       dotStarInto(x, toVector(y), result);
00130       return result;
00131     }
00132 
00133   template <class Scalar> inline  
00134   void dotSlashInto(const Converter<Scalar, ConstVector<Scalar> >& x, 
00135                    const Converter<Scalar, ConstVector<Scalar> >& y,
00136                    Vector<Scalar>& result)
00137     {
00138       zeroOut(result);
00139       Thyra::ele_wise_divide(Teuchos::ScalarTraits<Scalar>::one(), 
00140                              *(toVector(x).constPtr()), *(toVector(y).constPtr()), 
00141                              result.ptr().get());
00142     }
00143 
00144   template <class Scalar> inline  
00145   Vector<Scalar> dotSlash(const Converter<Scalar, ConstVector<Scalar> >& xIn, 
00146                           const Converter<Scalar, ConstVector<Scalar> >& y)
00147     {
00148       ConstVector<Scalar> x = xIn.convert();
00149       Vector<Scalar> result = space(x).createMember();
00150       dotSlashInto(x, toVector(y), result);
00151       return result;
00152     }
00153 
00154   template <class Scalar> inline  
00155   void axpy(const Scalar& a, const Converter<Scalar, ConstVector<Scalar> >& xIn, 
00156             Vector<Scalar>& y)
00157   {
00158     ConstVector<Scalar> x = xIn.convert();
00159     VectorBase<Scalar>* p = y.ptr().get();
00160     const VectorBase<Scalar>* px = x.rawPtr();
00161     TEST_FOR_EXCEPT(px==0);
00162     Vp_StV(p, a, *px);
00163   }
00164 
00165   template <class Scalar> inline  
00166   void scale(Vector<Scalar>& x, const Scalar& a)
00167   {
00168     VectorBase<Scalar>* p = x.rawPtr();
00169     TEST_FOR_EXCEPT(p==0);
00170     Thyra::scale(a, p);
00171   }
00172 
00173   template <class Scalar> inline     
00174   void scaleInto(const Converter<Scalar, ConstVector<Scalar> >& x,
00175                  const Scalar& alpha, Vector<Scalar>& result)
00176   {
00177     x.evalInto(result);
00178     result.scale(alpha);
00179   }
00180  
00181 }
00182 
00183 #endif // THYRA_VECTOR_HANDLE_OPS_IMPL_HPP

Generated on Thu Sep 18 12:33:03 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1