FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_AztecDVBR_Matrix.hpp
1 /*
2 // @HEADER
3 // ************************************************************************
4 // FEI: Finite Element Interface to Linear Solvers
5 // Copyright (2005) Sandia Corporation.
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Alan Williams (william@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 */
42 
43 #ifndef _fei_AztecDVBR_Matrix_hpp_
44 #define _fei_AztecDVBR_Matrix_hpp_
45 
46 
47 #include <fei_SharedPtr.hpp>
48 //
49 // This class provides a wrapper for the Aztec DVBR matrix data structure.
50 //
51 // Some functions return an int. This will be the ESI_error_code. It
52 // will be 0 if there were no errors, 1 if an error occurred.
53 //
54 namespace fei_trilinos {
55 
56 class Aztec_BlockMap;
57 
58 class AztecDVBR_Matrix {
59 
60  public:
61  // Constructor.
62  AztecDVBR_Matrix(fei::SharedPtr<Aztec_BlockMap> map);
63 
64  //Copy constructor.
65  AztecDVBR_Matrix(const AztecDVBR_Matrix& src);
66 
67  virtual ~AztecDVBR_Matrix ();
68 
69  //query functions.
70 
71  int getNumBlocksPerRow(int blkRow, int& nnzBlksPerRow) const;
72  int getNumNonzerosPerRow(int blkRow, int& nnzPerRow) const;
73  int getNumBlocksPerRow(int* nnzBlksPerRow) const;
74  int getNumNonzerosPerRow(int* nnzPerRow) const;
75  int getBlockSize(int blkRow, int blkCol, int& ptRows, int& ptCols);
76 
77  // Mathematical functions.
78  void matvec(const Aztec_LSVector& x, Aztec_LSVector& y) const;
79 
80  void put(double s);
81 
82  // ... to read matrix.
83 
84  int getBlockRow(int blk_row,
85  double* vals,
86  int* blk_col_inds,
87  int num_nz_blocks) const;
88 
89  // ... to write matrix.
90 
91  int putBlockRow(int blk_row,
92  double* vals,
93  int* blk_col_inds,
94  int num_nz_blocks) const;
95 
96  int sumIntoBlockRow(int blk_row,
97  double* vals,
98  int* blk_col_inds,
99  int num_nz_blocks) const;
100 
101  // configuration function.
102  void allocate(int* num_nz_blocks, int* blk_col_inds);
103 
104  void loadComplete();
105 
106  bool isLoaded() const {return(isLoaded_);};
107  void setLoaded(bool flag) {isLoaded_ = flag;};
108  bool isAllocated() const {return(isAllocated_);};
109  void setAllocated(bool flag) {isAllocated_ = flag;};
110 
111  AZ_MATRIX* getAZ_MATRIX_Ptr() const {return(Amat_);};
112 
113  bool readFromFile(const char *filename);
114  bool writeToFile(const char *fileName) const;
115 
116  //numRemoteBlocks is the number of block-column-indices on this processor
117  //that correspond to block-rows that reside on another processor.
118  int getNumRemoteBlocks() {return(numRemoteBlocks_);};
119  int* getRemoteBlockIndices() {return(remoteInds_);};
120  int* getRemoteBlockSizes() {return(remoteBlockSizes_);};
121 
122  int* getUpdate_index() {return(update_index_);};
123  int* getData_org() {return(data_org_);};
124 
125  private:
126  int inUpdate(int globalIndex, int& localIndex) const;
127 
128  void readAllocateInfo(FILE* infile, int*& num_nz_blocks, int*& blk_col_inds);
129  void readMatrixData(FILE* infile);
130 
131  void calcRpntr();
132  void calcBpntr(int* nzBlksPerRow);
133  void setBindx(int nnzBlks, int* blkColInds);
134  void calcIndx(int nnzBlks);
135 
136  int getBindxOffset(int blkInd, int bpntrStart, int bpntrEnd) const;
137 
138  void calcRemoteInds(int*& remoteInds, int& len);
139  void getRemoteBlkSizes(int* remoteBlkSizes, int* remoteInds, int len);
140  void insertList(int item, int*& list, int& len);
141  void getValuesFromString(char *line, int len, double *values,
142  int lenValues);
143  void messageAbort(const char* mesg) const;
144 
146 
147  AZ_MATRIX *Amat_;
148 
149  int N_update_;
150  int* external_;
151  int* extern_index_;
152  int* update_index_;
153  int* data_org_;
154  int* orderingUpdate_;
155 
156  bool isLoaded_;
157  bool isAllocated_;
158 
159  int localNNZ_;
160  int* nnzPerRow_;
161 
162  int numRemoteBlocks_;
163  int* remoteInds_;
164  int* remoteBlockSizes_;
165 };
166 
167 }//namespace fei_trilinos
168 
169 #endif