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 TSFVECTORTYPEEXTENSIONS_HPP 00028 #define TSFVECTORTYPEEXTENSIONS_HPP 00029 00030 #include "SundanceHandle.hpp" 00031 #include "Thyra_VectorSpaceFactoryBase.hpp" 00032 #include "TSFVectorSpaceDecl.hpp" 00033 #include "TSFLinearOperatorDecl.hpp" //Decl added by ptb 00034 #include "TSFMatrixFactory.hpp" 00035 #include "TSFGhostImporter.hpp" 00036 00037 namespace TSFExtended 00038 { 00039 using namespace Teuchos; 00040 00041 /** 00042 * VectorTypeExtensions provides extensions to 00043 * the Thyra::VectorSpaceFactoryBase 00044 * object, appropriate to the interface with applications codes. 00045 * Thyra::VectorSpaceFactoryBase has a method to create a small serial 00046 * vector space for use in multivector operators, however, that is 00047 * insufficient for the needs of applications. 00048 * 00049 * <h4> Notes for subclass developers </h4> 00050 * 00051 * Subclasses should also derive from some subclass of 00052 * Thyra::VectorSpaceFactoryBase in order to use the createReplicatedSpace() 00053 * method. 00054 * 00055 * Because applications may use the clean syntax 00056 * \code 00057 * VectorType vt = new MyVectorType(); 00058 * \endcode 00059 * subclasses should also derive from 00060 * Handleable<VectorTypeBase<Scalar> and implement the getRcp() method. 00061 * 00062 * Subclasses might optionally implement the Printable and Describable 00063 * interfaces 00064 * 00065 */ 00066 template <class Scalar> 00067 class VectorTypeExtensions 00068 { 00069 public: 00070 /** */ 00071 virtual ~VectorTypeExtensions() {;} 00072 00073 /** create a distributed vector space. 00074 * @param dimension the dimension of the space 00075 * @param nLocal number of indices owned by the local processor 00076 * @param locallyOwnedIndices array of indices owned by this processor 00077 */ 00078 virtual RCP<const Thyra::VectorSpaceBase<Scalar> > 00079 createSpace(int dimension, 00080 int nLocal, 00081 const int* locallyOwnedIndices, 00082 const MPIComm& comm) const = 0 ; 00083 00084 00085 /** Default implementation creates a vector space having 00086 * nLocal elements on each processor. Serial types should override this 00087 * to produce a replicated space. */ 00088 virtual VectorSpace<Scalar> 00089 createEvenlyPartitionedSpace(const MPIComm& comm, 00090 int nLocal) const ; 00091 00092 /** 00093 * Create an importer for accessing ghost elements. 00094 * @param space the distributed vector space on which ghost elements 00095 * are to be shared 00096 * @param nGhost number of ghost elements needed by this processor 00097 * @param ghostIndices read-only C array of off-processor indices needed 00098 * by this processor. 00099 * @return A RCP to a GhostImporter object. 00100 */ 00101 virtual RCP<GhostImporter<Scalar> > 00102 createGhostImporter(const VectorSpace<Scalar>& space, 00103 int nGhost, 00104 const int* ghostIndices) const = 0 ; 00105 00106 00107 /** 00108 * Create a matrix factory of type compatible with this vector type, 00109 * sized according to the given domain and range spaces. 00110 */ 00111 virtual RCP<MatrixFactory<Scalar> > 00112 createMatrixFactory(const VectorSpace<Scalar>& domain, 00113 const VectorSpace<Scalar>& range) const = 0 ; 00114 00115 00116 00117 }; 00118 00119 00120 /* Default implementation */ 00121 template <class Scalar> inline 00122 VectorSpace<Scalar> VectorTypeExtensions<Scalar> 00123 ::createEvenlyPartitionedSpace(const MPIComm& comm, 00124 int nLocal) const 00125 { 00126 int rank = comm.getRank(); 00127 int nProc = comm.getNProc(); 00128 int dimension = nLocal * nProc; 00129 Array<int> locallyOwnedIndices(nLocal); 00130 int lowestLocalRow = rank*nLocal; 00131 for (int i=0; i<nLocal; i++) 00132 { 00133 locallyOwnedIndices[i] = lowestLocalRow + i; 00134 } 00135 return this->createSpace(dimension, nLocal, &(locallyOwnedIndices[0]), comm); 00136 } 00137 00138 00139 } 00140 00141 #endif