Ifpack2 Templated Preconditioning Package  Version 1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ifpack2_Details_getCrsMatrix.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
4 //
5 // Copyright 2009 NTESS and the Ifpack2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef IFPACK2_DETAILS_GETCRSMATRIX_HPP
11 #define IFPACK2_DETAILS_GETCRSMATRIX_HPP
12 
13 #include "Ifpack2_ConfigDefs.hpp"
14 #include "Tpetra_CrsMatrix.hpp"
15 #include "Tpetra_BlockCrsMatrix.hpp"
16 #include "Ifpack2_Details_AdditiveSchwarzFilter.hpp"
17 
18 namespace Ifpack2 {
19 namespace Details {
20 
21 // Helper to get A as a Tpetra::CrsMatrix, if that is possible cheaply and without copying.
22 // In the simplest case (when A is already a CrsMatrix), this is just a dynamic cast.
23 template <typename SC, typename LO, typename GO, typename NO>
24 Teuchos::RCP<const Tpetra::CrsMatrix<SC, LO, GO, NO>> getCrsMatrix(const Teuchos::RCP<const Tpetra::RowMatrix<SC, LO, GO, NO>>& A) {
25  using row_matrix_type = Tpetra::RowMatrix<SC, LO, GO, NO>;
26  using crs_matrix_type = Tpetra::CrsMatrix<SC, LO, GO, NO>;
27  auto Acrs = Teuchos::rcp_dynamic_cast<const crs_matrix_type>(A);
28  if (!Acrs.is_null())
29  return Acrs;
30  auto Aasf = Teuchos::rcp_dynamic_cast<const AdditiveSchwarzFilter<row_matrix_type>>(A);
31  if (!Aasf.is_null())
32  return Aasf->getFilteredMatrix();
33  return Teuchos::null;
34 }
35 
36 // Helper to get A as a Tpetra::BlockCrsMatrix, if that is possible cheaply and without copying.
37 // This is just a dynamic cast.
38 template <typename SC, typename LO, typename GO, typename NO>
39 Teuchos::RCP<const Tpetra::BlockCrsMatrix<SC, LO, GO, NO>> getBcrsMatrix(const Teuchos::RCP<const Tpetra::RowMatrix<SC, LO, GO, NO>>& A) {
40  using bcrs_matrix_type = Tpetra::BlockCrsMatrix<SC, LO, GO, NO>;
41  auto Abcrs = Teuchos::rcp_dynamic_cast<const bcrs_matrix_type>(A);
42  if (!Abcrs.is_null())
43  return Abcrs;
44 
45  return Teuchos::null;
46 }
47 
48 } // namespace Details
49 } // namespace Ifpack2
50 
51 #endif
Wraps a Tpetra::CrsMatrix or Ifpack2::OverlappingRowMatrix in a filter that removes off-process edges...