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
16#include "Xpetra_BlockedCrsMatrix.hpp"
17
18namespace Xpetra {
19
20template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
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
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));
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
Concrete implementation of Xpetra::Matrix.
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
static RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > BuildCopy(const RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > A, bool setFixedBlockSize=true)
Xpetra-specific matrix class.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TypeTo as(const TypeFrom &t)