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 if (result == Belos::MaxItersReached) {
172 return "MaxItersReached";
173 } else if (result == Belos::MaxRestartsReached) {
174 return "MaxRestartsReached";
175 } else if (result == Belos::OrthonormFailure) {
176 return "OrthonormFailure";
177 } else if (result == Belos::NaNDetected) {
178 return "NaNDetected";
179 } else if (result == Belos::BreakdownDetected) {
180 return "BreakdownDetected";
181 } else if (result == Belos::LossOfAccuracyDetected) {
182 return "LossOfAccuracyDetected";
183 } else if (result == Belos::NonspecificException) {
184 return "NonspecificException";
185 } else if (result == Belos::InconsistentState) {
186 return "InconsistentState";
187 } else if (result == Belos::Undetermined) {
188 return "Undetermined";
189 } else {
190 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
191 "Belos::convertReturnTypeToString: Invalid ReturnType enum value "
192 << result << ".");
193 }
194 }
195
196 // Initialize DefaultSolverParameters. Has to be done this way because
197 // the "static consexpr double blah = ...;" pattern can create ODR-used
198 // linking errors (usually in debug builds).
199 const double DefaultSolverParameters::convTol = 1.0e-8;
200 const double DefaultSolverParameters::polyTol = 1.0e-12;
201 const double DefaultSolverParameters::orthoKappa = -1.0;
203 const double DefaultSolverParameters::impTolScale = 10.0;
204
205} // end Belos namespace
206
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
ReturnType
Whether the Belos solve converged for all linear systems.
@ NaNDetected
@ Unconverged
@ MaxItersReached
@ NonspecificException
@ MaxRestartsReached
@ LossOfAccuracyDetected
@ InconsistentState
@ BreakdownDetected
@ OrthonormFailure
@ Undetermined
StatusType
Whether the StatusTest wants iteration to stop.
NormType convertStringToNormType(const std::string &normType)
Convert the given string to its NormType enum value.
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