FEI Version of the Day
fei_AztecDMSR_Matrix.hpp
00001 #ifndef _AztecDMSR_Matrix_h_
00002 #define _AztecDMSR_Matrix_h_
00003 
00004 #ifdef HAVE_FEI_AZTECOO
00005 
00006 /*--------------------------------------------------------------------*/
00007 /*    Copyright 2005 Sandia Corporation.                              */
00008 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00009 /*    non-exclusive license for use of this work by or on behalf      */
00010 /*    of the U.S. Government.  Export of this program may require     */
00011 /*    a license from the United States Government.                    */
00012 /*--------------------------------------------------------------------*/
00013 
00014 //
00015 // This class is a wrapper for the Aztec DMSR matrix data structure.
00016 //
00017 // Important usage notes:
00018 //
00019 // * The 'oneBased' argument to the constructor indicates whether the
00020 //   matrix should use 1-based indices (row numbers and column indices) in
00021 //   the input and output arguments to its interfaces (e.g., getRow),
00022 //   with the exception of the update list -- keep reading.
00023 //   'oneBased' should be 1 for 1-based indices, 0 for 0-based.
00024 //   Here's the confusing part -- the update list should contain 0-based
00025 //   indices, regardless of the value of 'oneBased'.  That's because the
00026 //   update list gets used internally by Aztec functions that only work
00027 //   in 0-based numbers.
00028 //
00029 // * The 'rowLengths' array, input argument to the configure function,
00030 //   must contain the lengths of each row, *NOT* including the
00031 //   coefficient on the diagonal.
00032 //
00033 #include <az_aztec.h>
00034 #include <fei_SharedPtr.hpp>
00035 #include <fei_Aztec_Map.hpp>
00036 
00037 namespace fei_trilinos {
00038 
00039 class Aztec_LSVector;
00040 
00041 class AztecDMSR_Matrix {
00042     
00043   public:
00044     // Constructor.
00045     AztecDMSR_Matrix(fei::SharedPtr<Aztec_Map> map);
00046 
00047     //Copy constructor
00048     AztecDMSR_Matrix(const AztecDMSR_Matrix& src);
00049 
00050     virtual ~AztecDMSR_Matrix ();
00051 
00052     // Mathematical functions.
00053     void matvec(const Aztec_LSVector& x, Aztec_LSVector& y) const;
00054 
00055     void put(double s);
00056     void getDiagonal(Aztec_LSVector& diagVector) const;
00057 
00058     fei::SharedPtr<Aztec_Map> getAztec_Map() const {return(amap_);};
00059 
00060     int rowLength(int row) const;
00061     
00062     // ... to read matrix.
00063     void getRow(int row, int& length, double *coefs, int *colInd) const;
00064     void getRow(int row, int& length, double *coefs) const;
00065     void getRow(int row, int& length, int *colInd) const;
00066 
00068     int setDiagEntry(int row, double value);
00069 
00071     double getDiagEntry(int row) const;
00072 
00073     // ... to write matrix.
00074     int putRow(int row, int len, const double *coefs, 
00075                        const int *colInd);
00076 
00077     int sumIntoRow(int numRows, const int* rows,
00078                  int numCols, const int* cols,
00079                  const double* const* coefs);
00080 
00081     int sumIntoRow(int row, int len, const double *coefs, 
00082                            const int *colInd);
00083 
00084     int addScaledMatrix(double scalar, const AztecDMSR_Matrix& source);
00085 
00086     void scale(double scalar);
00087 
00090     int getOffDiagRowPointers(int row, int*& colIndices, double*& coefs,
00091             int& offDiagRowLength);
00092 
00093     void allocate(int *rowLengths);
00094 
00095     //inform about structure, including column-indices, so that val and bindx
00096     //can be allocated *and* so that bindx can be populated.
00097     void allocate(int *rowLengths, const int* const* colIndices);
00098 
00099     //inform that data fill is complete, so AZ_transform can be called.
00100     void fillComplete();
00101 
00102     bool isFilled() const {return(isFilled_);};
00103     void setFilled(bool flag) {isFilled_ = flag;};
00104     bool isAllocated() const {return(isAllocated_);};
00105     void setAllocated(bool flag) {isAllocated_ = flag;};
00106 
00107     void copyStructure(AztecDMSR_Matrix& source);
00108 
00109     bool readFromFile(const char *filename);
00110     bool writeToFile(const char *fileName) const;
00111     bool rowMax() const {return true;};
00112     double rowMax(int row) const;
00113  
00114     int getNumNonZeros() {return(nnzeros_);};
00115 
00116     //Aztec-specific functions:
00117 
00118     AZ_MATRIX* getAZ_MATRIX_PTR() {return(Amat_);};
00119 
00120   private:
00121     void messageAbort(const char* mesg);
00122     int insert(int item, int offset, int* list, int& len, int allocLen);
00123     int insert(double item, int offset, double* list, int& len, int allocLen);
00124     void expand_array(int*& array, int& arraylen, int newlen);
00125     void expand_array(double*& array, int& arraylen, int newlen);
00126 
00127     bool isFilled_;
00128     bool isAllocated_;
00129 
00130     int localOffset_;
00131     int localSize_;
00132 
00133     fei::SharedPtr<Aztec_Map> amap_;
00134 
00135     AZ_MATRIX* Amat_;
00136 
00137     bool arraysAllocated_;
00138     double *val;
00139     int *bindx;
00140     int *rowLengths_;
00141     int nnzeros_; //val and bindx are of length nnzeros_+1
00142 
00143     int N_update_;
00144 
00145     int* tmp_array_;
00146     int tmp_array_len_;
00147     double* dtmp_array_;
00148     int dtmp_array_len_;
00149 
00150     bool azTransformed_;
00151 };
00152 
00153 }//namespace fei_trilinos
00154 
00155 #endif //HAVE_FEI_AZTECOO
00156 
00157 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends