Belos  Version of the Day
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 
44 namespace Belos {
45 
46  namespace {
47  const char*
48  convertStatusTypeToRawString (const StatusType status)
49  {
50  if (status == Passed) {
51  return "Passed";
52  } else if (status == Failed) {
53  return "Failed";
54  } else if (status == Undefined) {
55  return "Undefined";
56  } else {
57  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
58  "Belos::convertStatusTypeToRawString: Invalid StatusType enum value "
59  << status << ".");
60  }
61  }
62  } // namespace (anonymous)
63 
64  std::string
66  {
67  return convertStatusTypeToRawString (status);
68  }
69 
71  convertStringToStatusType (const std::string& status)
72  {
73  if (status == "Passed") {
74  return Passed;
75  } else if (status == "Failed") {
76  return Failed;
77  } else if (status == "Undefined") {
78  return Undefined;
79  } else {
80  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
81  "Belos::convertStringToStatusType: Invalid string \"" << status
82  << "\".");
83  }
84  }
85 
86  ScaleType
87  convertStringToScaleType (const std::string& scaleType)
88  {
89  if (scaleType == "Norm of Initial Residual") {
90  return Belos::NormOfInitRes;
91  } else if (scaleType == "Norm of Preconditioned Initial Residual") {
93  } else if (scaleType == "Norm of RHS") {
94  return Belos::NormOfRHS;
95  } else if (scaleType == "None") {
96  return Belos::None;
97  } else if (scaleType == "User Provided") {
98  return Belos::UserProvided;
99  } else {
100  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
101  "Belos::convertStringToScaleType(): Invalid residual scaling type \""
102  << scaleType << "\".");
103  }
104  }
105 
106  std::string
108  {
109  if (scaleType == Belos::NormOfInitRes) {
110  return "Norm of Initial Residual";
111  } else if (scaleType == Belos::NormOfPrecInitRes) {
112  return "Norm of Preconditioned Initial Residual";
113  } else if (scaleType == Belos::NormOfRHS) {
114  return "Norm of RHS";
115  } else if (scaleType == Belos::None) {
116  return "None";
117  } else if (scaleType == Belos::UserProvided) {
118  return "User Provided";
119  } else {
120  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
121  "Belos::convertScaleTypeToString(): Invalid residual scaling type "
122  "value " << scaleType << ".");
123  }
124  }
125 
126  std::string
128  {
129  typedef std::vector<int>::size_type size_type;
130 
131  // Wouldn't it be nice if C++ enums had introspection and could
132  // be enumerated?
133  const size_type numValidTypes = 8;
134  const int validTypes[] = {
143  };
144  const char* typeNames[] = {
145  "Errors",
146  "Warnings",
147  "IterationDetails",
148  "OrthoDetails",
149  "FinalSummary",
150  "TimingDetails",
151  "StatusTestDetails",
152  "Debug"
153  };
154 
155  // We first generate a list, and only then build a single string.
156  // This helps us decide where to put the commas. The list just
157  // uses the indices of the valid names, rather than the valid
158  // names themselves, in order to save space and time. We use
159  // size_type for the indices to avoid signed/unsigned comparisons.
160  std::vector<size_type> theList;
161  for (size_type nameIndex = 0; nameIndex < numValidTypes; ++nameIndex) {
162  if (msgType & validTypes[nameIndex]) {
163  theList.push_back (nameIndex);
164  }
165  }
166  std::ostringstream os;
167  for (size_type k = 0; k < theList.size(); ++k) {
168  const size_type nameIndex = theList[k];
169  os << typeNames[nameIndex];
170  if (nameIndex < theList.size() - 1) {
171  os << ",";
172  }
173  }
174  return os.str();
175  }
176 
177  std::string
179  {
180  if (result == Belos::Converged) {
181  return "Converged";
182  } else if (result == Belos::Unconverged) {
183  return "Unconverged";
184  } else {
185  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
186  "Belos::convertReturnTypeToString: Invalid ReturnType enum value "
187  << result << ".");
188  }
189  }
190 
191 } // end Belos namespace
192 
ScaleType convertStringToScaleType(const std::string &scaleType)
Convert the given string to its ScaleType enum value.
Definition: BelosTypes.cpp:87
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:119
MsgType
Available message types recognized by the linear solvers.
Definition: BelosTypes.hpp:252
StatusType
Whether the StatusTest wants iteration to stop.
Definition: BelosTypes.hpp:183
std::string convertStatusTypeToString(const StatusType status)
The string name corresponding to the given StatusType enum value.
Definition: BelosTypes.cpp:65
std::string convertScaleTypeToString(const ScaleType scaleType)
Convert the given ScaleType enum value to its corresponding string.
Definition: BelosTypes.cpp:107
std::string convertMsgTypeToString(const MsgType msgType)
Show MsgType as a comma-delimited list of names.
Definition: BelosTypes.cpp:127
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:149
std::string convertReturnTypeToString(const ReturnType result)
Convert the given ReturnType enum value to its corresponding string.
Definition: BelosTypes.cpp:178
StatusType convertStringToStatusType(const std::string &status)
The StatusType enum value corresponding to the given string name.
Definition: BelosTypes.cpp:71

Generated on Thu Jul 21 2016 14:43:57 for Belos by doxygen 1.8.11