PlayaVectorTypeBase.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 //   
00003 /* @HEADER@ */
00004 
00005 #ifndef PLAYA_VECTORTYPEBASE_HPP
00006 #define PLAYA_VECTORTYPEBASE_HPP
00007 
00008 #include "PlayaHandle.hpp"
00009 #include "PlayaVectorSpaceDecl.hpp"
00010 #include "PlayaLinearOperatorDecl.hpp" 
00011 #include "PlayaMatrixFactory.hpp" 
00012 #include "PlayaGhostImporter.hpp"
00013 
00014 namespace Playa
00015 {
00016 using namespace Teuchos;
00017 
00018 /**
00019  *
00020  */
00021 template <class Scalar>
00022 class VectorTypeBase
00023 {
00024 public:
00025   /** Virtual dtor */
00026   virtual ~VectorTypeBase() {;}
00027 
00028   /** create a distributed vector space.
00029    * @param dimension the dimension of the space 
00030    * @param nLocal number of indices owned by the local processor
00031    * @param locallyOwnedIndices array of indices owned by this processor  
00032    */
00033   virtual RCP<const VectorSpaceBase<Scalar> >
00034   createSpace(int dimension, 
00035     int nLocal,
00036     const int* locallyOwnedIndices,
00037     const MPIComm& comm) const = 0 ;
00038    
00039 
00040   /** Default implementation creates a vector space having 
00041    * nLocal elements on each processor. Serial types should override this
00042    * to produce a replicated space. */
00043   virtual VectorSpace<Scalar> 
00044   createEvenlyPartitionedSpace(const MPIComm& comm,
00045     int nLocal) const ;
00046 
00047   /**  
00048    * Create an importer for accessing ghost elements.
00049    * @param space the distributed vector space on which ghost elements
00050    * are to be shared
00051    * @param nGhost number of ghost elements needed by this processor
00052    * @param ghostIndices read-only C array of off-processor indices needed
00053    * by this processor.
00054    * @return A RCP to a GhostImporter object.
00055    */
00056   virtual RCP<GhostImporter<Scalar> > 
00057   createGhostImporter(const VectorSpace<Scalar>& space,
00058     int nGhost,
00059     const int* ghostIndices) const = 0 ;
00060 
00061     
00062   /**
00063    * Create a matrix factory of type compatible with this vector type,
00064    * sized according to the given domain and range spaces.
00065    */
00066   virtual RCP<MatrixFactory<Scalar> >
00067   createMatrixFactory(const VectorSpace<Scalar>& domain,
00068     const VectorSpace<Scalar>& range) const = 0 ;
00069     
00070     
00071 };
00072 
00073 
00074 
00075 /* Default implementation */
00076 template <class Scalar> inline 
00077 VectorSpace<Scalar> VectorTypeBase<Scalar>
00078 ::createEvenlyPartitionedSpace(const MPIComm& comm,
00079   int nLocal) const
00080 {
00081   int rank = comm.getRank();
00082   int nProc = comm.getNProc();
00083   int dimension = nLocal * nProc;
00084   Array<int> locallyOwnedIndices(nLocal);
00085   int lowestLocalRow = rank*nLocal;
00086   for (int i=0; i<nLocal; i++)
00087   {
00088     locallyOwnedIndices[i] = lowestLocalRow + i;
00089   }
00090   return this->createSpace(dimension, nLocal, &(locallyOwnedIndices[0]), comm);
00091 }
00092 
00093   
00094 }
00095 
00096 #endif

Site Contact