MOOCHO/Thyra Adapter Software  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AbstractLinAlgPack_MatrixOpThyra.cpp
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 #include <assert.h>
43 
44 #include "AbstractLinAlgPack_MatrixOpThyra.hpp"
45 #include "AbstractLinAlgPack_VectorMutableThyra.hpp"
46 #include "AbstractLinAlgPack_ThyraAccessors.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::LinearOpBase<value_type> > &thyra_linear_op
59  ,BLAS_Cpp::Transp thyra_linear_op_trans
60  )
61 {
62  this->initialize(thyra_linear_op,thyra_linear_op_trans);
63 }
64 
66  const Teuchos::RCP<const Thyra::LinearOpBase<value_type> > &thyra_linear_op
67  ,BLAS_Cpp::Transp thyra_linear_op_trans
68  )
69 {
70  namespace mmp = MemMngPack;
72  thyra_linear_op.get()==NULL, std::invalid_argument
73  ,"MatrixOpThyra::initialize(thyra_linear_op): Error!"
74  );
75  const bool adjointSupported = ( ::Thyra::opSupported(*thyra_linear_op,Thyra::NOTRANS) && ::Thyra::opSupported(*thyra_linear_op,Thyra::TRANS) );
77  !adjointSupported, std::invalid_argument
78  ,"MatrixOpThyra::initialize(thyra_linear_op): Error, the operator opSupported(thyra_linear_op,transp) must return true "
79  "for both values of transp==NOTRANS and transp=TRANS!"
80  );
81  thyra_linear_op_ = thyra_linear_op;
82  thyra_linear_op_trans_ = thyra_linear_op_trans;
83  space_cols_.initialize(thyra_linear_op_->range());
84  space_rows_.initialize(thyra_linear_op_->domain());
85 }
86 
89 {
90  Teuchos::RCP<const Thyra::LinearOpBase<value_type> > tmp_thyra_linear_op = thyra_linear_op_;
91  thyra_linear_op_ = Teuchos::null;
92  thyra_linear_op_trans_ = BLAS_Cpp::no_trans;
93  space_cols_.set_uninitialized();
94  space_rows_.set_uninitialized();
95  return tmp_thyra_linear_op;
96 }
97 
98 // Overridden from MatrixBase
99 
100 const VectorSpace&
102 {
103  return space_cols_;
104 }
105 
106 const VectorSpace&
108 {
109  return space_rows_;
110 }
111 
112 // Overridden from MatrixOp
113 
114 MatrixOp::mat_mut_ptr_t
116 {
117  return Teuchos::rcp(new MatrixOpThyra(thyra_linear_op_->clone()));
118 }
119 
121 {
122  using Teuchos::dyn_cast;
123  const MatrixOpThyra &mwo_rhs_thyra = dyn_cast<const MatrixOpThyra>(mwo_rhs);
124  thyra_linear_op_ = mwo_rhs_thyra.thyra_linear_op_; // ToDo: Clone this!
125  thyra_linear_op_trans_ = mwo_rhs_thyra.thyra_linear_op_trans_;
126  space_cols_ = mwo_rhs_thyra.space_cols_; // ToDo: Clone this!
127  space_rows_ = mwo_rhs_thyra.space_rows_; // ToDo: Clone this!
128  return *this;
129 }
130 
132  VectorMutable* v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
133  ,const Vector& v_rhs2, value_type beta
134  ) const
135 {
136  using BLAS_Cpp::trans_trans;
137  // Get Thyra views of the vectors
139  get_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_rows_ : space_cols_, v_rhs2, &thyra_vec_rhs2 );
141  get_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_cols_ : space_rows_, v_lhs, &thyra_vec_lhs );
142  // Perform the multiplication
143  ::Thyra::apply(
144  *thyra_linear_op_
146  ,*thyra_vec_rhs2 // x
147  ,thyra_vec_lhs.ptr() // y
148  ,alpha // alpha
149  ,beta // beta
150  );
151  // Free/commit Thyra vector views
152  free_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_rows_ : space_cols_, v_rhs2, &thyra_vec_rhs2 );
153  commit_thyra_vector( BLAS_Cpp::no_trans==trans_rhs1 ? space_cols_ : space_rows_, v_lhs, &thyra_vec_lhs );
154 }
155 
157  MatrixOp* mwo_lhs, value_type alpha
158  ,BLAS_Cpp::Transp trans_rhs1
159  ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
160  ,value_type beta
161  ) const
162 {
163  return false; // ToDo: Specialize!
164 }
165 
166 } // end namespace AbstractLinAlgPack
MatrixOp & operator=(const MatrixOp &mwo_rhs)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_To & dyn_cast(T_From &from)
Teuchos::RCP< const Thyra::VectorSpaceBase< value_type > > set_uninitialized()
Set to uninitialized and return smart pointer to the internal Thyra::VectorSpaceBase<value_type> obj...
void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta) const
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.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Ptr< T > ptr() const
EOpTransp trans_trans(EOpTransp trans1, EOpTransp trans2)
bool Mp_StMtM(MatrixOp *mwo_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta) const
Works for MultiVectorMutableThyra arguments.
Teuchos::RCP< const Thyra::LinearOpBase< value_type > > set_uninitialized()
Set to uninitialized and return smart pointer to the internal Thyra::VectorBase object.
MatrixOp adapter subclass for Thyra::LinearOpBase.
void initialize(const Teuchos::RCP< const Thyra::VectorSpaceBase< value_type > > &thyra_vec_spc, const inner_prod_ptr_t &inner_prod=Teuchos::null)
Initalize given a smart pointer to a Thyra::VetorSpace object.
Transp
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...