FEI Version of the Day
fei_AztecDVBR_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 _fei_AztecDVBR_Matrix_hpp_
00044 #define _fei_AztecDVBR_Matrix_hpp_
00045 
00046 
00047 #include <fei_SharedPtr.hpp>
00048 //
00049 // This class provides a wrapper for the Aztec DVBR matrix data structure.
00050 //
00051 // Some functions return an int. This will be the ESI_error_code. It
00052 // will be 0 if there were no errors, 1 if an error occurred.
00053 //
00054 namespace fei_trilinos {
00055 
00056 class Aztec_BlockMap;
00057 
00058 class AztecDVBR_Matrix {
00059  
00060   public:
00061     // Constructor.
00062     AztecDVBR_Matrix(fei::SharedPtr<Aztec_BlockMap> map);
00063 
00064     //Copy constructor.
00065     AztecDVBR_Matrix(const AztecDVBR_Matrix& src);
00066 
00067     virtual ~AztecDVBR_Matrix ();
00068 
00069     //query functions.
00070 
00071     int getNumBlocksPerRow(int blkRow, int& nnzBlksPerRow) const;
00072     int getNumNonzerosPerRow(int blkRow, int& nnzPerRow) const;
00073     int getNumBlocksPerRow(int* nnzBlksPerRow) const;
00074     int getNumNonzerosPerRow(int* nnzPerRow) const;
00075     int getBlockSize(int blkRow, int blkCol, int& ptRows, int& ptCols);
00076 
00077     // Mathematical functions.
00078     void matvec(const Aztec_LSVector& x, Aztec_LSVector& y) const;
00079 
00080     void put(double s);
00081 
00082     // ... to read matrix.
00083 
00084     int getBlockRow(int blk_row,
00085                     double* vals,
00086                     int* blk_col_inds,
00087                     int num_nz_blocks) const;
00088     
00089     // ... to write matrix.
00090 
00091     int putBlockRow(int blk_row,
00092                     double* vals,
00093                     int* blk_col_inds,
00094                     int num_nz_blocks) const;
00095 
00096     int sumIntoBlockRow(int blk_row,
00097                         double* vals,
00098                         int* blk_col_inds,
00099                         int num_nz_blocks) const;
00100  
00101     // configuration function.
00102     void allocate(int* num_nz_blocks, int* blk_col_inds);
00103 
00104     void loadComplete();
00105 
00106     bool isLoaded() const {return(isLoaded_);};
00107     void setLoaded(bool flag) {isLoaded_ = flag;};
00108     bool isAllocated() const {return(isAllocated_);};
00109     void setAllocated(bool flag) {isAllocated_ = flag;};
00110 
00111     AZ_MATRIX* getAZ_MATRIX_Ptr() const {return(Amat_);};
00112 
00113     bool readFromFile(const char *filename);
00114     bool writeToFile(const char *fileName) const;
00115 
00116     //numRemoteBlocks is the number of block-column-indices on this processor
00117     //that correspond to block-rows that reside on another processor.
00118     int getNumRemoteBlocks() {return(numRemoteBlocks_);};
00119     int* getRemoteBlockIndices() {return(remoteInds_);};
00120     int* getRemoteBlockSizes() {return(remoteBlockSizes_);};
00121 
00122     int* getUpdate_index() {return(update_index_);};
00123     int* getData_org() {return(data_org_);};
00124 
00125   private:
00126     int inUpdate(int globalIndex, int& localIndex) const;
00127 
00128     void readAllocateInfo(FILE* infile, int*& num_nz_blocks, int*& blk_col_inds);
00129     void readMatrixData(FILE* infile);
00130 
00131     void calcRpntr();
00132     void calcBpntr(int* nzBlksPerRow);
00133     void setBindx(int nnzBlks, int* blkColInds);
00134     void calcIndx(int nnzBlks);
00135 
00136     int getBindxOffset(int blkInd, int bpntrStart, int bpntrEnd) const;
00137 
00138     void calcRemoteInds(int*& remoteInds, int& len);
00139     void getRemoteBlkSizes(int* remoteBlkSizes, int* remoteInds, int len);
00140     void insertList(int item, int*& list, int& len);
00141     void getValuesFromString(char *line, int len, double *values,
00142                              int lenValues);
00143     void messageAbort(const char* mesg) const;
00144 
00145     fei::SharedPtr<Aztec_BlockMap> amap_;
00146 
00147     AZ_MATRIX *Amat_;
00148 
00149     int N_update_;
00150     int* external_;
00151     int* extern_index_;
00152     int* update_index_;
00153     int* data_org_;
00154     int* orderingUpdate_;
00155 
00156     bool isLoaded_;
00157     bool isAllocated_;
00158 
00159     int localNNZ_;
00160     int* nnzPerRow_;
00161 
00162     int numRemoteBlocks_;
00163     int* remoteInds_;
00164     int* remoteBlockSizes_;
00165 };
00166 
00167 }//namespace fei_trilinos
00168 
00169 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends