本文整理汇总了C++中nox::abstract::Group::getF方法的典型用法代码示例。如果您正苦于以下问题:C++ Group::getF方法的具体用法?C++ Group::getF怎么用?C++ Group::getF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nox::abstract::Group
的用法示例。
在下文中一共展示了Group::getF方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
double
NOX::Solver::TensorBased::getNormModelResidual(
const NOX::Abstract::Vector& dir,
const NOX::Abstract::Group& soln,
bool isTensorModel) const
{
// Compute residual of Newton model...
Teuchos::RCP<NOX::Abstract::Vector> residualPtr =
soln.getF().clone(ShapeCopy);
soln.applyJacobian(dir, *residualPtr);
numJvMults++;
residualPtr->update(1.0, soln.getF(), 1.0);
// Compute residual of Tensor model, if requested...
if (isTensorModel)
{
double tmp = sVecPtr->innerProduct(dir);
if (utilsPtr->isPrintType(NOX::Utils::Details))
utilsPtr->out() << " sc'*dt = " << utilsPtr->sciformat(tmp, 6) << std::endl;
residualPtr->update(tmp*tmp, *aVecPtr, 1.0);
}
double modelNorm = residualPtr->norm();
return modelNorm;
}
示例2: switch
double NOX::StatusTest::NormF::computeNorm(const NOX::Abstract::Group& grp)
{
if (!grp.isF())
return -1.0;
double norm;
int n = grp.getX().length();
switch (normType)
{
case NOX::Abstract::Vector::TwoNorm:
norm = grp.getNormF();
if (scaleType == Scaled)
norm /= sqrt(1.0 * n);
break;
default:
norm = grp.getF().norm(normType);
if (scaleType == Scaled)
norm /= n;
break;
}
return norm;
}
示例3:
void NOX::MeritFunction::SumOfSquares::
computeGradient(const NOX::Abstract::Group& grp,
NOX::Abstract::Vector& result) const
{
if ( !(grp.isF()) ) {
utils->err()
<< "ERROR: NOX::MeritFunction::SumOfSquares::computeGradient() - "
<< "F has not been computed yet!. Please call "
<< "computeF() on the group passed into this function."
<< std::endl;
throw "NOX Error";
}
if ( !(grp.isJacobian()) ) {
utils->err()
<< "ERROR: NOX::MeritFunction::SumOfSquares::computeGradient() - "
<< "Jacobian has not been computed yet!. Please call "
<< "computeJacobian() on the group passed into this function."
<< std::endl;
throw "NOX Error";
}
NOX::Abstract::Group::ReturnType status =
grp.applyJacobianTranspose(grp.getF(), result);
if (status != NOX::Abstract::Group::Ok) {
utils->err() << "ERROR: NOX::MeritFunction::SumOfSquares::compute"
<< "Gradient - applyJacobianTranspose failed!" << std::endl;
throw "NOX Error";
}
return;
}
示例4: return
double NOX::MeritFunction::SumOfSquares::
computeSlopeWithoutJacobian(const NOX::Abstract::Vector& dir,
const NOX::Abstract::Group& grp) const
{
if (Teuchos::is_null(tmpVecPtr))
tmpVecPtr = grp.getF().clone(NOX::ShapeCopy);
if (Teuchos::is_null(tmpGrpPtr))
tmpGrpPtr = grp.clone(NOX::ShapeCopy);
// Compute the perturbation parameter
double lambda = 1.0e-6;
double denominator = dir.norm();
// Don't divide by zero
if (denominator == 0.0)
denominator = 1.0;
double eta = lambda * (lambda + grp.getX().norm() / denominator);
// Don't divide by zero
if (eta == 0.0)
eta = 1.0e-6;
// Perturb the solution vector
tmpVecPtr->update(eta, dir, 1.0, grp.getX(), 0.0);
// Compute the new F --> F(x + eta * dir)
tmpGrpPtr->setX(*(tmpVecPtr.get()));
tmpGrpPtr->computeF();
// Compute Js = (F(x + eta * dir) - F(x))/eta
tmpVecPtr->update(-1.0/eta, grp.getF(), 1.0/eta, tmpGrpPtr->getF(), 0.0);
return(tmpVecPtr->innerProduct(grp.getF()));
}
示例5: if
double NOX::MeritFunction::SumOfSquares::
computeSlope(const NOX::Abstract::Vector& dir,
const NOX::Abstract::Group& grp) const
{
if (Teuchos::is_null(tmpVecPtr))
tmpVecPtr = grp.getF().clone();
// If the Jacobian is not computed, approximate it with
// directional derivatives. dir^T J^T F = F^T Jd
if (!(grp.isJacobian()))
return this->computeSlopeWithoutJacobian(dir, grp);
// If the Jacobian is computed but doesn't support a gradient,
// employ a different form for the inner product, eg
// return <v, F> = F' * J * dir = <J'F, dir> = <g, dir>
else if(!(grp.isGradient()))
return this->computeSlopeWithoutJacobianTranspose(dir, grp);
this->computeGradient(grp, *(tmpVecPtr.get()));
return dir.innerProduct(*(tmpVecPtr.get()));
}
示例6: if
// **************************************************************************
// *** computeForcingTerm
// **************************************************************************
double NOX::Direction::Utils::InexactNewton::
computeForcingTerm(const NOX::Abstract::Group& soln,
const NOX::Abstract::Group& oldsoln,
int niter,
const NOX::Solver::Generic& solver,
double eta_last)
{
const std::string indent = " ";
if (forcingTermMethod == Constant) {
if (printing->isPrintType(NOX::Utils::Details)) {
printing->out() << indent << "CALCULATING FORCING TERM" << std::endl;
printing->out() << indent << "Method: Constant" << std::endl;
printing->out() << indent << "Forcing Term: " << eta_k << std::endl;
}
if (setTolerance)
paramsPtr->sublist(directionMethod).sublist("Linear Solver").
set("Tolerance", eta_k);
return eta_k;
}
// Get linear solver current tolerance.
// NOTE: These values are changing at each nonlinear iteration and
// must either be updated from the parameter list each time a compute
// is called or supplied during the function call!
double eta_km1 = 0.0;
if (eta_last < 0.0)
eta_km1 = paramsPtr->sublist(directionMethod).
sublist("Linear Solver").get("Tolerance", 0.0);
else
eta_km1 = eta_last;
// Tolerance may have been adjusted in a line search algorithm so we
// have to account for this.
const NOX::Solver::LineSearchBased* solverPtr = 0;
solverPtr = dynamic_cast<const NOX::Solver::LineSearchBased*>(&solver);
if (solverPtr != 0) {
eta_km1 = 1.0 - solverPtr->getStepSize() * (1.0 - eta_km1);
}
if (printing->isPrintType(NOX::Utils::Details)) {
printing->out() << indent << "CALCULATING FORCING TERM" << std::endl;
printing->out() << indent << "Method: " << method << std::endl;
}
if (forcingTermMethod == Type1) {
if (niter == 0) {
eta_k = eta_initial;
}
else {
// Return norm of predicted F
// do NOT use the following lines!! This does NOT account for
// line search step length taken.
// const double normpredf = 0.0;
// oldsoln.getNormLastLinearSolveResidual(normpredf);
// Create a new vector to be the predicted RHS
if (Teuchos::is_null(predRhs)) {
predRhs = oldsoln.getF().clone(ShapeCopy);
}
if (Teuchos::is_null(stepDir)) {
stepDir = oldsoln.getF().clone(ShapeCopy);
}
// stepDir = X - oldX (i.e., the step times the direction)
stepDir->update(1.0, soln.getX(), -1.0, oldsoln.getX(), 0);
// Compute predRhs = Jacobian * step * dir
if (!(oldsoln.isJacobian())) {
if (printing->isPrintType(NOX::Utils::Details)) {
printing->out() << "WARNING: NOX::InexactNewtonUtils::resetForcingTerm() - "
<< "Jacobian is out of date! Recomputing Jacobian." << std::endl;
}
const_cast<NOX::Abstract::Group&>(oldsoln).computeJacobian();
}
oldsoln.applyJacobian(*stepDir, *predRhs);
// Compute predRhs = RHSVector + predRhs (this is the predicted RHS)
predRhs->update(1.0, oldsoln.getF(), 1.0);
// Compute the norms
double normpredf = predRhs->norm();
double normf = soln.getNormF();
double normoldf = oldsoln.getNormF();
if (printing->isPrintType(NOX::Utils::Details)) {
printing->out() << indent << "Forcing Term Norm: Using L-2 Norm."
<< std::endl;
}
//.........这里部分代码省略.........
示例7: if
bool NOX::Direction::ModifiedNewton::
compute(NOX::Abstract::Vector& dir,
NOX::Abstract::Group& soln,
const NOX::Solver::Generic& solver)
{
NOX::Abstract::Group::ReturnType status;
// Compute F at current solution
status = soln.computeF();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute F");
maxAgeOfJacobian = paramsPtr->sublist("Modified-Newton").get("Max Age of Jacobian", 10);
if (Teuchos::is_null(oldJacobianGrpPtr)) {
oldJacobianGrpPtr = soln.clone(DeepCopy);
}
NOX::Abstract::Group& oldJacobianGrp = *oldJacobianGrpPtr;
status = NOX::Abstract::Group::Failed;
while (status != NOX::Abstract::Group::Ok) {
// Conditionally compute Jacobian at current solution.
if ( (ageOfJacobian == -1) || (ageOfJacobian == maxAgeOfJacobian) ) {
if (ageOfJacobian > 0)
oldJacobianGrp = soln;
status = oldJacobianGrp.computeJacobian();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute Jacobian");
ageOfJacobian = 1;
}
else
ageOfJacobian++;
// Compute the Modified Newton direction
status = oldJacobianGrp.applyJacobianInverse(paramsPtr->sublist("Modified-Newton").sublist("Linear Solver"), soln.getF(), dir);
dir.scale(-1.0);
// It didn't converge, but maybe we can recover.
if ((status != NOX::Abstract::Group::Ok) &&
(doRescue == false)) {
throwError("compute", "Unable to solve Newton system");
}
else if ((status != NOX::Abstract::Group::Ok) &&
(doRescue == true)) {
if (utils->isPrintType(NOX::Utils::Warning))
utils->out() << "WARNING: NOX::Direction::ModifiedNewton::compute() - "
<< "Linear solve failed to achieve convergence - "
<< "using the step anyway since \"Rescue Bad Newton Solve\" "
<< "is true. Also, flagging recompute of Jacobian." << std::endl;
ageOfJacobian = maxAgeOfJacobian;
status = NOX::Abstract::Group::Ok;
}
}
return true;
}
示例8: if
bool
NOX::Solver::TensorBased::computeTensorDirection(NOX::Abstract::Group& soln,
const NOX::Solver::Generic& solver)
{
NOX::Abstract::Group::ReturnType dir_status;
Teuchos::ParameterList& linearParams = paramsPtr->sublist("Direction").
sublist(paramsPtr->sublist("Direction").
get("Method","Tensor")).
sublist("Linear Solver");
// Compute F at current solution.
dir_status = soln.computeF();
if (dir_status != NOX::Abstract::Group::Ok)
throwError("computeTensorDirection", "Unable to compute F");
// Compute Jacobian at current solution.
dir_status = soln.computeJacobian();
if (dir_status != NOX::Abstract::Group::Ok)
throwError("computeTensorDirection", "Unable to compute Jacobian");
// Begin processing for the tensor step, if necessary.
double sDotS = 0.0;
int tempVal1 = 0;
if ((nIter > 0) && (requestedBaseStep == TensorStep))
{
// Compute the tensor term s = x_{k-1} - x_k
*sVecPtr = soln.getX();
sVecPtr->update(1.0, solver.getPreviousSolutionGroup().getX(), -1.0);
double normS = sVecPtr->norm();
sDotS = normS * normS;
// Form the tensor term a = (F_{k-1} - F_k - J*s) / (s^T s)^2
soln.applyJacobian(*sVecPtr, *aVecPtr);
numJvMults++;
aVecPtr->update(1.0, solver.getPreviousSolutionGroup().getF(), -1.0);
aVecPtr->update(-1.0, soln.getF(), 1.0);
if (sDotS != 0)
aVecPtr->scale(1.0 / (sDotS * sDotS));
// Save old Newton step as initial guess to second system
*tmpVecPtr = *newtonVecPtr;
tmpVecPtr->scale(-1.0); // Rewrite to avoid this?
// Compute residual of linear system using initial guess...
soln.applyJacobian(*tmpVecPtr, *residualVecPtr);
numJvMults++;
residualVecPtr->update(1.0, solver.getPreviousSolutionGroup().getF(),-1.0);
double residualNorm = residualVecPtr->norm();
#if DEBUG_LEVEL > 0
double tmpVecNorm = tmpVecPtr->norm();
double residualNormRel = residualNorm /
solver.getPreviousSolutionGroup().getNormF();
if (utilsPtr->isPrintType(NOX::Utils::Details))
{
utilsPtr->out() << " Norm of initial guess: " << utilsPtr->sciformat(tmpVecNorm, 6)
<< std::endl;
utilsPtr->out() << " initg norm of model residual = "
<< utilsPtr->sciformat(residualNorm, 6) << " (abs) "
<< utilsPtr->sciformat(residualNormRel, 6) << " (rel)" << std::endl;
}
#endif
// Save some parameters and use them later...
double tol = linearParams.get("Tolerance", 1e-4);
double relativeResidual = residualNorm /
solver.getPreviousSolutionGroup().getNormF();
// Decide whether to use initial guess...
bool isInitialGuessGood = false;
#ifdef USE_INITIAL_GUESS_LOGIC
if (relativeResidual < 1.0)
{
if (utilsPtr->isPrintType(NOX::Utils::Details))
utilsPtr->out() << " Initial guess is good..." << std::endl;
isInitialGuessGood = true;
// RPP - Brett please make sure the line below is correct.
*tensorVecPtr = *tmpVecPtr;
double newTol = tol / relativeResidual;
if (newTol > 0.99)
newTol = 0.99; // force at least one iteration
linearParams.set("Tolerance", newTol);
if (utilsPtr->isPrintType(NOX::Utils::Details))
utilsPtr->out() << " Setting tolerance to " << utilsPtr->sciformat(newTol,6) << std::endl;
}
else
#endif // USE_INITIAL_GUESS_LOGIC
{
//utilsPtr->out() << " Initial guess is BAD... do not use!\n";
isInitialGuessGood = false;
*residualVecPtr = solver.getPreviousSolutionGroup().getF();
}
// Compute the term inv(J)*Fp....
tmpVecPtr->init(0.0);
dir_status = soln.applyJacobianInverse(linearParams, *residualVecPtr,
*tmpVecPtr);
// If it didn't converge, maybe we can recover.
//.........这里部分代码省略.........
示例9: throwError
bool NOX::Direction::Broyden::compute(NOX::Abstract::Vector& dir,
NOX::Abstract::Group& soln,
const NOX::Solver::LineSearchBased& solver)
{
// Return value for group operations (temp variable)
NOX::Abstract::Group::ReturnType status;
// Compute F at current solution
status = soln.computeF();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute F");
// Check for restart
if (doRestart(soln, solver))
{
// Reset memory
memory.reset();
// Update group
if (Teuchos::is_null(oldJacobianGrpPtr))
oldJacobianGrpPtr = soln.clone(NOX::DeepCopy);
else
// RPP - update the entire group (this grabs state vectors in xyce).
// Otherwise, xyce is forced to recalculate F at each iteration.
//oldJacobianGrpPtr->setX(soln.getX());
*oldJacobianGrpPtr = soln;
// Calcuate new Jacobian
if (utils->isPrintType(NOX::Utils::Details))
utils->out() << " Recomputing Jacobian" << endl;
status = oldJacobianGrpPtr->computeJacobian();
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to compute Jacobian");
// Reset counter
cnt = 0;
}
// If necesary, scale the s-vector from the last iteration
if (!memory.empty())
{
double step = solver.getStepSize();
memory[memory.size() - 1].setStep(step);
}
// --- Calculate the Broyden direction ---
// Compute inexact forcing term if requested.
inexactNewtonUtils.computeForcingTerm(soln,
solver.getPreviousSolutionGroup(),
solver.getNumIterations(),
solver);
// dir = - J_old^{-1} * F
cnt ++;
status = oldJacobianGrpPtr->applyJacobianInverse(*lsParamsPtr,
soln.getF(),
dir);
if (status != NOX::Abstract::Group::Ok)
throwError("compute", "Unable to apply Jacobian inverse");
dir.scale(-1.0);
// Apply the Broyden modifications to the old Jacobian (implicitly)
if (!memory.empty())
{
// Number of elements in the memory
int m = memory.size();
// Information corresponding to index i
double step;
Teuchos::RCP<const NOX::Abstract::Vector> sPtr;
// Information corresponding to index i + 1
// (initialized for i = -1)
double stepNext = memory[0].step();
Teuchos::RCP<const NOX::Abstract::Vector> sPtrNext =
memory[0].sPtr();
// Intermediate storage
double a, b, c, denom;
for (int i = 0; i < m-1; i ++)
{
step = stepNext;
sPtr = sPtrNext;
stepNext = memory[i+1].step();
sPtrNext = memory[i+1].sPtr();
a = step / stepNext;
b = step - 1;
c = sPtr->innerProduct(dir) / memory[i].sNormSqr();
dir.update(a * c, *sPtrNext, b * c, *sPtr, 1.0);
}
step = stepNext;
sPtr = sPtrNext;
a = sPtr->innerProduct(dir); // <s,z>
//.........这里部分代码省略.........