FEI Version of the Day
fei_AztecDMSR_Matrix.hpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 #ifndef _AztecDMSR_Matrix_h_
00044 #define _AztecDMSR_Matrix_h_
00045 
00046 #ifdef HAVE_FEI_AZTECOO
00047 
00048 
00049 //
00050 // This class is a wrapper for the Aztec DMSR matrix data structure.
00051 //
00052 // Important usage notes:
00053 //
00054 // * The 'oneBased' argument to the constructor indicates whether the
00055 //   matrix should use 1-based indices (row numbers and column indices) in
00056 //   the input and output arguments to its interfaces (e.g., getRow),
00057 //   with the exception of the update list -- keep reading.
00058 //   'oneBased' should be 1 for 1-based indices, 0 for 0-based.
00059 //   Here's the confusing part -- the update list should contain 0-based
00060 //   indices, regardless of the value of 'oneBased'.  That's because the
00061 //   update list gets used internally by Aztec functions that only work
00062 //   in 0-based numbers.
00063 //
00064 // * The 'rowLengths' array, input argument to the configure function,
00065 //   must contain the lengths of each row, *NOT* including the
00066 //   coefficient on the diagonal.
00067 //
00068 #include <az_aztec.h>
00069 #include <fei_SharedPtr.hpp>
00070 #include <fei_Aztec_Map.hpp>
00071 
00072 namespace fei_trilinos {
00073 
00074 class Aztec_LSVector;
00075 
00076 class AztecDMSR_Matrix {
00077     
00078   public:
00079     // Constructor.
00080     AztecDMSR_Matrix(fei::SharedPtr<Aztec_Map> map);
00081 
00082     //Copy constructor
00083     AztecDMSR_Matrix(const AztecDMSR_Matrix& src);
00084 
00085     virtual ~AztecDMSR_Matrix ();
00086 
00087     // Mathematical functions.
00088     void matvec(const Aztec_LSVector& x, Aztec_LSVector& y) const;
00089 
00090     void put(double s);
00091     void getDiagonal(Aztec_LSVector& diagVector) const;
00092 
00093     fei::SharedPtr<Aztec_Map> getAztec_Map() const {return(amap_);};
00094 
00095     int rowLength(int row) const;
00096     
00097     // ... to read matrix.
00098     void getRow(int row, int& length, double *coefs, int *colInd) const;
00099     void getRow(int row, int& length, double *coefs) const;
00100     void getRow(int row, int& length, int *colInd) const;
00101 
00103     int setDiagEntry(int row, double value);
00104 
00106     double getDiagEntry(int row) const;
00107 
00108     // ... to write matrix.
00109     int putRow(int row, int len, const double *coefs, 
00110                        const int *colInd);
00111 
00112     int sumIntoRow(int numRows, const int* rows,
00113                  int numCols, const int* cols,
00114                  const double* const* coefs);
00115 
00116     int sumIntoRow(int row, int len, const double *coefs, 
00117                            const int *colInd);
00118 
00119     int addScaledMatrix(double scalar, const AztecDMSR_Matrix& source);
00120 
00121     void scale(double scalar);
00122 
00125     int getOffDiagRowPointers(int row, int*& colIndices, double*& coefs,
00126             int& offDiagRowLength);
00127 
00128     void allocate(int *rowLengths);
00129 
00130     //inform about structure, including column-indices, so that val and bindx
00131     //can be allocated *and* so that bindx can be populated.
00132     void allocate(int *rowLengths, const int* const* colIndices);
00133 
00134     //inform that data fill is complete, so AZ_transform can be called.
00135     void fillComplete();
00136 
00137     bool isFilled() const {return(isFilled_);};
00138     void setFilled(bool flag) {isFilled_ = flag;};
00139     bool isAllocated() const {return(isAllocated_);};
00140     void setAllocated(bool flag) {isAllocated_ = flag;};
00141 
00142     void copyStructure(AztecDMSR_Matrix& source);
00143 
00144     bool readFromFile(const char *filename);
00145     bool writeToFile(const char *fileName) const;
00146     bool rowMax() const {return true;};
00147     double rowMax(int row) const;
00148  
00149     int getNumNonZeros() {return(nnzeros_);};
00150 
00151     //Aztec-specific functions:
00152 
00153     AZ_MATRIX* getAZ_MATRIX_PTR() {return(Amat_);};
00154 
00155   private:
00156     void messageAbort(const char* mesg);
00157     int insert(int item, int offset, int* list, int& len, int allocLen);
00158     int insert(double item, int offset, double* list, int& len, int allocLen);
00159     void expand_array(int*& array, int& arraylen, int newlen);
00160     void expand_array(double*& array, int& arraylen, int newlen);
00161 
00162     bool isFilled_;
00163     bool isAllocated_;
00164 
00165     int localOffset_;
00166     int localSize_;
00167 
00168     fei::SharedPtr<Aztec_Map> amap_;
00169 
00170     AZ_MATRIX* Amat_;
00171 
00172     bool arraysAllocated_;
00173     double *val;
00174     int *bindx;
00175     int *rowLengths_;
00176     int nnzeros_; //val and bindx are of length nnzeros_+1
00177 
00178     int N_update_;
00179 
00180     int* tmp_array_;
00181     int tmp_array_len_;
00182     double* dtmp_array_;
00183     int dtmp_array_len_;
00184 
00185     bool azTransformed_;
00186 };
00187 
00188 }//namespace fei_trilinos
00189 
00190 #endif //HAVE_FEI_AZTECOO
00191 
00192 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends