Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_VectorSpaceBase_def.hpp
Go to the documentation of this file.
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_DEF_HPP
00030 #define THYRA_VECTOR_SPACE_BASE_DEF_HPP
00031 
00032 #include "Thyra_VectorSpaceBase_decl.hpp"
00033 #include "Thyra_VectorBase.hpp"
00034 #include "Thyra_MultiVectorBase.hpp"
00035 #include "Teuchos_Tuple.hpp"
00036 
00037 
00038 #ifdef TEUCHOS_DEBUG
00039 #  define THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00040 #endif
00041 
00042 
00043 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00044 #include "RTOpPack_TOpAssignScalar.hpp"
00045 // 2008/02/13: rabartl: This include represents a bad dependency to a concrete
00046 // implementation of an RTOp. However, this is better than a dependency on
00047 // Thyra_[Multi]VectorStdOps.hpp!  I don't know of a better alternative at
00048 // this point.
00049 // 2010/01/13: rabartl: I could just write a simple RTOp implementation to
00050 // assgin to null to remove this dependency.
00051 #endif // THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00052 
00053 
00054 namespace Thyra {
00055 
00056 
00057 //
00058 // VectorSpaceBase
00059 //
00060 
00061 
00062 
00063 // Virtual functions with default implementations
00064 
00065 
00066 template<class Scalar>
00067 bool VectorSpaceBase<Scalar>::isEuclidean() const
00068 {
00069   return false;
00070 }
00071 
00072 
00073 template<class Scalar>
00074 bool VectorSpaceBase<Scalar>::hasInCoreView(const Range1D& rng,
00075   const EViewType viewType, const EStrideType strideType) const
00076 {
00077   return false;
00078 }
00079 
00080 
00081 template<class Scalar>
00082 RCP< const VectorSpaceBase<Scalar> >
00083 VectorSpaceBase<Scalar>::clone() const
00084 {
00085   return Teuchos::null;
00086 }
00087 
00088 
00089 // Deprecated
00090 
00091 
00092 template<class Scalar>
00093 void VectorSpaceBase<Scalar>::scalarProds(
00094   const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y,
00095   Scalar scalarProds_out[]
00096   ) const
00097 {
00098   this->scalarProds( X, Y,
00099     Teuchos::arrayView(scalarProds_out, X.domain()->dim()) );
00100 }
00101 
00102 
00103 } // end namespace Thyra
00104 
00105 
00106 //
00107 // Nonmember functions
00108 //
00109 
00110 
00111 template<class Scalar>
00112 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00113 Thyra::makeHaveOwnership( const RCP<const VectorSpaceBase<Scalar> > &vs_in )
00114 {
00115   if (vs_in.has_ownership())
00116     return vs_in;
00117   const RCP<const VectorSpaceBase<Scalar> > vs = vs_in->clone();
00118   TEST_FOR_EXCEPTION(
00119     is_null(vs), std::logic_error
00120     ,"Thyra::makeHaveOwnership(vs): Error, the concrete VectorSpaceBase object identified as \'"
00121     << vs->description() << "\' does not support the clone() function!"
00122     );
00123   return vs;
00124 }
00125 
00126 
00127 template<class Scalar>
00128 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00129 Thyra::createMember(
00130   const RCP<const VectorSpaceBase<Scalar> > &vs,
00131   const std::string &label
00132   )
00133 {
00134   RCP<VectorBase<Scalar> > v = vs->createMember();
00135 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00136   if (vs->dim()) {
00137     applyOp<Scalar>(
00138       RTOpPack::TOpAssignScalar<Scalar>(ScalarTraits<Scalar>::nan()),
00139       Teuchos::null, Teuchos::tuple(v.ptr()), Teuchos::null );
00140   }
00141 #endif  
00142   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00143     Teuchos::outArg(v) );
00144   if (label.length()) v->setObjectLabel(label);
00145   return v;
00146 }
00147   
00148 
00149 template<class Scalar>
00150 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00151 Thyra::createMember(
00152   const VectorSpaceBase<Scalar> &vs, const std::string &label
00153   )
00154 {
00155   return createMember(Teuchos::rcpFromRef(vs), label);
00156 }
00157 
00158 
00159 template<class Scalar>
00160 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00161 Thyra::createMembers(
00162   const RCP<const VectorSpaceBase<Scalar> > &vs,
00163   int numMembers,  const std::string &label
00164   )
00165 {
00166   RCP<MultiVectorBase<Scalar> >
00167     mv = vs->createMembers(numMembers);
00168 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00169   if (vs->dim()) {
00170     applyOp<Scalar>(
00171       RTOpPack::TOpAssignScalar<Scalar>(ScalarTraits<Scalar>::nan()),
00172       Teuchos::null, Teuchos::tuple(mv.ptr()), Teuchos::null );
00173   }
00174 #endif  
00175   Teuchos::set_extra_data(makeHaveOwnership(vs), "VectorSpaceBase",
00176     Teuchos::outArg(mv));
00177   if(label.length()) mv->setObjectLabel(label);
00178   return mv;
00179 }
00180 
00181 
00182 template<class Scalar>
00183 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00184 Thyra::createMembers(
00185   const RCP<const VectorSpaceBase<Scalar> > &vs,
00186   const RCP<const VectorSpaceBase<Scalar> > &domain,
00187   const std::string &label
00188   )
00189 {
00190   return createMembers(vs, domain->dim(), label);
00191 }
00192 
00193 
00194 template<class Scalar>
00195 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00196 Thyra::createMembers(
00197   const VectorSpaceBase<Scalar> &vs, int numMembers,
00198   const std::string &label
00199   )
00200 {
00201   return createMembers(Teuchos::rcp(&vs,false), numMembers, label);
00202 }
00203 
00204 
00205 template<class Scalar>
00206 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00207 Thyra::createMemberView(
00208   const RCP<const VectorSpaceBase<Scalar> > &vs,
00209   const RTOpPack::SubVectorView<Scalar> &raw_v,
00210   const std::string &label
00211   )
00212 {
00213   RCP<VectorBase<Scalar> >
00214     v = vs->createMemberView(raw_v);
00215   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00216     Teuchos::outArg(v) );
00217   if (label.length()) v->setObjectLabel(label);
00218   return v;
00219 }
00220 
00221 
00222 template<class Scalar>
00223 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00224 Thyra::createMemberView(
00225   const VectorSpaceBase<Scalar> &vs,
00226   const RTOpPack::SubVectorView<Scalar> &raw_v,
00227   const std::string &label
00228   )
00229 {
00230   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00231 }
00232 
00233 
00234 template<class Scalar>
00235 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00236 Thyra::createMemberView(
00237   const RCP<const VectorSpaceBase<Scalar> > &vs,
00238   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00239   const std::string &label
00240   )
00241 {
00242   RCP<const VectorBase<Scalar> >
00243     v = vs->createMemberView(raw_v);
00244   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00245     Teuchos::outArg(v) );
00246   if (label.length())
00247     Teuchos::rcp_const_cast<VectorBase<Scalar> >(v)->setObjectLabel(label);
00248   return v;
00249 }
00250 
00251 
00252 template<class Scalar>
00253 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00254 Thyra::createMemberView(
00255   const VectorSpaceBase<Scalar> &vs,
00256   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00257   const std::string &label
00258   )
00259 {
00260   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00261 }
00262 
00263 
00264 template<class Scalar>
00265 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00266 Thyra::createMembersView(
00267   const RCP<const VectorSpaceBase<Scalar> > &vs,
00268   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00269   const std::string &label
00270   )
00271 {
00272   RCP<MultiVectorBase<Scalar> >
00273     mv = vs->createMembersView(raw_mv);
00274   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00275     Teuchos::outArg(mv) );
00276   if (label.length()) mv->setObjectLabel(label);
00277   return mv;
00278 }
00279 
00280 
00281 template<class Scalar>
00282 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00283 Thyra::createMembersView(
00284   const VectorSpaceBase<Scalar> &vs,
00285   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00286   const std::string &label
00287   )
00288 {
00289   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00290 }
00291 
00292 
00293 template<class Scalar>
00294 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00295 Thyra::createMembersView(
00296   const RCP<const VectorSpaceBase<Scalar> > &vs,
00297   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00298   const std::string &label
00299   )
00300 {
00301   RCP<const MultiVectorBase<Scalar> >
00302     mv = vs->createMembersView(raw_mv);
00303   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00304     Teuchos::outArg(mv) );
00305   if (label.length())
00306     Teuchos::rcp_const_cast<MultiVectorBase<Scalar> >(mv)->setObjectLabel(label);
00307   return mv;
00308 }
00309 
00310 
00311 template<class Scalar>
00312 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00313 Thyra::createMembersView( const VectorSpaceBase<Scalar> &vs,
00314   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00315   const std::string &label
00316   )
00317 {
00318   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00319 }
00320 
00321 
00322 
00323 //
00324 // Explicit instantiation macro
00325 //
00326 // Must be expanded from within the Thyra namespace!
00327 //
00328 
00329 
00330 #define THYRA_VECTOR_SPACE_BASE_INSTANT(SCALAR) \
00331   \
00332   template class VectorSpaceBase<SCALAR >; \
00333    \
00334   template RCP< VectorBase<SCALAR > > \
00335   createMember( \
00336     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00337     const std::string &label \
00338     ); \
00339    \
00340   template RCP< VectorBase<SCALAR > > \
00341   createMember( \
00342     const VectorSpaceBase<SCALAR > &vs, const std::string &label \
00343     ); \
00344    \
00345   template RCP< MultiVectorBase<SCALAR > > \
00346   createMembers( \
00347     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00348     int numMembers,  const std::string &label \
00349     ); \
00350    \
00351   template RCP< Thyra::MultiVectorBase<SCALAR > > \
00352   createMembers( \
00353     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00354     const RCP<const VectorSpaceBase<SCALAR > > &domain, \
00355     const std::string &label \
00356     ); \
00357   \
00358   template RCP< MultiVectorBase<SCALAR > > \
00359   createMembers( \
00360     const VectorSpaceBase<SCALAR > &vs, int numMembers, \
00361     const std::string &label \
00362     ); \
00363    \
00364   template RCP<VectorBase<SCALAR > > \
00365   createMemberView( \
00366     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00367     const RTOpPack::SubVectorView<SCALAR > &raw_v, \
00368     const std::string &label \
00369     ); \
00370    \
00371   template RCP<VectorBase<SCALAR > > \
00372   createMemberView( \
00373     const VectorSpaceBase<SCALAR > &vs, \
00374     const RTOpPack::SubVectorView<SCALAR > &raw_v, \
00375     const std::string &label \
00376     ); \
00377    \
00378   template RCP<const VectorBase<SCALAR > > \
00379   createMemberView( \
00380     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00381     const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
00382     const std::string &label \
00383     ); \
00384    \
00385   template RCP<const VectorBase<SCALAR > > \
00386   createMemberView( \
00387     const VectorSpaceBase<SCALAR > &vs, \
00388     const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
00389     const std::string &label \
00390     ); \
00391    \
00392   template RCP<MultiVectorBase<SCALAR > > \
00393   createMembersView( \
00394     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00395     const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
00396     const std::string &label \
00397     ); \
00398    \
00399   template RCP<MultiVectorBase<SCALAR > > \
00400   createMembersView( \
00401     const VectorSpaceBase<SCALAR > &vs, \
00402     const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
00403     const std::string &label \
00404     ); \
00405    \
00406   template RCP<const MultiVectorBase<SCALAR > > \
00407   createMembersView( \
00408     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00409     const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
00410     const std::string &label \
00411     ); \
00412    \
00413   template RCP<const MultiVectorBase<SCALAR > > \
00414   createMembersView( const VectorSpaceBase<SCALAR > &vs, \
00415     const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
00416     const std::string &label \
00417     );
00418 
00419 
00420 #endif // THYRA_VECTOR_SPACE_BASE_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines