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