Exemplo n.º 1
0
// Protected
void NOX::Solver::PseudoTransient::init()
{
  // Initialize 
  stepSize = 0.0;
  nIter = 0;
  status = NOX::StatusTest::Unconverged;
  checkType = parseStatusTestCheckType(paramsPtr->sublist("Solver Options"));

  lineSearchPtr = NOX::LineSearch::
    buildLineSearch(globalDataPtr, paramsPtr->sublist("Line Search"));

  directionPtr = NOX::Direction::
    buildDirection(globalDataPtr, paramsPtr->sublist("Direction"));

  deltaInit = paramsPtr->sublist("Pseudo-Transient").get<double>("deltaInit",1.0e-4);
  delta = deltaInit;
  inv_delta = 1.0 / delta;
  deltaMax = paramsPtr->sublist("Pseudo-Transient").get<double>("deltaMax",1.0e+0);
  deltaMin = paramsPtr->sublist("Pseudo-Transient").get<double>("deltaMin",1.0e-5);
  time = 0.0;

  // Print out parameters
  if (utilsPtr->isPrintType(NOX::Utils::Parameters)) 
  {
    utilsPtr->out() << "\n" << NOX::Utils::fill(72) << "\n";
    utilsPtr->out() << "\n-- Parameters Passed to Nonlinear Solver --\n\n";
    paramsPtr->print(utilsPtr->out(),5);
  }

}
// Protected
void NOX::Solver::PseudoTransient::init()
{
  // Initialize
  stepSize = 0.0;
  nIter = 0;
  status = NOX::StatusTest::Unconverged;

  Teuchos::RCP<Teuchos::ParameterList> paramsPtr = this->getMyNonconstParamList();
  paramsPtr->validateParametersAndSetDefaults(*this->getValidParameters());

  checkType = parseStatusTestCheckType(paramsPtr->sublist("Solver Options"));

  lineSearchPtr = NOX::LineSearch::
    buildLineSearch(globalDataPtr, paramsPtr->sublist("Line Search"));

  directionPtr = NOX::Direction::
    buildDirection(globalDataPtr, paramsPtr->sublist("Direction"));

  deltaInit = paramsPtr->sublist("Pseudo-Transient").get<double>("deltaInit");
  delta = deltaInit;
  inv_delta = 1.0 / delta;
  deltaMax = paramsPtr->sublist("Pseudo-Transient").get<double>("deltaMax");
  deltaMin = paramsPtr->sublist("Pseudo-Transient").get<double>("deltaMin");
  time = 0.0;

  use_transient_residual =
    paramsPtr->sublist("Pseudo-Transient").get<bool>("Use Transient Residual in Direction Computation");

  max_pseudo_transient_iterations =
    paramsPtr->sublist("Pseudo-Transient").get<int>("Maximum Number of Pseudo-Transient Iterations");

  // Print out parameters
  if (utilsPtr->isPrintType(NOX::Utils::Parameters))
  {
    utilsPtr->out() << "\n" << NOX::Utils::fill(72) << "\n";
    utilsPtr->out() << "\n-- Parameters Passed to Nonlinear Solver --\n\n";
    paramsPtr->print(utilsPtr->out(),5);
  }

}
// Protected
void NOX::Solver::LineSearchBased::init()
{
  // Initialize 
  stepSize = 0.0;
  nIter = 0;
  status = NOX::StatusTest::Unconverged;
  checkType = parseStatusTestCheckType(paramsPtr->sublist("Solver Options"));

  lineSearchPtr = NOX::LineSearch::
    buildLineSearch(globalDataPtr, paramsPtr->sublist("Line Search"));

  directionPtr = NOX::Direction::
    buildDirection(globalDataPtr, paramsPtr->sublist("Direction"));

  // Print out parameters
  if (utilsPtr->isPrintType(NOX::Utils::Parameters)) 
  {
    utilsPtr->out() << "\n" << NOX::Utils::fill(72) << "\n";
    utilsPtr->out() << "\n-- Parameters Passed to Nonlinear Solver --\n\n";
    paramsPtr->print(utilsPtr->out(),5);
  }

}
bool NOX::Solver::TensorBased::
reset(const Teuchos::RCP<NOX::Abstract::Group>& xGrp,
      const Teuchos::RCP<NOX::StatusTest::Generic>& t,
      const Teuchos::RCP<Teuchos::ParameterList>& p)
{
  solnPtr = xGrp;
  testPtr = t;
  paramsPtr = p;

  globalDataPtr = Teuchos::rcp(new NOX::GlobalData(p));
  utilsPtr->reset(paramsPtr->sublist("Printing"));
  print.reset(utilsPtr);
  slopeObj.reset(globalDataPtr);
  prePostOperator.reset(utilsPtr, paramsPtr->sublist("Solver Options"));

  // *** Reset direction parameters ***
  Teuchos::ParameterList& dirParams = paramsPtr->sublist("Direction");

  // Determine the specific type of direction to compute
  std::string choice = dirParams.get("Method", "Tensor");
  if (choice == "Tensor")
    requestedBaseStep = TensorStep;
  else if (choice == "Newton")
    requestedBaseStep = NewtonStep;
  else
  {
    if (utilsPtr->isPrintType(NOX::Utils::Error))
      utilsPtr->err() << "NOX::Direction::Tensor::reset() - The choice of "
       << "\"Method\" parameter \"" << choice
       << "\" is invalid." << std::endl;
    throw "NOX error";
  }

  // Make a reference to the sublist holding the global strategy parameters
  Teuchos::ParameterList& teParams = dirParams.sublist(choice);

  //  Copy Method into "Compute Step" (temporary hack for data scripts)
  dirParams.set("Compute Step", choice);

  // Initialize direction parameters for this object
  doRescue = teParams.get("Rescue Bad Newton Solve", true);

  checkType = parseStatusTestCheckType(paramsPtr->sublist("Solver Options"));

  // Determine whether we should use the Modified Tensor method
  useModifiedMethod = false;
  if (requestedBaseStep == TensorStep)
  {
    useModifiedMethod =
      dirParams.get("Use Modified Bouaricha", true);
    if (useModifiedMethod  &&
    utilsPtr->isPrintType(NOX::Utils::Parameters))
      utilsPtr->out() << "Using Modifed Bouaricha method" << std::endl;
  }


  // *** Reset parameters for Line Search ***
  Teuchos::ParameterList& lsParams = paramsPtr->sublist("Line Search");

  // Determine the specific type of tensor linesearch to perform
  choice = lsParams.get("Method", "Curvilinear");

  if (choice == "Curvilinear")
    lsType = Curvilinear;
  else if (choice == "Dual")
    lsType = Dual;
  else if (choice == "Standard")
    lsType = Standard;
  else if (choice == "Full Step")
    lsType = FullStep;
  else if (choice == "Newton")
    lsType = Newton;
  else
  {
    if (utilsPtr->isPrintType(NOX::Utils::Error))
      utilsPtr->err() << "NOX::Direction::Tensor::reset() - The choice of "
       << "\"Line Search\" parameter " << choice
       << " is invalid." << std::endl;
    throw "NOX Error";
  }
  //  Copy Method into "Submethod" (temporary hack for data scripts)
  lsParams.set("Submethod", choice);

  // Make a reference to the sublist holding the global strategy parameters
  Teuchos::ParameterList& gsParams = lsParams.sublist(choice);

  // Decide what step to use in case of linesearch failure
  choice = gsParams.get("Recovery Step Type", "Constant");
  if (choice == "Constant")
    recoveryStepType = Constant;          // Use value in "Recovery Step"
  else if (choice == "Last Computed Step")
    recoveryStepType = LastComputedStep;  // Use last step from linesearch
  else
  {
    utilsPtr->err() << "NOX::Solver::TensorBased::reset() - "
     << "Invalid \"Recovery Step Type\"" << std::endl;
    throw "NOX Error";
  }

  // Initialize linesearch parameters for this object
  minStep = gsParams.get("Minimum Step", 1.0e-12);
  defaultStep = gsParams.get("Default Step", 1.0);
  recoveryStep = gsParams.get("Recovery Step", 0.0); // exit on fail
  maxIters = gsParams.get("Max Iters", 40);
  alpha = gsParams.get("Alpha Factor", 1.0e-4);

  choice = gsParams.get("Lambda Selection", "Halving");
  if (choice == "Halving")
    lambdaSelection = Halving;
  else if (choice == "Quadratic")
    lambdaSelection = Quadratic;
  else
  {
    if (utilsPtr->isPrintType(NOX::Utils::Error))
      utilsPtr->err() << "NOX::Solver::TensorBased::reset() - The choice of "
       << "\"Lambda Selection\" parameter " << choice
       << " is invalid." << std::endl;
    throw "NOX Error";
  }

  choice = gsParams.get("Sufficient Decrease Condition",
                 "Armijo-Goldstein");
  if (choice == "Armijo-Goldstein")
    convCriteria = ArmijoGoldstein;     // This is the only one implemented
  //else if (choice == "Ared/Pred")
  //  convCriteria = AredPred;
  //else if (choice == "None")
  //  convCriteria = None;
  else
  {
    if (utilsPtr->isPrintType(NOX::Utils::Error))
      utilsPtr->err() << "NOX::Solver::TensorBased::reset() - The choice of "
       << "\"Sufficient Decrease Condition\" parameter " << choice
       << " is invalid." << std::endl;
    throw "NOX Error";
  }

  init();
  return true;
}
// Protected
void NOX::Solver::AndersonAcceleration::init()
{
  // Set up the parameter list
  {
    Teuchos::ParameterList validParams;
    validParams.set("Storage Depth", 2, "max number of previous iterates for which data stored");
    validParams.set("Disable Checks for Unit Testing", false, "If set to true, the check on the storage depth size is disabled so that we can generate some corner cases for unit testing.  WARNING: users should never set this to true!");
    validParams.set("Mixing Parameter", 1.0, "damping factor applied to residuals");
    validParams.set("Reorthogonalization Frequency", 0, "Least-squares problem solved by updating previous QR factorization. Number of iterations between reorthogonalizing columns of Q. Never reorthogonalize if less than 1.");
    validParams.sublist("Preconditioning").set("Precondition", false, "flag for preconditioning");
    validParams.sublist("Preconditioning").set("Recompute Jacobian", false, "set true if preconditioner requires computation of Jacobian");
    validParams.set("Adjust Matrix for Condition Number", false, "If true, the QR matrix will be resized if the condiiton number is greater than the dropTolerance");
    validParams.set("Condition Number Drop Tolerance", 1.0e+12, "If adjusting for condition number, this is the condition number value above which the QR matrix will be resized.");
    validParams.set("Acceleration Start Iteration",1,"The nonlinear iteration where Anderson Acceleration will start. Normally AA starts from the first iteration, but it can be advantageous to delay the start and allow normal picard iteration to get a better initial guess for the AA history.");
    paramsPtr->sublist("Anderson Parameters").validateParametersAndSetDefaults(validParams);
  }

  storeParam = paramsPtr->sublist("Anderson Parameters").get<int>("Storage Depth");
  disableChecksForUnitTesting = paramsPtr->sublist("Anderson Parameters").get<bool>("Disable Checks for Unit Testing");

  if (!disableChecksForUnitTesting) {
    TEUCHOS_TEST_FOR_EXCEPTION((storeParam > solnPtr->getX().length()),std::logic_error,"Error - The \"Storage Depth\" with a value of " << storeParam << " must be less than the number of unknowns in the nonlinear problem which is currently " << solnPtr->getX().length() << ".  This reults in an ill-conditioned F matrix.");
  }

  mixParam = paramsPtr->sublist("Anderson Parameters").get<double>("Mixing Parameter");
  if (storeParam < 0) {
    utilsPtr->out() << "NOX::Solver::AndersonAcceleration::init - "
      << "Storage parameter must be non-negative" << std::endl;
    throw "NOX Error";
  }
  if ((mixParam < -1.0) || (mixParam == 0) || (mixParam > 1.0)) {
    utilsPtr->out() << "NOX::Solver::AndersonAcceleration::init - "
      << "Mixing parameter must be in [-1,0)U(0,1]" << std::endl;
    throw "NOX Error";
  }
  orthoFrequency = paramsPtr->sublist("Anderson Parameters").get<int>("Reorthogonalization Frequency");
  precond = paramsPtr->sublist("Anderson Parameters").sublist("Preconditioning").get<bool>("Precondition");
  recomputeJacobian = paramsPtr->sublist("Anderson Parameters").sublist("Preconditioning").get<bool>("Recompute Jacobian");
  adjustForConditionNumber = paramsPtr->sublist("Anderson Parameters").get<bool>("Adjust Matrix for Condition Number");
  dropTolerance = paramsPtr->sublist("Anderson Parameters").get<double>("Condition Number Drop Tolerance");
  accelerationStartIteration = paramsPtr->sublist("Anderson Parameters").get<int>("Acceleration Start Iteration");

  TEUCHOS_TEST_FOR_EXCEPTION((accelerationStartIteration < 1),std::logic_error,"Error - The \"Acceleration Start Iteration\" should be greater than 0!");

  // Initialize
  stepSize = 0.0;
  nIter = 0;
  nStore = 0;
  workVec->init(0.0);
  xMat.resize(0);
  qMat.resize(0);
  for (int ii=0; ii < storeParam; ii++) {
    xMat.push_back(solnPtr->getX().clone(NOX::ShapeCopy));
    qMat.push_back(solnPtr->getX().clone(NOX::ShapeCopy));
  }

  status = NOX::StatusTest::Unconverged;
  checkType = parseStatusTestCheckType(paramsPtr->sublist("Solver Options"));

  lineSearchPtr = NOX::LineSearch::
    buildLineSearch(globalDataPtr, paramsPtr->sublist("Line Search"));

  // Print out parameters
  if (utilsPtr->isPrintType(NOX::Utils::Parameters))
  {
    utilsPtr->out() << "\n" << NOX::Utils::fill(72) << "\n";
    utilsPtr->out() << "\n-- Parameters Passed to Nonlinear Solver --\n\n";
    paramsPtr->print(utilsPtr->out(),5);
  }

}