TSFEpetraVectorSpace.cpp
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 #include "TSFEpetraVectorSpace.hpp"
00028 #include "TSFEpetraVector.hpp"
00029 #include "Teuchos_Utils.hpp"
00030 
00031 #include "Teuchos_DefaultSerialComm.hpp"
00032 #include "Thyra_DefaultSpmdVectorSpaceFactory.hpp"
00033 #include "Thyra_DefaultSpmdVectorSpace_decl.hpp"
00034 #include "Thyra_DefaultColumnwiseMultiVector.hpp"
00035 #include "SundanceOut.hpp"
00036 #include "Epetra_SerialComm.h"
00037 #include "Epetra_Comm.h"
00038 #ifdef HAVE_MPI
00039 #include "Epetra_MpiComm.h"
00040 #include "Teuchos_DefaultMpiComm.hpp"
00041 #endif
00042 
00043 
00044 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00045 #include "TSFVectorSpaceImpl.hpp"
00046 #endif
00047 
00048 
00049 
00050 using namespace TSFExtended;
00051 using namespace Thyra;
00052 
00053 using Teuchos::RCP;
00054 
00055 EpetraVectorSpace::EpetraVectorSpace(const RCP<const Epetra_Map>& m)
00056   : ScalarProdVectorSpaceBase<double>(),
00057     SpmdVectorSpaceBase<double>(),
00058     smallVecSpcFactory_(rcp(new DefaultSpmdVectorSpaceFactory<double>())),
00059     epetraMap_(m),
00060     comm_(epetraCommToTeuchosComm(m->Comm())),
00061     localSubDim_(epetraMap_->NumMyElements()),
00062     localOffset_(epetraMap_->MinMyGID())
00063 {}
00064 
00065 
00066 OrdType EpetraVectorSpace::dim() const 
00067 {
00068   return epetraMap_->NumGlobalElements();
00069 }
00070 
00071 bool EpetraVectorSpace::isCompatible(const VectorSpaceBase<double>& other) const 
00072 {
00073   const EpetraVectorSpace* epvs = dynamic_cast<const EpetraVectorSpace*>(&other);
00074   if (epvs != 0)
00075   {
00076     return epetraMap_->SameAs(*(epvs->epetraMap_));
00077   }
00078   return false;
00079 }
00080 
00081 RCP<const VectorSpaceFactoryBase<double> > 
00082 EpetraVectorSpace::smallVecSpcFcty() const 
00083 {
00084   return smallVecSpcFactory_;
00085 }
00086 
00087 
00088 
00089 // Overridden from VectorSpace
00090 
00091 Teuchos::RCP<VectorBase<double> >
00092 EpetraVectorSpace::createMember() const
00093 {
00094 //  cout << "creating vector" << std::endl;
00095   return rcp(new EpetraVector(rcp(this, false)));
00096 }
00097 
00098 
00099 
00100 Teuchos::RCP<MultiVectorBase<double> >
00101 EpetraVectorSpace::createMembers(int n) const
00102 {
00103   RCP<const VectorSpaceBase<double> > self = rcp(this, false);
00104   RCP<const VectorSpaceBase<double> > small 
00105     = Thyra::defaultSpmdVectorSpace<double>(n);
00106   Array<RCP<VectorBase<double> > > vecs(n);
00107   for (int i=0; i<vecs.size(); i++)
00108     {
00109       vecs[i] = createMember();
00110     }
00111   return rcp(
00112     new Thyra::DefaultColumnwiseMultiVector<double>(
00113       self, small,
00114 #ifndef TRILINOS_8
00115       vecs
00116 #else
00117       &(vecs[0])
00118 #endif
00119       )
00120     );
00121 }
00122 
00123 
00124 
00125 Teuchos::RCP< const VectorSpaceBase<double> >
00126 EpetraVectorSpace::clone() const
00127 {
00128   return Teuchos::rcp(new EpetraVectorSpace(epetraMap_));
00129 }
00130 
00131 
00132 
00133 string EpetraVectorSpace::description() const
00134 {
00135   std::string rtn = "EpetraVS[d=" + Teuchos::toString(dim());
00136   if (localSubDim() != dim()) rtn += ", local="
00137     + Teuchos::toString(localSubDim());
00138   rtn += "]";
00139   return rtn;
00140 }
00141 
00142 
00143 
00144 Teuchos::RCP<const Teuchos::Comm<OrdType> > 
00145 EpetraVectorSpace::epetraCommToTeuchosComm(const Epetra_Comm& epComm) const 
00146 {
00147   RCP<const Comm<OrdType> > rtn;
00148 
00149 #ifdef HAVE_MPI
00150   const Epetra_MpiComm* mpiComm 
00151     = dynamic_cast<const Epetra_MpiComm*>(&epComm);
00152 #endif
00153 
00154   const Epetra_SerialComm* serialComm 
00155     = dynamic_cast<const Epetra_SerialComm*>(&epComm);
00156 
00157   if (serialComm != 0)
00158   {
00159     rtn  = rcp(new SerialComm<OrdType>());
00160   }
00161 #ifdef HAVE_MPI
00162   else if (mpiComm != 0)
00163   {
00164     MPI_Comm rawMpiComm = mpiComm->GetMpiComm();
00165     RCP<const OpaqueWrapper<MPI_Comm> > ptr 
00166       = rcp(new OpaqueWrapper<MPI_Comm>(rawMpiComm));
00167     rtn  = rcp(new MpiComm<OrdType>(ptr));
00168   }
00169 #endif
00170   else
00171   {
00172     TEST_FOR_EXCEPTION(true, std::runtime_error, "Epetra_Comm is neither "
00173       "a SerialComm or MpiComm");
00174   }
00175   return rtn;
00176 }
00177 
00178 
00179 
00180 

Site Contact