TSFMultiVectorOperatorImpl.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 /* ***********************************************************************
00003 // 
00004 //           TSFExtended: Trilinos Solver Framework Extended
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 TSFMULTIVECTOROPERATOR_IMPL_HPP
00030 #define TSFMULTIVECTOROPERATOR_IMPL_HPP
00031 
00032 #include "TSFMultiVectorOperatorDecl.hpp"
00033 #include "Thyra_VectorStdOps.hpp"
00034 #include "Thyra_DefaultSpmdVectorSpace.hpp"
00035 #include "TSFVectorImpl.hpp"
00036 
00037 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00038 #include "TSFLinearOperatorImpl.hpp"
00039 #include "TSFSimpleTransposedOpImpl.hpp"
00040 #include "TSFSimplifiedLinearOpBaseImpl.hpp"
00041 #endif
00042 
00043 namespace TSFExtended
00044 {
00045 
00046 /*
00047  * Construct from an array of vectors and a specifier for the 
00048  * domain space. 
00049  */
00050 template <class Scalar> inline
00051 MultiVectorOperator<Scalar>
00052 ::MultiVectorOperator(const Teuchos::Array<Vector<Scalar> >& cols,
00053   const VectorSpace<Scalar>& domain)
00054   : cols_(cols),
00055     domain_(domain.ptr()),
00056     range_()
00057 {
00058   TEST_FOR_EXCEPTION(cols.size() == 0, std::runtime_error,
00059     "empty multivector given to MultiVectorOperator ctor");
00060   range_ = cols[0].space();
00061   for (int i=1; i<cols.size(); i++)
00062   {
00063     TEST_FOR_EXCEPTION(cols[i].space() != range_, std::runtime_error,
00064       "inconsistent vector spaces in  MultiVectorOperator ctor");
00065   }
00066 }
00067 
00068 
00069 /*
00070  * Apply does an element-by-element multiply between the input 
00071  * vector, x, and the diagonal values.
00072  */
00073 template <class Scalar> inline
00074 void MultiVectorOperator<Scalar>
00075 ::generalApply(
00076   const Thyra::EOpTransp            M_trans,
00077   const Thyra::VectorBase<Scalar>    &x,
00078   Thyra::VectorBase<Scalar>          *y,
00079   const Scalar            alpha ,
00080   const Scalar            beta  
00081   ) const 
00082 {
00083   if (M_trans == Thyra::NOTRANS)
00084   {
00085     Vector<Scalar> vx 
00086       = rcp(const_cast<Thyra::VectorBase<Scalar>*>(&x), false);
00087     Vector<Scalar> vy = rcp(y, false);
00088 
00089     if (beta != 0.0) vy.scale(beta);
00090     else vy.zero();
00091 
00092     for (int i=0; i<cols_.size(); i++)
00093     {
00094       vy.update(alpha * vx.getElement(i), cols_[i]);
00095     }
00096   }
00097   else
00098   {
00099     Vector<Scalar> vx 
00100       = rcp(const_cast<Thyra::VectorBase<Scalar>*>(&x), false);
00101     Vector<Scalar> vy = rcp(y, false);
00102 
00103     if (beta != 0.0) vy.scale(beta);
00104     else vy.zero();
00105 
00106     for (int i=0; i<cols_.size(); i++)
00107     {
00108       vy.addToElement(i, alpha * vx.dot(cols_[i]));
00109     }
00110   }
00111 }
00112 
00113 
00114 
00115 
00116 /* Return the domain of the operator */
00117 template <class Scalar> inline
00118 RCP< const Thyra::VectorSpaceBase<Scalar> > 
00119 MultiVectorOperator<Scalar>
00120 ::domain() const 
00121 {return domain_.ptr();}
00122  
00123 
00124 
00125 
00126 /* Return the range of the operator */
00127 template <class Scalar> inline
00128 RCP< const Thyra::VectorSpaceBase<Scalar> > 
00129 MultiVectorOperator<Scalar>
00130 ::range() const 
00131 {return range_.ptr();}
00132 
00133 
00134 
00135 /* Return the kth row  */
00136 template <class Scalar> inline
00137 void MultiVectorOperator<Scalar>
00138 ::getRow(const int& k, 
00139   Teuchos::Array<int>& indices, 
00140   Teuchos::Array<Scalar>& values) const
00141 {
00142   indices.resize(cols_.size());
00143   values.resize(cols_.size());
00144   for (int j=0; j<cols_.size(); j++)
00145   {
00146     indices[j] = j;
00147     values[j] = cols_[j].getElement(k);
00148   }
00149 }
00150 
00151 
00152   
00153 template <class Scalar> inline
00154 LinearOperator<Scalar> multiVectorOperator(
00155   const Teuchos::Array<Vector<Scalar> >& cols,
00156   const VectorSpace<Scalar>& domain)
00157 {
00158   RCP<LinearOpBase<Scalar> > A
00159     = rcp(new MultiVectorOperator<Scalar>(cols, domain));
00160 
00161   return A;
00162 }
00163 
00164 
00165 }
00166 
00167 #endif

Site Contact