|
Belos
Version of the Day
|
00001 //@HEADER 00002 // ************************************************************************ 00003 // 00004 // Belos: Block Linear Solvers Package 00005 // Copyright 2004 Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // ************************************************************************ 00040 //@HEADER 00041 00042 #include <BelosTypes.hpp> 00043 00044 namespace Belos { 00045 00046 namespace { 00047 const char* 00048 convertStatusTypeToRawString (const StatusType status) 00049 { 00050 if (status == Passed) { 00051 return "Passed"; 00052 } else if (status == Failed) { 00053 return "Failed"; 00054 } else if (status == Undefined) { 00055 return "Undefined"; 00056 } else { 00057 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, 00058 "Belos::convertStatusTypeToRawString: Invalid StatusType enum value " 00059 << status << "."); 00060 } 00061 } 00062 } // namespace (anonymous) 00063 00064 const char* TEUCHOS_DEPRECATED 00065 toString (const StatusType status) 00066 { 00067 return convertStatusTypeToRawString (status); 00068 } 00069 00070 std::string 00071 convertStatusTypeToString (const StatusType status) 00072 { 00073 return convertStatusTypeToRawString (status); 00074 } 00075 00076 StatusType 00077 convertStringToStatusType (const std::string& status) 00078 { 00079 if (status == "Passed") { 00080 return Passed; 00081 } else if (status == "Failed") { 00082 return Failed; 00083 } else if (status == "Undefined") { 00084 return Undefined; 00085 } else { 00086 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, 00087 "Belos::convertStringToStatusType: Invalid string \"" << status 00088 << "\"."); 00089 } 00090 } 00091 00092 ScaleType 00093 convertStringToScaleType (const std::string& scaleType) 00094 { 00095 if (scaleType == "Norm of Initial Residual") { 00096 return Belos::NormOfInitRes; 00097 } else if (scaleType == "Norm of Preconditioned Initial Residual") { 00098 return Belos::NormOfPrecInitRes; 00099 } else if (scaleType == "Norm of RHS") { 00100 return Belos::NormOfRHS; 00101 } else if (scaleType == "None") { 00102 return Belos::None; 00103 } else { 00104 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, 00105 "Belos::convertStringToScaleType(): Invalid residual scaling type \"" 00106 << scaleType << "\"."); 00107 } 00108 } 00109 00110 std::string 00111 convertScaleTypeToString (const ScaleType scaleType) 00112 { 00113 if (scaleType == Belos::NormOfInitRes) { 00114 return "Norm of Initial Residual"; 00115 } else if (scaleType == Belos::NormOfPrecInitRes) { 00116 return "Norm of Preconditioned Initial Residual"; 00117 } else if (scaleType == Belos::NormOfRHS) { 00118 return "Norm of RHS"; 00119 } else if (scaleType == Belos::None) { 00120 return "None"; 00121 } else { 00122 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error, 00123 "Belos::convertScaleTypeToString(): Invalid residual scaling type " 00124 "value " << scaleType << "."); 00125 } 00126 } 00127 00128 std::string 00129 convertMsgTypeToString (const MsgType msgType) 00130 { 00131 typedef std::vector<int>::size_type size_type; 00132 00133 // Wouldn't it be nice if C++ enums had introspection and could 00134 // be enumerated? 00135 const size_type numValidTypes = 8; 00136 const int validTypes[] = { 00137 Belos::Errors, 00138 Belos::Warnings, 00139 Belos::IterationDetails, 00140 Belos::OrthoDetails, 00141 Belos::FinalSummary, 00142 Belos::TimingDetails, 00143 Belos::StatusTestDetails, 00144 Belos::Debug 00145 }; 00146 const char* typeNames[] = { 00147 "Errors", 00148 "Warnings", 00149 "IterationDetails", 00150 "OrthoDetails", 00151 "FinalSummary", 00152 "TimingDetails", 00153 "StatusTestDetails", 00154 "Debug" 00155 }; 00156 00157 // We first generate a list, and only then build a single string. 00158 // This helps us decide where to put the commas. The list just 00159 // uses the indices of the valid names, rather than the valid 00160 // names themselves, in order to save space and time. We use 00161 // size_type for the indices to avoid signed/unsigned comparisons. 00162 std::vector<size_type> theList; 00163 for (size_type nameIndex = 0; nameIndex < numValidTypes; ++nameIndex) { 00164 if (msgType & validTypes[nameIndex]) { 00165 theList.push_back (nameIndex); 00166 } 00167 } 00168 std::ostringstream os; 00169 for (size_type k = 0; k < theList.size(); ++k) { 00170 const size_type nameIndex = theList[k]; 00171 os << typeNames[nameIndex]; 00172 if (nameIndex < theList.size() - 1) { 00173 os << ","; 00174 } 00175 } 00176 return os.str(); 00177 } 00178 00179 std::string 00180 convertReturnTypeToString (const ReturnType result) 00181 { 00182 if (result == Belos::Converged) { 00183 return "Converged"; 00184 } else if (result == Belos::Unconverged) { 00185 return "Unconverged"; 00186 } else { 00187 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, 00188 "Belos::convertReturnTypeToString: Invalid ReturnType enum value " 00189 << result << "."); 00190 } 00191 } 00192 00193 } // end Belos namespace 00194
1.7.6.1