00001
00002
00003
00004
00005 #include "PlayaEpetraGhostImporter.hpp"
00006 #include "PlayaEpetraGhostView.hpp"
00007 #include "PlayaEpetraVector.hpp"
00008 #include "PlayaTabs.hpp"
00009 #include "PlayaOut.hpp"
00010
00011
00012 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00013 #include "PlayaVectorImpl.hpp"
00014 #endif
00015
00016
00017 namespace Playa
00018 {
00019 using namespace Teuchos;
00020
00021
00022 EpetraGhostImporter
00023 ::EpetraGhostImporter(const RCP<const Epetra_Map>& localMap,
00024 int nGhost,
00025 const int* ghostElements)
00026 : localMap_(localMap),
00027 ghostMap_(),
00028 importer_()
00029 {
00030 if (false && nGhost==0)
00031 {
00032 ghostMap_ = localMap_;
00033
00034 importer_ = rcp(new Epetra_Import(*ghostMap_, *localMap_));
00035 }
00036 else
00037 {
00038
00039 int nLocal = localMap_->NumMyElements();
00040 int nGhostView = nLocal+nGhost;
00041 std::vector<int> globalIndices(nGhostView);
00042 for (int i=0; i<nLocal; i++) globalIndices[i] = localMap_->GID(i);
00043 for (int i=0; i<nGhost; i++) globalIndices[i+nLocal] = ghostElements[i];
00044
00045 const Epetra_Comm& comm = localMap_->Comm();
00046
00047 ghostMap_ = rcp(new Epetra_Map(-1, nGhostView,
00048 &(globalIndices[0]), 0, comm));
00049
00050 importer_ = rcp(new Epetra_Import(*ghostMap_, *localMap_));
00051 }
00052 }
00053
00054 void EpetraGhostImporter
00055 ::importView(const Vector<double>& x,
00056 RCP<GhostView<double> >& ghostView) const
00057 {
00058 Tabs tab;
00059
00060
00061 if (ghostView.get()==0)
00062 {
00063 ghostView = rcp(new EpetraGhostView());
00064 }
00065
00066
00067 EpetraGhostView* epgv
00068 = dynamic_cast<EpetraGhostView*>(ghostView.get());
00069
00070 TEUCHOS_TEST_FOR_EXCEPTION(epgv==0, std::runtime_error,
00071 "argument ghostView to EpetraGhostImporter::importView() "
00072 "could not be cast to a EpetraGhostView pointer");
00073
00074 const Epetra_Vector& xVec = EpetraVector::getConcrete(x);
00075
00076
00077 epgv->import(*importer_, xVec);
00078 }
00079
00080 }