PlayaLoadableVector.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 //   
00003  /* @HEADER@ */
00004 
00005 #ifndef PLAYA_LOADABLEVECTOR_HPP
00006 #define PLAYA_LOADABLEVECTOR_HPP
00007 
00008 #include "PlayaDefs.hpp"
00009 
00010 namespace Playa
00011 {
00012 /**
00013  * LoadableVector defines an interface through which elements can 
00014  * be loaded into a vector. Element loading is used extensively
00015  * by application codes in creating vectors, 
00016  * but should never be used by high-performance solver codes.
00017  *
00018  * A vector type that will be
00019  * used in a context where loading is required should multiply inherit
00020  * from both VectorBase andLoadableVector.
00021  * 
00022  * Elements can by loaded one at a time
00023  * or in batches. The methods to load single elements arew pure virtual
00024  * and thus must be defined by derived classes. 
00025  * Loading in batches will usually be more efficient
00026  * provided the underlying vector implementation supports it. 
00027  * For those types not supporting batch loading, LoadableVector provides
00028  * default batch loading functions which delegate to single-element loading.
00029  *
00030  * Elements can by loaded either by setting a value, or adding to an 
00031  * existing value. The latter will typically by used in finite-element
00032  * codes.
00033  *
00034  * @author Kevin Long (kevin.long@ttu.edu)
00035  */
00036 template <class Scalar>
00037 class LoadableVector 
00038 {
00039 public:
00040   /** virtual dtor */
00041   virtual ~LoadableVector() {;}
00042 
00043   /** set a single element at the given global index */
00044   virtual void setElement(int globalIndex, const Scalar& value) = 0 ;
00045 
00046   /** add to the existing value of 
00047    * a single element at the given global index */
00048   virtual void addToElement(int globalIndex, const Scalar& value) = 0 ;
00049 
00050   /** set a group of elements */
00051   virtual void setElements(int numElems, 
00052     const int* globalIndices, 
00053     const Scalar* values) ;
00054 
00055   /** add to a group of elements */
00056   virtual void addToElements(int numElems, 
00057     const int* globalIndices, 
00058     const Scalar* values);
00059 
00060   /** Do whatever finalization steps are needed by the implementation,
00061       for instance, synchronizing border elements. The default implementation
00062       * is a no-op. */
00063   virtual void finalizeAssembly() {;}
00064 };
00065 
00066 /* Default implementation of setElements makes multiple calls to
00067  * setElement(). If at all possible, this should be overridden
00068  * with a method specialized to the underlying type.  */
00069 template <class Scalar> 
00070 inline void LoadableVector<Scalar>::setElements(int numElems, 
00071   const int* globalIndices, 
00072   const Scalar* values)
00073 {
00074   for (int i=0; i<numElems; i++)
00075   {
00076     setElement(globalIndices[i], values[i]);
00077   }
00078 }
00079 
00080 /* Default implementation of addToElements makes multiple calls to
00081  * addToElement(). If at all possible, this should be overridden
00082  * with a method specialized to the underlying type.  */
00083 template <class Scalar> 
00084 inline void LoadableVector<Scalar>::addToElements(int numElems, 
00085   const int* globalIndices, 
00086   const Scalar* values)
00087 {
00088   for (int i=0; i<numElems; i++)
00089   {
00090     addToElement(globalIndices[i], values[i]);
00091   }
00092 }
00093 
00094   
00095   
00096 }
00097 
00098 #endif

Site Contact