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

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