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

Generated on Thu Sep 18 12:33:52 2008 for AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects by doxygen 1.3.9.1