44 #include <fei_trilinos_macros.hpp> 
   45 #include <fei_SparseRowGraph.hpp> 
   47 #ifdef HAVE_FEI_EPETRA 
   49 #include <fei_LinProbMgr_EpetraBasic.hpp> 
   51 LinProbMgr_EpetraBasic::LinProbMgr_EpetraBasic(MPI_Comm comm)
 
   72 LinProbMgr_EpetraBasic::~LinProbMgr_EpetraBasic()
 
   77 void LinProbMgr_EpetraBasic
 
   78 ::setRowDistribution(
const std::vector<int>& ownedGlobalRows)
 
   80   if (ownedGlobalRows == ownedRows_) {
 
   84   if (!ownedRows_.empty()) {
 
   85     throw std::runtime_error(
"setRowDistribution called multiple times with different distributions. not allowed.");
 
   88   int* rows = 
const_cast<int*
>(&ownedGlobalRows[0]);
 
   89   epetra_rowmap_.reset(
new Epetra_Map(-1, ownedGlobalRows.size(),
 
   98 void LinProbMgr_EpetraBasic
 
  101   if (fei_srgraph_.get() != NULL) {
 
  102     if (*fei_srgraph_ != *matrixGraph) {
 
  103       throw std::runtime_error(
"setMatrixGraph called multiple times with different graphs. not allowed.");
 
  108     fei_srgraph_ = matrixGraph;
 
  111   if (epetra_rowmap_.get() == NULL) {
 
  115   if ((
int)fei_srgraph_->rowNumbers.size() != epetra_rowmap_->NumMyElements()) {
 
  116     throw std::runtime_error(
"setMatrixGraph: num-rows not consistent with value from setRowDistribution");
 
  121   std::vector<int>& rowNumbers = fei_srgraph_->rowNumbers;
 
  122   std::vector<int>& rowOffsets = fei_srgraph_->rowOffsets;
 
  125   std::vector<int> numIndicesPerRow; numIndicesPerRow.reserve(rowNumbers.size());
 
  129   for(i=0; i<numIndicesPerRow.size(); ++i) {
 
  130     numIndicesPerRow.push_back(rowOffsets[i+1] - rowOffsets[i]);
 
  133   bool static_profile = 
true;
 
  136                   &numIndicesPerRow[0], static_profile));
 
  140   std::vector<int>& colIndices = fei_srgraph_->packedColumnIndices;
 
  141   for(i=0; i<rowNumbers.size(); ++i) {
 
  142     int offset = rowOffsets[i];
 
  143     err = crsgraph_->InsertGlobalIndices(rowNumbers[i], numIndicesPerRow[i],
 
  144                                         &colIndices[offset]);
 
  146       throw std::runtime_error(
"setMatrixGraph: err from Epetra_CrsGraph::InsertGlobalIndices.");
 
  150   err = crsgraph_->FillComplete();
 
  152     throw std::runtime_error(
"setMatrixGraph: err from Epetra_CrsGraph::FillComplete.");
 
  159 void LinProbMgr_EpetraBasic::setMatrixValues(
double scalar)
 
  161   int err = A_->PutScalar(scalar);
 
  163     throw std::runtime_error(
"error in Epetra_CrsMatrix->PutScalar");
 
  167 void LinProbMgr_EpetraBasic::setVectorValues(
double scalar,
 
  170   int err = soln_vector ?
 
  171     x_->PutScalar(scalar) : b_->PutScalar(scalar);
 
  173     throw std::runtime_error(
"error in Epetra_MultiVector->PutScalar");
 
  177 int LinProbMgr_EpetraBasic::getLocalNumRows()
 
  179   if (epetra_rowmap_.get() == NULL) 
return(-1);
 
  181   return(epetra_rowmap_->NumMyElements());
 
  184 int LinProbMgr_EpetraBasic::getRowLength(
int row)
 
  186   if (A_.get() == NULL) 
return(-1);
 
  188   return( A_->NumGlobalEntries(row) );
 
  191 int LinProbMgr_EpetraBasic::copyOutMatrixRow(
int row, 
int len,
 
  192                                              double* coefs, 
int* indices)
 
  195   return( A_->ExtractGlobalRowCopy(row, len, dummy, coefs, indices) );
 
  198 int LinProbMgr_EpetraBasic::insertMatrixValues(
int numRows, 
const int* rows,
 
  199                                                int numCols, 
const int* cols,
 
  200                                                const double* 
const* values,
 
  203   int* nc_cols = 
const_cast<int*
>(cols);
 
  204   double** nc_values = 
const_cast<double**
>(values);
 
  207     for(
int i=0; i<numRows; ++i) {
 
  208       err = A_->SumIntoGlobalValues(rows[i], numCols, nc_values[i], nc_cols);
 
  215     for(
int i=0; i<numRows; ++i) {
 
  216       err = A_->ReplaceGlobalValues(rows[i], numCols, nc_values[i], nc_cols);
 
  225 int LinProbMgr_EpetraBasic::insertVectorValues(
int numValues,
 
  226                                                const int* globalIndices,
 
  227                                                const double* values,
 
  232   double* localvaluesptr = soln_vector ?
 
  233     x_->Pointers()[vectorIndex] : b_->Pointers()[vectorIndex];
 
  235   int min_my_gid = epetra_rowmap_->MinMyGID();
 
  239     for(
int i=0; i<numValues; ++i) {
 
  240       int offset = globalIndices[i] - min_my_gid;
 
  245       localvaluesptr[offset] += values[i];
 
  249     for(
int i=0; i<numValues; ++i) {
 
  250       int offset = globalIndices[i] - min_my_gid;
 
  255       localvaluesptr[offset] = values[i];
 
  262 int LinProbMgr_EpetraBasic::copyOutVectorValues(
int numValues,
 
  263                                                 const int* globalIndices,
 
  268   double* localvaluesptr = soln_vector ?
 
  269     x_->Pointers()[vectorIndex] : b_->Pointers()[vectorIndex];
 
  271   int min_my_gid = epetra_rowmap_->MinMyGID();
 
  273   for(
int i=0; i<numValues; ++i) {
 
  274     int offset = globalIndices[i] - min_my_gid;
 
  275     values[i] = localvaluesptr[offset];
 
  280 double* LinProbMgr_EpetraBasic::getLocalVectorValuesPtr(
bool soln_vector,
 
  283   double* localvaluesptr = soln_vector ?
 
  284     x_->Pointers()[vectorIndex] : b_->Pointers()[vectorIndex];
 
  286   return(localvaluesptr);
 
  289 int LinProbMgr_EpetraBasic::globalAssemble()
 
  293     int err = A_->FillComplete();
 
  299   if (!A_->StorageOptimized()) {
 
  300     A_->OptimizeStorage();
 
  307 LinProbMgr_EpetraBasic::get_A_matrix()
 
  313 LinProbMgr_EpetraBasic::get_rhs_vector()
 
  319 LinProbMgr_EpetraBasic::get_solution_vector()
 
std::vector< int > rowNumbers