Belos Version of the Day
Loading...
Searching...
No Matches
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
13namespace 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
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
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
75 {
76 if (scaleType == "Norm of Initial Residual") {
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") {
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 {
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) {
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];
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;
185 const double DefaultSolverParameters::impTolScale = 10.0;
186
187} // end Belos namespace
188
Collection of types and exceptions used within the Belos solvers.
Alternative run-time polymorphic interface for operators.
std::string convertMsgTypeToString(const MsgType msgType)
Show MsgType as a comma-delimited list of names.
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
NormType
The type of vector norm to compute.
@ PreconditionerNorm
MsgType
Available message types recognized by the linear solvers.
@ OrthoDetails
@ StatusTestDetails
@ FinalSummary
@ TimingDetails
@ IterationDetails
StatusType
Whether the StatusTest wants iteration to stop.
NormType convertStringToNormType(const std::string &normType)
Convert the given string to its NormType enum value.
ReturnType
Whether the Belos solve converged for all linear systems.
@ Unconverged
std::string convertScaleTypeToString(const ScaleType scaleType)
Convert the given ScaleType enum value to its corresponding string.
std::string convertStatusTypeToString(const StatusType status)
The string name corresponding to the given StatusType enum value.
ScaleType
The type of scaling to use on the residual norm value.
@ UserProvided
@ NormOfPrecInitRes
@ NormOfInitRes
@ NormOfRHS
std::string convertReturnTypeToString(const ReturnType result)
Convert the given ReturnType enum value to its corresponding string.
StatusType convertStringToStatusType(const std::string &status)
The StatusType enum value corresponding to the given string name.
static const double resScaleFactor
User-defined residual scaling factor.
static const double impTolScale
"Implicit Tolerance Scale Factor"
static const double convTol
Default convergence tolerance.
static const double orthoKappa
DGKS orthogonalization constant.
static const double polyTol
Relative residual tolerance for matrix polynomial construction.

Generated for Belos by doxygen 1.9.8