Thyra Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_VECTOR_SPACE_BASE_DEF_HPP
00043 #define THYRA_VECTOR_SPACE_BASE_DEF_HPP
00044 
00045 #include "Thyra_VectorSpaceBase_decl.hpp"
00046 #include "Thyra_VectorBase.hpp"
00047 #include "Thyra_MultiVectorBase.hpp"
00048 #include "Teuchos_Tuple.hpp"
00049 
00050 
00051 #ifdef TEUCHOS_DEBUG
00052 #  define THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00053 #endif
00054 
00055 
00056 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00057 #include "RTOpPack_TOpAssignScalar.hpp"
00058 // 2008/02/13: rabartl: This include represents a bad dependency to a concrete
00059 // implementation of an RTOp. However, this is better than a dependency on
00060 // Thyra_[Multi]VectorStdOps.hpp!  I don't know of a better alternative at
00061 // this point.
00062 // 2010/01/13: rabartl: I could just write a simple RTOp implementation to
00063 // assgin to null to remove this dependency.
00064 #endif // THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00065 
00066 
00067 namespace Thyra {
00068 
00069 
00070 //
00071 // VectorSpaceBase
00072 //
00073 
00074 
00075 
00076 // Virtual functions with default implementations
00077 
00078 
00079 template<class Scalar>
00080 bool VectorSpaceBase<Scalar>::isEuclidean() const
00081 {
00082   return false;
00083 }
00084 
00085 
00086 template<class Scalar>
00087 bool VectorSpaceBase<Scalar>::hasInCoreView(const Range1D& rng,
00088   const EViewType viewType, const EStrideType strideType) const
00089 {
00090   return false;
00091 }
00092 
00093 
00094 template<class Scalar>
00095 RCP< const VectorSpaceBase<Scalar> >
00096 VectorSpaceBase<Scalar>::clone() const
00097 {
00098   return Teuchos::null;
00099 }
00100 
00101 
00102 // Deprecated
00103 
00104 
00105 template<class Scalar>
00106 void VectorSpaceBase<Scalar>::scalarProds(
00107   const MultiVectorBase<Scalar>& X, const MultiVectorBase<Scalar>& Y,
00108   Scalar scalarProds_out[]
00109   ) const
00110 {
00111   this->scalarProds( X, Y,
00112     Teuchos::arrayView(scalarProds_out, X.domain()->dim()) );
00113 }
00114 
00115 
00116 } // end namespace Thyra
00117 
00118 
00119 //
00120 // Nonmember functions
00121 //
00122 
00123 
00124 template<class Scalar>
00125 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00126 Thyra::makeHaveOwnership( const RCP<const VectorSpaceBase<Scalar> > &vs_in )
00127 {
00128   if (vs_in.has_ownership())
00129     return vs_in;
00130   const RCP<const VectorSpaceBase<Scalar> > vs = vs_in->clone();
00131   TEUCHOS_TEST_FOR_EXCEPTION(
00132     is_null(vs), std::logic_error
00133     ,"Thyra::makeHaveOwnership(vs): Error, the concrete VectorSpaceBase object identified as \'"
00134     << vs->description() << "\' does not support the clone() function!"
00135     );
00136   return vs;
00137 }
00138 
00139 
00140 template<class Scalar>
00141 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00142 Thyra::createMember(
00143   const RCP<const VectorSpaceBase<Scalar> > &vs,
00144   const std::string &label
00145   )
00146 {
00147   RCP<VectorBase<Scalar> > v = vs->createMember();
00148 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00149   if (vs->dim()) {
00150     applyOp<Scalar>(
00151       RTOpPack::TOpAssignScalar<Scalar>(ScalarTraits<Scalar>::nan()),
00152       Teuchos::null, Teuchos::tuple(v.ptr()), Teuchos::null );
00153   }
00154 #endif  
00155   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00156     Teuchos::outArg(v) );
00157   if (label.length()) v->setObjectLabel(label);
00158   return v;
00159 }
00160   
00161 
00162 template<class Scalar>
00163 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00164 Thyra::createMember(
00165   const VectorSpaceBase<Scalar> &vs, const std::string &label
00166   )
00167 {
00168   return createMember(Teuchos::rcpFromRef(vs), label);
00169 }
00170 
00171 
00172 template<class Scalar>
00173 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00174 Thyra::createMembers(
00175   const RCP<const VectorSpaceBase<Scalar> > &vs,
00176   int numMembers,  const std::string &label
00177   )
00178 {
00179   RCP<MultiVectorBase<Scalar> >
00180     mv = vs->createMembers(numMembers);
00181 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00182   if (vs->dim()) {
00183     applyOp<Scalar>(
00184       RTOpPack::TOpAssignScalar<Scalar>(ScalarTraits<Scalar>::nan()),
00185       Teuchos::null, Teuchos::tuple(mv.ptr()), Teuchos::null );
00186   }
00187 #endif  
00188   Teuchos::set_extra_data(makeHaveOwnership(vs), "VectorSpaceBase",
00189     Teuchos::outArg(mv));
00190   if(label.length()) mv->setObjectLabel(label);
00191   return mv;
00192 }
00193 
00194 
00195 template<class Scalar>
00196 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00197 Thyra::createMembers(
00198   const RCP<const VectorSpaceBase<Scalar> > &vs,
00199   const RCP<const VectorSpaceBase<Scalar> > &domain,
00200   const std::string &label
00201   )
00202 {
00203   return createMembers(vs, domain->dim(), label);
00204 }
00205 
00206 
00207 template<class Scalar>
00208 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00209 Thyra::createMembers(
00210   const VectorSpaceBase<Scalar> &vs, int numMembers,
00211   const std::string &label
00212   )
00213 {
00214   return createMembers(Teuchos::rcp(&vs,false), numMembers, label);
00215 }
00216 
00217 
00218 template<class Scalar>
00219 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00220 Thyra::createMemberView(
00221   const RCP<const VectorSpaceBase<Scalar> > &vs,
00222   const RTOpPack::SubVectorView<Scalar> &raw_v,
00223   const std::string &label
00224   )
00225 {
00226   RCP<VectorBase<Scalar> >
00227     v = vs->createMemberView(raw_v);
00228   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00229     Teuchos::outArg(v) );
00230   if (label.length()) v->setObjectLabel(label);
00231   return v;
00232 }
00233 
00234 
00235 template<class Scalar>
00236 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00237 Thyra::createMemberView(
00238   const VectorSpaceBase<Scalar> &vs,
00239   const RTOpPack::SubVectorView<Scalar> &raw_v,
00240   const std::string &label
00241   )
00242 {
00243   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00244 }
00245 
00246 
00247 template<class Scalar>
00248 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00249 Thyra::createMemberView(
00250   const RCP<const VectorSpaceBase<Scalar> > &vs,
00251   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00252   const std::string &label
00253   )
00254 {
00255   RCP<const VectorBase<Scalar> >
00256     v = vs->createMemberView(raw_v);
00257   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00258     Teuchos::outArg(v) );
00259   if (label.length())
00260     Teuchos::rcp_const_cast<VectorBase<Scalar> >(v)->setObjectLabel(label);
00261   return v;
00262 }
00263 
00264 
00265 template<class Scalar>
00266 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00267 Thyra::createMemberView(
00268   const VectorSpaceBase<Scalar> &vs,
00269   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00270   const std::string &label
00271   )
00272 {
00273   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00274 }
00275 
00276 
00277 template<class Scalar>
00278 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00279 Thyra::createMembersView(
00280   const RCP<const VectorSpaceBase<Scalar> > &vs,
00281   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00282   const std::string &label
00283   )
00284 {
00285   RCP<MultiVectorBase<Scalar> >
00286     mv = vs->createMembersView(raw_mv);
00287   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00288     Teuchos::outArg(mv) );
00289   if (label.length()) mv->setObjectLabel(label);
00290   return mv;
00291 }
00292 
00293 
00294 template<class Scalar>
00295 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00296 Thyra::createMembersView(
00297   const VectorSpaceBase<Scalar> &vs,
00298   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00299   const std::string &label
00300   )
00301 {
00302   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00303 }
00304 
00305 
00306 template<class Scalar>
00307 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00308 Thyra::createMembersView(
00309   const RCP<const VectorSpaceBase<Scalar> > &vs,
00310   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00311   const std::string &label
00312   )
00313 {
00314   RCP<const MultiVectorBase<Scalar> >
00315     mv = vs->createMembersView(raw_mv);
00316   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00317     Teuchos::outArg(mv) );
00318   if (label.length())
00319     Teuchos::rcp_const_cast<MultiVectorBase<Scalar> >(mv)->setObjectLabel(label);
00320   return mv;
00321 }
00322 
00323 
00324 template<class Scalar>
00325 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00326 Thyra::createMembersView( const VectorSpaceBase<Scalar> &vs,
00327   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00328   const std::string &label
00329   )
00330 {
00331   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00332 }
00333 
00334 
00335 
00336 //
00337 // Explicit instantiation macro
00338 //
00339 // Must be expanded from within the Thyra namespace!
00340 //
00341 
00342 
00343 #define THYRA_VECTOR_SPACE_BASE_INSTANT(SCALAR) \
00344   \
00345   template class VectorSpaceBase<SCALAR >; \
00346    \
00347   template RCP< VectorBase<SCALAR > > \
00348   createMember( \
00349     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00350     const std::string &label \
00351     ); \
00352    \
00353   template RCP< VectorBase<SCALAR > > \
00354   createMember( \
00355     const VectorSpaceBase<SCALAR > &vs, const std::string &label \
00356     ); \
00357    \
00358   template RCP< MultiVectorBase<SCALAR > > \
00359   createMembers( \
00360     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00361     int numMembers,  const std::string &label \
00362     ); \
00363    \
00364   template RCP< Thyra::MultiVectorBase<SCALAR > > \
00365   createMembers( \
00366     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00367     const RCP<const VectorSpaceBase<SCALAR > > &domain, \
00368     const std::string &label \
00369     ); \
00370   \
00371   template RCP< MultiVectorBase<SCALAR > > \
00372   createMembers( \
00373     const VectorSpaceBase<SCALAR > &vs, int numMembers, \
00374     const std::string &label \
00375     ); \
00376    \
00377   template RCP<VectorBase<SCALAR > > \
00378   createMemberView( \
00379     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00380     const RTOpPack::SubVectorView<SCALAR > &raw_v, \
00381     const std::string &label \
00382     ); \
00383    \
00384   template RCP<VectorBase<SCALAR > > \
00385   createMemberView( \
00386     const VectorSpaceBase<SCALAR > &vs, \
00387     const RTOpPack::SubVectorView<SCALAR > &raw_v, \
00388     const std::string &label \
00389     ); \
00390    \
00391   template RCP<const VectorBase<SCALAR > > \
00392   createMemberView( \
00393     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00394     const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
00395     const std::string &label \
00396     ); \
00397    \
00398   template RCP<const VectorBase<SCALAR > > \
00399   createMemberView( \
00400     const VectorSpaceBase<SCALAR > &vs, \
00401     const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
00402     const std::string &label \
00403     ); \
00404    \
00405   template RCP<MultiVectorBase<SCALAR > > \
00406   createMembersView( \
00407     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00408     const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
00409     const std::string &label \
00410     ); \
00411    \
00412   template RCP<MultiVectorBase<SCALAR > > \
00413   createMembersView( \
00414     const VectorSpaceBase<SCALAR > &vs, \
00415     const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
00416     const std::string &label \
00417     ); \
00418    \
00419   template RCP<const MultiVectorBase<SCALAR > > \
00420   createMembersView( \
00421     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00422     const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
00423     const std::string &label \
00424     ); \
00425    \
00426   template RCP<const MultiVectorBase<SCALAR > > \
00427   createMembersView( const VectorSpaceBase<SCALAR > &vs, \
00428     const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
00429     const std::string &label \
00430     );
00431 
00432 
00433 #endif // THYRA_VECTOR_SPACE_BASE_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines