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_LineSearch_Utils_Slope.H"
00043 #include "NOX_Abstract_Vector.H"
00044 #include "NOX_Abstract_Group.H"
00045 #include "NOX_GlobalData.H"
00046
00047 NOX::LineSearch::Utils::Slope::
00048 Slope(const Teuchos::RCP<NOX::GlobalData>& gd) :
00049 utils(*(gd->getUtils()))
00050 {
00051
00052 }
00053
00054 NOX::LineSearch::Utils::Slope::~Slope()
00055 {
00056
00057 }
00058
00059 void NOX::LineSearch::Utils::Slope::
00060 reset(const Teuchos::RCP<NOX::GlobalData>& gd)
00061 {
00062 utils = *(gd->getUtils());
00063 }
00064
00065 double NOX::LineSearch::Utils::Slope::
00066 computeSlope(const Abstract::Vector& dir, const Abstract::Group& grp)
00067 {
00068 if (grp.isGradient())
00069 return(dir.innerProduct(grp.getGradient()));
00070
00071
00072 if (Teuchos::is_null(vecPtr))
00073 vecPtr = dir.clone(ShapeCopy);
00074
00075
00076 NOX::Abstract::Group::ReturnType status = grp.applyJacobian(dir,*vecPtr);
00077
00078 if (status != NOX::Abstract::Group::Ok)
00079 {
00080 utils.out() << "NOX::LineSearch::Utils::Slope::computeSlope - Unable to apply Jacobian!" << endl;
00081 throw "NOX Error";
00082 }
00083
00084
00085 if (!grp.isF())
00086 {
00087 utils.out() << "NOX::LineSearch::Utils::Slope::computeSlope - Invalid F" << endl;
00088 throw "NOX Error";
00089 }
00090
00091
00092 return(vecPtr->innerProduct(grp.getF()));
00093 }
00094
00095 double NOX::LineSearch::Utils::Slope::
00096 computeSlopeWithOutJac(const Abstract::Vector& dir,
00097 const Abstract::Group& grp)
00098 {
00099
00100 if (Teuchos::is_null(vecPtr))
00101 vecPtr = dir.clone(ShapeCopy);
00102 if (Teuchos::is_null(grpPtr))
00103 grpPtr = grp.clone(ShapeCopy);
00104
00105
00106 if (!grp.isF())
00107 {
00108 utils.out() << "NOX::LineSearch::Utils::Slope::computeSlope - Invalid F" << endl;
00109 throw "NOX Error";
00110 }
00111
00112
00113 double lambda = 1.0e-6;
00114 double denominator = dir.norm();
00115
00116
00117 if (denominator == 0.0)
00118 denominator = 1.0;
00119
00120 double eta = lambda * (lambda + grp.getX().norm() / denominator);
00121
00122
00123 if (eta == 0.0)
00124 eta = 1.0e-6;
00125
00126
00127 vecPtr->update(eta, dir, 1.0, grp.getX(), 0.0);
00128
00129
00130 grpPtr->setX(*vecPtr);
00131 grpPtr->computeF();
00132
00133
00134 vecPtr->update(-1.0/eta, grp.getF(), 1.0/eta, grpPtr->getF(), 0.0);
00135
00136 return(vecPtr->innerProduct(grp.getF()));
00137 }