Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_Utils.cpp
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#include "Xpetra_Utils.hpp"
11#include "Xpetra_Exceptions.hpp"
12
13namespace Xpetra {
14
16 if (lib == Xpetra::UseTpetra) {
17 return "Tpetra";
18 } else if (lib == Xpetra::UseEpetra) {
19 return "Epetra";
20 } else {
21 TEUCHOS_TEST_FOR_EXCEPTION(true, Xpetra::Exceptions::RuntimeError, "lib != UseTpetra && lib != UseEpetra");
22 }
23}
24
25#ifdef HAVE_XPETRA_TPETRA
26
27Xpetra::LookupStatus toXpetra(Tpetra::LookupStatus ls) {
28 if (ls == Tpetra::AllIDsPresent)
30 if (ls == Tpetra::IDNotPresent)
32
34}
35
36Tpetra::OptimizeOption toTpetra(Xpetra::OptimizeOption os) {
38 return Tpetra::DoOptimizeStorage;
40 return Tpetra::DoNotOptimizeStorage;
41
43}
44
45Tpetra::CombineMode toTpetra(Xpetra::CombineMode cm) {
46 if (cm == Xpetra::ADD)
47 return Tpetra::ADD;
48
49 if (cm == Xpetra::INSERT)
50 return Tpetra::INSERT;
51
52 if (cm == Xpetra::ABSMAX)
53 return Tpetra::ABSMAX;
54
55 TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Cannot convert Xpetra::CombineMode to Tpetra::CombineMode: unsupported CombineMode.");
56}
57
58Tpetra::LocalGlobal toTpetra(LocalGlobal lg) {
60 return Tpetra::LocallyReplicated;
62 return Tpetra::GloballyDistributed;
63
65}
66
67#endif // HAVE_XPETRA_TPETRA
68
69#ifdef HAVE_XPETRA_EPETRA
70
72 // This function is used only to convert the return value of Epetra_BlockMap::RemoteIDList() and Epetra_DirectoryBase::GetDirectoryEntries().
73 // In the current implementation of Epetra (01/2012), these functions returns 0 (= success) or 1 (= a GID is not present on any processor).
74
75 if (ls == 0)
77 else if (ls == 1)
79
80 TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Epetra returned the following error code: " << ls << ". Xpetra do not know how to interpret this error code.");
81}
82
85 return true;
87 return false;
88
90}
91
93 // Note: all the CombineMode are not supported.
94 // According to Chris B., the behavior in Tpetra is the same as Epetra but I prefer to limit my tests for now.
95 // See also the discussion of March 22 on the Tpetra developers mailing list.
96
97 if (cm == Xpetra::ADD)
98 return Add;
99 if (cm == Xpetra::INSERT)
100 return Insert;
101 if (cm == Xpetra::ABSMAX)
102 return AbsMax;
103
104 TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Cannot convert Xpetra::CombineMode to Epetra_CombineMode: unsupported CombineMode.");
105}
106
107#endif // HAVE_XPETRA_EPETRA
108
109} // namespace Xpetra
Epetra_CombineMode
Insert
Add
AbsMax
Exception throws to report errors in the internal logical of the program.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.
CombineMode
Xpetra::Combine Mode enumerable type.