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

Generated on Wed May 12 21:42:09 2010 for Fundamental Thyra ANA Operator/Vector Interfaces by  doxygen 1.4.7