00001 /* @HEADER@ */ 00002 /* *********************************************************************** 00003 // 00004 // TSFExtended: Trilinos Solver Framework Extended 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // **********************************************************************/ 00027 /* @HEADER@ */ 00028 00029 #ifndef TSFLOADABLEMATRIX_HPP 00030 #define TSFLOADABLEMATRIX_HPP 00031 00032 #include "SundanceDefs.hpp" 00033 00034 namespace TSFExtended 00035 { 00036 /** 00037 * Class LoadableMatrix provides an abstract interface for 00038 * loading elements into a matrix. 00039 */ 00040 template <class Scalar> 00041 class LoadableMatrix 00042 { 00043 public: 00044 /** Virtual dtor */ 00045 virtual ~LoadableMatrix(){;} 00046 00047 /** Insert a set of elements in a row, adding to any previously 00048 * existing values. The nonzero structure of the matrix must have 00049 * been determined at construction time. 00050 * 00051 * @param globalRowIndex the global index of the row to which these 00052 * elements belong. 00053 * @param nElemsToInsert the number of elements being inserted in this 00054 * step 00055 * @param globalColumnIndices array of column indices. Must 00056 * be nElemsToInsert in length. 00057 * @param elements array of element values. Must be nElemsToInsert in 00058 * length 00059 */ 00060 virtual void addToRow(int globalRowIndex, 00061 int nElemsToInsert, 00062 const int* globalColumnIndices, 00063 const Scalar* elementValues) = 0 ; 00064 00065 /** Set all elements to zero, preserving the existing structure */ 00066 virtual void zero() = 0 ; 00067 00068 /** 00069 * Add to a batch of elements 00070 */ 00071 virtual void addToElementBatch(int numRows, 00072 int rowBlockSize, 00073 const int* globalRowIndices, 00074 int numColumnsPerRow, 00075 const int* globalColumnIndices, 00076 const Scalar* values, 00077 const int* skipRow); 00078 00079 00080 }; 00081 00082 00083 /* Default implementation of addElementBatch */ 00084 template <class Scalar> 00085 void LoadableMatrix<Scalar>::addToElementBatch(int numRows, 00086 int rowBlockSize, 00087 const int* globalRowIndices, 00088 int numColumnsPerRow, 00089 const int* globalColumnIndices, 00090 const Scalar* values, 00091 const int* skipRow) 00092 { 00093 int numRowBlocks = numRows/rowBlockSize; 00094 int row = 0; 00095 00096 for (int rb=0; rb<numRowBlocks; rb++) 00097 { 00098 const int* cols = globalColumnIndices + rb*numColumnsPerRow; 00099 for (int r=0; r<rowBlockSize; r++, row++) 00100 { 00101 if (skipRow[row]) continue; 00102 const double* rowVals = values + row*numColumnsPerRow; 00103 addToRow(globalRowIndices[row], numColumnsPerRow, 00104 cols, rowVals); 00105 } 00106 } 00107 } 00108 } 00109 00110 #endif