FEI Version of the Day
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 
00029     static double* getBeginPointer(FillableMat* /*mat*/)
00030       {
00031         return NULL;
00032       }
00033 
00034     static int getOffset(FillableMat* /*mat*/, int /*row*/, int /*col*/)
00035       {
00036         return -1;
00037       }
00038 
00041     static int setValues(FillableMat* mat, double scalar)
00042       {
00043         mat->setValues(scalar);
00044         return(0);
00045       }
00046 
00050     static int getNumLocalRows(FillableMat* mat, int& numRows)
00051     {
00052       numRows = mat->getNumRows();
00053       return(0);
00054     }
00055 
00058     static int getRowLength(FillableMat* mat, int row, int& length)
00059       {
00060         try {
00061           const CSVec* matrixrow = mat->getRow(row);
00062           length = matrixrow->size();
00063         }
00064         catch(...) {
00065           length = 0;
00066         }
00067         return( 0 );
00068       }
00069 
00082     static int copyOutRow(FillableMat* mat,
00083                       int row, int len, double* coefs, int* indices)
00084       {
00085         try {
00086           const CSVec* matrixrow = mat->getRow(row);
00087 
00088           const std::vector<int>& row_indices = matrixrow->indices();
00089           const std::vector<double>& row_coefs = matrixrow->coefs();
00090           const int rowlen = row_indices.size();
00091           for(int i=0; i<rowlen; ++i) {
00092             if (i >= len) break;
00093             coefs[i] = row_coefs[i];
00094             indices[i] = row_indices[i];
00095           }
00096         }
00097         catch(...) {
00098           //what should we do here???
00099         }
00100 
00101         return( 0 );
00102       }
00103 
00106     static int putValuesIn(FillableMat* mat,
00107                            int numRows, const int* rows,
00108                            int numCols, const int* cols,
00109                            const double* const* values,
00110                            bool sum_into)
00111       {
00112         if (numCols < 1 || numRows < 1) return(0);
00113         if (sum_into) {
00114           for(int i=0; i<numRows; ++i) {
00115             mat->sumInRow(rows[i], cols, values[i], numCols);
00116           }
00117         }
00118         else {
00119           for(int i=0; i<numRows; ++i) {
00120             mat->putRow(rows[i], cols, values[i], numCols);
00121           }
00122         }
00123 
00124         return( 0 );
00125       }
00126 
00131     static int globalAssemble(FillableMat* mat)
00132     {
00133       return(0);
00134     }
00135 
00137     static int matvec(FillableMat* mat,
00138                       fei::Vector* x,
00139                       fei::Vector* y)
00140     {
00141       fei::Vector_Impl<CSVec>* fvx =
00142         dynamic_cast<fei::Vector_Impl<CSVec>* >(x);
00143       fei::Vector_Impl<CSVec>* fvy =
00144         dynamic_cast<fei::Vector_Impl<CSVec>* >(y);
00145 
00146       if (fvx == NULL || fvy == NULL) {
00147         return(-1);
00148       }
00149 
00150       fei::CSRMat A(*mat);
00151       fei::CSVec csx(*(fvx->getUnderlyingVector()));
00152       fei::CSVec csy(*(fvy->getUnderlyingVector()));
00153 
00154       fei::multiply_CSRMat_CSVec(A, csx, csy);
00155 
00156       return( 0 );
00157     }
00158 
00159   };//struct MatrixTraits
00160 }//namespace fei
00161 
00162 #endif // _fei_MatrixTraits_FillableMat_hpp_
00163 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends