Thyra_SerialVectorBase.hpp

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_SERIAL_BASE_HPP
00030 #define THYRA_VECTOR_SERIAL_BASE_HPP
00031 
00032 #include "Thyra_SerialVectorBaseDecl.hpp"
00033 #include "Thyra_apply_op_helper.hpp"
00034 #include "Teuchos_Workspace.hpp"
00035 #include "Teuchos_TestForException.hpp"
00036 
00037 namespace Thyra {
00038 
00039 template<class Scalar>
00040 SerialVectorBase<Scalar>::SerialVectorBase()
00041   :in_applyOp_(false)
00042 {}
00043 
00044 // Virtual methods with default implementations
00045 
00046 template<class Scalar>
00047 void SerialVectorBase<Scalar>::getData( const Scalar** values, Index* stride ) const
00048 {
00049   const_cast<SerialVectorBase<Scalar>*>(this)->getData(const_cast<Scalar**>(values),stride);
00050 }
00051 
00052 template<class Scalar>
00053 void SerialVectorBase<Scalar>::freeData( const Scalar** values ) const
00054 {
00055   const_cast<SerialVectorBase<Scalar>*>(this)->commitData(const_cast<Scalar**>(values));
00056 }
00057 
00058 // Overridden from VectorBase
00059 
00060 template<class Scalar>
00061 void SerialVectorBase<Scalar>::applyOp(
00062   const RTOpPack::RTOpT<Scalar>   &op
00063   ,const int                      num_vecs
00064   ,const VectorBase<Scalar>*      vecs[]
00065   ,const int                      num_targ_vecs
00066   ,VectorBase<Scalar>*            targ_vecs[]
00067   ,RTOpPack::ReductTarget         *reduct_obj
00068   ,const Index                    first_ele
00069   ,const Index                    sub_dim
00070   ,const Index                    global_offset
00071   ) const
00072 {
00073 #ifdef _DEBUG
00074   TEST_FOR_EXCEPTION(
00075     in_applyOp_, std::logic_error
00076     ,"SerialVectorBase::applyOp(...): Error, something is not right here!" );
00077   Thyra::apply_op_validate_input(
00078     "SerialVectorBase<>::applyOp(...)",*this->space()
00079     ,op,num_vecs,vecs,num_targ_vecs,targ_vecs,reduct_obj,first_ele,sub_dim,global_offset
00080     );
00081 #endif
00082   in_applyOp_ = true;
00083   Thyra::apply_op_serial(
00084     *(this->space())
00085     ,op,num_vecs,vecs,num_targ_vecs,targ_vecs,reduct_obj
00086     ,first_ele,sub_dim,global_offset
00087     );
00088   in_applyOp_ = false;
00089 }
00090 
00091 template<class Scalar>
00092 void SerialVectorBase<Scalar>::getSubVector( const Range1D& rng_in, RTOpPack::SubVectorT<Scalar>* sub_vec ) const
00093 {
00094   const Index   this_dim = this->space()->dim(); // ToDo: Cache this!
00095   const Range1D rng      = RangePack::full_range(rng_in,1,this_dim);
00096 #ifdef _DEBUG
00097   TEST_FOR_EXCEPTION(
00098     rng.ubound() > this_dim, std::out_of_range
00099     ,"SerialVectorBase<Scalar>::getSubVector(...) : Error, "
00100     "rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] "
00101     "is not in the range [1,this->dim()] = [1," << this_dim << "]!" );
00102 #endif
00103   const Scalar *values = NULL; Index stride = 0;
00104   this->getData(&values,&stride);
00105   sub_vec->initialize(
00106     rng.lbound()-1                   // globalOffset
00107     ,rng.size()                      // subDim
00108     ,values+stride*(rng.lbound()-1)  // values
00109     ,stride                          // stride
00110     );
00111 }
00112 
00113 template<class Scalar>
00114 void SerialVectorBase<Scalar>::freeSubVector( RTOpPack::SubVectorT<Scalar>* sub_vec ) const
00115 {
00116   sub_vec->set_uninitialized();  // Nothing to deallocate!
00117 }
00118 
00119 template<class Scalar>
00120 void SerialVectorBase<Scalar>::getSubVector( const Range1D& rng_in, RTOpPack::MutableSubVectorT<Scalar>* sub_vec )
00121 {
00122   const Index   this_dim = this->space()->dim(); // ToDo: Cache this!
00123   const Range1D rng      = RangePack::full_range(rng_in,1,this_dim);
00124 #ifdef _DEBUG
00125   TEST_FOR_EXCEPTION(
00126     rng.ubound() > this_dim, std::out_of_range
00127     ,"SerialVectorBase<Scalar>::getSubVector(...) : Error, "
00128     "rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] "
00129     "is not in the range [1,this->dim()] = [1," << this_dim << "]!" );
00130 #endif
00131   Scalar *values = NULL; Index stride = 0;
00132   this->getData(&values,&stride);
00133   sub_vec->initialize(
00134     rng.lbound()-1                   // globalOffset
00135     ,rng.size()                      // subDim
00136     ,values+stride*(rng.lbound()-1)  // values
00137     ,stride                          // stride
00138     );
00139 }
00140 
00141 template<class Scalar>
00142 void SerialVectorBase<Scalar>::commitSubVector( RTOpPack::MutableSubVectorT<Scalar>* sub_vec )
00143 {
00144   sub_vec->set_uninitialized();  // Nothing to deallocate!
00145 }
00146 
00147 template<class Scalar>
00148 void SerialVectorBase<Scalar>::setSubVector( const RTOpPack::SparseSubVectorT<Scalar>& sub_vec )
00149 {
00150   VectorBase<Scalar>::setSubVector(sub_vec);  // This implementation is okay
00151 }
00152 
00153 } // end namespace Thyra
00154 
00155 #endif // THYRA_VECTOR_SERIAL_BASE_HPP

Generated on Thu Sep 18 12:39:52 2008 for Thyra ANA Operator/VectorBase Interfaces and Related Software by doxygen 1.3.9.1