Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tpetra SparseMatrix::add(). #16731

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 21 additions & 10 deletions include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,17 +1137,28 @@ namespace LinearAlgebra
AssertDimension(source.local_range().second, local_range().second);
Assert(matrix->getRowMap()->isSameAs(*source.matrix->getRowMap()),
ExcMessage(
"Can only add matrices with same distribution of rows"));
"Can only add matrices with same distribution of rows."));
Assert(matrix->isFillComplete() && source.matrix->isFillComplete(),
ExcMessage("Addition of matrices only allowed if matrices are "
"filled, i.e., compress() has been called"));

matrix->add(factor,
*source.matrix,
1.0,
matrix->getDomainMap(),
matrix->getRangeMap(),
Teuchos::null);
ExcMessage("Addition of matrices is only allowed if the matrices "
"are filled, i.e., if compress() has been called."));

// Tpetra does not have a function that adds a matrix in-place to the
// we're currently storing. But it (inefficiently) has one that returns a
// new matrix with the result. As a consequence, replace the current one
// by the one that is returned.
//
// Inconveniently, however, the Tpetra::CrsMatrix::add() function returns
// a RCP<Tpetra::RowMatrix>, though it guarantees that the stored object
// is actually a Tpetra::CrsMatrix for our combination of arguments. So,
// we have to do some casting around to assign things back to 'matrix':
auto result = matrix->add(factor,
*source.matrix,
1.0,
matrix->getDomainMap(),
matrix->getRangeMap(),
Teuchos::null);
Assert(dynamic_cast<MatrixType *>(result.get()), ExcInternalError());
matrix.reset(dynamic_cast<MatrixType *>(result.release().get()));
}


Expand Down