AbstractLinAlgPack_MatrixComposite.hpp

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 #ifndef MATRIX_COMPOSITE_STD_H
00030 #define MATRIX_COMPOSITE_STD_H
00031 
00032 #include <deque>
00033 
00034 #include "AbstractLinAlgPack_MatrixOp.hpp"
00035 #include "AbstractLinAlgPack_GenPermMatrixSlice.hpp"
00036 #include "AbstractLinAlgPack_VectorSpace.hpp"
00037 #include "Teuchos_RefCountPtr.hpp"
00038 #include "ReleaseResource.hpp"
00039 
00040 namespace AbstractLinAlgPack {
00041 
00113 class MatrixComposite : public MatrixOp {
00114 public:
00115 
00116   // ///////////////////////////////////
00117   // Public types
00118 
00120   typedef Teuchos::RefCountPtr<
00121     MemMngPack::ReleaseResource>  release_resource_ptr_t;
00122 
00127   struct SubVectorEntry {
00129     typedef Teuchos::RefCountPtr<const GenPermMatrixSlice> GPMS_ptr_t;
00131     SubVectorEntry(
00132       size_type r_l, size_type c_l, value_type beta
00133       ,const Range1D& rng_G
00134       ,const GPMS_ptr_t& G, const release_resource_ptr_t& G_release, BLAS_Cpp::Transp G_trans
00135       ,const Vector* v
00136       ,const release_resource_ptr_t& v_release, BLAS_Cpp::Transp v_trans
00137       )
00138       :r_l_(r_l),c_l_(c_l),beta_(beta),rng_G_(rng_G),G_(G),G_release_(G_release),G_trans_(G_trans)
00139       ,v_(v),v_release_(v_release),v_trans_(v_trans)
00140       {}
00142     bool operator==(const SubVectorEntry v)
00143       {
00144         return 
00145           r_l_==v.r_l_ && c_l_==v.c_l_ && beta_==v.beta_
00146           && rng_G_==v.rng_G_ && G_.get()==v.G_.get() && G_release_.get()==v.G_release_.get() && G_trans_==v.G_trans_
00147           && v_==v.v_ && v_release_.get()==v.v_release_.get() && v_trans_==v.v_trans_;
00148       }
00150     size_type                  r_l_,   
00151                                c_l_;   
00152 
00153     value_type                 beta_;  
00154 
00155     Range1D                    rng_G_; 
00156 
00157     GPMS_ptr_t                 G_;     
00158 
00159     release_resource_ptr_t     G_release_;
00161     BLAS_Cpp::Transp           G_trans_;
00162 
00163     const Vector         *v_;     
00164 
00165     release_resource_ptr_t     v_release_;
00167     BLAS_Cpp::Transp           v_trans_;
00168   }; // end struct SubVectorEntry
00169 
00171   typedef std::deque<SubVectorEntry> vector_list_t;
00172 
00177   struct SubMatrixEntry {
00179     typedef Teuchos::RefCountPtr<const GenPermMatrixSlice> GPMS_ptr_t;
00181     SubMatrixEntry(
00182       size_type r_l, size_type r_u, size_type c_l, size_type c_u, value_type alpha
00183       ,const Range1D& rng_P
00184       ,const GPMS_ptr_t& P, const release_resource_ptr_t& P_release, BLAS_Cpp::Transp P_trans
00185       ,const MatrixOp* A, const release_resource_ptr_t& A_release, BLAS_Cpp::Transp A_trans
00186       ,const Range1D& rng_Q
00187       ,const GPMS_ptr_t& Q, const release_resource_ptr_t& Q_release, BLAS_Cpp::Transp Q_trans
00188       )
00189       :r_l_(r_l),r_u_(r_u),c_l_(c_l),c_u_(c_u),alpha_(alpha),rng_P_(rng_P),P_(P),P_release_(P_release),P_trans_(P_trans)
00190       ,A_(A),A_release_(A_release),A_trans_(A_trans),rng_Q_(rng_Q),Q_(Q),Q_release_(Q_release),Q_trans_(Q_trans)
00191       {}
00193     bool operator==(const SubMatrixEntry m)
00194       {
00195         return
00196           r_l_==m.r_l_ && r_u_==m.r_u_ && c_l_==m.c_l_ && c_u_==m.c_u_ && alpha_==m.alpha_
00197           && rng_P_==m.rng_P_ && P_.get()==m.P_.get() && P_release_.get()==m.P_release_.get() && P_trans_==m.P_trans_
00198           && A_==m.A_ && A_release_.get()==m.A_release_.get() && A_trans_==m.A_trans_
00199           && rng_Q_==m.rng_Q_ && Q_.get()==m.Q_.get() && Q_release_.get()==m.Q_release_.get() && Q_trans_==m.Q_trans_;
00200       }
00202     size_type                  r_l_, r_u_, c_l_, c_u_;
00204     value_type                 alpha_;
00206     Range1D                    rng_P_;  // rng_P_.size() > 0 => P_ is ignored, rng_P_.full_range() => all rows op(A)
00208     GPMS_ptr_t                 P_;
00210     release_resource_ptr_t     P_release_;
00212     BLAS_Cpp::Transp           P_trans_;
00214     const MatrixOp         *A_;
00216     release_resource_ptr_t     A_release_;
00218     BLAS_Cpp::Transp           A_trans_;
00220     Range1D                    rng_Q_; // rng_Q_.size() > 0 => Q_ is ignored, rng_Q_.full_range() => all columns op(A)
00222     GPMS_ptr_t                 Q_;
00224     release_resource_ptr_t     Q_release_;
00226     BLAS_Cpp::Transp           Q_trans_;
00227   }; // end struct SubMatrixEntry
00228 
00230   typedef std::deque<SubMatrixEntry> matrix_list_t;
00231 
00234 
00239   MatrixComposite( size_type rows = 0, size_type cols = 0 );
00240 
00252   void reinitialize( size_type rows = 0, size_type cols = 0 );
00253 
00258   void add_vector(
00259     size_type                      row_offset
00260     ,size_type                     col_offset
00261     ,value_type                    beta
00262     ,const GenPermMatrixSlice      *G
00263     ,const release_resource_ptr_t  &G_release
00264     ,BLAS_Cpp::Transp              G_trans
00265     ,const Vector            *v
00266     ,const release_resource_ptr_t  &v_release
00267     ,BLAS_Cpp::Transp              v_trans
00268     );
00269 
00274   void add_vector(
00275     size_type                      row_offset
00276     ,size_type                     col_offset
00277     ,value_type                    beta
00278     ,const Range1D                 &rng_G
00279     ,const Vector            *v
00280     ,const release_resource_ptr_t  &v_release
00281     ,BLAS_Cpp::Transp              v_trans
00282     );
00283 
00288   void add_vector(
00289     size_type                      row_offset
00290     ,size_type                     col_offset
00291     ,value_type                    beta
00292     ,const Vector            *v
00293     ,const release_resource_ptr_t  &v_release
00294     ,BLAS_Cpp::Transp              v_trans
00295     );
00296 
00304   void remove_vector( vector_list_t::iterator itr );
00305 
00310   void add_matrix(
00311     size_type                      row_offset
00312     ,size_type                     col_offset
00313     ,value_type                    alpha
00314     ,const GenPermMatrixSlice      *P
00315     ,const release_resource_ptr_t  &P_release
00316     ,BLAS_Cpp::Transp              P_trans
00317     ,const MatrixOp            *A
00318     ,const release_resource_ptr_t  &A_release
00319     ,BLAS_Cpp::Transp              A_trans
00320     ,const GenPermMatrixSlice      *Q
00321     ,const release_resource_ptr_t  &Q_release
00322     ,BLAS_Cpp::Transp              Q_trans
00323     );
00324 
00329   void add_matrix(
00330     size_type                      row_offset
00331     ,size_type                     col_offset
00332     ,value_type                    alpha
00333     ,const Range1D                 &rng_P
00334     ,const MatrixOp            *A
00335     ,const release_resource_ptr_t  &A_release
00336     ,BLAS_Cpp::Transp              A_trans
00337     ,const Range1D                 &rng_Q
00338     );
00339 
00344   void add_matrix(
00345     size_type                      row_offset
00346     ,size_type                     col_offset
00347     ,value_type                    alpha
00348     ,const Range1D                 &rng_P
00349     ,const MatrixOp            *A
00350     ,const release_resource_ptr_t  &A_release
00351     ,BLAS_Cpp::Transp              A_trans
00352     ,const GenPermMatrixSlice      *Q
00353     ,const release_resource_ptr_t  &Q_release
00354     ,BLAS_Cpp::Transp              Q_trans
00355     );
00356 
00361   void add_matrix(
00362     size_type                      row_offset
00363     ,size_type                     col_offset
00364     ,value_type                    alpha
00365     ,const GenPermMatrixSlice      *P
00366     ,const release_resource_ptr_t  &P_release
00367     ,BLAS_Cpp::Transp              P_trans
00368     ,const MatrixOp            *A
00369     ,const release_resource_ptr_t  &A_release
00370     ,BLAS_Cpp::Transp              A_trans
00371     ,const Range1D                 &rng_Q
00372     );
00373 
00378   void add_matrix(
00379     size_type                      row_offset
00380     ,size_type                     col_offset
00381     ,value_type                    alpha
00382     ,const MatrixOp            *A
00383     ,const release_resource_ptr_t  &A_release
00384     ,BLAS_Cpp::Transp              A_trans
00385     );
00386 
00391   void add_matrix(
00392     size_type                      row_offset
00393     ,size_type                     col_offset
00394     ,value_type                    alpha
00395     ,const GenPermMatrixSlice      *P
00396     ,const release_resource_ptr_t  &P_release
00397     ,BLAS_Cpp::Transp              P_trans
00398     );
00399 
00407   void remove_matrix( matrix_list_t::iterator itr );
00408 
00439   virtual void finish_construction(
00440     const VectorSpace::space_ptr_t&  space_cols
00441     ,const VectorSpace::space_ptr_t& space_rows
00442     );
00443 
00445 
00448 
00450   int                             num_vectors() const;
00452   vector_list_t::iterator         vectors_begin();
00454   vector_list_t::iterator         vectors_end();
00456   vector_list_t::const_iterator   vectors_begin() const;
00458   vector_list_t::const_iterator   vectors_end() const;
00460   int                             num_matrices() const;
00462   matrix_list_t::iterator         matrices_begin();
00464   matrix_list_t::iterator         matrices_end();
00466   matrix_list_t::const_iterator   matrices_begin() const;
00468   matrix_list_t::const_iterator   matrices_end() const;
00469 
00471 
00474 
00476   size_type rows() const;
00478   size_type cols() const;
00480   size_type nz() const;
00481 
00483 
00486 
00488   const VectorSpace& space_rows() const;
00490   const VectorSpace& space_cols() const;
00492   mat_ptr_t sub_view(const Range1D& row_rng, const Range1D& col_rng) const;
00494   void Vp_StMtV(VectorMutable* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00495     , const Vector& v_rhs2, value_type beta) const;
00497   void Vp_StMtV(VectorMutable* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00498     , const SpVectorSlice& sv_rhs2, value_type beta) const;
00500   void Vp_StPtMtV(VectorMutable* vs_lhs, value_type alpha
00501     , const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00502     , BLAS_Cpp::Transp M_rhs2_trans
00503     , const Vector& v_rhs3, value_type beta) const;
00505   void Vp_StPtMtV(VectorMutable* vs_lhs, value_type alpha
00506     , const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00507     , BLAS_Cpp::Transp M_rhs2_trans
00508     , const SpVectorSlice& sv_rhs3, value_type beta) const;
00509 
00511 
00512 private:
00513 
00514   // ///////////////////////////////
00515   // private data members
00516 
00517   bool                       fully_constructed_;
00518   size_type                  rows_, cols_;
00519 #ifdef DOXYGEN_COMPILE
00520   MatrixOp               *matrices;
00521     Vector               *vectors;
00522     VectorSpace                *space_cols;
00523     VectorSpace                *space_rows;
00524 #else
00525   matrix_list_t              matrix_list_;
00526   vector_list_t              vector_list_;
00527   VectorSpace::space_ptr_t   space_cols_;
00528   VectorSpace::space_ptr_t   space_rows_;
00529 #endif
00530 
00531   // ///////////////////////////////
00532   // private member functions
00533 
00534   void assert_fully_constructed() const;
00535 
00536 }; // end class MatrixComposite
00537 
00538 } // end namespace AbstractLinAlgPack
00539 
00540 #endif // MATRIX_COMPOSITE_STD_H

Generated on Thu Sep 18 12:35:11 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1