MOOCHO/Thyra Adapter Software Version of the Day
AbstractLinAlgPack_MultiVectorMutableThyra.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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include <assert.h>
00043 
00044 #include "AbstractLinAlgPack_MultiVectorMutableThyra.hpp"
00045 #include "AbstractLinAlgPack_VectorMutableThyra.hpp"
00046 #include "Teuchos_Assert.hpp"
00047 #include "Teuchos_dyn_cast.hpp"
00048 
00049 namespace AbstractLinAlgPack {
00050 
00051 // Constructors / Initializers
00052 
00053 MultiVectorMutableThyra::MultiVectorMutableThyra()
00054 {}
00055 
00056 MultiVectorMutableThyra::MultiVectorMutableThyra(
00057   const Teuchos::RCP<Thyra::MultiVectorBase<value_type> >& thyra_multi_vec
00058   )
00059 {
00060   this->initialize(thyra_multi_vec);
00061 }
00062 
00063 void MultiVectorMutableThyra::initialize(
00064   const Teuchos::RCP<Thyra::MultiVectorBase<value_type> >& thyra_multi_vec
00065   )
00066 {
00067   namespace mmp = MemMngPack;
00068   TEUCHOS_TEST_FOR_EXCEPTION(
00069     thyra_multi_vec.get()==NULL, std::invalid_argument
00070     ,"MultiVectorMutableThyra::initialize(thyra_multi_vec): Error!"
00071     );
00072   MatrixOpThyra::initialize(thyra_multi_vec);
00073 }
00074 
00075 Teuchos::RCP<Thyra::MultiVectorBase<value_type> > 
00076 MultiVectorMutableThyra::set_uninitialized()
00077 {
00078   Teuchos::RCP<Thyra::MultiVectorBase<value_type> >
00079     tmp_thyra_multi_vec = cast_thyra_multi_vec();
00080   MatrixOpThyra::set_uninitialized();
00081   return tmp_thyra_multi_vec;
00082 }
00083 
00084 Teuchos::RCP<const Thyra::MultiVectorBase<value_type> >
00085 MultiVectorMutableThyra::thyra_multi_vec() const
00086 {
00087   return Teuchos::rcp_dynamic_cast<const Thyra::MultiVectorBase<value_type> >(this->thyra_linear_op());
00088 }
00089 
00090 // Overridden from MatrixOpThyra
00091 
00092 void MultiVectorMutableThyra::initialize(
00093   const Teuchos::RCP<const Thyra::LinearOpBase<value_type> >& thyra_linear_op
00094   )
00095 {
00096   namespace mmp = MemMngPack;
00097   this->initialize(
00098     Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<value_type> >(
00099       Teuchos::rcp_const_cast<Thyra::LinearOpBase<value_type> >(thyra_linear_op)
00100       )
00101     );
00102 }
00103 
00104 // Overridden from MatrixOp
00105 
00106 MatrixOp::mat_mut_ptr_t
00107 MultiVectorMutableThyra::clone()
00108 {
00109   return this->MatrixOpThyra::clone();
00110 }
00111 
00112 MatrixOp& MultiVectorMutableThyra::operator=(const MatrixOp& mwo_rhs)
00113 {
00114   return this->MultiVectorMutable::operator=(mwo_rhs);
00115 }
00116 
00117 void MultiVectorMutableThyra::Vp_StMtV(
00118   VectorMutable* v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00119   ,const Vector& v_rhs2, value_type beta
00120   ) const
00121 {
00122   this->MatrixOpThyra::Vp_StMtV(v_lhs,alpha,trans_rhs1,v_rhs2,beta);
00123 }
00124 
00125 bool MultiVectorMutableThyra::Mp_StMtM(
00126   MatrixOp* mwo_lhs, value_type alpha
00127   ,BLAS_Cpp::Transp trans_rhs1
00128   ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
00129   ,value_type beta
00130   ) const
00131 {
00132   return this->MatrixOpThyra::Mp_StMtM(mwo_lhs,alpha,trans_rhs1,mwo_rhs2,trans_rhs2,beta);
00133 }
00134 
00135 // Overridden from MultiVector
00136 
00137 MultiVector::access_by_t
00138 MultiVectorMutableThyra::access_by() const
00139 {
00140   return COL_ACCESS;
00141 }
00142 
00143 void MultiVectorMutableThyra::apply_op(
00144   EApplyBy apply_by, const RTOpPack::RTOp& primary_op
00145   ,const size_t num_multi_vecs,      const MultiVector*   multi_vecs[]
00146   ,const size_t num_targ_multi_vecs, MultiVectorMutable*  targ_multi_vecs[]
00147   ,RTOpPack::ReductTarget* reduct_objs[]
00148   ,const index_type primary_first_ele,   const index_type primary_sub_dim, const index_type primary_global_offset
00149   ,const index_type secondary_first_ele, const index_type secondary_sub_dim
00150   ) const
00151 {
00152   MultiVector::apply_op(
00153     apply_by,primary_op,num_multi_vecs,multi_vecs,num_targ_multi_vecs,targ_multi_vecs
00154     ,reduct_objs
00155     ,primary_first_ele,primary_sub_dim,primary_global_offset
00156     ,secondary_first_ele,secondary_sub_dim
00157     ); // ToDo: Specialize!
00158 }
00159 
00160 void MultiVectorMutableThyra::apply_op(
00161   EApplyBy apply_by, const RTOpPack::RTOp& primary_op, const RTOpPack::RTOp& secondary_op
00162   ,const size_t num_multi_vecs,      const MultiVector*   multi_vecs[]
00163   ,const size_t num_targ_multi_vecs, MultiVectorMutable*  targ_multi_vecs[]
00164   ,RTOpPack::ReductTarget *reduct_obj
00165   ,const index_type primary_first_ele, const index_type primary_sub_dim, const index_type primary_global_offset
00166   ,const index_type secondary_first_ele, const index_type secondary_sub_dim
00167   ) const
00168 {
00169   MultiVector::apply_op(
00170     apply_by,primary_op,secondary_op,num_multi_vecs,multi_vecs,num_targ_multi_vecs,targ_multi_vecs
00171     ,reduct_obj
00172     ,primary_first_ele,primary_sub_dim,primary_global_offset
00173     ,secondary_first_ele,secondary_sub_dim
00174     ); // ToDo: Specialize!
00175 }
00176 
00177 // Overridden from MultiVectorMutable
00178 
00179 MultiVectorMutable::vec_mut_ptr_t
00180 MultiVectorMutableThyra::col(index_type j)
00181 {
00182   return Teuchos::rcp(new VectorMutableThyra(cast_thyra_multi_vec()->col(j-1)));
00183 }
00184 
00185 MultiVectorMutable::vec_mut_ptr_t
00186 MultiVectorMutableThyra::row(index_type i)
00187 {
00188   return Teuchos::null;
00189 }
00190 
00191 MultiVectorMutable::vec_mut_ptr_t
00192 MultiVectorMutableThyra::diag(int k)
00193 {
00194   return Teuchos::null;
00195 }
00196 
00197 MultiVectorMutable::multi_vec_mut_ptr_t
00198 MultiVectorMutableThyra::mv_sub_view(const Range1D& row_rng_in, const Range1D& col_rng_in)
00199 {
00200   const index_type  this_rows = this->rows();
00201   const Range1D     row_rng = RangePack::full_range(row_rng_in,1,this->rows());
00202   TEUCHOS_TEST_FOR_EXCEPTION(
00203     !(row_rng.lbound()==1 && row_rng.ubound()==this_rows), std::invalid_argument
00204     ,"MultiVectorMutableThyra::mv_sub_view(thyra_multi_vec): Error, can not handle subviews of the"
00205     " elements in a row yet!"
00206     );
00207   return Teuchos::rcp(new MultiVectorMutableThyra(cast_thyra_multi_vec()->subView(convert(col_rng_in))));
00208 }
00209 
00210 // private
00211 
00212 Teuchos::RCP<Thyra::MultiVectorBase<value_type> >
00213 MultiVectorMutableThyra::cast_thyra_multi_vec()
00214 {
00215   namespace mmp = MemMngPack;
00216   return Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<value_type> >(
00217     Teuchos::rcp_const_cast<Thyra::LinearOpBase<value_type> >(this->thyra_linear_op())
00218     );
00219 }
00220 
00221 } // end namespace AbstractLinAlgPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends