FEI Version of the Day
fei_MatrixTraits_Aztec.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 
00044 #ifndef _fei_MatrixTraits_Aztec_hpp_
00045 #define _fei_MatrixTraits_Aztec_hpp_
00046 
00047 #include <fei_trilinos_macros.hpp>
00048 
00049 #ifdef HAVE_FEI_AZTECOO
00050 
00051 //
00052 //IMPORTANT NOTE: Make sure that wherever this file is included from, it
00053 //appears BEFORE any include of fei_Vector_Impl.hpp or fei_Matrix_Impl.hpp !!!
00054 //
00055 #include <fei_MatrixTraits.hpp>
00056 #include <snl_fei_BlockMatrixTraits.hpp>
00057 #include <fei_VectorTraits_Aztec.hpp>
00058 #include <fei_Include_Trilinos.hpp>
00059 #include <fei_Vector_Impl.hpp>
00060 
00061 namespace fei {
00068   template<>
00069   struct MatrixTraits<AztecDMSR_Matrix> {
00070     static const char* typeName()
00071       { return("fei::AztecDMSR_Matrix"); }
00072 
00073     static int setValues(AztecDMSR_Matrix* mat, double scalar)
00074       {
00075         return( mat->put(scalar) );
00076       }
00077 
00078     static int getNumLocalRows(AztecDMSR_Matrix* mat, int& numRows)
00079     {
00080       numRows = mat->getAztec_Map().localSize();
00081       return(0);
00082     }
00083 
00084     static int getRowLength(AztecDMSR_Matrix* mat, int row, int& length)
00085       {
00086         length = mat->rowLength(row);
00087         if (length < 0) return(-1);
00088         return( 0 );
00089       }
00090 
00091     static int copyOutRow(AztecDMSR_Matrix* mat,
00092                       int row, int len, double* coefs, int* indices)
00093       {
00094         int dummy;
00095         mat->getRow(row, dummy, coefs, indices);
00096         return(0);
00097       }
00098 
00099     static int putValuesIn(AztecDMSR_Matrix* mat,
00100                      int numRows, const int* rows,
00101                      int numCols, const int* cols,
00102                      const double* const* values,
00103                            bool sum_into)
00104       {
00105         int err = 0;
00106         if (sum_into) {
00107           err = mat->sumIntoRow(numRows, rows, numCols, cols, coefs);
00108         }
00109         else {
00110           for(int i=0; i<numRows; ++i) {
00111             err = mat->putRow(rows[i], numCols, values[i], cols);
00112             if (err != 0) {
00113               return(err);
00114             }
00115           }
00116         }
00117         return(err);
00118       }
00119 
00120     static int globalAssemble(AztecDMSR_Matrix* mat)
00121     {
00122       if (!mat->isFilled()) {
00123         int err = mat->fillComplete();
00124         if (err != 0) {
00125           fei::console_out() << "MatrixTraits<AztecDMSR_Matrix>::globalAssemble"
00126                    << " ERROR in mat->fillComplete" << FEI_ENDL;
00127           return(-1);
00128         }
00129       }
00130 
00131       return( 0 );
00132     }
00133 
00134     static int matvec(AztecDMSR_Matrix* mat,
00135                       fei::Vector* x,
00136                       fei::Vector* y)
00137     {
00138       fei::Vector_Impl<Aztec_LSVector>* avx =
00139         dynamic_cast<fei::Vector_Impl<Aztec_LSVector>* >(x);
00140       fei::Vector_Impl<Aztec_LSVector>* avy =
00141         dynamic_cast<fei::Vector_Impl<Aztec_LSVector>* >(y);
00142 
00143       if (avx == NULL || avy == NULL) {
00144         return(-1);
00145       }
00146 
00147       Aztec_LSVector* ax = avx->getUnderlyingVector();
00148       Aztec_LSVector* ay = avy->getUnderlyingVector();
00149 
00150       return( mat->matvec(*ax, *ay) );
00151     }
00152 
00153   };//struct MatrixTraits<AztecDMSR_Matrix>
00154 }//namespace fei
00155 
00156 namespace snl_fei {
00163   template<>
00164   struct BlockMatrixTraits<AztecDVBR_Matrix> {
00165     static const char* typeName()
00166       { return("fei::AztecDVBR_Matrix"); }
00167 
00168     static int putScalar(AztecDVBR_Matrix* mat, double scalar)
00169       {
00170         return( mat->put(scalar) );
00171       }
00172 
00173     static int getRowLength(AztecDVBR_Matrix* mat, int row, int& length)
00174       {
00175         return(-1);
00176       }
00177 
00178     static int getPointRowLength(AztecDVBR_Matrix* mat, int row, int& length)
00179     {
00180       return(-1);
00181     }
00182 
00183     static int copyOutRow(AztecDVBR_Matrix* mat,
00184                           int row, int numBlkCols,
00185                           int rowDim,
00186                           int* blkCols,
00187                           int* colDims,
00188                           double* coefs,
00189                           int coefsLen,
00190                           int& blkRowLength)
00191       {
00192         return(-1);
00193       }
00194 
00195     static int copyOutPointRow(AztecDVBR_Matrix* mat,
00196                                int firstLocalOffset,
00197                                int row,
00198                                int len,
00199                                double* coefs,
00200                                int* indices,
00201                                int& rowLength)
00202       {
00203         return(-1);
00204       }
00205 
00206     static int sumIn(AztecDVBR_Matrix* mat,
00207                      int blockRow,
00208                      int rowDim,
00209                      int numBlockCols,
00210                      const int* blockCols,
00211                      const int* colDims,
00212                      int LDA,
00213                      const double* values)
00214     {
00215       return(-1);
00216     }
00217 
00218     static int copyIn(AztecDVBR_Matrix* mat,
00219                       int blockRow,
00220                       int rowDim,
00221                       int numBlockCols,
00222                       const int* blockCols,
00223                       const int* colDims,
00224                       int LDA,
00225                       const double* values)
00226     {
00227       return(-1);
00228     }
00229 
00230     static int sumIn(AztecDVBR_Matrix* mat,
00231                      int row,
00232                      int rowDim,
00233                      int numCols,
00234                      const int* cols,
00235                      const int* LDAs,
00236                      const int* colDims,
00237                      const double* const* values)
00238       {
00239         return(-1);
00240       }
00241 
00242     static int copyIn(AztecDVBR_Matrix* mat,
00243                       int row,
00244                       int rowDim,
00245                       int numCols,
00246                       const int* cols,
00247                       const int* LDAs,
00248                       const int* colDims,
00249                       const double* const* values)
00250       {
00251         return(-1);
00252       }
00253 
00254     static int globalAssemble(AztecDVBR_Matrix* mat)
00255     {
00256       return( mat->loadComplete() );
00257     }
00258   };//struct BlockMatrixTraits<AztecDVBR_Matrix>
00259 }//namespace snl_fei
00260 #endif //HAVE_FEI_AZTECOO
00261 #endif // _fei_MatrixTraits_Aztec_hpp_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends