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_Common.H"
00043 #include "NOX_Direction_SteepestDescent.H"
00044 #include "NOX_Abstract_Vector.H"
00045 #include "NOX_Abstract_Group.H"
00046 #include "Teuchos_ParameterList.hpp"
00047 #include "NOX_Utils.H"
00048 #include "NOX_MeritFunction_Generic.H"
00049 #include "NOX_GlobalData.H"
00050
00051 NOX::Direction::SteepestDescent::
00052 SteepestDescent(const Teuchos::RCP<NOX::GlobalData>& gd,
00053 Teuchos::ParameterList& params)
00054 {
00055 reset(gd, params);
00056 }
00057
00058 NOX::Direction::SteepestDescent::~SteepestDescent()
00059 {
00060
00061 }
00062
00063 bool NOX::Direction::SteepestDescent::
00064 reset(const Teuchos::RCP<NOX::GlobalData>& gd,
00065 Teuchos::ParameterList& params)
00066 {
00067 globalDataPtr = gd;
00068 utils = gd->getUtils();
00069 meritFuncPtr = gd->getMeritFunction();
00070
00071 Teuchos::ParameterList& p = params.sublist("Steepest Descent");
00072
00073 const string tmp = p.get("Scaling Type", "2-Norm");
00074 if (tmp == "2-Norm")
00075 scaleType = NOX::Direction::SteepestDescent::TwoNorm;
00076 else if (tmp == "F 2-Norm")
00077 scaleType = NOX::Direction::SteepestDescent::FunctionTwoNorm;
00078 else if (tmp == "Quadratic Model Min")
00079 scaleType = NOX::Direction::SteepestDescent::QuadMin;
00080 else if (tmp == "None")
00081 scaleType = NOX::Direction::SteepestDescent::None;
00082 else {
00083 utils->out() << "NOX::Direction::SteepestDescent::reset - Invalid choice "
00084 << "\"" << tmp << "\" for \"Scaling Type\"" << endl;
00085 throw "NOX Error";
00086 }
00087
00088 return true;
00089 }
00090
00091 bool NOX::Direction::SteepestDescent::compute(Abstract::Vector& dir,
00092 Abstract::Group& soln,
00093 const Solver::Generic& solver)
00094 {
00095 NOX::Abstract::Group::ReturnType status;
00096
00097
00098 status = soln.computeF();
00099 if (status != NOX::Abstract::Group::Ok)
00100 throwError("compute", "Unable to compute F");
00101
00102
00103 status = soln.computeJacobian();
00104 if (status != NOX::Abstract::Group::Ok)
00105 throwError("compute", "Unable to compute Jacobian");
00106
00107
00108 switch (scaleType) {
00109
00110 case NOX::Direction::SteepestDescent::TwoNorm:
00111
00112 meritFuncPtr->computeGradient(soln, dir);
00113 dir.scale(-1.0/dir.norm());
00114 break;
00115
00116 case NOX::Direction::SteepestDescent::FunctionTwoNorm:
00117
00118 meritFuncPtr->computeGradient(soln, dir);
00119 dir.scale(-1.0/soln.getNormF());
00120 break;
00121
00122 case NOX::Direction::SteepestDescent::QuadMin:
00123
00124 meritFuncPtr->computeQuadraticMinimizer(soln, dir);
00125
00126 break;
00127
00128 case NOX::Direction::SteepestDescent::None:
00129
00130 meritFuncPtr->computeGradient(soln, dir);
00131 dir.scale( -1.0 );
00132 break;
00133
00134 default:
00135
00136 throwError("compute", "Invalid scaleType");
00137
00138 }
00139
00140 return true;
00141 }
00142
00143 bool NOX::Direction::SteepestDescent::compute(Abstract::Vector& dir,
00144 Abstract::Group& soln,
00145 const Solver::LineSearchBased& solver)
00146 {
00147 return NOX::Direction::Generic::compute( dir, soln, solver );
00148 }
00149
00150 void NOX::Direction::SteepestDescent::throwError(const string& functionName,
00151 const string& errorMsg)
00152 {
00153 if (utils->isPrintType(Utils::Error))
00154 utils->err() << "NOX::Direction::SteepestDescent::" << functionName
00155 << " - " << errorMsg << endl;
00156 throw "NOX Error";
00157 }