FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fei_MatrixTraits_Aztec.hpp
Go to the documentation of this file.
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 
44 #ifndef _fei_MatrixTraits_Aztec_hpp_
45 #define _fei_MatrixTraits_Aztec_hpp_
46 
47 #include <fei_trilinos_macros.hpp>
48 
49 #ifdef HAVE_FEI_AZTECOO
50 
51 //
52 //IMPORTANT NOTE: Make sure that wherever this file is included from, it
53 //appears BEFORE any include of fei_Vector_Impl.hpp or fei_Matrix_Impl.hpp !!!
54 //
55 #include <fei_MatrixTraits.hpp>
58 #include <fei_Include_Trilinos.hpp>
59 #include <fei_Vector_Impl.hpp>
60 
61 namespace fei {
68  template<>
69  struct MatrixTraits<AztecDMSR_Matrix> {
70  static const char* typeName()
71  { return("fei::AztecDMSR_Matrix"); }
72 
73  static int setValues(AztecDMSR_Matrix* mat, double scalar)
74  {
75  return( mat->put(scalar) );
76  }
77 
78  static int getNumLocalRows(AztecDMSR_Matrix* mat, int& numRows)
79  {
80  numRows = mat->getAztec_Map().localSize();
81  return(0);
82  }
83 
84  static int getRowLength(AztecDMSR_Matrix* mat, int row, int& length)
85  {
86  length = mat->rowLength(row);
87  if (length < 0) return(-1);
88  return( 0 );
89  }
90 
91  static int copyOutRow(AztecDMSR_Matrix* mat,
92  int row, int len, double* coefs, int* indices)
93  {
94  int dummy;
95  mat->getRow(row, dummy, coefs, indices);
96  return(0);
97  }
98 
99  static int putValuesIn(AztecDMSR_Matrix* mat,
100  int numRows, const int* rows,
101  int numCols, const int* cols,
102  const double* const* values,
103  bool sum_into)
104  {
105  int err = 0;
106  if (sum_into) {
107  err = mat->sumIntoRow(numRows, rows, numCols, cols, coefs);
108  }
109  else {
110  for(int i=0; i<numRows; ++i) {
111  err = mat->putRow(rows[i], numCols, values[i], cols);
112  if (err != 0) {
113  return(err);
114  }
115  }
116  }
117  return(err);
118  }
119 
120  static int globalAssemble(AztecDMSR_Matrix* mat)
121  {
122  if (!mat->isFilled()) {
123  int err = mat->fillComplete();
124  if (err != 0) {
125  fei::console_out() << "MatrixTraits<AztecDMSR_Matrix>::globalAssemble"
126  << " ERROR in mat->fillComplete" << FEI_ENDL;
127  return(-1);
128  }
129  }
130 
131  return( 0 );
132  }
133 
134  static int matvec(AztecDMSR_Matrix* mat,
135  fei::Vector* x,
136  fei::Vector* y)
137  {
139  dynamic_cast<fei::Vector_Impl<Aztec_LSVector>* >(x);
141  dynamic_cast<fei::Vector_Impl<Aztec_LSVector>* >(y);
142 
143  if (avx == NULL || avy == NULL) {
144  return(-1);
145  }
146 
147  Aztec_LSVector* ax = avx->getUnderlyingVector();
148  Aztec_LSVector* ay = avy->getUnderlyingVector();
149 
150  return( mat->matvec(*ax, *ay) );
151  }
152 
153  };//struct MatrixTraits<AztecDMSR_Matrix>
154 }//namespace fei
155 
156 namespace snl_fei {
163  template<>
164  struct BlockMatrixTraits<AztecDVBR_Matrix> {
165  static const char* typeName()
166  { return("fei::AztecDVBR_Matrix"); }
167 
168  static int putScalar(AztecDVBR_Matrix* mat, double scalar)
169  {
170  return( mat->put(scalar) );
171  }
172 
173  static int getRowLength(AztecDVBR_Matrix* mat, int row, int& length)
174  {
175  return(-1);
176  }
177 
178  static int getPointRowLength(AztecDVBR_Matrix* mat, int row, int& length)
179  {
180  return(-1);
181  }
182 
183  static int copyOutRow(AztecDVBR_Matrix* mat,
184  int row, int numBlkCols,
185  int rowDim,
186  int* blkCols,
187  int* colDims,
188  double* coefs,
189  int coefsLen,
190  int& blkRowLength)
191  {
192  return(-1);
193  }
194 
195  static int copyOutPointRow(AztecDVBR_Matrix* mat,
196  int firstLocalOffset,
197  int row,
198  int len,
199  double* coefs,
200  int* indices,
201  int& rowLength)
202  {
203  return(-1);
204  }
205 
206  static int sumIn(AztecDVBR_Matrix* mat,
207  int blockRow,
208  int rowDim,
209  int numBlockCols,
210  const int* blockCols,
211  const int* colDims,
212  int LDA,
213  const double* values)
214  {
215  return(-1);
216  }
217 
218  static int copyIn(AztecDVBR_Matrix* mat,
219  int blockRow,
220  int rowDim,
221  int numBlockCols,
222  const int* blockCols,
223  const int* colDims,
224  int LDA,
225  const double* values)
226  {
227  return(-1);
228  }
229 
230  static int sumIn(AztecDVBR_Matrix* mat,
231  int row,
232  int rowDim,
233  int numCols,
234  const int* cols,
235  const int* LDAs,
236  const int* colDims,
237  const double* const* values)
238  {
239  return(-1);
240  }
241 
242  static int copyIn(AztecDVBR_Matrix* mat,
243  int row,
244  int rowDim,
245  int numCols,
246  const int* cols,
247  const int* LDAs,
248  const int* colDims,
249  const double* const* values)
250  {
251  return(-1);
252  }
253 
254  static int globalAssemble(AztecDVBR_Matrix* mat)
255  {
256  return( mat->loadComplete() );
257  }
258  };//struct BlockMatrixTraits<AztecDVBR_Matrix>
259 }//namespace snl_fei
260 #endif //HAVE_FEI_AZTECOO
261 #endif // _fei_MatrixTraits_Aztec_hpp_
static int getPointRowLength(T *, int, int &)
static int copyIn(T *, int, int, int, const int *, const int *, int, const double *)
static const char * typeName()
static int matvec(T *A, fei::Vector *x, fei::Vector *y)
static int getRowLength(T *mat, int row, int &length)
static int copyOutPointRow(T *, int, int, int, double *, int *, int &)
static int getNumLocalRows(T *mat, int &numRows)
static int getRowLength(T *, int, int &)
#define FEI_ENDL
std::ostream & console_out()
static int copyOutRow(T *, int, int, int, int *, int *, double *, int, int &)
static int setValues(T *mat, double scalar)
static int sumIn(T *, int, int, int, const int *, const int *, int, const double *)
static int copyOutRow(T *mat, int row, int len, double *coefs, int *indices)
static int putValuesIn(T *mat, int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sum_into)
static int globalAssemble(T *A)