Thyra_VectorSpaceBase.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_SPACE_BASE_HPP
00030 #define THYRA_VECTOR_SPACE_BASE_HPP
00031 
00032 #include "Thyra_VectorSpaceBaseDecl.hpp"
00033 #include "Thyra_VectorBase.hpp"
00034 #include "Thyra_VectorStdOps.hpp"
00035 #include "Thyra_MultiVectorStdOps.hpp"
00036 
00037 #ifdef TEUCHOS_DEBUG
00038 #define THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00039 #endif
00040 
00041 namespace Thyra {
00042 
00043 // Virtual functions with default implementations
00044 
00045 template<class Scalar>
00046 bool VectorSpaceBase<Scalar>::isEuclidean() const
00047 {
00048   return false;
00049 }
00050 
00051 template<class Scalar>
00052 bool VectorSpaceBase<Scalar>::hasInCoreView(const Range1D& rng, const EViewType viewType, const EStrideType strideType) const
00053 {
00054   return false;
00055 }
00056 
00057 template<class Scalar>
00058 RCP< const VectorSpaceBase<Scalar> >
00059 VectorSpaceBase<Scalar>::clone() const
00060 {
00061   return Teuchos::null;
00062 }
00063 
00064 } // end namespace Thyra
00065 
00066 // Nonmember functions
00067 
00068 template<class Scalar>
00069 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00070 Thyra::makeHaveOwnership( const RCP<const VectorSpaceBase<Scalar> > &vs )
00071 {
00072   if( vs.has_ownership() ) return vs;
00073   RCP<const Thyra::VectorSpaceBase<Scalar> > _vs = vs->clone();
00074   TEST_FOR_EXCEPTION(
00075     _vs.get() == NULL, std::logic_error
00076     ,"Thyra::makeHaveOwnership(vs): Error, the concrete VectorSpaceBase object identified as \'"
00077     << vs->description() << "\' does not support the clone() function!"
00078     );
00079   return _vs;
00080 }
00081 
00082 template<class Scalar>
00083 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00084 Thyra::createMember(
00085   const RCP<const VectorSpaceBase<Scalar> > &vs,
00086   const std::string &label
00087   )
00088 {
00089   RCP<VectorBase<Scalar> > v = vs->createMember();
00090 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00091   assign(&*v,Teuchos::ScalarTraits<Scalar>::nan());
00092 #endif  
00093   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase", &v );
00094   if(label.length()) v->setObjectLabel(label);
00095   return v;
00096 }
00097   
00098 template<class Scalar>
00099 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00100 Thyra::createMember(
00101   const VectorSpaceBase<Scalar> &vs, const std::string &label
00102   )
00103 {
00104   return createMember(Teuchos::rcp(&vs,false),label);
00105 }
00106 
00107 template<class Scalar>
00108 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00109 Thyra::createMembers(
00110   const RCP<const VectorSpaceBase<Scalar> > &vs,
00111   int numMembers,  const std::string &label
00112   )
00113 {
00114   RCP<MultiVectorBase<Scalar> >
00115     mv = vs->createMembers(numMembers);
00116 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00117   assign(&*mv,Teuchos::ScalarTraits<Scalar>::nan());
00118 #endif  
00119   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase", &mv );
00120   if(label.length()) mv->setObjectLabel(label);
00121   return mv;
00122 }
00123 
00124 template<class Scalar>
00125 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00126 Thyra::createMembers(
00127   const VectorSpaceBase<Scalar> &vs, int numMembers,
00128   const std::string &label
00129   )
00130 {
00131   return createMembers(Teuchos::rcp(&vs,false),numMembers,label);
00132 }
00133 
00134 template<class Scalar>
00135 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00136 Thyra::createMemberView(
00137   const RCP<const VectorSpaceBase<Scalar> > &vs,
00138   const RTOpPack::SubVectorView<Scalar> &raw_v,
00139   const std::string &label
00140   )
00141 {
00142   RCP<VectorBase<Scalar> >
00143     v = vs->createMemberView(raw_v);
00144   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase", &v );
00145   if(label.length()) v->setObjectLabel(label);
00146   return v;
00147 }
00148 
00149 template<class Scalar>
00150 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00151 Thyra::createMemberView(
00152   const VectorSpaceBase<Scalar> &vs,
00153   const RTOpPack::SubVectorView<Scalar> &raw_v,
00154   const std::string &label
00155   )
00156 {
00157   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00158 }
00159 
00160 template<class Scalar>
00161 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00162 Thyra::createMemberView(
00163   const RCP<const VectorSpaceBase<Scalar> > &vs,
00164   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00165   const std::string &label
00166   )
00167 {
00168   RCP<const VectorBase<Scalar> >
00169     v = vs->createMemberView(raw_v);
00170   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase", &v );
00171   if(label.length())
00172     Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(v)->setObjectLabel(label);
00173   return v;
00174 }
00175 
00176 template<class Scalar>
00177 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00178 Thyra::createMemberView(
00179   const VectorSpaceBase<Scalar> &vs,
00180   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00181   const std::string &label
00182   )
00183 {
00184   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00185 }
00186 
00187 template<class Scalar>
00188 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00189 Thyra::createMembersView(
00190   const RCP<const VectorSpaceBase<Scalar> > &vs,
00191   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00192   const std::string &label
00193   )
00194 {
00195   RCP<MultiVectorBase<Scalar> >
00196     mv = vs->createMembersView(raw_mv);
00197   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase", &mv );
00198   if(label.length()) mv->setObjectLabel(label);
00199   return mv;
00200 }
00201 
00202 template<class Scalar>
00203 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00204 Thyra::createMembersView(
00205   const VectorSpaceBase<Scalar> &vs,
00206   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00207   const std::string &label
00208   )
00209 {
00210   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00211 }
00212 
00213 template<class Scalar>
00214 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00215 Thyra::createMembersView(
00216   const RCP<const VectorSpaceBase<Scalar> > &vs,
00217   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00218   const std::string &label
00219   )
00220 {
00221   RCP<const MultiVectorBase<Scalar> >
00222     mv = vs->createMembersView(raw_mv);
00223   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase", &mv );
00224   if(label.length())
00225     Teuchos::rcp_const_cast<MultiVectorBase<Scalar> >(mv)->setObjectLabel(label);
00226   return mv;
00227 }
00228 
00229 template<class Scalar>
00230 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00231 Thyra::createMembersView( const VectorSpaceBase<Scalar> &vs,
00232   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00233   const std::string &label
00234   )
00235 {
00236   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00237 }
00238 
00239 #endif // THYRA_VECTOR_SPACE_BASE_HPP

Generated on Tue Oct 20 12:46:45 2009 for Fundamental Thyra ANA Operator/Vector Interfaces by doxygen 1.4.7