fei_MatrixTraits_FillableMat.hpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2008 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_MatrixTraits_FillableMat_hpp_
00010 #define _fei_MatrixTraits_FillableMat_hpp_
00011 
00012 //This file defines matrix traits for fei::FillableMat matrices
00013 //
00014 
00015 #include <fei_CSRMat.hpp>
00016 #include <fei_CSVec.hpp>
00017 #include <fei_Vector_Impl.hpp>
00018 
00019 namespace fei {
00020 
00022   template<>
00023   struct MatrixTraits<FillableMat> {
00024 
00026     static const char* typeName()
00027       { return("FillableMat"); }
00028 
00031     static int setValues(FillableMat* mat, double scalar)
00032       {
00033         mat->setValues(scalar);
00034         return(0);
00035       }
00036 
00040     static int getNumLocalRows(FillableMat* mat, int& numRows)
00041     {
00042       numRows = mat->getNumRows();
00043       return(0);
00044     }
00045 
00048     static int getRowLength(FillableMat* mat, int row, int& length)
00049       {
00050         try {
00051           FillableVec* matrixrow = mat->getRow(row);
00052           length = matrixrow->size();
00053         }
00054         catch(...) {
00055           length = 0;
00056         }
00057         return( 0 );
00058       }
00059 
00072     static int copyOutRow(FillableMat* mat,
00073                       int row, int len, double* coefs, int* indices)
00074       {
00075         try {
00076           FillableVec* matrixrow = mat->getRow(row);
00077 
00078           FillableVec::iterator
00079             row_iter = matrixrow->begin(),
00080             row_end = matrixrow->end();
00081 
00082           int i=0;
00083           for(; row_iter != row_end; ++row_iter, ++i) {
00084             if (i >= len) break;
00085             coefs[i] = row_iter->second;
00086             indices[i] = row_iter->first;
00087           }
00088         }
00089         catch(...) {
00090           //what should we do here???
00091         }
00092 
00093         return( 0 );
00094       }
00095 
00098     static int putValuesIn(FillableMat* mat,
00099                            int numRows, const int* rows,
00100                            int numCols, const int* cols,
00101                            const double* const* values,
00102                            bool sum_into)
00103       {
00104         if (numCols < 1 || numRows < 1) return(0);
00105         if (sum_into) {
00106           for(int i=0; i<numRows; ++i) {
00107             mat->sumInRow(rows[i], cols, values[i], numCols);
00108           }
00109         }
00110         else {
00111           for(int i=0; i<numRows; ++i) {
00112             mat->putRow(rows[i], cols, values[i], numCols);
00113           }
00114         }
00115 
00116         return( 0 );
00117       }
00118 
00123     static int globalAssemble(FillableMat* mat)
00124     {
00125       return(0);
00126     }
00127 
00129     static int matvec(FillableMat* mat,
00130                       fei::Vector* x,
00131                       fei::Vector* y)
00132     {
00133       fei::Vector_Impl<FillableVec>* fvx =
00134         dynamic_cast<fei::Vector_Impl<FillableVec>* >(x);
00135       fei::Vector_Impl<FillableVec>* fvy =
00136         dynamic_cast<fei::Vector_Impl<FillableVec>* >(y);
00137 
00138       if (fvx == NULL || fvy == NULL) {
00139         return(-1);
00140       }
00141 
00142       fei::CSRMat A(*mat);
00143       fei::CSVec csx(*(fvx->getUnderlyingVector()));
00144       fei::CSVec csy(*(fvy->getUnderlyingVector()));
00145 
00146       fei::multiply_CSRMat_CSVec(A, csx, csy);
00147 
00148       return( 0 );
00149     }
00150 
00151   };//struct MatrixTraits
00152 }//namespace fei
00153 
00154 #endif // _fei_MatrixTraits_FillableMat_hpp_
00155 

Generated on Tue Jul 13 09:27:45 2010 for FEI by  doxygen 1.4.7