Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BelosTypes.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Belos: Block Linear Solvers Package
4 //
5 // Copyright 2004-2016 NTESS and the Belos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include <BelosTypes.hpp>
11 #include <vector>
12 
13 namespace Belos {
14 
15  namespace {
16  const char*
17  convertStatusTypeToRawString (const StatusType status)
18  {
19  if (status == Passed) {
20  return "Passed";
21  } else if (status == Failed) {
22  return "Failed";
23  } else if (status == Undefined) {
24  return "Undefined";
25  } else {
26  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
27  "Belos::convertStatusTypeToRawString: Invalid StatusType enum value "
28  << status << ".");
29  }
30  }
31  } // namespace (anonymous)
32 
33  std::string
35  {
36  return convertStatusTypeToRawString (status);
37  }
38 
40  convertStringToStatusType (const std::string& status)
41  {
42  if (status == "Passed") {
43  return Passed;
44  } else if (status == "Failed") {
45  return Failed;
46  } else if (status == "Undefined") {
47  return Undefined;
48  } else {
49  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
50  "Belos::convertStringToStatusType: Invalid string \"" << status
51  << "\".");
52  }
53  }
54 
55  NormType
56  convertStringToNormType (const std::string& normType)
57  {
58  if (normType == "OneNorm") {
59  return Belos::OneNorm;
60  } else if (normType == "TwoNorm") {
61  return Belos::TwoNorm;
62  } else if (normType == "InfNorm") {
63  return Belos::InfNorm;
64  } else if (normType == "PreconditionerNorm") {
66  } else {
67  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
68  "Belos::convertStringToNormType(): Invalid norm type \""
69  << normType << "\".");
70  }
71  }
72 
73  ScaleType
74  convertStringToScaleType (const std::string& scaleType)
75  {
76  if (scaleType == "Norm of Initial Residual") {
77  return Belos::NormOfInitRes;
78  } else if (scaleType == "Norm of Preconditioned Initial Residual") {
80  } else if (scaleType == "Norm of RHS") {
81  return Belos::NormOfRHS;
82  } else if (scaleType == "None") {
83  return Belos::None;
84  } else if (scaleType == "User Provided") {
85  return Belos::UserProvided;
86  } else {
87  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
88  "Belos::convertStringToScaleType(): Invalid residual scaling type \""
89  << scaleType << "\".");
90  }
91  }
92 
93  std::string
95  {
96  if (scaleType == Belos::NormOfInitRes) {
97  return "Norm of Initial Residual";
98  } else if (scaleType == Belos::NormOfPrecInitRes) {
99  return "Norm of Preconditioned Initial Residual";
100  } else if (scaleType == Belos::NormOfRHS) {
101  return "Norm of RHS";
102  } else if (scaleType == Belos::None) {
103  return "None";
104  } else if (scaleType == Belos::UserProvided) {
105  return "User Provided";
106  } else {
107  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
108  "Belos::convertScaleTypeToString(): Invalid residual scaling type "
109  "value " << scaleType << ".");
110  }
111  }
112 
113  std::string
115  {
116  typedef std::vector<int>::size_type size_type;
117 
118  // Wouldn't it be nice if C++ enums had introspection and could
119  // be enumerated?
120  const size_type numValidTypes = 8;
121  const int validTypes[] = {
130  };
131  const char* typeNames[] = {
132  "Errors",
133  "Warnings",
134  "IterationDetails",
135  "OrthoDetails",
136  "FinalSummary",
137  "TimingDetails",
138  "StatusTestDetails",
139  "Debug"
140  };
141 
142  // We first generate a list, and only then build a single string.
143  // This helps us decide where to put the commas. The list just
144  // uses the indices of the valid names, rather than the valid
145  // names themselves, in order to save space and time. We use
146  // size_type for the indices to avoid signed/unsigned comparisons.
147  std::vector<size_type> theList;
148  for (size_type nameIndex = 0; nameIndex < numValidTypes; ++nameIndex) {
149  if (msgType & validTypes[nameIndex]) {
150  theList.push_back (nameIndex);
151  }
152  }
153  std::ostringstream os;
154  for (size_type k = 0; k < theList.size(); ++k) {
155  const size_type nameIndex = theList[k];
156  os << typeNames[nameIndex];
157  if (nameIndex < theList.size() - 1) {
158  os << ",";
159  }
160  }
161  return os.str();
162  }
163 
164  std::string
166  {
167  if (result == Belos::Converged) {
168  return "Converged";
169  } else if (result == Belos::Unconverged) {
170  return "Unconverged";
171  } else {
172  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
173  "Belos::convertReturnTypeToString: Invalid ReturnType enum value "
174  << result << ".");
175  }
176  }
177 
178  // Initialize DefaultSolverParameters. Has to be done this way because
179  // the "static consexpr double blah = ...;" pattern can create ODR-used
180  // linking errors (usually in debug builds).
181  const double DefaultSolverParameters::convTol = 1.0e-8;
182  const double DefaultSolverParameters::polyTol = 1.0e-12;
183  const double DefaultSolverParameters::orthoKappa = -1.0;
184  const double DefaultSolverParameters::resScaleFactor = 1.0;
185  const double DefaultSolverParameters::impTolScale = 10.0;
186 
187 } // end Belos namespace
188 
static const double orthoKappa
DGKS orthogonalization constant.
Definition: BelosTypes.hpp:267
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:74
Collection of types and exceptions used within the Belos solvers.
ScaleType
The type of scaling to use on the residual norm value.
Definition: BelosTypes.hpp:88
MsgType
Available message types recognized by the linear solvers.
Definition: BelosTypes.hpp:222
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static const double convTol
Default convergence tolerance.
Definition: BelosTypes.hpp:261
static const double polyTol
Relative residual tolerance for matrix polynomial construction.
Definition: BelosTypes.hpp:264
StatusType
Whether the StatusTest wants iteration to stop.
Definition: BelosTypes.hpp:157
std::string convertStatusTypeToString(const StatusType status)
The string name corresponding to the given StatusType enum value.
Definition: BelosTypes.cpp:34
std::string convertScaleTypeToString(const ScaleType scaleType)
Convert the given ScaleType enum value to its corresponding string.
Definition: BelosTypes.cpp:94
static const double impTolScale
&quot;Implicit Tolerance Scale Factor&quot;
Definition: BelosTypes.hpp:273
NormType convertStringToNormType(const std::string &normType)
Convert the given string to its NormType enum value.
Definition: BelosTypes.cpp:56
std::string convertMsgTypeToString(const MsgType msgType)
Show MsgType as a comma-delimited list of names.
Definition: BelosTypes.cpp:114
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:123
NormType
The type of vector norm to compute.
Definition: BelosTypes.hpp:65
std::string convertReturnTypeToString(const ReturnType result)
Convert the given ReturnType enum value to its corresponding string.
Definition: BelosTypes.cpp:165
StatusType convertStringToStatusType(const std::string &status)
The StatusType enum value corresponding to the given string name.
Definition: BelosTypes.cpp:40
static const double resScaleFactor
User-defined residual scaling factor.
Definition: BelosTypes.hpp:270

Generated on Fri Dec 20 2024 09:24:49 for Belos by doxygen 1.8.5