Belos
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
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
34
convertStatusTypeToString
(
const
StatusType
status)
35
{
36
return
convertStatusTypeToRawString (status);
37
}
38
39
StatusType
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"
) {
65
return
Belos::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"
) {
79
return
Belos::NormOfPrecInitRes
;
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
94
convertScaleTypeToString
(
const
ScaleType
scaleType)
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
114
convertMsgTypeToString
(
const
MsgType
msgType)
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[] = {
122
Belos::Errors
,
123
Belos::Warnings
,
124
Belos::IterationDetails
,
125
Belos::OrthoDetails
,
126
Belos::FinalSummary
,
127
Belos::TimingDetails
,
128
Belos::StatusTestDetails
,
129
Belos::Debug
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
165
convertReturnTypeToString
(
const
ReturnType
result)
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
BelosTypes.hpp
Collection of types and exceptions used within the Belos solvers.
Belos
Definition
Belos_Details_EBelosSolverType.cpp:13
Belos::convertMsgTypeToString
std::string convertMsgTypeToString(const MsgType msgType)
Show MsgType as a comma-delimited list of names.
Definition
BelosTypes.cpp:114
Belos::convertStringToScaleType
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition
BelosTypes.cpp:74
Belos::NormType
NormType
The type of vector norm to compute.
Definition
BelosTypes.hpp:65
Belos::InfNorm
@ InfNorm
Definition
BelosTypes.hpp:67
Belos::OneNorm
@ OneNorm
Definition
BelosTypes.hpp:65
Belos::PreconditionerNorm
@ PreconditionerNorm
Definition
BelosTypes.hpp:68
Belos::TwoNorm
@ TwoNorm
Definition
BelosTypes.hpp:66
Belos::MsgType
MsgType
Available message types recognized by the linear solvers.
Definition
BelosTypes.hpp:222
Belos::OrthoDetails
@ OrthoDetails
Definition
BelosTypes.hpp:226
Belos::StatusTestDetails
@ StatusTestDetails
Definition
BelosTypes.hpp:229
Belos::FinalSummary
@ FinalSummary
Definition
BelosTypes.hpp:227
Belos::TimingDetails
@ TimingDetails
Definition
BelosTypes.hpp:228
Belos::Errors
@ Errors
Definition
BelosTypes.hpp:223
Belos::IterationDetails
@ IterationDetails
Definition
BelosTypes.hpp:225
Belos::Warnings
@ Warnings
Definition
BelosTypes.hpp:224
Belos::Debug
@ Debug
Definition
BelosTypes.hpp:230
Belos::StatusType
StatusType
Whether the StatusTest wants iteration to stop.
Definition
BelosTypes.hpp:157
Belos::Failed
@ Failed
Definition
BelosTypes.hpp:158
Belos::Undefined
@ Undefined
Definition
BelosTypes.hpp:159
Belos::Passed
@ Passed
Definition
BelosTypes.hpp:157
Belos::convertStringToNormType
NormType convertStringToNormType(const std::string &normType)
Convert the given string to its NormType enum value.
Definition
BelosTypes.cpp:56
Belos::ReturnType
ReturnType
Whether the Belos solve converged for all linear systems.
Definition
BelosTypes.hpp:123
Belos::Unconverged
@ Unconverged
Definition
BelosTypes.hpp:125
Belos::Converged
@ Converged
Definition
BelosTypes.hpp:124
Belos::convertScaleTypeToString
std::string convertScaleTypeToString(const ScaleType scaleType)
Convert the given ScaleType enum value to its corresponding string.
Definition
BelosTypes.cpp:94
Belos::convertStatusTypeToString
std::string convertStatusTypeToString(const StatusType status)
The string name corresponding to the given StatusType enum value.
Definition
BelosTypes.cpp:34
Belos::ScaleType
ScaleType
The type of scaling to use on the residual norm value.
Definition
BelosTypes.hpp:88
Belos::UserProvided
@ UserProvided
Definition
BelosTypes.hpp:92
Belos::None
@ None
Definition
BelosTypes.hpp:91
Belos::NormOfPrecInitRes
@ NormOfPrecInitRes
Definition
BelosTypes.hpp:90
Belos::NormOfInitRes
@ NormOfInitRes
Definition
BelosTypes.hpp:89
Belos::NormOfRHS
@ NormOfRHS
Definition
BelosTypes.hpp:88
Belos::convertReturnTypeToString
std::string convertReturnTypeToString(const ReturnType result)
Convert the given ReturnType enum value to its corresponding string.
Definition
BelosTypes.cpp:165
Belos::convertStringToStatusType
StatusType convertStringToStatusType(const std::string &status)
The StatusType enum value corresponding to the given string name.
Definition
BelosTypes.cpp:40
Belos::DefaultSolverParameters::resScaleFactor
static const double resScaleFactor
User-defined residual scaling factor.
Definition
BelosTypes.hpp:270
Belos::DefaultSolverParameters::impTolScale
static const double impTolScale
"Implicit Tolerance Scale Factor"
Definition
BelosTypes.hpp:273
Belos::DefaultSolverParameters::convTol
static const double convTol
Default convergence tolerance.
Definition
BelosTypes.hpp:261
Belos::DefaultSolverParameters::orthoKappa
static const double orthoKappa
DGKS orthogonalization constant.
Definition
BelosTypes.hpp:267
Belos::DefaultSolverParameters::polyTol
static const double polyTol
Relative residual tolerance for matrix polynomial construction.
Definition
BelosTypes.hpp:264
Generated for Belos by
1.17.0