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 
00035 namespace fei_trilinos {
00036 
00037 class Aztec_Map;
00038 class Aztec_Vector;
00039 
00040 class AztecDMSR_Matrix {
00041     
00042   public:
00043     // Constructor.
00044     AztecDMSR_Matrix(Aztec_Map& map, int* update,
00045          bool linearDistribution=false);
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_Vector& x, Aztec_Vector& y) const;
00054 
00055     void put(double s);
00056     void getDiagonal(Aztec_Vector& diagVector) const;
00057 
00058     const 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 
00095     //int enforceEssentialBCs(int numBCEqns, int* bcEqns, double* bcValues,
00096     //        double* rhsVector);
00097 
00098     //inform about structure, so that val and bindx can be allocated.
00099     void allocate(int *rowLengths);
00100 
00101     //inform about structure, including column-indices, so that val and bindx
00102     //can be allocated *and* so that bindx can be populated.
00103     void allocate(int *rowLengths, const int* const* colIndices);
00104 
00105     //inform that data fill is complete, so AZ_transform can be called.
00106     void fillComplete();
00107 
00108     int getTransformedEqn(int eqn) const {
00109       if (isFilled_) {
00110   if(eqn<N_update_) return( update_[orderingUpdate_[eqn]] );
00111   else return( external_[eqn-N_update_] );
00112       }
00113       else {
00114   return( eqn );
00115       }
00116     }
00117 
00118     bool isFilled() const {return(isFilled_);};
00119     void setFilled(bool flag) {isFilled_ = flag;};
00120     bool isAllocated() const {return(isAllocated_);};
00121     void setAllocated(bool flag) {isAllocated_ = flag;};
00122 
00123     void copyStructure(AztecDMSR_Matrix& source);
00124 
00125     bool readFromFile(const char *filename);
00126     bool writeToFile(const char *fileName) const;
00127     bool rowMax() const {return true;};
00128     double rowMax(int row) const;
00129  
00130     int getNumNonZeros() {return(nnzeros_);};
00131 
00132     //Aztec-specific functions:
00133 
00134     AZ_MATRIX* getAZ_MATRIX_PTR() {return(Amat_);};
00135 
00136     int* getUpdate() {return(update_);};
00137     int* getUpdate_index() {return(update_index_);};
00138 
00139   private:
00140     int inUpdate(int globalIndex, int& localIndex) const;
00141     void messageAbort(const char* mesg);
00142     int insert(int item, int offset, int* list, int& len, int allocLen);
00143     int insert(double item, int offset, double* list, int& len, int allocLen);
00144     void expand_array(int*& array, int& arraylen, int newlen);
00145     void expand_array(double*& array, int& arraylen, int newlen);
00146 
00147     bool isFilled_;
00148     bool isAllocated_;
00149     bool linearDistribution_;
00150 
00151     int localOffset_;
00152     int localSize_;
00153 
00154     Aztec_Map& amap_;
00155 
00156     AZ_MATRIX* Amat_;
00157 
00158     bool arraysAllocated_;
00159     double *val;
00160     int *bindx;
00161     int *rowLengths_;
00162     int nnzeros_; //val and bindx are of length nnzeros_+1
00163 
00164     int N_update_;
00165     int* update_;
00166 
00167     int* update_index_;
00168     int* orderingUpdate_;
00169     int* external_;
00170     int* extern_index_;
00171     int* data_org_;
00172 
00173     int* tmp_array_;
00174     int tmp_array_len_;
00175     double* dtmp_array_;
00176     int dtmp_array_len_;
00177 
00178     bool azTransformed_;
00179 };
00180 
00181 }//namespace fei_trilinos
00182 
00183 #endif //HAVE_FEI_AZTECOO
00184 
00185 #endif

Generated on Tue Jul 13 09:27:44 2010 for FEI by  doxygen 1.4.7