TSFEpetraMultiVector.hpp
Go to the documentation of this file.
00001 /* ***********************************************************************
00002 // 
00003 //           TSFExtended: Trilinos Solver Framework Extended
00004 //                 Copyright (2004) Sandia Corporation
00005 // 
00006 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00007 // license for use of this work by or on behalf of the U.S. Government.
00008 // 
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Lesser General Public License as
00011 // published by the Free Software Foundation; either version 2.1 of the
00012 // License, or (at your option) any later version.
00013 //  
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //  
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022 // USA
00023 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00024 // 
00025 // **********************************************************************/
00026 
00027 #ifndef TSFEPETRAMULTIVECTOR_HPP
00028 #define TSFEPETRAMULTIVECTOR_HPP
00029 
00030 #include "SundanceDefs.hpp"
00031 #include "SundancePrintable.hpp"
00032 #include "TSFIndexableVector.hpp"
00033 #include "TSFRawDataAccessibleVector.hpp"
00034 #include "TSFVectorDecl.hpp"
00035 #include "Epetra_FEVector.h"
00036 #include "Epetra_Vector.h"
00037 
00038 #ifdef TRILINOS_6
00039 #include "Thyra_MPIVectorStdDecl.hpp"
00040 #else
00041 #define MPIMultiVectorStd DefaultMPIMultiVector
00042 #include "Thyra_DefaultMPIMultiVectorDecl.hpp"
00043 #endif
00044 
00045 namespace TSFExtended
00046 {
00047   using namespace Teuchos;
00048   using namespace Thyra;
00049   /**
00050    * TSF extension of Thyra::EpetraMultiVector, implementing the 
00051    * LoadableMultiVector
00052    * interface allowing an application to access elements. This class derives
00053    * from Thyra::EpetraVector, so it can be used seamlessly in any 
00054    * Thyra-based code.
00055    */
00056   class EpetraMultiVector : public MPIMultiVectorStd<double>,
00057                             public Sundance::Handleable<MultiVectorBase<double> >,
00058                             public IndexableVector<double>,
00059                             public RawDataAccessibleVector<double>,
00060                             public Printable
00061   {
00062   public:
00063     GET_RCP(MultiVectorBase<double>);
00064 
00065     /** Construct with a smart pointer to an Epetra vector space. */
00066     EpetraMultiVector(const RCP<const VectorSpaceBase<double> >& vs);
00067 
00068     /** Construct with smart pointers to an Epetra vector space
00069         and an existing Epetra vector. */
00070     EpetraMultiVector(const RCP<const VectorSpaceBase<double> >& vs,
00071                       const RCP<Epetra_MultiVector>& vec);
00072 
00073     /** \name IndexableVector interface */
00074     //@{
00075     /** read the element at the given global index */
00076     virtual const double& operator[](OrdType globalIndex) const 
00077     {return getElement(globalIndex);}
00078 
00079     /** writable access to the element at the given global index */
00080     virtual double& operator[](OrdType globalIndex) ;
00081     //@}
00082 
00083     /** \name Raw data access interface */
00084     //@{
00085     /** */
00086     virtual const double* dataPtr() const {return &(epetraVec_->operator[](0));}
00087     /** */
00088     virtual double* dataPtr() {return &(epetraVec_->operator[](0));}
00089     //@}
00090 
00091     /** \name LoadableVector interface */
00092     //@{
00093     /** set a single element */
00094     void setElement(OrdType globalIndex, const double& value);
00095 
00096     /** add to a single element */
00097     void addToElement(OrdType globalIndex, const double& value);
00098 
00099     /** set a group of elements */
00100     void setElements(int numElems, const OrdType* globalIndices, 
00101                      const double* values);
00102 
00103 
00104     /** add to a group of elements */
00105     void addToElements(int numElems, const OrdType* globalIndices, 
00106                        const double* values);
00107 
00108     /** */
00109     void finalizeAssembly();
00110     //@}
00111 
00112     /** \name AccessibleVector interface */
00113     //@{
00114     /** */
00115     const double& getElement(OrdType globalIndex) const ;
00116 
00117     /** */
00118     void getElements(const OrdType* globalIndices, int numElems,
00119                      vector<double>& elems) const ;
00120     //@}
00121       
00122 
00123     /** \name Printable interface */
00124     //@{
00125     /** Write to a stream  */
00126     void print(std::ostream& os) const 
00127     {
00128       epetraVec()->Print(os);
00129     }
00130     //@}
00131 
00132     /** Get a read-only Epetra_Vector */
00133     static const Epetra_Vector& getConcrete(const TSFExtended::Vector<double>& tsfVec);
00134     /** Get a read-write Epetra_Vector */
00135     static Epetra_Vector& getConcrete(TSFExtended::Vector<double>& tsfVec);
00136     /** Get a read-write Epetra_Vector pointer */
00137     static Epetra_Vector* getConcretePtr(TSFExtended::Vector<double>& tsfVec);
00138 
00139 
00140 
00141     
00142     /** */
00143     const RCP<Epetra_Vector>& epetraVec() const {return epetraVec_;}
00144     
00145     /** */
00146     RCP<Epetra_Vector>& epetraVec() {return epetraVec_;}
00147 
00148   protected:    
00149     /** */
00150     const RCP<const Epetra_Map>& epetraMap() const {return epetraMap_;}
00151 
00152   private:
00153 
00154     RCP<Epetra_Vector> epetraVec_;
00155 
00156     RCP<const MPIVectorSpaceBase<double> > mpiVecSpace_;
00157 
00158     RCP<const Epetra_Map> epetraMap_;
00159   };
00160   
00161 }
00162 
00163 #endif

Site Contact