Beispiel #1
0
void
petscSetOptions(FEProblem & problem)
{
  // Reference to the options stored in FEPRoblem
  PetscOptions & petsc = problem.getPetscOptions();

  if (petsc.inames.size() != petsc.values.size())
    mooseError("PETSc names and options are not the same length");

  PetscOptionsClear();

  { // Get any options specified on the command-line
    int argc;
    char ** args;

    PetscGetArgs(&argc, &args);
    PetscOptionsInsert(&argc, &args, NULL);
  }

  setSolverOptions(problem.solverParams());

  // Add any additional options specified in the input file
  for (MooseEnumIterator it = petsc.flags.begin(); it != petsc.flags.end(); ++it)
    PetscOptionsSetValue(it->c_str(), PETSC_NULL);
  for (unsigned int i=0; i<petsc.inames.size(); ++i)
    PetscOptionsSetValue(petsc.inames[i].c_str(), petsc.values[i].c_str());

  SolverParams& solver_params = problem.solverParams();
  if (solver_params._type != Moose::ST_JFNK  &&
      solver_params._type != Moose::ST_FD &&
      !problem.getNonlinearSystem().haveFiniteDifferencedPreconditioner() &&
      problem.getNonlinearSystem().haveDecomposition())
  {
    // Set up DM only if have a decomposition. Additionally, turn DM OFF if not using FD-based solvers,
    // (both -snes_mf and -snes_fd) and FDP. This is all rather crufty, but what's a good generic rule here?
    // In principle at least, splits should be able to work with ST_FD (-snes_fd) and FDP (a coloring-based
    // version of -snes_fd), but one has to be careful about the initialization order so as not to override
    // SNESComputeJacobianDefaultColor() set up by FDP, for instance.  However, it's unlikely that splits
    // will be used when running an FD solver (debugging).
    problem.getNonlinearSystem().setupDecomposition();
    petscSetupDM(problem.getNonlinearSystem());
  } else {
    // Otherwise turn off the decomposition
    std::vector<std::string> nosplits;
    problem.getNonlinearSystem().setDecomposition(nosplits);
  }

}
ComputeElemDampingThread::ComputeElemDampingThread(FEProblem & feproblem) :
    ThreadedElementLoop<ConstElemRange>(feproblem),
    _damping(1.0),
    _nl(feproblem.getNonlinearSystem()),
    _element_dampers(_nl.getElementDamperWarehouse())
{
}
ComputeNodalDampingThread::ComputeNodalDampingThread(FEProblem & feproblem) :
    ThreadedNodeLoop<ConstNodeRange, ConstNodeRange::const_iterator>(feproblem),
    _damping(1.0),
    _nl(feproblem.getNonlinearSystem()),
    _nodal_dampers(_nl.getNodalDamperWarehouse())
{
}
Beispiel #4
0
void
petscSetOptions(FEProblem & problem)
{
  // Reference to the options stored in FEPRoblem
  PetscOptions & petsc = problem.getPetscOptions();

  if (petsc.inames.size() != petsc.values.size())
    mooseError("PETSc names and options are not the same length");

#if PETSC_VERSION_LESS_THAN(3,7,0)
  PetscOptionsClear();
#else
  PetscOptionsClear(PETSC_NULL);
#endif

  setSolverOptions(problem.solverParams());

  // Add any additional options specified in the input file
  for (const auto & flag : petsc.flags)
    setSinglePetscOption(flag.c_str());
  for (unsigned int i=0; i<petsc.inames.size(); ++i)
    setSinglePetscOption(petsc.inames[i], petsc.values[i]);

  // set up DM which is required if use a field split preconditioner
  if (problem.getNonlinearSystem().haveFieldSplitPreconditioner())
    petscSetupDM(problem.getNonlinearSystem());

  // commandline options always win
  // the options from a user commandline will overwrite the existing ones if any conflicts
  { // Get any options specified on the command-line
    int argc;
    char ** args;

    PetscGetArgs(&argc, &args);
#if PETSC_VERSION_LESS_THAN(3,7,0)
    PetscOptionsInsert(&argc, &args, NULL);
#else
    PetscOptionsInsert(PETSC_NULL, &argc, &args, NULL);
#endif
  }
}
Beispiel #5
0
void
petscSetDefaults(FEProblem & problem)
{
  // dig out Petsc solver
  NonlinearSystem & nl = problem.getNonlinearSystem();
  PetscNonlinearSolver<Number> * petsc_solver = dynamic_cast<PetscNonlinearSolver<Number> *>(nl.sys().nonlinear_solver.get());
  SNES snes = petsc_solver->snes();
  KSP ksp;
  SNESGetKSP(snes, &ksp);
  PCSide pcside = getPetscPCSide(nl.getPCSide());
#if PETSC_VERSION_LESS_THAN(3,2,0)
  // PETSc 3.1.x-
  KSPSetPreconditionerSide(ksp, pcside);
#else
  // PETSc 3.2.x+
  KSPSetPCSide(ksp, pcside);
#endif
  SNESSetMaxLinearSolveFailures(snes, 1000000);

#if PETSC_VERSION_LESS_THAN(3,0,0)
  // PETSc 2.3.3-
  KSPSetConvergenceTest(ksp, petscConverged, &problem);
  SNESSetConvergenceTest(snes, petscNonlinearConverged, &problem);
#else
  // PETSc 3.0.0+

  // In 3.0.0, the context pointer must actually be used, and the
  // final argument to KSPSetConvergenceTest() is a pointer to a
  // routine for destroying said private data context.  In this case,
  // we use the default context provided by PETSc in addition to
  // a few other tests.
  {
    PetscErrorCode ierr = KSPSetConvergenceTest(ksp,
                                                petscConverged,
                                                &problem,
                                                PETSC_NULL);
    CHKERRABORT(nl.comm().get(),ierr);
    ierr = SNESSetConvergenceTest(snes,
                                  petscNonlinearConverged,
                                  &problem,
                                  PETSC_NULL);
    CHKERRABORT(nl.comm().get(),ierr);
  }
#endif
}
Beispiel #6
0
void petscSetupDampers(NonlinearImplicitSystem& sys)
{
  FEProblem * problem = sys.get_equation_systems().parameters.get<FEProblem *>("_fe_problem");
  NonlinearSystem & nl = problem->getNonlinearSystem();
  PetscNonlinearSolver<Number> * petsc_solver = dynamic_cast<PetscNonlinearSolver<Number> *>(nl.sys().nonlinear_solver.get());
  SNES snes = petsc_solver->snes();

#if PETSC_VERSION_LESS_THAN(3,3,0)
  // PETSc 3.2.x-
  SNESLineSearchSetPostCheck(snes, dampedCheck, problem);
#else
  // PETSc 3.3.0+
  SNESLineSearch linesearch;
#if PETSC_VERSION_LESS_THAN(3,4,0)
  PetscErrorCode ierr = SNESGetSNESLineSearch(snes, &linesearch);
#else
  PetscErrorCode ierr = SNESGetLineSearch(snes, &linesearch);
#endif
  CHKERRABORT(problem->comm().get(),ierr);

  ierr = SNESLineSearchSetPostCheck(linesearch, dampedCheck, problem);
  CHKERRABORT(problem->comm().get(),ierr);
#endif
}
Beispiel #7
0
std::string
outputNonlinearSystemInformation(FEProblem & problem)
{
  return outputSystemInformationHelper(problem.getNonlinearSystem().system());
}