Belos Package Browser (Single Doxygen Collection)
Development
Toggle main menu visibility
Loading...
Searching...
No Matches
src
BelosTypes.cpp
Go to the documentation of this file.
1
//@HEADER
2
// ************************************************************************
3
//
4
// Belos: Block Linear Solvers Package
5
// Copyright 2004 Sandia Corporation
6
//
7
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8
// the U.S. Government retains certain rights in this software.
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are
12
// met:
13
//
14
// 1. Redistributions of source code must retain the above copyright
15
// notice, this list of conditions and the following disclaimer.
16
//
17
// 2. Redistributions in binary form must reproduce the above copyright
18
// notice, this list of conditions and the following disclaimer in the
19
// documentation and/or other materials provided with the distribution.
20
//
21
// 3. Neither the name of the Corporation nor the names of the
22
// contributors may be used to endorse or promote products derived from
23
// this software without specific prior written permission.
24
//
25
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38
//
39
// ************************************************************************
40
//@HEADER
41
42
#include <
BelosTypes.hpp
>
43
#include <vector>
44
45
namespace
Belos
{
46
47
namespace
{
48
const
char
*
49
convertStatusTypeToRawString (
const
StatusType
status)
50
{
51
if
(status ==
Passed
) {
52
return
"Passed"
;
53
}
else
if
(status ==
Failed
) {
54
return
"Failed"
;
55
}
else
if
(status ==
Undefined
) {
56
return
"Undefined"
;
57
}
else
{
58
TEUCHOS_TEST_FOR_EXCEPTION(
true
, std::logic_error,
59
"Belos::convertStatusTypeToRawString: Invalid StatusType enum value "
60
<< status <<
"."
);
61
}
62
}
63
}
// namespace (anonymous)
64
65
std::string
66
convertStatusTypeToString
(
const
StatusType
status)
67
{
68
return
convertStatusTypeToRawString (status);
69
}
70
71
StatusType
72
convertStringToStatusType
(
const
std::string& status)
73
{
74
if
(status ==
"Passed"
) {
75
return
Passed
;
76
}
else
if
(status ==
"Failed"
) {
77
return
Failed
;
78
}
else
if
(status ==
"Undefined"
) {
79
return
Undefined
;
80
}
else
{
81
TEUCHOS_TEST_FOR_EXCEPTION(
true
, std::logic_error,
82
"Belos::convertStringToStatusType: Invalid string \""
<< status
83
<<
"\"."
);
84
}
85
}
86
87
NormType
88
convertStringToNormType
(
const
std::string& normType)
89
{
90
if
(normType ==
"OneNorm"
) {
91
return
Belos::OneNorm
;
92
}
else
if
(normType ==
"TwoNorm"
) {
93
return
Belos::TwoNorm
;
94
}
else
if
(normType ==
"InfNorm"
) {
95
return
Belos::InfNorm
;
96
}
else
if
(normType ==
"PreconditionerNorm"
) {
97
return
Belos::PreconditionerNorm
;
98
}
else
{
99
TEUCHOS_TEST_FOR_EXCEPTION(
true
, std::logic_error,
100
"Belos::convertStringToNormType(): Invalid norm type \""
101
<< normType <<
"\"."
);
102
}
103
}
104
105
ScaleType
106
convertStringToScaleType
(
const
std::string& scaleType)
107
{
108
if
(scaleType ==
"Norm of Initial Residual"
) {
109
return
Belos::NormOfInitRes
;
110
}
else
if
(scaleType ==
"Norm of Preconditioned Initial Residual"
) {
111
return
Belos::NormOfPrecInitRes
;
112
}
else
if
(scaleType ==
"Norm of RHS"
) {
113
return
Belos::NormOfRHS
;
114
}
else
if
(scaleType ==
"None"
) {
115
return
Belos::None
;
116
}
else
if
(scaleType ==
"User Provided"
) {
117
return
Belos::UserProvided
;
118
}
else
{
119
TEUCHOS_TEST_FOR_EXCEPTION(
true
, std::logic_error,
120
"Belos::convertStringToScaleType(): Invalid residual scaling type \""
121
<< scaleType <<
"\"."
);
122
}
123
}
124
125
std::string
126
convertScaleTypeToString
(
const
ScaleType
scaleType)
127
{
128
if
(scaleType ==
Belos::NormOfInitRes
) {
129
return
"Norm of Initial Residual"
;
130
}
else
if
(scaleType ==
Belos::NormOfPrecInitRes
) {
131
return
"Norm of Preconditioned Initial Residual"
;
132
}
else
if
(scaleType ==
Belos::NormOfRHS
) {
133
return
"Norm of RHS"
;
134
}
else
if
(scaleType ==
Belos::None
) {
135
return
"None"
;
136
}
else
if
(scaleType ==
Belos::UserProvided
) {
137
return
"User Provided"
;
138
}
else
{
139
TEUCHOS_TEST_FOR_EXCEPTION(
true
, std::logic_error,
140
"Belos::convertScaleTypeToString(): Invalid residual scaling type "
141
"value "
<< scaleType <<
"."
);
142
}
143
}
144
145
std::string
146
convertMsgTypeToString
(
const
MsgType
msgType)
147
{
148
typedef
std::vector<int>::size_type size_type;
149
150
// Wouldn't it be nice if C++ enums had introspection and could
151
// be enumerated?
152
const
size_type numValidTypes = 8;
153
const
int
validTypes[] = {
154
Belos::Errors
,
155
Belos::Warnings
,
156
Belos::IterationDetails
,
157
Belos::OrthoDetails
,
158
Belos::FinalSummary
,
159
Belos::TimingDetails
,
160
Belos::StatusTestDetails
,
161
Belos::Debug
162
};
163
const
char
* typeNames[] = {
164
"Errors"
,
165
"Warnings"
,
166
"IterationDetails"
,
167
"OrthoDetails"
,
168
"FinalSummary"
,
169
"TimingDetails"
,
170
"StatusTestDetails"
,
171
"Debug"
172
};
173
174
// We first generate a list, and only then build a single string.
175
// This helps us decide where to put the commas. The list just
176
// uses the indices of the valid names, rather than the valid
177
// names themselves, in order to save space and time. We use
178
// size_type for the indices to avoid signed/unsigned comparisons.
179
std::vector<size_type> theList;
180
for
(size_type nameIndex = 0; nameIndex < numValidTypes; ++nameIndex) {
181
if
(msgType & validTypes[nameIndex]) {
182
theList.push_back (nameIndex);
183
}
184
}
185
std::ostringstream os;
186
for
(size_type k = 0; k < theList.size(); ++k) {
187
const
size_type nameIndex = theList[k];
188
os << typeNames[nameIndex];
189
if
(nameIndex < theList.size() - 1) {
190
os <<
","
;
191
}
192
}
193
return
os.str();
194
}
195
196
std::string
197
convertReturnTypeToString
(
const
ReturnType
result)
198
{
199
if
(result ==
Belos::Converged
) {
200
return
"Converged"
;
201
}
else
if
(result ==
Belos::Unconverged
) {
202
return
"Unconverged"
;
203
}
else
{
204
TEUCHOS_TEST_FOR_EXCEPTION(
true
, std::logic_error,
205
"Belos::convertReturnTypeToString: Invalid ReturnType enum value "
206
<< result <<
"."
);
207
}
208
}
209
210
// Initialize DefaultSolverParameters. Has to be done this way because
211
// the "static consexpr double blah = ...;" pattern can create ODR-used
212
// linking errors (usually in debug builds).
213
const
double
DefaultSolverParameters::convTol
= 1.0e-8;
214
const
double
DefaultSolverParameters::polyTol
= 1.0e-12;
215
const
double
DefaultSolverParameters::orthoKappa
= -1.0;
216
const
double
DefaultSolverParameters::resScaleFactor
= 1.0;
217
const
double
DefaultSolverParameters::impTolScale
= 10.0;
218
219
}
// end Belos namespace
220
BelosTypes.hpp
Collection of types and exceptions used within the Belos solvers.
Belos
Definition
Belos_Details_EBelosSolverType.cpp:45
Belos::convertMsgTypeToString
std::string convertMsgTypeToString(const MsgType msgType)
Show MsgType as a comma-delimited list of names.
Definition
BelosTypes.cpp:146
Belos::convertStringToScaleType
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition
BelosTypes.cpp:106
Belos::NormType
NormType
The type of vector norm to compute.
Definition
BelosTypes.hpp:97
Belos::InfNorm
@ InfNorm
Definition
BelosTypes.hpp:99
Belos::OneNorm
@ OneNorm
Definition
BelosTypes.hpp:97
Belos::PreconditionerNorm
@ PreconditionerNorm
Definition
BelosTypes.hpp:100
Belos::TwoNorm
@ TwoNorm
Definition
BelosTypes.hpp:98
Belos::MsgType
MsgType
Available message types recognized by the linear solvers.
Definition
BelosTypes.hpp:254
Belos::OrthoDetails
@ OrthoDetails
Definition
BelosTypes.hpp:258
Belos::StatusTestDetails
@ StatusTestDetails
Definition
BelosTypes.hpp:261
Belos::FinalSummary
@ FinalSummary
Definition
BelosTypes.hpp:259
Belos::TimingDetails
@ TimingDetails
Definition
BelosTypes.hpp:260
Belos::Errors
@ Errors
Definition
BelosTypes.hpp:255
Belos::IterationDetails
@ IterationDetails
Definition
BelosTypes.hpp:257
Belos::Warnings
@ Warnings
Definition
BelosTypes.hpp:256
Belos::Debug
@ Debug
Definition
BelosTypes.hpp:262
Belos::StatusType
StatusType
Whether the StatusTest wants iteration to stop.
Definition
BelosTypes.hpp:189
Belos::Failed
@ Failed
Definition
BelosTypes.hpp:190
Belos::Undefined
@ Undefined
Definition
BelosTypes.hpp:191
Belos::Passed
@ Passed
Definition
BelosTypes.hpp:189
Belos::convertStringToNormType
NormType convertStringToNormType(const std::string &normType)
Convert the given string to its NormType enum value.
Definition
BelosTypes.cpp:88
Belos::ReturnType
ReturnType
Whether the Belos solve converged for all linear systems.
Definition
BelosTypes.hpp:155
Belos::Unconverged
@ Unconverged
Definition
BelosTypes.hpp:157
Belos::Converged
@ Converged
Definition
BelosTypes.hpp:156
Belos::convertScaleTypeToString
std::string convertScaleTypeToString(const ScaleType scaleType)
Convert the given ScaleType enum value to its corresponding string.
Definition
BelosTypes.cpp:126
Belos::convertStatusTypeToString
std::string convertStatusTypeToString(const StatusType status)
The string name corresponding to the given StatusType enum value.
Definition
BelosTypes.cpp:66
Belos::ScaleType
ScaleType
The type of scaling to use on the residual norm value.
Definition
BelosTypes.hpp:120
Belos::UserProvided
@ UserProvided
Definition
BelosTypes.hpp:124
Belos::None
@ None
Definition
BelosTypes.hpp:123
Belos::NormOfPrecInitRes
@ NormOfPrecInitRes
Definition
BelosTypes.hpp:122
Belos::NormOfInitRes
@ NormOfInitRes
Definition
BelosTypes.hpp:121
Belos::NormOfRHS
@ NormOfRHS
Definition
BelosTypes.hpp:120
Belos::convertReturnTypeToString
std::string convertReturnTypeToString(const ReturnType result)
Convert the given ReturnType enum value to its corresponding string.
Definition
BelosTypes.cpp:197
Belos::convertStringToStatusType
StatusType convertStringToStatusType(const std::string &status)
The StatusType enum value corresponding to the given string name.
Definition
BelosTypes.cpp:72
Belos::DefaultSolverParameters::resScaleFactor
static const double resScaleFactor
User-defined residual scaling factor.
Definition
BelosTypes.hpp:302
Belos::DefaultSolverParameters::impTolScale
static const double impTolScale
"Implicit Tolerance Scale Factor"
Definition
BelosTypes.hpp:305
Belos::DefaultSolverParameters::convTol
static const double convTol
Default convergence tolerance.
Definition
BelosTypes.hpp:293
Belos::DefaultSolverParameters::orthoKappa
static const double orthoKappa
DGKS orthogonalization constant.
Definition
BelosTypes.hpp:299
Belos::DefaultSolverParameters::polyTol
static const double polyTol
Relative residual tolerance for matrix polynomial construction.
Definition
BelosTypes.hpp:296
Generated by
1.17.0