PlayaEpetraGhostView.cpp

00001 /* @HEADER@ */
00002 //
00003 /* @HEADER@ */
00004 
00005 #include "PlayaEpetraGhostView.hpp"
00006 #include "Epetra_Import.h"
00007 
00008 
00009 namespace Playa
00010 {
00011 
00012 using namespace Teuchos;
00013 
00014 const double& EpetraGhostView::getElement(int globalIndex) const 
00015 {
00016   const Epetra_BlockMap& myMap = ghostView_->Map();
00017   return (*ghostView_)[myMap.LID(globalIndex)];
00018 }
00019 
00020 void EpetraGhostView::getElements(const int* globalIndices, int numElems,
00021   Array<double>& elems) const
00022 {
00023   elems.resize(numElems);
00024   const Epetra_BlockMap& myMap = ghostView_->Map();
00025 
00026   for (int i=0; i<numElems; i++)
00027   {
00028     elems[i] = (*ghostView_)[myMap.LID(globalIndices[i])];
00029   }
00030 }
00031 
00032 void  EpetraGhostView::import(const Epetra_Import& importer,
00033   const Epetra_Vector& srcObject)
00034 {
00035   /* If my vector does not yet exist, create it using the target map of the
00036    * importer */
00037   if (ghostView_.get()==0)
00038   {
00039     ghostView_ = rcp(new Epetra_Vector(importer.TargetMap()));
00040   }
00041 
00042   /* do the import */
00043   int ierr = ghostView_->Import(srcObject, importer, Insert);
00044 
00045   if (ierr < 0)
00046   {
00047     Out::os() << "target map=" << endl;
00048     importer.TargetMap().Print(Out::os());
00049     Out::os() << "source map=" << endl;
00050     srcObject.Map().Print(Out::os());
00051   }
00052   TEUCHOS_TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error, "ierr=" << ierr << " in EpetraGhostView::import()");
00053 }
00054 
00055 void EpetraGhostView::print(std::ostream& os) const
00056 {
00057   if (ghostView_.get()==0) 
00058   {
00059     os << "[null Epetra ghost view]" << std::endl;
00060   }
00061   else
00062   {
00063     ghostView_->Print(os);
00064   }
00065 }
00066 
00067 }

doxygen