Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
13 namespace Xpetra {
14 
15 std::string toString(Xpetra::UnderlyingLib lib) {
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 
28  if (ls == Tpetra::AllIDsPresent)
29  return Xpetra::AllIDsPresent;
30  if (ls == Tpetra::IDNotPresent)
31  return Xpetra::IDNotPresent;
32 
33  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown LookupStatus");
34 }
35 
37  if (os == Xpetra::DoOptimizeStorage)
41 
42  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown OptimizeOption");
43 }
44 
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 
59  if (lg == Xpetra::LocallyReplicated)
63 
64  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown LocalGlobal");
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)
76  return Xpetra::AllIDsPresent;
77  else if (ls == 1)
78  return Xpetra::IDNotPresent;
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 
84  if (os == Xpetra::DoOptimizeStorage)
85  return true;
87  return false;
88 
89  TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::RuntimeError, "Unknown OptimizeOption");
90 }
91 
92 Epetra_CombineMode toEpetra(Xpetra::CombineMode cm) {
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
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.
Exception throws to report errors in the internal logical of the program.
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
CombineMode
Xpetra::Combine Mode enumerable type.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal, Node > > &graph)
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)