cgma
CubitSparseMatrix.hpp
Go to the documentation of this file.
00001 //- Class: CubitSparseMatrix
00002 //-
00003 //- Description: This file defines the CubitSparseMatrix class which is a
00004 //- sparse NxM Matrix.
00005 //-
00006 //- Author: Matt Staten
00007 //- Data: 4/15/2011
00008 //- Checked by:
00009 
00010 #ifndef CUBITSPARSEMATRIX_HPP
00011 #define CUBITSPARSEMATRIX_HPP
00012 
00013 #include <map>
00014 #include <vector>
00015 #include "CGMUtilConfigure.h"
00016 #include <stddef.h>
00017 
00018 class CUBIT_UTIL_EXPORT CubitSparseMatrix
00019 {
00020 public:
00021   
00022   CubitSparseMatrix();
00023   CubitSparseMatrix( int numRows,
00024                      int numCols,
00025                      std::vector<int> &is,
00026                      std::vector<int> &js,
00027                      std::vector<double> &es );
00028 
00029   ~CubitSparseMatrix();
00030     //- destructor
00031   
00032   void reset( int numRows,
00033               int numCols,
00034               std::vector<int> &is,
00035               std::vector<int> &js,
00036               std::vector<double> &es );
00037   void clear(); // Delete all data, free all memory and set sizes to 0
00038   void print( char *filename = 0 ) const;
00039 
00040   void add( int row, int col, double data );
00041 
00042   int num_non_zeros( void ) const;
00043   void num_non_zeros_per_row( double &ave, 
00044                               int &max, 
00045                               int &min ) const;
00046   int num_rows( void ) const { return numRows; };
00047   int num_cols( void ) const { return numCols; };
00048 
00049   // - Get an entry int the matrix, 0 <= idx < this->num_non_zeros()
00050   const std::map<int,double> * get_row( int row ) const;
00051 
00052   // Create a matrix containing the rows and cols of this that are true in
00053   // rows_to_include and cols_to_include.
00054   void sub_matrix( const std::vector<bool> &rows_to_include,
00055                    const std::vector<bool> &cols_to_include,
00056                    CubitSparseMatrix &submatrix );
00057 
00058   std::vector<double> operator* (const std::vector<double> &vec ) const;
00059 
00060      //- Add an identity matrix into this matrix.
00061   void plus_identity();
00062 
00063 private:
00064 
00065   void delete_data( void );
00066 
00067   std::map< int, std::map< int, double> * > matrixData;
00068 
00069   int numRows;
00070   int numCols;
00071 };
00072 
00073 #endif
00074 
00075 
00076 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines