AbstractLinAlgPack_MatrixOpThyra.cpp

Go to the documentation of this file.
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_MatrixOpThyra.hpp"
00032 #include "AbstractLinAlgPack_VectorMutableThyra.hpp"
00033 #include "AbstractLinAlgPack_ThyraAccessors.hpp"
00034 #include "Teuchos_TestForException.hpp"
00035 #include "Teuchos_dyn_cast.hpp"
00036 
00037 namespace AbstractLinAlgPack {
00038 
00039 // Constructors / Initializers
00040 
00041 MatrixOpThyra::MatrixOpThyra()
00042 {}
00043 
00044 MatrixOpThyra::MatrixOpThyra(
00045   const Teuchos::RefCountPtr<const Thyra::LinearOpBase<value_type> >   &thyra_linear_op
00046   ,BLAS_Cpp::Transp                                                    thyra_linear_op_trans
00047   )
00048 {
00049   this->initialize(thyra_linear_op,thyra_linear_op_trans);
00050 }
00051 
00052 void MatrixOpThyra::initialize(
00053   const Teuchos::RefCountPtr<const Thyra::LinearOpBase<value_type> >   &thyra_linear_op
00054   ,BLAS_Cpp::Transp                                                    thyra_linear_op_trans
00055   )
00056 {
00057   namespace mmp = MemMngPack;
00058   TEST_FOR_EXCEPTION(
00059     thyra_linear_op.get()==NULL, std::invalid_argument
00060     ,"MatrixOpThyra::initialize(thyra_linear_op): Error!"
00061     );
00062   const bool adjointSupported = ( ::Thyra::opSupported(*thyra_linear_op,Thyra::NOTRANS) && ::Thyra::opSupported(*thyra_linear_op,Thyra::TRANS) );
00063   TEST_FOR_EXCEPTION(
00064     !adjointSupported, std::invalid_argument
00065     ,"MatrixOpThyra::initialize(thyra_linear_op): Error, the operator opSupported(thyra_linear_op,transp) must return true "
00066     "for both values of transp==NOTRANS and transp=TRANS!"
00067     );
00068   thyra_linear_op_       = thyra_linear_op;
00069   thyra_linear_op_trans_ = thyra_linear_op_trans;
00070   space_cols_.initialize(thyra_linear_op_->range());
00071   space_rows_.initialize(thyra_linear_op_->domain());
00072 }
00073 
00074 Teuchos::RefCountPtr<const Thyra::LinearOpBase<value_type> > 
00075 MatrixOpThyra::set_uninitialized()
00076 {
00077   Teuchos::RefCountPtr<const Thyra::LinearOpBase<value_type> > tmp_thyra_linear_op = thyra_linear_op_;
00078   thyra_linear_op_       = Teuchos::null;
00079   thyra_linear_op_trans_ = BLAS_Cpp::no_trans;
00080   space_cols_.set_uninitialized();
00081   space_rows_.set_uninitialized();
00082   return tmp_thyra_linear_op;
00083 }
00084 
00085 // Overridden from MatrixBase
00086 
00087 const VectorSpace&
00088 MatrixOpThyra::space_cols() const
00089 {
00090   return space_cols_;
00091 }
00092 
00093 const VectorSpace&
00094 MatrixOpThyra::space_rows() const
00095 {
00096   return space_rows_;
00097 }
00098 
00099 // Overridden from MatrixOp
00100 
00101 MatrixOp::mat_mut_ptr_t
00102 MatrixOpThyra::clone()
00103 {
00104   return Teuchos::rcp(new MatrixOpThyra(thyra_linear_op_->clone()));
00105 }
00106 
00107 MatrixOp& MatrixOpThyra::operator=(const MatrixOp& mwo_rhs)
00108 {
00109   using Teuchos::dyn_cast;
00110   const MatrixOpThyra &mwo_rhs_thyra = dyn_cast<const MatrixOpThyra>(mwo_rhs);
00111   thyra_linear_op_       = mwo_rhs_thyra.thyra_linear_op_;  // ToDo: Clone this!
00112   thyra_linear_op_trans_ = mwo_rhs_thyra.thyra_linear_op_trans_;
00113   space_cols_           = mwo_rhs_thyra.space_cols_;  // ToDo: Clone this!
00114   space_rows_           = mwo_rhs_thyra.space_rows_;  // ToDo: Clone this!
00115   return *this;
00116 }
00117 
00118 void MatrixOpThyra::Vp_StMtV(
00119   VectorMutable* v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00120   ,const Vector& v_rhs2, value_type beta
00121   ) const
00122 {
00123   using BLAS_Cpp::trans_trans;
00124   // Get Thyra views of the vectors
00125   Teuchos::RefCountPtr<const Thyra::VectorBase<value_type> > thyra_vec_rhs2;
00126   get_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_rows_ : space_cols_, v_rhs2, &thyra_vec_rhs2 );
00127   Teuchos::RefCountPtr<Thyra::VectorBase<value_type> > thyra_vec_lhs;
00128   get_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_cols_ : space_rows_, v_lhs, &thyra_vec_lhs );
00129   // Perform the multiplication
00130   ::Thyra::apply(
00131     *thyra_linear_op_
00132     ,trans_trans(trans_rhs1,thyra_linear_op_trans())==BLAS_Cpp::no_trans ? Thyra::NOTRANS : Thyra::TRANS  // M_trans
00133     ,*thyra_vec_rhs2                                                                                      // x
00134     ,&*thyra_vec_lhs                                                                                      // y
00135     ,alpha                                                                                                // alpha
00136     ,beta                                                                                                // beta
00137     );
00138   // Free/commit Thyra vector views
00139   free_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_rows_ : space_cols_, v_rhs2, &thyra_vec_rhs2 );
00140   commit_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_cols_ : space_rows_, v_lhs, &thyra_vec_lhs );
00141 }
00142 
00143 bool MatrixOpThyra::Mp_StMtM(
00144   MatrixOp* mwo_lhs, value_type alpha
00145   ,BLAS_Cpp::Transp trans_rhs1
00146   ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
00147   ,value_type beta
00148   ) const
00149 {
00150   return false; // ToDo: Specialize!
00151 }
00152 
00153 } // end namespace AbstractLinAlgPack

Generated on Thu Sep 18 12:35:12 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1