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 } // end namespace Thyra
00103 
00104 
00105 //
00106 // Nonmember functions
00107 //
00108 
00109 
00110 template<class Scalar>
00111 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00112 Thyra::makeHaveOwnership( const RCP<const VectorSpaceBase<Scalar> > &vs_in )
00113 {
00114   if (vs_in.has_ownership())
00115     return vs_in;
00116   const RCP<const VectorSpaceBase<Scalar> > vs = vs_in->clone();
00117   TEUCHOS_TEST_FOR_EXCEPTION(
00118     is_null(vs), std::logic_error
00119     ,"Thyra::makeHaveOwnership(vs): Error, the concrete VectorSpaceBase object identified as \'"
00120     << vs->description() << "\' does not support the clone() function!"
00121     );
00122   return vs;
00123 }
00124 
00125 
00126 template<class Scalar>
00127 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00128 Thyra::createMember(
00129   const RCP<const VectorSpaceBase<Scalar> > &vs,
00130   const std::string &label
00131   )
00132 {
00133   RCP<VectorBase<Scalar> > v = vs->createMember();
00134 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00135   if (vs->dim()) {
00136     applyOp<Scalar>(
00137       RTOpPack::TOpAssignScalar<Scalar>(ScalarTraits<Scalar>::nan()),
00138       Teuchos::null, Teuchos::tuple(v.ptr()), Teuchos::null );
00139   }
00140 #endif  
00141   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00142     Teuchos::outArg(v) );
00143   if (label.length()) v->setObjectLabel(label);
00144   return v;
00145 }
00146   
00147 
00148 template<class Scalar>
00149 Teuchos::RCP< Thyra::VectorBase<Scalar> >
00150 Thyra::createMember(
00151   const VectorSpaceBase<Scalar> &vs, const std::string &label
00152   )
00153 {
00154   return createMember(Teuchos::rcpFromRef(vs), label);
00155 }
00156 
00157 
00158 template<class Scalar>
00159 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00160 Thyra::createMembers(
00161   const RCP<const VectorSpaceBase<Scalar> > &vs,
00162   int numMembers,  const std::string &label
00163   )
00164 {
00165   RCP<MultiVectorBase<Scalar> >
00166     mv = vs->createMembers(numMembers);
00167 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00168   if (vs->dim()) {
00169     applyOp<Scalar>(
00170       RTOpPack::TOpAssignScalar<Scalar>(ScalarTraits<Scalar>::nan()),
00171       Teuchos::null, Teuchos::tuple(mv.ptr()), Teuchos::null );
00172   }
00173 #endif  
00174   Teuchos::set_extra_data(makeHaveOwnership(vs), "VectorSpaceBase",
00175     Teuchos::outArg(mv));
00176   if(label.length()) mv->setObjectLabel(label);
00177   return mv;
00178 }
00179 
00180 
00181 template<class Scalar>
00182 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00183 Thyra::createMembers(
00184   const RCP<const VectorSpaceBase<Scalar> > &vs,
00185   const RCP<const VectorSpaceBase<Scalar> > &domain,
00186   const std::string &label
00187   )
00188 {
00189   return createMembers(vs, domain->dim(), label);
00190 }
00191 
00192 
00193 template<class Scalar>
00194 Teuchos::RCP< Thyra::MultiVectorBase<Scalar> >
00195 Thyra::createMembers(
00196   const VectorSpaceBase<Scalar> &vs, int numMembers,
00197   const std::string &label
00198   )
00199 {
00200   return createMembers(Teuchos::rcp(&vs,false), numMembers, label);
00201 }
00202 
00203 
00204 template<class Scalar>
00205 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00206 Thyra::createMemberView(
00207   const RCP<const VectorSpaceBase<Scalar> > &vs,
00208   const RTOpPack::SubVectorView<Scalar> &raw_v,
00209   const std::string &label
00210   )
00211 {
00212   RCP<VectorBase<Scalar> >
00213     v = vs->createMemberView(raw_v);
00214   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00215     Teuchos::outArg(v) );
00216   if (label.length()) v->setObjectLabel(label);
00217   return v;
00218 }
00219 
00220 
00221 template<class Scalar>
00222 Teuchos::RCP<Thyra::VectorBase<Scalar> >
00223 Thyra::createMemberView(
00224   const VectorSpaceBase<Scalar> &vs,
00225   const RTOpPack::SubVectorView<Scalar> &raw_v,
00226   const std::string &label
00227   )
00228 {
00229   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00230 }
00231 
00232 
00233 template<class Scalar>
00234 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00235 Thyra::createMemberView(
00236   const RCP<const VectorSpaceBase<Scalar> > &vs,
00237   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00238   const std::string &label
00239   )
00240 {
00241   RCP<const VectorBase<Scalar> >
00242     v = vs->createMemberView(raw_v);
00243   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00244     Teuchos::outArg(v) );
00245   if (label.length())
00246     Teuchos::rcp_const_cast<VectorBase<Scalar> >(v)->setObjectLabel(label);
00247   return v;
00248 }
00249 
00250 
00251 template<class Scalar>
00252 Teuchos::RCP<const Thyra::VectorBase<Scalar> >
00253 Thyra::createMemberView(
00254   const VectorSpaceBase<Scalar> &vs,
00255   const RTOpPack::ConstSubVectorView<Scalar> &raw_v,
00256   const std::string &label
00257   )
00258 {
00259   return createMemberView(Teuchos::rcp(&vs,false),raw_v,label);
00260 }
00261 
00262 
00263 template<class Scalar>
00264 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00265 Thyra::createMembersView(
00266   const RCP<const VectorSpaceBase<Scalar> > &vs,
00267   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00268   const std::string &label
00269   )
00270 {
00271   RCP<MultiVectorBase<Scalar> >
00272     mv = vs->createMembersView(raw_mv);
00273   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00274     Teuchos::outArg(mv) );
00275   if (label.length()) mv->setObjectLabel(label);
00276   return mv;
00277 }
00278 
00279 
00280 template<class Scalar>
00281 Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00282 Thyra::createMembersView(
00283   const VectorSpaceBase<Scalar> &vs,
00284   const RTOpPack::SubMultiVectorView<Scalar> &raw_mv,
00285   const std::string &label
00286   )
00287 {
00288   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00289 }
00290 
00291 
00292 template<class Scalar>
00293 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00294 Thyra::createMembersView(
00295   const RCP<const VectorSpaceBase<Scalar> > &vs,
00296   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00297   const std::string &label
00298   )
00299 {
00300   RCP<const MultiVectorBase<Scalar> >
00301     mv = vs->createMembersView(raw_mv);
00302   Teuchos::set_extra_data( makeHaveOwnership(vs), "VectorSpaceBase",
00303     Teuchos::outArg(mv) );
00304   if (label.length())
00305     Teuchos::rcp_const_cast<MultiVectorBase<Scalar> >(mv)->setObjectLabel(label);
00306   return mv;
00307 }
00308 
00309 
00310 template<class Scalar>
00311 Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> >
00312 Thyra::createMembersView( const VectorSpaceBase<Scalar> &vs,
00313   const RTOpPack::ConstSubMultiVectorView<Scalar> &raw_mv,
00314   const std::string &label
00315   )
00316 {
00317   return createMembersView(Teuchos::rcp(&vs,false),raw_mv,label);
00318 }
00319 
00320 
00321 
00322 //
00323 // Explicit instantiation macro
00324 //
00325 // Must be expanded from within the Thyra namespace!
00326 //
00327 
00328 
00329 #define THYRA_VECTOR_SPACE_BASE_INSTANT(SCALAR) \
00330   \
00331   template class VectorSpaceBase<SCALAR >; \
00332    \
00333   template RCP< VectorBase<SCALAR > > \
00334   createMember( \
00335     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00336     const std::string &label \
00337     ); \
00338    \
00339   template RCP< VectorBase<SCALAR > > \
00340   createMember( \
00341     const VectorSpaceBase<SCALAR > &vs, const std::string &label \
00342     ); \
00343    \
00344   template RCP< MultiVectorBase<SCALAR > > \
00345   createMembers( \
00346     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00347     int numMembers,  const std::string &label \
00348     ); \
00349    \
00350   template RCP< Thyra::MultiVectorBase<SCALAR > > \
00351   createMembers( \
00352     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00353     const RCP<const VectorSpaceBase<SCALAR > > &domain, \
00354     const std::string &label \
00355     ); \
00356   \
00357   template RCP< MultiVectorBase<SCALAR > > \
00358   createMembers( \
00359     const VectorSpaceBase<SCALAR > &vs, int numMembers, \
00360     const std::string &label \
00361     ); \
00362    \
00363   template RCP<VectorBase<SCALAR > > \
00364   createMemberView( \
00365     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00366     const RTOpPack::SubVectorView<SCALAR > &raw_v, \
00367     const std::string &label \
00368     ); \
00369    \
00370   template RCP<VectorBase<SCALAR > > \
00371   createMemberView( \
00372     const VectorSpaceBase<SCALAR > &vs, \
00373     const RTOpPack::SubVectorView<SCALAR > &raw_v, \
00374     const std::string &label \
00375     ); \
00376    \
00377   template RCP<const VectorBase<SCALAR > > \
00378   createMemberView( \
00379     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00380     const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
00381     const std::string &label \
00382     ); \
00383    \
00384   template RCP<const VectorBase<SCALAR > > \
00385   createMemberView( \
00386     const VectorSpaceBase<SCALAR > &vs, \
00387     const RTOpPack::ConstSubVectorView<SCALAR > &raw_v, \
00388     const std::string &label \
00389     ); \
00390    \
00391   template RCP<MultiVectorBase<SCALAR > > \
00392   createMembersView( \
00393     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00394     const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
00395     const std::string &label \
00396     ); \
00397    \
00398   template RCP<MultiVectorBase<SCALAR > > \
00399   createMembersView( \
00400     const VectorSpaceBase<SCALAR > &vs, \
00401     const RTOpPack::SubMultiVectorView<SCALAR > &raw_mv, \
00402     const std::string &label \
00403     ); \
00404    \
00405   template RCP<const MultiVectorBase<SCALAR > > \
00406   createMembersView( \
00407     const RCP<const VectorSpaceBase<SCALAR > > &vs, \
00408     const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
00409     const std::string &label \
00410     ); \
00411    \
00412   template RCP<const MultiVectorBase<SCALAR > > \
00413   createMembersView( const VectorSpaceBase<SCALAR > &vs, \
00414     const RTOpPack::ConstSubMultiVectorView<SCALAR > &raw_mv, \
00415     const std::string &label \
00416     );
00417 
00418 
00419 #endif // THYRA_VECTOR_SPACE_BASE_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines