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_NormUpdate.H"
00043 #include "NOX_Common.H"
00044 #include "NOX_Abstract_Vector.H"
00045 #include "NOX_Abstract_Group.H"
00046 #include "NOX_Solver_Generic.H"
00047 #include "NOX_Utils.H"
00048
00049 using namespace NOX;
00050 using namespace NOX::StatusTest;
00051
00052 NormUpdate::NormUpdate(double tol, Abstract::Vector::NormType ntype, ScaleType stype) :
00053 status(Unevaluated),
00054 normType(ntype),
00055 scaleType(stype),
00056 tolerance(tol),
00057 normUpdate(0.0)
00058 {
00059 }
00060
00061 NormUpdate::NormUpdate(double tol, ScaleType stype) :
00062 status(Unevaluated),
00063 normType(NOX::Abstract::Vector::TwoNorm),
00064 scaleType(stype),
00065 tolerance(tol),
00066 normUpdate(0.0)
00067 {
00068 }
00069
00070 NormUpdate::~NormUpdate()
00071 {
00072
00073 }
00074
00075 StatusType NormUpdate::checkStatus(const Solver::Generic& problem,
00076 NOX::StatusTest::CheckType checkType)
00077 {
00078 if (checkType == None)
00079 {
00080 status = Unevaluated;
00081 normUpdate = -1.0;
00082 return status;
00083 }
00084
00085
00086
00087
00088 int niters = problem.getNumIterations();
00089 if (niters == 0)
00090 {
00091 status = Unconverged;
00092 normUpdate = -1.0;
00093 return status;
00094 }
00095
00096
00097 if (!problem.getSolutionGroup().isF())
00098 {
00099 status = Unconverged;
00100 normUpdate = -1.0;
00101 return status;
00102 }
00103
00104 const Abstract::Vector& oldSoln = problem.getPreviousSolutionGroup().getX();
00105 const Abstract::Vector& curSoln = problem.getSolutionGroup().getX();
00106
00107 if (Teuchos::is_null(updateVectorPtr))
00108 updateVectorPtr = curSoln.clone();
00109
00110 updateVectorPtr->update(1.0, curSoln, -1.0, oldSoln, 0.0);
00111
00112 int n = (scaleType == Scaled) ? updateVectorPtr->length() : 0;
00113
00114 switch (normType) {
00115
00116 case NOX::Abstract::Vector::TwoNorm:
00117 normUpdate = updateVectorPtr->norm();
00118 if (scaleType == Scaled)
00119 normUpdate /= sqrt(1.0 * n);
00120 break;
00121
00122 default:
00123 normUpdate = updateVectorPtr->norm(normType);
00124 if (scaleType == Scaled)
00125 normUpdate /= n;
00126 break;
00127
00128 }
00129
00130 status = (normUpdate < tolerance) ? Converged : Unconverged;
00131 return status;
00132 }
00133
00134 StatusType NormUpdate::getStatus() const
00135 {
00136 return status;
00137 }
00138
00139 ostream& NormUpdate::print(ostream& stream, int indent) const
00140 {
00141 for (int j = 0; j < indent; j ++)
00142 stream << ' ';
00143 stream << status;
00144 stream << "Absolute Update-Norm = " << Utils::sciformat(normUpdate, 3)
00145 << " < " << Utils::sciformat(tolerance, 3) << endl;
00146 return stream;
00147 }
00148
00149 double NOX::StatusTest::NormUpdate::getNormUpdate() const
00150 {
00151 return normUpdate;
00152 }
00153
00154 double NOX::StatusTest::NormUpdate::getTolerance() const
00155 {
00156 return tolerance;
00157 }