Thyra Package Browser (Single Doxygen Collection) Version of the Day
EpetraThyraAdaptersTestHelpers.hpp
Go to the documentation of this file.
00001 #include "Epetra_SerialComm.h"
00002 #ifdef HAVE_MPI
00003 #  include "Epetra_MpiComm.h"
00004 #endif
00005 #include "Epetra_Map.h"
00006 #include "Epetra_CrsMatrix.h"
00007 #include "Teuchos_Array.hpp"
00008 #include "Teuchos_RCP.hpp"
00009 #include "Teuchos_as.hpp"
00010 
00011 
00012 namespace {
00013 
00014 
00015 //
00016 // Helper code and declarations
00017 //
00018 
00019 using Teuchos::as;
00020 using Teuchos::RCP;
00021 using Teuchos::rcp;
00022 using Teuchos::Array;
00023 
00024 
00025 const int g_localDim = 4; // ToDo: Make variable!
00026 
00027 
00028 RCP<const Epetra_Comm> getEpetraComm()
00029 {
00030 #ifdef HAVE_MPI
00031   return rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
00032 #else
00033   return rcp(new Epetra_SerialComm());
00034 #endif
00035 }
00036 
00037 
00038 RCP<Epetra_CrsMatrix> getEpetraMatrix(int numRows, int numCols, double shift=0.0) 
00039 {
00040 
00041   const RCP<const Epetra_Comm> comm = getEpetraComm();
00042 
00043   const Epetra_Map rowMap(numRows, 0, *comm);
00044   const Epetra_Map domainMap(numCols, numCols, 0, *comm);
00045  
00046   const RCP<Epetra_CrsMatrix> epetraCrsM =
00047     rcp(new Epetra_CrsMatrix(Copy, rowMap, numCols));
00048 
00049   Array<double> rowEntries(numCols);
00050   Array<int> columnIndices(numCols);
00051   for (int j = 0; j < numCols; ++j) {
00052     columnIndices[j] = j;
00053   }
00054 
00055   const int numLocalRows = rowMap.NumMyElements();
00056 
00057   for (int i = 0; i < numLocalRows; ++i) {
00058     
00059     for (int j = 0; j < numCols; ++j) {
00060       rowEntries[j] = as<double>(i+1) + as<double>(j+1) / 10 + shift;
00061     }
00062 
00063     epetraCrsM->InsertMyValues( i, numCols, &rowEntries[0], &columnIndices[0] );
00064 
00065   }
00066 
00067   epetraCrsM->FillComplete(domainMap, rowMap);
00068 
00069   return epetraCrsM;
00070 }
00071 
00072 
00073 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines