コード例 #1
0
//TpetraCrsMatrix_To_EpetraCrsMatrix: copies Tpetra::CrsMatrix object into its analogous
//Epetra_CrsMatrix object
void Petra::TpetraCrsMatrix_To_EpetraCrsMatrix(const Teuchos::RCP<const Tpetra_CrsMatrix>& tpetraCrsMatrix_,
                                               Epetra_CrsMatrix& epetraCrsMatrix_,
                                               const Teuchos::RCP<const Epetra_Comm>& comm_)
{
  //check if row maps of epetraCrsMatrix_ and tpetraCrsMatrix_ are the same
  const Epetra_BlockMap epetraRowMap_ = epetraCrsMatrix_.RowMap();
  Teuchos::RCP<const Tpetra_Map> tpetraRowMap_ = tpetraCrsMatrix_->getRowMap();
  Teuchos::RCP<const Epetra_Map> tpetraRowMapE_ = TpetraMap_To_EpetraMap(tpetraRowMap_, comm_);
  bool isRowSame = tpetraRowMapE_->SameAs(epetraRowMap_);
  //if epetraCrsMatrix_ and tpetraCrsMatrix_ do not have the same row map, throw an exception
  if (isRowSame != true)
  {
    EpetraExt::BlockMapToMatrixMarketFile("epetraRowMap.mm", epetraRowMap_);
    EpetraExt::BlockMapToMatrixMarketFile("tpetraRowMapE.mm", *tpetraRowMapE_);
  }
  TEUCHOS_TEST_FOR_EXCEPTION((isRowSame != true),
                             std::logic_error,
                             "Error in Petra::TpetraCrsMatrix_To_EpetraCrsMatrix! Arguments Epetra_CrsMatrix and Tpetra::CrsMatrix do not have same row map." <<  std::endl) ;

 //check if column maps of epetraCrsMatrix_ and tpetraCrsMatrix_ are the same
 const Epetra_BlockMap epetraColMap_ = epetraCrsMatrix_.ColMap();
 Teuchos::RCP<const Tpetra_Map> tpetraColMap_ = tpetraCrsMatrix_->getColMap();
 Teuchos::RCP<const Epetra_Map> tpetraColMapE_ = TpetraMap_To_EpetraMap(tpetraColMap_, comm_);
 bool isColSame = tpetraColMapE_->SameAs(epetraColMap_);
 //if epetraCrsMatrix_ and tpetraCrsMatrix_ do not have the same column map, throw an exception
 TEUCHOS_TEST_FOR_EXCEPTION((isColSame != true),
                            std::logic_error,
                            "Error in Petra::TpetraCrsMatrix_To_EpetraCrsMatrix! Arguments Epetra_CrsMatrix and Tpetra::CrsMatrix do not have same column map." <<  std::endl) ;

  epetraCrsMatrix_.PutScalar(0.0);

  for (LO i = 0; i<tpetraCrsMatrix_->getNodeNumRows(); i++) {
     LO NumEntries; const LO *Indices; const ST *Values;
     tpetraCrsMatrix_->getLocalRowView(i, NumEntries, Values, Indices);
     epetraCrsMatrix_.ReplaceMyValues(i, NumEntries, Values, Indices);
  }
}