AbstractLinAlgPack_MatrixOpNonsingThyra.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 
00030 #include "AbstractLinAlgPack_MatrixOpNonsingThyra.hpp"
00031 #include "AbstractLinAlgPack_VectorMutableThyra.hpp"
00032 #include "Teuchos_TestForException.hpp"
00033 #include "Teuchos_dyn_cast.hpp"
00034 
00035 namespace AbstractLinAlgPack {
00036 
00037 // Constructors / Initializers
00038 
00039 MatrixOpNonsingThyra::MatrixOpNonsingThyra()
00040 {}
00041 
00042 MatrixOpNonsingThyra::MatrixOpNonsingThyra(
00043   const Teuchos::RefCountPtr<const Thyra::LinearOpWithSolveBase<value_type> >  &thyra_linear_op_ns
00044   ,BLAS_Cpp::Transp                                                            thyra_linear_op_trans
00045   )
00046 {
00047   this->initialize(thyra_linear_op_ns,thyra_linear_op_trans);
00048 }
00049 
00050 void MatrixOpNonsingThyra::initialize(
00051   const Teuchos::RefCountPtr<const Thyra::LinearOpWithSolveBase<value_type> >  &thyra_linear_op_ns
00052   ,BLAS_Cpp::Transp                                                            thyra_linear_op_trans
00053   )
00054 {
00055   namespace mmp = MemMngPack;
00056   TEST_FOR_EXCEPTION(
00057     thyra_linear_op_ns.get()==NULL, std::invalid_argument
00058     ,"MatrixOpNonsingThyra::initialize(thyra_linear_op_ns): Error!"
00059     );
00060   MatrixOpThyra::initialize(thyra_linear_op_ns,thyra_linear_op_trans);
00061 }
00062 
00063 Teuchos::RefCountPtr<const Thyra::LinearOpWithSolveBase<value_type> > 
00064 MatrixOpNonsingThyra::set_uninitialized()
00065 {
00066   Teuchos::RefCountPtr<const Thyra::LinearOpWithSolveBase<value_type> >
00067     tmp_thyra_linear_op_ns = thyra_linear_op_ns();
00068   MatrixOpThyra::set_uninitialized();
00069   return tmp_thyra_linear_op_ns;
00070 }
00071 
00072 Teuchos::RefCountPtr<const Thyra::LinearOpWithSolveBase<value_type> >
00073 MatrixOpNonsingThyra::thyra_linear_op_ns() const
00074 {
00075   return Teuchos::rcp_dynamic_cast<const Thyra::LinearOpWithSolveBase<value_type> >(this->thyra_linear_op());
00076 }
00077 
00078 // Overridden from MatrixOp (needed to remove ambiguities)
00079 
00080 MatrixOp::mat_mut_ptr_t
00081 MatrixOpNonsingThyra::clone()
00082 {
00083   return this->MatrixOpThyra::clone();
00084 }
00085 
00086 // Overridden from MatrixNonsing
00087 
00088 void MatrixOpNonsingThyra::V_InvMtV(
00089   VectorMutable* v_lhs, BLAS_Cpp::Transp trans_rhs1
00090   ,const Vector& v_rhs2
00091   ) const
00092 {
00093   using Teuchos::dyn_cast;
00094   using BLAS_Cpp::trans_trans;
00095 #ifdef TEUCHOS_DEBUG
00096   TEST_FOR_EXCEPTION(
00097     v_lhs==NULL, std::invalid_argument
00098     ,"MatrixOpThyra::Vp_StMtV(...): Error!"
00099     );
00100 #endif
00101   *v_lhs = 0.0; // Must initialize before sending to solve(...)!
00102   VectorMutableThyra &v_thyra_lhs = dyn_cast<VectorMutableThyra>(*v_lhs);
00103   Teuchos::RefCountPtr<Thyra::VectorBase<value_type> > thyra_vec_lhs = v_thyra_lhs.set_uninitialized();
00104   Thyra::solve(
00105     *thyra_linear_op_ns()
00106     ,trans_trans(trans_rhs1,thyra_linear_op_trans())==BLAS_Cpp::no_trans ? Thyra::NOTRANS : Thyra::TRANS  // M_trans
00107     ,*dyn_cast<const VectorMutableThyra>(v_rhs2).thyra_vec()                                              // y
00108     ,thyra_vec_lhs.get()                                                                                  // x
00109     );
00110   v_thyra_lhs.initialize(thyra_vec_lhs);
00111 }
00112 
00113 void MatrixOpNonsingThyra::M_StInvMtM(
00114   MatrixOp* m_lhs, value_type alpha
00115   ,BLAS_Cpp::Transp trans_rhs1
00116   ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
00117   ) const
00118 {
00119   MatrixNonsing::M_StInvMtM(m_lhs,alpha,trans_rhs1,mwo_rhs2,trans_rhs2); // ToDo: Specialize!
00120 }
00121 
00122 // Overridden from MatrixOpNonsing
00123 
00124 MatrixOpNonsing::mat_mwons_ptr_t
00125 MatrixOpNonsingThyra::clone_mwons() const
00126 {
00127   return Teuchos::null; // ToDo: Add a clone function to Thyra::LinearOpWithSolveBase???
00128   //return Teuchos::rcp(new MatrixOpNonsingThyra(thyra_linear_op_ns()->clone_lows()));
00129 }
00130 
00131 } // end namespace AbstractLinAlgPack

Generated on Thu Sep 18 12:34:37 2008 for MOOCHO/Thyra Adapter Software by doxygen 1.3.9.1