AbstractLinAlgPack_VectorSpaceThyra.cpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) 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 Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <assert.h>
00030 
00031 #include "AbstractLinAlgPack_VectorSpaceThyra.hpp"
00032 #include "AbstractLinAlgPack_VectorSpaceFactoryThyra.hpp"
00033 #include "AbstractLinAlgPack_VectorMutableThyra.hpp"
00034 #include "AbstractLinAlgPack_MultiVectorMutableThyra.hpp"
00035 #include "AbstractLinAlgPack_InnerProductThyra.hpp"
00036 #include "Teuchos_TestForException.hpp"
00037 #include "Teuchos_dyn_cast.hpp"
00038 
00039 namespace AbstractLinAlgPack {
00040 
00041 // Constructors / initializers
00042 
00043 VectorSpaceThyra::VectorSpaceThyra()
00044 {}
00045 
00046 VectorSpaceThyra::VectorSpaceThyra(
00047   const Teuchos::RCP<const Thyra::VectorSpaceBase<value_type> >    &thyra_vec_spc
00048   ,const inner_prod_ptr_t                                                  &inner_prod
00049   )
00050 {
00051   this->initialize(thyra_vec_spc,inner_prod);
00052 }
00053 
00054 void VectorSpaceThyra::initialize(
00055   const Teuchos::RCP<const Thyra::VectorSpaceBase<value_type> >    &thyra_vec_spc
00056   ,const inner_prod_ptr_t                                                  &inner_prod
00057   )
00058 {
00059   namespace mmp = MemMngPack;
00060   TEST_FOR_EXCEPTION(
00061     thyra_vec_spc.get()==NULL, std::invalid_argument
00062     ,"VectorSpaceThyra::initialize(thyra_vec_spc): Error!"
00063     );
00064   thyra_vec_spc_ = thyra_vec_spc;
00065   if(inner_prod.get())
00066     this->inner_prod(inner_prod);
00067   else
00068     this->inner_prod(Teuchos::rcp(new InnerProductThyra(thyra_vec_spc)));
00069 }
00070 
00071 Teuchos::RCP<const Thyra::VectorSpaceBase<value_type> >
00072 VectorSpaceThyra::set_uninitialized()
00073 {
00074   Teuchos::RCP<const Thyra::VectorSpaceBase<value_type> > tmp_thyra_vec_spc = thyra_vec_spc_;
00075   thyra_vec_spc_ = Teuchos::null;
00076   return tmp_thyra_vec_spc;
00077 }
00078 
00079 // Overridden from VectorSpace
00080 
00081 VectorSpace::space_ptr_t
00082 VectorSpaceThyra::clone() const
00083 {
00084   return Teuchos::rcp(new VectorSpaceThyra(thyra_vec_spc_->clone()));
00085 }
00086 
00087 bool VectorSpaceThyra::is_compatible(const VectorSpace& vec_spc ) const
00088 {
00089   if( this->dim()==vec_spc.dim() && this->is_in_core() && vec_spc.is_in_core() )
00090     return true;
00091   const VectorSpaceThyra
00092     *thyra_vec_spc = dynamic_cast<const VectorSpaceThyra*>(&vec_spc);
00093   if( thyra_vec_spc->thyra_vec_spc()->isCompatible(*thyra_vec_spc_) )
00094     return true;
00095   return false;
00096 }
00097 
00098 bool VectorSpaceThyra::is_in_core() const
00099 {
00100   return thyra_vec_spc_->hasInCoreView();
00101 }
00102 
00103 index_type VectorSpaceThyra::dim() const
00104 {
00105   return thyra_vec_spc_->dim();
00106 }
00107 
00108 VectorSpace::vec_mut_ptr_t
00109 VectorSpaceThyra::create_member() const
00110 {
00111   return Teuchos::rcp(new VectorMutableThyra(Thyra::createMember(thyra_vec_spc_)));
00112 }
00113 
00114 VectorSpace::space_fcty_ptr_t
00115 VectorSpaceThyra::small_vec_spc_fcty() const
00116 {
00117   return Teuchos::rcp(new VectorSpaceFactoryThyra(thyra_vec_spc_->smallVecSpcFcty()));
00118 }
00119 
00120 VectorSpace::multi_vec_mut_ptr_t
00121 VectorSpaceThyra::create_members(size_type num_vecs) const
00122 {
00123   return Teuchos::rcp(new MultiVectorMutableThyra(Thyra::createMembers(thyra_vec_spc_,num_vecs)));
00124 }
00125 
00126 } // end namespace AbstractLinAlgPack

Generated on Wed May 12 21:51:33 2010 for MOOCHO/Thyra Adapter Software by  doxygen 1.4.7