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 TSFLOADABLEVECTOR_HPP 00030 #define TSFLOADABLEVECTOR_HPP 00031 00032 #include "SundanceDefs.hpp" 00033 #include "Thyra_VectorBase.hpp" 00034 00035 namespace TSFExtended 00036 { 00037 /** 00038 * LoadableVector defines an interface through which elements can 00039 * be loaded into a vector. Element loading is used extensively 00040 * by application codes in creating vectors, 00041 * but should never be used by high-performance solver codes; this 00042 * capability is therefore in TSFExtended rather than Thyra. 00043 * 00044 * A TSFExtended vector type that will be 00045 * used in a context where loading is required should multiply inherit 00046 * from both Thyra::VectorBase and TSFExtended::LoadableVector. 00047 * 00048 * Elements can by loaded one at a time 00049 * or in batches. The methods to load single elements arew pure virtual 00050 * and thus must be defined by derived classes. 00051 * Loading in batches will usually be more efficient 00052 * provided the underlying vector implementation supports it. 00053 * For those types not supporting batch loading, LoadableVector provides 00054 * default batch loading functions which delegate to single-element loading. 00055 * 00056 * Elements can by loaded either by setting a value, or adding to an 00057 * existing value. The latter will typically by used in finite-element 00058 * codes. 00059 * 00060 * @author Kevin Long (krlong@sandia.gov) 00061 */ 00062 template <class Scalar> 00063 class LoadableVector 00064 { 00065 public: 00066 /** virtual dtor */ 00067 virtual ~LoadableVector() {;} 00068 00069 /** set a single element at the given global index */ 00070 virtual void setElement(OrdType globalIndex, const Scalar& value) = 0 ; 00071 00072 /** add to the existing value of 00073 * a single element at the given global index */ 00074 virtual void addToElement(OrdType globalIndex, const Scalar& value) = 0 ; 00075 00076 /** set a group of elements */ 00077 virtual void setElements(OrdType numElems, 00078 const OrdType* globalIndices, 00079 const Scalar* values) ; 00080 00081 /** add to a group of elements */ 00082 virtual void addToElements(OrdType numElems, 00083 const OrdType* globalIndices, 00084 const Scalar* values); 00085 00086 /** Do whatever finalization steps are needed by the implementation, 00087 for instance, synchronizing border elements. The default implementation 00088 * is a no-op. */ 00089 virtual void finalizeAssembly() {;} 00090 }; 00091 00092 /* Default implementation of setElements makes multiple calls to 00093 * setElement(). If at all possible, this should be overridden 00094 * with a method specialized to the underlying type. */ 00095 template <class Scalar> 00096 inline void LoadableVector<Scalar>::setElements(OrdType numElems, 00097 const OrdType* globalIndices, 00098 const Scalar* values) 00099 { 00100 for (int i=0; i<numElems; i++) 00101 { 00102 setElement(globalIndices[i], values[i]); 00103 } 00104 } 00105 00106 /* Default implementation of addToElements makes multiple calls to 00107 * addToElement(). If at all possible, this should be overridden 00108 * with a method specialized to the underlying type. */ 00109 template <class Scalar> 00110 inline void LoadableVector<Scalar>::addToElements(OrdType numElems, 00111 const OrdType* globalIndices, 00112 const Scalar* values) 00113 { 00114 for (OrdType i=0; i<numElems; i++) 00115 { 00116 addToElement(globalIndices[i], values[i]); 00117 } 00118 } 00119 00120 00121 00122 } 00123 00124 #endif