AbstractLinAlgPack_MatrixExtractSparseElements.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 <assert.h>
00030 
00031 #include "AbstractLinAlgPack_MatrixExtractSparseElements.hpp"
00032 
00033 namespace AbstractLinAlgPack {
00034 
00035 // Overridden from MatrixConvertToSparseFortranCompatible
00036 
00037 index_type
00038 MatrixExtractSparseElements::num_nonzeros(
00039   EExtractRegion        extract_region
00040   ,EElementUniqueness   element_uniqueness
00041   ) const
00042 {
00043   index_type dl,du;
00044   get_dl_du(extract_region,&dl,&du);
00045   return count_nonzeros(
00046     element_uniqueness,NULL,NULL,Range1D(1,rows()),Range1D(1,cols()),dl,du);
00047 }
00048 
00049 void MatrixExtractSparseElements::coor_extract_nonzeros(
00050   EExtractRegion                extract_region
00051   ,EElementUniqueness           element_uniqueness
00052   ,const index_type             len_Aval
00053   ,value_type                   Aval[]
00054   ,const index_type             len_Aij
00055   ,index_type                   Arow[]
00056   ,index_type                   Acol[]
00057   ,const index_type             row_offset
00058   ,const index_type             col_offset
00059    ) const
00060 {
00061   int dl,du;
00062   get_dl_du(extract_region,&dl,&du);
00063   coor_extract_nonzeros(
00064     element_uniqueness
00065     ,NULL,NULL,Range1D(1,rows()),Range1D(1,cols()),dl,du
00066     ,1.0
00067     ,len_Aval,Aval,len_Aij,Arow,Acol,row_offset,col_offset);
00068 }
00069 
00070 // private
00071 
00072 void MatrixExtractSparseElements::get_dl_du(
00073   EExtractRegion extract_region, index_type* dl, index_type* du
00074   ) const
00075 {
00076   const size_type
00077     rows = this->rows(),
00078     cols = this->cols();
00079   switch(extract_region) {
00080     case EXTRACT_FULL_MATRIX:
00081       *dl = -(rows-1);
00082       *du = +(cols-1);
00083       break;
00084     case EXTRACT_UPPER_TRIANGULAR:
00085       *dl = 0;
00086       *du = +(cols-1);
00087       break;
00088     case EXTRACT_LOWER_TRIANGULAR:
00089       *dl = -(rows-1);
00090       *du = 0;
00091       break;
00092     default:
00093       TEST_FOR_EXCEPT(true);
00094       break;
00095   }
00096 }
00097 
00098 
00099 } // end namespace AbstractLinAlgPack 

Generated on Wed May 12 21:52:26 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7