Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "TSFEpetraMatrixFactory.hpp"
00030 #include "TSFEpetraMatrix.hpp"
00031 #include "TSFEpetraVector.hpp"
00032 #include "TSFVectorSpaceDecl.hpp"
00033 #include "TSFVectorDecl.hpp"
00034 #include "Teuchos_Array.hpp"
00035 #include "Teuchos_MPIComm.hpp"
00036 #include "TSFLinearOperatorDecl.hpp"
00037
00038 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00039 #include "TSFLinearOperatorImpl.hpp"
00040 #include "TSFVectorImpl.hpp"
00041 #endif
00042
00043
00044 using namespace TSFExtended;
00045 using namespace Teuchos;
00046 using namespace Thyra;
00047
00048 EpetraMatrixFactory::EpetraMatrixFactory(const RCP<const EpetraVectorSpace>& domain,
00049 const RCP<const EpetraVectorSpace>& range)
00050 : graph_(rcp(new Epetra_CrsGraph(Copy, *(range->epetraMap()), 0))),
00051 range_(range),
00052 domain_(domain)
00053 {}
00054
00055
00056 void EpetraMatrixFactory::finalize()
00057 {
00058 int ierr = graph_->FillComplete(*(domain_->epetraMap()), *(range_->epetraMap()));
00059
00060 TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error,
00061 "EpetraMatrixFactory::finalize() failed during call "
00062 "to FillComplete(). Error code was " << ierr);
00063
00064 if (!graph_->StorageOptimized())
00065 {
00066 ierr = graph_->OptimizeStorage();
00067
00068 TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error,
00069 "EpetraMatrixFactory::freezeValues() failed during call "
00070 "to OptimizeStorage(). Error code was " << ierr);
00071 }
00072 }
00073
00074 void EpetraMatrixFactory::initializeNonzerosInRow(int globalRowIndex,
00075 int nElemsToInsert,
00076 const int* globalColumnIndices)
00077 {
00078 int ierr = graph_->InsertGlobalIndices(globalRowIndex,
00079 nElemsToInsert,
00080 (int*) globalColumnIndices);
00081
00082 TEST_FOR_EXCEPTION(ierr < 0, std::runtime_error,
00083 "failed to add to row " << globalRowIndex
00084 << " in EpetraMatrixFactory::setRowValues() with nnz="
00085 << nElemsToInsert
00086 << ". Error code was " << ierr);
00087 }
00088
00089
00090 void EpetraMatrixFactory::initializeNonzeroBatch(int numRows,
00091 int rowBlockSize,
00092 const int* globalRowIndices,
00093 int numColumnsPerRow,
00094 const int* globalColumnIndices,
00095 const int* skipRow)
00096 {
00097 int numRowBlocks = numRows/rowBlockSize;
00098 int row = 0;
00099
00100 for (int rb=0; rb<numRowBlocks; rb++)
00101 {
00102 const int* cols = globalColumnIndices + rb*numColumnsPerRow;
00103 for (int r=0; r<rowBlockSize; r++, row++)
00104 {
00105 if (skipRow[row]) continue;
00106 graph_->InsertGlobalIndices(globalRowIndices[row],
00107 numColumnsPerRow, (int*) cols);
00108 }
00109 }
00110 }
00111
00112
00113 void EpetraMatrixFactory::configure(int lowestRow,
00114 const std::vector<int>& rowPtrs,
00115 const std::vector<int>& nnzPerRow,
00116 const std::vector<int>& data)
00117 {
00118
00119 graph_ = rcp(new Epetra_CrsGraph(Copy, *(range_->epetraMap()),
00120 (const int*) &(nnzPerRow[0]),
00121 true));
00122
00123 for (unsigned int i=0; i<rowPtrs.size(); i++)
00124 {
00125 graph_->InsertGlobalIndices(lowestRow + i, nnzPerRow[i],
00126 (int*) &(data[rowPtrs[i]]));
00127 }
00128
00129 finalize();
00130 }
00131
00132 const Epetra_CrsGraph& EpetraMatrixFactory::graph() const
00133 {
00134 return *(graph_.get());
00135 }
00136
00137
00138 LinearOperator<double> EpetraMatrixFactory::createMatrix() const
00139 {
00140 RCP<LinearOpBase<double> > A
00141 = rcp(new EpetraMatrix(graph(), epDomain(), epRange()));
00142 return A;
00143 }