MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_MatrixOpNonsingThyra.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 //
42 
45 #include "Thyra_VectorStdOps.hpp"
46 #include "Thyra_MultiVectorStdOps.hpp"
47 #include "Teuchos_Assert.hpp"
48 #include "Teuchos_dyn_cast.hpp"
49 
50 namespace AbstractLinAlgPack {
51 
52 // Constructors / Initializers
53 
55 {}
56 
58  const Teuchos::RCP<const Thyra::LinearOpWithSolveBase<value_type> > &thyra_linear_op_ns
59  ,BLAS_Cpp::Transp thyra_linear_op_trans
60  )
61 {
62  this->initialize(thyra_linear_op_ns,thyra_linear_op_trans);
63 }
64 
66  const Teuchos::RCP<const Thyra::LinearOpWithSolveBase<value_type> > &thyra_linear_op_ns
67  ,BLAS_Cpp::Transp thyra_linear_op_trans
68  )
69 {
70  namespace mmp = MemMngPack;
72  thyra_linear_op_ns.get()==NULL, std::invalid_argument
73  ,"MatrixOpNonsingThyra::initialize(thyra_linear_op_ns): Error!"
74  );
75  MatrixOpThyra::initialize(thyra_linear_op_ns,thyra_linear_op_trans);
76 }
77 
80 {
82  tmp_thyra_linear_op_ns = thyra_linear_op_ns();
84  return tmp_thyra_linear_op_ns;
85 }
86 
89 {
90  return Teuchos::rcp_dynamic_cast<const Thyra::LinearOpWithSolveBase<value_type> >(this->thyra_linear_op());
91 }
92 
93 // Overridden from MatrixOp (needed to remove ambiguities)
94 
95 MatrixOp::mat_mut_ptr_t
97 {
98  return this->MatrixOpThyra::clone();
99 }
100 
101 // Overridden from MatrixNonsing
102 
104  VectorMutable* v_lhs, BLAS_Cpp::Transp trans_rhs1
105  ,const Vector& v_rhs2
106  ) const
107 {
108  using Teuchos::dyn_cast;
109  using BLAS_Cpp::trans_trans;
110 #ifdef TEUCHOS_DEBUG
112  v_lhs==NULL, std::invalid_argument
113  ,"MatrixOpThyra::Vp_StMtV(...): Error!"
114  );
115 #endif
116  *v_lhs = 0.0; // Must initialize before sending to solve(...)!
117  VectorMutableThyra &v_thyra_lhs = dyn_cast<VectorMutableThyra>(*v_lhs);
118  Teuchos::RCP<Thyra::VectorBase<value_type> > thyra_vec_lhs = v_thyra_lhs.set_uninitialized();
119  Thyra::solve<value_type>(
121  ,trans_trans(trans_rhs1,thyra_linear_op_trans())==BLAS_Cpp::no_trans ? Thyra::NOTRANS : Thyra::TRANS // M_trans
122  ,*dyn_cast<const VectorMutableThyra>(v_rhs2).thyra_vec() // y
123  ,thyra_vec_lhs.ptr() // x
124  );
125  v_thyra_lhs.initialize(thyra_vec_lhs);
126 }
127 
129  MatrixOp* m_lhs, value_type alpha
130  ,BLAS_Cpp::Transp trans_rhs1
131  ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
132  ) const
133 {
134  MatrixNonsing::M_StInvMtM(m_lhs,alpha,trans_rhs1,mwo_rhs2,trans_rhs2); // ToDo: Specialize!
135 }
136 
137 // Overridden from MatrixOpNonsing
138 
139 MatrixOpNonsing::mat_mwons_ptr_t
141 {
142  return Teuchos::null; // ToDo: Add a clone function to Thyra::LinearOpWithSolveBase???
143  //return Teuchos::rcp(new MatrixOpNonsingThyra(thyra_linear_op_ns()->clone_lows()));
144 }
145 
146 } // end namespace AbstractLinAlgPack
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
Teuchos::RCP< const Thyra::LinearOpWithSolveBase< value_type > > thyra_linear_op_ns() const
Return a smart pointer to the Thyra::LinearOpWithSolveBase object.
void initialize(const Teuchos::RCP< const Thyra::LinearOpWithSolveBase< value_type > > &thyra_linear_op_ns, BLAS_Cpp::Transp thyra_linear_op_trans=BLAS_Cpp::no_trans)
Initalize given a smart pointer to a Thyra::LinearOpWithSolveBase object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void initialize(const Teuchos::RCP< const Thyra::LinearOpBase< value_type > > &thyra_linear_op, BLAS_Cpp::Transp thyra_linear_op_trans=BLAS_Cpp::no_trans)
Initalize given a smart pointer to a Thyra::LinearOpBase object.
void V_InvMtV(VectorMutable *v_lhs, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2) const
void M_StInvMtM(MatrixOp *m_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2) const
Not transposed.
mat_mut_ptr_t clone()
Overridden to call MatrixOpThyra::clone()
T_To & dyn_cast(T_From &from)
Ptr< T > ptr() const
VectorMutable adapter subclass for Thyra::VectorBase.
Transp trans_trans(Transp _trans1, Transp _trans2)
Return the transpose of the transpose argument.
Teuchos::RCP< const Thyra::LinearOpBase< value_type > > set_uninitialized()
Set to uninitialized and return smart pointer to the internal Thyra::VectorBase object.
Base class for all matrices that support basic matrix operations.
Teuchos::RCP< Thyra::VectorBase< value_type > > set_uninitialized()
Set to uninitialized and return smart pointer to the internal Thyra::VectorBase object.
Abstract interface for mutable coordinate vectors {abstract}.
friend void M_StInvMtM(MatrixOp *m_lhs, value_type alpha, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2)
Teuchos::RCP< const Thyra::LinearOpWithSolveBase< value_type > > set_uninitialized()
Set to uninitialized and return smart pointer to the internal Thyra::LinearOpWithSolveBase object...
Transp
TRANS.
void initialize(const Teuchos::RCP< Thyra::VectorBase< value_type > > &thyra_vec)
Initalize given a smart pointer to a Thyra::Vetor object.
const Teuchos::RCP< const Thyra::LinearOpBase< value_type > > & thyra_linear_op() const
Return a (converted) smart pointer to the internal smart pointer to the Thyra::VectorBase object...