Ifpack2 Templated Preconditioning Package Version 1.0
Loading...
Searching...
No Matches
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
18namespace Ifpack2 {
19namespace 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.
23template<typename SC, typename LO, typename GO, typename NO>
24Teuchos::RCP<const Tpetra::CrsMatrix<SC, LO, GO, NO>> getCrsMatrix(const Teuchos::RCP<const Tpetra::RowMatrix<SC, LO, GO, NO>>& A)
25{
26 using row_matrix_type = Tpetra::RowMatrix<SC, LO, GO, NO>;
27 using crs_matrix_type = Tpetra::CrsMatrix<SC, LO, GO, NO>;
28 auto Acrs = Teuchos::rcp_dynamic_cast<const crs_matrix_type>(A);
29 if(!Acrs.is_null())
30 return Acrs;
31 auto Aasf = Teuchos::rcp_dynamic_cast<const AdditiveSchwarzFilter<row_matrix_type>>(A);
32 if(!Aasf.is_null())
33 return Aasf->getFilteredMatrix();
34 return Teuchos::null;
35}
36
37//Helper to get A as a Tpetra::BlockCrsMatrix, if that is possible cheaply and without copying.
38//This is just a dynamic cast.
39template<typename SC, typename LO, typename GO, typename NO>
40Teuchos::RCP<const Tpetra::BlockCrsMatrix<SC, LO, GO, NO>> getBcrsMatrix(const Teuchos::RCP<const Tpetra::RowMatrix<SC, LO, GO, NO>>& A)
41{
42 using bcrs_matrix_type = Tpetra::BlockCrsMatrix<SC, LO, GO, NO>;
43 auto Abcrs = Teuchos::rcp_dynamic_cast<const bcrs_matrix_type>(A);
44 if(!Abcrs.is_null())
45 return Abcrs;
46
47 return Teuchos::null;
48}
49
50} // namespace Details
51} // namespace Ifpack2
52
53#endif
Preconditioners and smoothers for Tpetra sparse matrices.
Definition Ifpack2_AdditiveSchwarz_decl.hpp:41