Xpetra
Version of the Day
Loading...
Searching...
No Matches
Xpetra_MatrixFactory2_def.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Xpetra: A linear algebra interface package
4
//
5
// Copyright 2012 NTESS and the Xpetra contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
// WARNING: This code is experimental. Backwards compatibility should not be expected.
11
12
#ifndef XPETRA_MATRIXFACTORY2_DEF_HPP
13
#define XPETRA_MATRIXFACTORY2_DEF_HPP
14
15
#include "
Xpetra_MatrixFactory2_decl.hpp
"
16
#include "Xpetra_BlockedCrsMatrix.hpp"
17
18
namespace
Xpetra
{
19
20
template
<
class
Scalar,
class
LocalOrdinal,
class
GlobalOrdinal,
class
Node>
21
RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>
>
MatrixFactory2<Scalar, LocalOrdinal, GlobalOrdinal, Node>::BuildCopy
(
const
RCP
<
const
Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>
> A,
bool
setFixedBlockSize) {
22
RCP<const CrsMatrixWrap>
oldOp = Teuchos::rcp_dynamic_cast<const CrsMatrixWrap>(A);
23
if
(oldOp == Teuchos::null)
24
throw
Exceptions::BadCast
(
"Cast from Xpetra::Matrix to Xpetra::CrsMatrixWrap failed"
);
25
26
RCP<const CrsMatrix>
oldCrsOp = oldOp->getCrsMatrix();
27
28
UnderlyingLib
lib = A->getRowMap()->lib();
29
30
TEUCHOS_TEST_FOR_EXCEPTION
(lib !=
UseEpetra
&& lib !=
UseTpetra
,
Exceptions::RuntimeError
,
31
"Not Epetra or Tpetra matrix"
);
32
33
#ifdef HAVE_XPETRA_EPETRA
34
if
(lib ==
UseEpetra
) {
35
// NOTE: The proper Epetra conversion in Xpetra_MatrixFactory.cpp
36
throw
Exceptions::RuntimeError
(
"Xpetra::BuildCopy(): matrix templates are incompatible with Epetra"
);
37
}
38
#endif
39
40
#ifdef HAVE_XPETRA_TPETRA
41
if
(lib ==
UseTpetra
) {
42
// Underlying matrix is Tpetra
43
RCP<const TpetraCrsMatrix>
oldTCrsOp = Teuchos::rcp_dynamic_cast<const TpetraCrsMatrix>(oldCrsOp);
44
45
if
(oldTCrsOp != Teuchos::null) {
46
RCP<TpetraCrsMatrix>
newTCrsOp(
new
TpetraCrsMatrix
(*oldTCrsOp));
47
RCP<CrsMatrixWrap>
newOp(
new
CrsMatrixWrap
(
Teuchos::as
<
RCP<CrsMatrix>
>(newTCrsOp)));
48
if
(setFixedBlockSize)
49
newOp->SetFixedBlockSize(A->GetFixedBlockSize());
50
51
return
newOp;
52
}
else
{
53
throw
Exceptions::BadCast
(
"Cast from Xpetra::Matrix to Xpetra::TpetraCrsMatrix failed"
);
54
}
55
}
56
#endif
57
58
return
Teuchos::null;
59
}
60
61
}
// namespace Xpetra
62
63
#endif
Xpetra_MatrixFactory2_decl.hpp
Teuchos::RCP
Xpetra::CrsMatrixWrap
Concrete implementation of Xpetra::Matrix.
Definition
Xpetra_CrsMatrixWrap_decl.hpp:50
Xpetra::Exceptions::BadCast
Exception indicating invalid cast attempted.
Definition
Xpetra_Exceptions.hpp:50
Xpetra::Exceptions::RuntimeError
Exception throws to report errors in the internal logical of the program.
Definition
Xpetra_Exceptions.hpp:65
Xpetra::MatrixFactory2::BuildCopy
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A, bool setFixedBlockSize=true)
Definition
Xpetra_MatrixFactory2_def.hpp:21
Xpetra::Matrix
Xpetra-specific matrix class.
Definition
Xpetra_Matrix_decl.hpp:60
Xpetra::TpetraCrsMatrix
Definition
Xpetra_TpetraCrsMatrix_decl.hpp:42
TEUCHOS_TEST_FOR_EXCEPTION
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::as
TypeTo as(const TypeFrom &t)
Xpetra
Xpetra namespace
Definition
Xpetra_BlockedCrsMatrix_decl.hpp:52
Xpetra::UnderlyingLib
UnderlyingLib
Definition
Xpetra_Map_decl.hpp:39
Xpetra::UseEpetra
@ UseEpetra
Definition
Xpetra_Map_decl.hpp:40
Xpetra::UseTpetra
@ UseTpetra
Definition
Xpetra_Map_decl.hpp:41
src
Matrix
Xpetra_MatrixFactory2_def.hpp
Generated by
1.9.8