AbstractLinAlgPack_MultiVectorMutable.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 "AbstractLinAlgPack_MultiVectorMutable.hpp"
00030 #include "AbstractLinAlgPack_VectorMutable.hpp"
00031 #include "AbstractLinAlgPack_VectorSpace.hpp"
00032 #include "RTOp_TOp_assign_scalar.h"
00033 #include "RTOp_TOp_assign_vectors.h"
00034 #include "RTOp_TOp_scale_vector.h"
00035 #include "RTOpPack_RTOpC.hpp"
00036 #include "Teuchos_Workspace.hpp"
00037 #include "Teuchos_dyn_cast.hpp"
00038 
00039 namespace {
00040 
00041 // vector scalar assignment operator
00042 RTOpPack::RTOpC& assign_scalar_op()
00043 {
00044   static RTOpPack::RTOpC          assign_scalar_op_;
00045   return(assign_scalar_op_);
00046 }
00047 // vector assignment operator
00048 static RTOpPack::RTOpC          assign_vec_op;
00049 // scale vector
00050 static RTOpPack::RTOpC          scale_vector_op;
00051 
00052 // Simple class for an object that will initialize the operator objects
00053 class init_rtop_server_t {
00054 public:
00055   init_rtop_server_t() {
00056     // Vector scalar assignment operator
00057     TEST_FOR_EXCEPT(0!=RTOp_TOp_assign_scalar_construct(0.0,&assign_scalar_op().op()));
00058     // Vector assignment operator
00059     TEST_FOR_EXCEPT(0!=RTOp_TOp_assign_vectors_construct(&assign_vec_op.op()));
00060     // Operator scale_vector
00061     TEST_FOR_EXCEPT(0!=RTOp_TOp_scale_vector_construct(0.0,&scale_vector_op.op()));
00062   }
00063 }; 
00064 
00065 // When the program starts, this object will be created and the RTOp_Server object will
00066 // be initialized before main() gets underway!
00067 init_rtop_server_t  init_rtop_server;
00068 
00069 } // end namespace
00070 
00071 namespace AbstractLinAlgPack {
00072 
00073 // Clone
00074 
00075 MultiVectorMutable::multi_vec_mut_ptr_t
00076 MultiVectorMutable::mv_clone()
00077 {
00078   multi_vec_mut_ptr_t
00079     new_mv = this->space_cols().create_members(this->cols());
00080   const MultiVector*  multi_vecs[]      = { this };
00081   MultiVectorMutable* targ_multi_vecs[] = { new_mv.get() };
00082   AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_vec_op,1,multi_vecs,1,targ_multi_vecs,NULL);
00083   return new_mv;
00084 }
00085 
00086 // Sub-view methods
00087 
00088 MultiVectorMutable::multi_vec_mut_ptr_t
00089 MultiVectorMutable::mv_sub_view(const Range1D& row_rng, const Range1D& col_rng)
00090 {
00091   TEST_FOR_EXCEPT(true); // ToDo: return a MultiVectorMutableSubView object.
00092   // Note that the MultiVectorMutableSubView class should derive from
00093   // MultiVectorSubView.
00094   return Teuchos::null;
00095 }
00096 
00097 // Overridden from MatrixOp
00098 
00099 void MultiVectorMutable::zero_out()
00100 {
00101   TEST_FOR_EXCEPT(0!=RTOp_TOp_assign_scalar_set_alpha(0.0,&assign_scalar_op().op()));
00102   MultiVectorMutable* targ_multi_vecs[] = { this };
00103   AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_scalar_op(),0,NULL,1,targ_multi_vecs,NULL);
00104 }
00105 
00106 void MultiVectorMutable::Mt_S( value_type alpha )
00107 {
00108   if( alpha == 0.0 ) {
00109     TEST_FOR_EXCEPT(0!=RTOp_TOp_assign_scalar_set_alpha(alpha,&assign_scalar_op().op()));
00110     MultiVectorMutable* targ_multi_vecs[] = { this };
00111     AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_scalar_op(),0,NULL,1,targ_multi_vecs,NULL);
00112   }
00113   else if( alpha != 1.0 ) {
00114     TEST_FOR_EXCEPT(0!=RTOp_TOp_scale_vector_set_alpha(alpha,&scale_vector_op.op()));
00115     MultiVectorMutable* targ_multi_vecs[] = { this };
00116     AbstractLinAlgPack::apply_op(APPLY_BY_COL,scale_vector_op,0,NULL,1,targ_multi_vecs,NULL);
00117   }
00118 }
00119 
00120 MatrixOp& MultiVectorMutable::operator=(const MatrixOp& mwo_rhs)
00121 {
00122   const MultiVector *mv_rhs = dynamic_cast<const MultiVector*>(&mwo_rhs);
00123   if(mv_rhs) {
00124     const MultiVector*  multi_vecs[]      = { mv_rhs };
00125     MultiVectorMutable* targ_multi_vecs[] = { this };
00126     AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_vec_op,1,multi_vecs,1,targ_multi_vecs,NULL);
00127   }
00128   else {
00129     TEST_FOR_EXCEPT(true); // ToDo: Get column by column or row by row
00130   }
00131   return *this;
00132 }
00133 
00134 MatrixOp::mat_mut_ptr_t
00135 MultiVectorMutable::clone()
00136 {
00137   return this->mv_clone();
00138 }
00139 
00140 bool MultiVectorMutable::Mp_StM(
00141   MatrixOp* mwo_lhs, value_type alpha
00142   ,BLAS_Cpp::Transp trans_rhs
00143   ) const
00144 {
00145   return false; // ToDo: Specialize!
00146 }
00147 
00148 bool MultiVectorMutable::Mp_StM(
00149   value_type alpha,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs
00150   )
00151 {
00152   return false; // ToDo: Specialize!
00153 }
00154 
00155 // Overridden form MultiVector
00156 
00157 MultiVector::multi_vec_ptr_t MultiVectorMutable::mv_clone() const
00158 {
00159   return const_cast<MultiVectorMutable*>(this)->mv_clone();
00160 }
00161 
00162 MultiVectorMutable::vec_ptr_t MultiVectorMutable::col(index_type j) const
00163 {
00164   return const_cast<MultiVectorMutable*>(this)->col(j);
00165 }
00166 
00167 MultiVectorMutable::vec_ptr_t MultiVectorMutable::row(index_type i) const
00168 {
00169   return const_cast<MultiVectorMutable*>(this)->row(i);
00170 }
00171 
00172 MultiVectorMutable::vec_ptr_t MultiVectorMutable::diag(int k) const
00173 {
00174   return const_cast<MultiVectorMutable*>(this)->diag(k);
00175 }
00176 
00177 MultiVectorMutable::multi_vec_ptr_t
00178 MultiVectorMutable::mv_sub_view(const Range1D& row_rng, const Range1D& col_rng) const
00179 {
00180   return const_cast<MultiVectorMutable*>(this)->mv_sub_view(row_rng,col_rng);
00181 }
00182 
00183 } // end namespace AbstractLinAlgPack

Generated on Tue Jul 13 09:30:50 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7