Thyra_SerialVectorStd.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_STD_HPP
00030 #define THYRA_VECTOR_SERIAL_STD_HPP
00031 
00032 #include "Thyra_SerialVectorStdDecl.hpp"
00033 #include "Thyra_SerialVectorBase.hpp"
00034 #include "Thyra_SerialVectorSpaceStd.hpp"
00035 #include "Teuchos_TestForException.hpp"
00036 #include "Teuchos_ScalarTraits.hpp"
00037 
00038 namespace Thyra {
00039 
00040 template<class Scalar>
00041 SerialVectorStd<Scalar>::SerialVectorStd(
00042   const Teuchos::RefCountPtr<const VectorSpaceBase<Scalar> > &vecSpc
00043   )
00044 {
00045   this->initialize(vecSpc);
00046 }
00047 
00048 template<class Scalar>
00049 SerialVectorStd<Scalar>::SerialVectorStd(
00050   const Index dim
00051   )
00052 {
00053   this->initialize(dim);
00054 }
00055 
00056 template<class Scalar>
00057 SerialVectorStd<Scalar>::SerialVectorStd(
00058   const Teuchos::RefCountPtr<Scalar>                          &v
00059   ,const Index                                                vs
00060   ,const Index                                                dim
00061   ,const Teuchos::RefCountPtr<const VectorSpaceBase<Scalar> > &vecSpc
00062   )
00063 {
00064   this->initialize(v,vs,dim,vecSpc);
00065 }
00066 
00067 template<class Scalar>
00068 void SerialVectorStd<Scalar>::initialize(
00069   const Teuchos::RefCountPtr<const VectorSpaceBase<Scalar> > &vecSpc
00070   )
00071 {
00072   const Index dim = vecSpc->dim();
00073   this->initialize(
00074     Teuchos::rcp( new Scalar[dim], Teuchos::DeallocArrayDelete<Scalar>(), true )
00075     ,1
00076     ,dim
00077     ,vecSpc
00078     );
00079 }
00080 
00081 template<class Scalar>
00082 void SerialVectorStd<Scalar>::initialize(
00083   const Index dim
00084   )
00085 {
00086   this->initialize(
00087     Teuchos::rcp( new Scalar[dim], Teuchos::DeallocArrayDelete<Scalar>(), true )
00088     ,1
00089     ,dim
00090     );
00091 }
00092 
00093 template<class Scalar>
00094 void SerialVectorStd<Scalar>::initialize(
00095   const Teuchos::RefCountPtr<Scalar>                          &v
00096   ,const Index                                                vs
00097   ,const Index                                                dim
00098   ,const Teuchos::RefCountPtr<const VectorSpaceBase<Scalar> > &vecSpc
00099   )
00100 {
00101   if(vecSpc.get()) {
00102 #ifdef _DEBUG
00103     TEST_FOR_EXCEPTION( vecSpc.get()!=NULL && dim != vecSpc->dim(), std::invalid_argument, "SerialVectorStd<Scalar>::initialize(...): Error!" );
00104 #endif
00105     space_serial_ = vecSpc;
00106   }
00107   else {
00108     space_serial_ = Teuchos::rcp(new SerialVectorSpaceStd<Scalar>(dim));
00109   }
00110   v_       = v;
00111   vs_      = vs;
00112   dim_     = dim;
00113 }
00114 
00115 // Overridden from SerialVectorBase
00116 
00117 template<class Scalar>
00118 void SerialVectorStd<Scalar>::getData( Scalar** values, Index* stride )
00119 {
00120 #ifdef _DEBUG
00121   TEST_FOR_EXCEPT(values==NULL || stride==NULL);
00122 #endif
00123   *values = v_.get();
00124   *stride = vs_;
00125 }
00126 
00127 template<class Scalar>
00128 void SerialVectorStd<Scalar>::commitData( Scalar** values )
00129 {
00130 #ifdef _DEBUG
00131   TEST_FOR_EXCEPT( values==NULL || *values==NULL );
00132 #endif
00133   // There is nothing to commit, the client had direct pointer access to internal data!
00134   *values = NULL;
00135 }
00136 
00137 template<class Scalar>
00138 void SerialVectorStd<Scalar>::getData( const Scalar** values, Index* stride ) const
00139 {
00140 #ifdef _DEBUG
00141   TEST_FOR_EXCEPT(values==NULL || stride==NULL);
00142 #endif
00143   *values = v_.get();
00144   *stride = vs_;
00145 }
00146 
00147 template<class Scalar>
00148 void SerialVectorStd<Scalar>::freeData( const Scalar** values ) const
00149 {
00150 #ifdef _DEBUG
00151   TEST_FOR_EXCEPT( values==NULL || *values==NULL );
00152 #endif
00153   // There is nothing to free!
00154   *values = NULL;
00155 }
00156 
00157 // Overridden from VectorBase
00158 
00159 template<class Scalar>
00160 Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> >
00161 SerialVectorStd<Scalar>::space() const
00162 {
00163   return space_serial_;
00164 }
00165 
00166 // Overridden from Teuchos::Describable
00167 
00168 template<class Scalar>
00169 std::string SerialVectorStd<Scalar>::description() const
00170 {
00171   return (std::string("Thyra::SerialVectorStd<") + Teuchos::ScalarTraits<Scalar>::name() + std::string(">"));
00172 }
00173 
00174 } // end namespace Thyra
00175 
00176 #endif // THYRA_VECTOR_SERIAL_STD_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