Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "SundanceDefs.hpp"
00034 #include "NOX_StatusTest_SafeCombo.H"
00035 #include "NOX_Utils.H"
00036
00037 NOX::StatusTest::SafeCombo::SafeCombo(ComboType t) :
00038 type(t)
00039 {
00040 status = Unevaluated;
00041 }
00042
00043 NOX::StatusTest::SafeCombo::SafeCombo(ComboType t,
00044 const Teuchos::RCP<Generic>& a) :
00045 type(t)
00046 {
00047 tests.push_back(a);
00048 status = Unevaluated;
00049 }
00050
00051 NOX::StatusTest::SafeCombo::SafeCombo(ComboType t,
00052 const Teuchos::RCP<Generic>& a,
00053 const Teuchos::RCP<Generic>& b) :
00054 type(t)
00055 {
00056 tests.push_back(a);
00057 addStatusTest(b);
00058 status = Unevaluated;
00059 }
00060
00061 NOX::StatusTest::SafeCombo& NOX::StatusTest::SafeCombo::addStatusTest(const Teuchos::RCP<Generic>& a)
00062 {
00063 if (isSafe(a))
00064 tests.push_back(a);
00065 else
00066 {
00067 const int indent = 2;
00068 cout << "\n*** WARNING! ***\n";
00069 cout << "This combo test currently consists of the following:\n";
00070 this->print(cout, indent);
00071 cout << "Unable to add the following test:\n";
00072 a->print(cout, indent);
00073 cout << "\n";
00074 }
00075 return *this;
00076 }
00077
00078 bool NOX::StatusTest::SafeCombo::isSafe(const Teuchos::RCP<Generic>& a)
00079 {
00080
00081 if (a.get() == this)
00082 return false;
00083
00084
00085
00086 for (vector<Teuchos::RCP<Generic> >::iterator i = tests.begin();
00087 i != tests.end(); ++i)
00088 {
00089
00090 SafeCombo* ptr = dynamic_cast<SafeCombo*>((*i).get());
00091 if (ptr != NULL)
00092 if (!ptr->isSafe(a))
00093 return false;
00094 }
00095
00096
00097 return true;
00098 }
00099
00100 NOX::StatusTest::SafeCombo::~SafeCombo()
00101 {
00102 }
00103
00104 NOX::StatusTest::StatusType NOX::StatusTest::SafeCombo::checkStatus(const Solver::Generic& problem)
00105 {
00106 #ifdef TRILINOS_6
00107 return checkStatusEfficiently(problem, NOX::StatusTest::Minimal);
00108 #else
00109 return checkStatus(problem, NOX::StatusTest::Minimal);
00110 #endif
00111 }
00112
00113 #ifdef TRILINOS_6
00114 NOX::StatusTest::StatusType NOX::StatusTest::SafeCombo
00115 ::checkStatusEfficiently(const Solver::Generic& problem,
00116 NOX::StatusTest::CheckType checkType)
00117 #else
00118 NOX::StatusTest::StatusType NOX::StatusTest::SafeCombo
00119 ::checkStatus(const Solver::Generic& problem,
00120 NOX::StatusTest::CheckType checkType)
00121 #endif
00122 {
00123 if (type == OR)
00124 orOp(problem, checkType);
00125 else
00126 andOp(problem, checkType);
00127
00128 return status;
00129 }
00130
00131 NOX::StatusTest::StatusType NOX::StatusTest::SafeCombo::getStatus() const
00132 {
00133 return status;
00134 }
00135
00136 void NOX::StatusTest::SafeCombo::orOp(const Solver::Generic& problem, NOX::StatusTest::CheckType checkType)
00137 {
00138 if (checkType == NOX::StatusTest::None)
00139 status = Unevaluated;
00140 else
00141 status = Unconverged;
00142
00143
00144
00145 for (vector<Teuchos::RCP<Generic> >::const_iterator i = tests.begin(); i != tests.end(); ++i)
00146 {
00147 #ifdef TRILINOS_6
00148 NOX::StatusTest::StatusType s = (*i)->checkStatusEfficiently(problem, checkType);
00149 #else
00150 NOX::StatusTest::StatusType s = (*i)->checkStatus(problem, checkType);
00151 #endif
00152 if ((status == Unconverged) && (s != Unconverged))
00153 {
00154 status = s;
00155
00156
00157 if (checkType == NOX::StatusTest::Minimal)
00158 checkType = NOX::StatusTest::None;
00159 }
00160
00161 }
00162
00163 return;
00164 }
00165
00166 void NOX::StatusTest::SafeCombo::andOp(const Solver::Generic& problem, NOX::StatusTest::CheckType checkType)
00167 {
00168 if (checkType == NOX::StatusTest::None)
00169 status = Unevaluated;
00170 else
00171 status = Unconverged;
00172
00173 bool isUnconverged = false;
00174
00175 for (vector<Teuchos::RCP<Generic> >::const_iterator i = tests.begin(); i != tests.end(); ++i) {
00176
00177
00178 #ifdef TRILINOS_6
00179 NOX::StatusTest::StatusType s = (*i)->checkStatusEfficiently(problem, checkType);
00180 #else
00181 NOX::StatusTest::StatusType s = (*i)->checkStatus(problem, checkType);
00182 #endif
00183
00184
00185
00186 if (s == Unconverged)
00187 {
00188 isUnconverged = true;
00189 status = Unconverged;
00190
00191
00192 if (checkType == NOX::StatusTest::Minimal)
00193 checkType = NOX::StatusTest::None;
00194 }
00195
00196
00197
00198 if ((!isUnconverged) && (status == Unconverged))
00199 {
00200 status = s;
00201 }
00202
00203 }
00204
00205 return;
00206 }
00207
00208
00209 ostream& NOX::StatusTest::SafeCombo::print(std::ostream& stream, int indent) const
00210 {
00211 for (int j = 0; j < indent; j ++)
00212 stream << ' ';
00213
00214
00215
00216
00217
00218
00219
00220 stream << status;
00221 stream << ((type == OR) ? "OR" : "AND");
00222 stream << " Combination";
00223 stream << " -> " << std::endl;
00224
00225 for (vector<Teuchos::RCP<Generic> >::const_iterator i = tests.begin(); i != tests.end(); ++i)
00226 (*i)->print(stream, indent+2);
00227
00228 return stream;
00229 }