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