20 #include "libmesh/libmesh_common.h"    22 #ifdef LIBMESH_HAVE_PETSC    25 #include "libmesh/libmesh_logging.h"    26 #include "libmesh/nonlinear_implicit_system.h"    27 #include "libmesh/petsc_nonlinear_solver.h"    28 #include "libmesh/petsc_linear_solver.h"    29 #include "libmesh/petsc_vector.h"    30 #include "libmesh/petsc_mffd_matrix.h"    31 #include "libmesh/dof_map.h"    32 #include "libmesh/preconditioner.h"    33 #include "libmesh/solver_configuration.h"    34 #include "libmesh/petscdmlibmesh.h"    35 #include "libmesh/petsc_mffd_matrix.h"    37 #if defined(LIBMESH_HAVE_PETSC_HYPRE) && PETSC_VERSION_LESS_THAN(3, 23, 0) &&                      \    38     !PETSC_VERSION_LESS_THAN(3, 12, 0) && defined(PETSC_HAVE_HYPRE_DEVICE)    39 #include <HYPRE_utilities.h>    59   LOG_SCOPE(
"residual()", 
"PetscNonlinearSolver");
    68   libmesh_parallel_only(solver->
comm());
    74     PetscInt n_iterations = 0;
    75     LibmeshPetscCall2(solver->
comm(), SNESGetIterationNumber(snes, &n_iterations));
   125     LibmeshPetscCall2(solver->
comm(), SNESGetKSP(snes, &ksp));
   128     LibmeshPetscCall2(solver->
comm(), KSPGetIterationNumber(ksp, &niter));
   134       LibmeshPetscCall2(solver->
comm(), SNESSetLagPreconditioner(snes, -2));
   146                  << std::setw(2) << its
   148                  << 
", |residual|_2 = " << fnorm
   153 #ifdef LIBMESH_ENABLE_DEPRECATED   158     libmesh_deprecated();
   173     libmesh_parallel_only(rc.
sys.
comm());
   185                          "ERROR: cannot specify both a function and object to compute the Residual!");
   188                          "ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
   218       libmesh_error_msg(
"Error! Unable to compute residual and/or Jacobian!");
   225     X_global.
swap(X_sys);
   227     X_global.swap(X_sys);
   240 #ifdef LIBMESH_ENABLE_DEPRECATED   245     libmesh_deprecated();
   259     libmesh_parallel_only(rc.
sys.
comm());
   274       libmesh_error_msg(
"Error! Unable to compute residual for forming finite difference Jacobian!");
   280     X_global.
swap(X_sys);
   282     X_global.swap(X_sys);
   295 #ifdef LIBMESH_ENABLE_DEPRECATED   300     libmesh_deprecated();
   315     libmesh_parallel_only(rc.
sys.
comm());
   330       libmesh_error_msg(
"Error! Unable to compute residual for forming finite differenced"   331                         "Jacobian-vector products!");
   337     X_global.
swap(X_sys);
   339     X_global.swap(X_sys);
   366 #if !PETSC_VERSION_LESS_THAN(3,8,4)   373       SNES snes = solver->
snes();
   376       LibmeshPetscCall2(solver->
comm(), SNESGetKSP(snes, &ksp));
   379       LibmeshPetscCall2(solver->
comm(), KSPGetIterationNumber(ksp, &ksp_it));
   382       LibmeshPetscCall2(solver->
comm(), SNESGetType(snes, &snes_type));
   384       libmesh_assert_msg(snes_type, 
"We're being called from SNES; snes_type should be non-null");
   387       LibmeshPetscCall2(solver->
comm(), SNESGetJacobian(snes, &J, NULL, NULL, NULL));
   388       libmesh_assert_msg(J, 
"We're being called from SNES; J should be non-null");
   391       LibmeshPetscCall2(solver->
comm(), MatGetType(J, &mat_type));
   392       libmesh_assert_msg(mat_type, 
"We're being called from SNES; mat_type should be non-null");
   394       bool is_operator_mffd = strcmp(mat_type, MATMFFD) == 0;
   396       if ((ksp_it == PetscInt(0)) && is_operator_mffd)
   400         if (computing_base_vector)
   402           Vec nonlinear_residual;
   404           LibmeshPetscCall2(solver->
comm(), SNESGetFunction(snes, &nonlinear_residual, NULL, NULL));
   406           PetscBool vecs_equal;
   407           LibmeshPetscCall2(solver->
comm(), VecEqual(r, nonlinear_residual, &vecs_equal));
   409           libmesh_error_msg_if(!(vecs_equal == PETSC_TRUE),
   410                                "You requested to reuse the nonlinear residual vector as the base vector for "   411                                "computing the action of the matrix-free Jacobian, but the vectors are not "   412                                "the same. Your physics must have states; either remove the states "   413                                "from your code or make sure that you set_mf_reuse_base(false)");
   429 #ifdef LIBMESH_ENABLE_DEPRECATED   434     libmesh_deprecated();
   446     LOG_SCOPE(
"jacobian()", 
"PetscNonlinearSolver");
   454     libmesh_parallel_only(solver->
comm());
   460       PetscInt n_iterations = 0;
   461       LibmeshPetscCall2(solver->
comm(), SNESGetIterationNumber(snes, &n_iterations));
   469                          "ERROR: cannot specify both a function and object to compute the Jacobian!");
   472                          "ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
   482     PetscBool p_is_shell = PETSC_FALSE;
   483     PetscBool j_is_mffd = PETSC_FALSE;
   484     PetscBool j_is_shell = PETSC_FALSE;
   486       LibmeshPetscCall2(sys.
comm(), PetscObjectTypeCompare((PetscObject)pc, MATSHELL, &p_is_shell));
   488     LibmeshPetscCall2(sys.
comm(), PetscObjectTypeCompare((PetscObject)jac, MATMFFD, &j_is_mffd));
   489     LibmeshPetscCall2(sys.
comm(), PetscObjectTypeCompare((PetscObject)jac, MATSHELL, &j_is_shell));
   490     if (j_is_mffd == PETSC_TRUE)
   502       if ((j_is_shell == PETSC_TRUE) || (j_is_mffd == PETSC_TRUE))
   505       if (pc && (p_is_shell == PETSC_TRUE))
   516     X_global.swap(X_sys);
   518     X_global.swap(X_sys);
   537     else if (solver->
matvec != 
nullptr)
   541       libmesh_error_msg(
"Error! Unable to compute residual and/or Jacobian!");
   554                        (j_is_shell == PETSC_TRUE));
   575     libmesh_parallel_only(solver->
comm());
   581 #ifdef LIBMESH_ENABLE_DEPRECATED   586     libmesh_deprecated();
   605     LOG_SCOPE(
"postcheck()", 
"PetscNonlinearSolver");
   609     *changed_w = PETSC_FALSE;
   610     *changed_y = PETSC_FALSE;
   618     libmesh_parallel_only(solver->
comm());
   623                          "ERROR: cannot specify both a function and object for performing the solve postcheck!");
   638       changed_search_direction = 
false,
   639       changed_new_soln = 
false;
   650                             changed_search_direction,
   658                                               changed_search_direction,
   664     if (changed_search_direction)
   665       *changed_y = PETSC_TRUE;
   667     if (changed_new_soln)
   668       *changed_w = PETSC_TRUE;
   673 #ifdef LIBMESH_ENABLE_DEPRECATED   677     libmesh_deprecated();
   686     LOG_SCOPE(
"precheck()", 
"PetscNonlinearSolver");
   690     *changed = PETSC_FALSE;
   698     libmesh_parallel_only(solver->
comm());
   708       petsc_changed = 
false;
   710     auto & sys = solver->
system();
   711     auto & x_sys = *cast_ptr<PetscVector<Number> *>(sys.solution.get());
   725     auto & local_soln = *sys.current_local_solution.get();
   727       sys.get_dof_map().enforce_constraints_exactly(sys, &local_soln);
   736       *changed = PETSC_TRUE;
   747 template <
typename T>
   750   linesearch_object(nullptr),
   751   _reason(SNES_CONVERGED_ITERATING), 
   752   _n_linear_iterations(0),
   753   _current_nonlinear_iteration_number(0),
   754   _zero_out_residual(true),
   755   _zero_out_jacobian(true),
   756   _default_monitor(true),
   757   _snesmf_reuse_base(true),
   758   _computing_base_vector(true),
   760   _mffd_jac(this->_communicator)
   766 template <
typename T>
   771 template <
typename T>
   781       if (!(reuse_preconditioner()))
   792       _current_nonlinear_iteration_number = 0;
   796 template <
typename T>
   799   parallel_object_only();
   809         LibmeshPetscCall(SNESCreate(this->comm().
get(), _snes.get()));
   818           LibmeshPetscCall(SNESSetOptionsPrefix(_snes, 
name));
   822 #if defined(LIBMESH_ENABLE_AMR) && defined(LIBMESH_HAVE_METAPHYSICL)   824           "--" + (
name ? std::string(
name) : std::string(
"")) + 
"use_petsc_dm");
   828         this->_dm_wrapper.init_and_attach_petscdm(this->system(), _snes);
   833         LibmeshPetscCall(DMCreate(this->comm().
get(), dm.
get()));
   834         LibmeshPetscCall(DMSetType(dm, DMLIBMESH));
   838           LibmeshPetscCall(DMSetOptionsPrefix(dm, 
name));
   840         LibmeshPetscCall(DMSetFromOptions(dm));
   841         LibmeshPetscCall(DMSetUp(dm));
   842         LibmeshPetscCall(SNESSetDM(_snes, dm));
   846       setup_default_monitor();
   850       if (this->_solver_configuration)
   852           this->_solver_configuration->set_options_during_init();
   855       if (this->_preconditioner)
   858           LibmeshPetscCall(SNESGetKSP (_snes, &ksp));
   860           LibmeshPetscCall(KSPGetPC(ksp,&pc));
   862           this->_preconditioner->init();
   864           LibmeshPetscCall(PCSetType(pc, PCSHELL));
   865           LibmeshPetscCall(PCShellSetContext(pc,(
void *)this->_preconditioner));
   878   if (this->postcheck || this->postcheck_object)
   880       SNESLineSearch linesearch;
   881       LibmeshPetscCall(SNESGetLineSearch(_snes, &linesearch));
   886   if (this->precheck_object)
   888       SNESLineSearch linesearch;
   889       LibmeshPetscCall(SNESGetLineSearch(_snes, &linesearch));
   896 template <
typename T>
   905 template <
typename T>
   911   parallel_object_only();
   913   std::vector<NumericVector<Number> *> sp;
   914   if (computeSubspaceObject)
   915     (*computeSubspaceObject)(sp, this->system());
   917     (*computeSubspace)(sp, this->system());
   919   *msp = LIBMESH_PETSC_NULLPTR;
   922       PetscInt nmodes = cast_int<PetscInt>(sp.size());
   924       std::vector<Vec> modes(nmodes);
   925       std::vector<PetscScalar> dots(nmodes);
   927       for (PetscInt i=0; i<nmodes; ++i)
   929           auto pv = cast_ptr<PetscVector<T> *>(sp[i]);
   931           LibmeshPetscCall(VecDuplicate(pv->vec(), &modes[i]));
   933           LibmeshPetscCall(VecCopy(pv->vec(), modes[i]));
   937       LibmeshPetscCall(VecNormalize(modes[0], LIBMESH_PETSC_NULLPTR));
   939       for (PetscInt i=1; i<nmodes; i++)
   942           LibmeshPetscCall(VecMDot(modes[i], i, modes.data(), dots.data()));
   944           for (PetscInt j=0; j<i; j++)
   947           LibmeshPetscCall(VecMAXPY(modes[i], i, dots.data(), modes.data()));
   949           LibmeshPetscCall(VecNormalize(modes[i], LIBMESH_PETSC_NULLPTR));
   952       LibmeshPetscCall(MatNullSpaceCreate(this->comm().
get(), PETSC_FALSE, nmodes, modes.data(), msp));
   954       for (PetscInt i=0; i<nmodes; ++i)
   955         LibmeshPetscCall(VecDestroy(&modes[i]));
   959 template <
typename T>
   960 std::pair<unsigned int, Real>
   967   parallel_object_only();
   969   LOG_SCOPE(
"solve()", 
"PetscNonlinearSolver");
   977   PetscInt n_iterations =0;
   979   Real final_residual_norm=0.;
   983   if ((reuse_preconditioner()) && (!_setup_reuse))
   986       LibmeshPetscCall(SNESSetLagPreconditionerPersists(_snes, PETSC_TRUE));
   989       LibmeshPetscCall(SNESSetLagPreconditioner(_snes, -2));
   996   else if (!(reuse_preconditioner()))
   999       LibmeshPetscCall(SNESSetLagPreconditionerPersists(_snes, PETSC_FALSE));
  1002           _setup_reuse = 
false;
  1003           LibmeshPetscCall(SNESMonitorCancel(_snes));
  1005           setup_default_monitor();
  1013   if (this->jacobian || this->jacobian_object || this->residual_and_jacobian_object)
  1018   LibmeshPetscCall(SNESGetKSP (_snes, &ksp));
  1022   LibmeshPetscCall(KSPSetTolerances (ksp, this->initial_linear_tolerance, PETSC_DEFAULT,
  1023                                      PETSC_DEFAULT, this->max_linear_iterations));
  1026   LibmeshPetscCall(SNESSetTolerances(_snes,
  1027                                      this->absolute_residual_tolerance,
  1028                                      this->relative_residual_tolerance,
  1029                                      this->relative_step_tolerance,
  1030                                      this->max_nonlinear_iterations,
  1031                                      this->max_function_evaluations));
  1034 #if !PETSC_VERSION_LESS_THAN(3,8,0)  1035   LibmeshPetscCall(SNESSetDivergenceTolerance(_snes, this->divergence_tolerance));
  1039 #if PETSC_VERSION_LESS_THAN(3,7,0)  1040   LibmeshPetscCall(KSPSetFromOptions(ksp));
  1042   LibmeshPetscCall(SNESSetFromOptions(_snes));
  1044 #if defined(LIBMESH_HAVE_PETSC_HYPRE) && PETSC_VERSION_LESS_THAN(3, 23, 0) &&                      \  1045     !PETSC_VERSION_LESS_THAN(3, 12, 0) && defined(PETSC_HAVE_HYPRE_DEVICE)  1048     LibmeshPetscCallExternal(HYPRE_Initialize);
  1049     PetscScalar * dummyarray;
  1051     LibmeshPetscCall(VecGetArrayAndMemType(x->vec(), &dummyarray, &mtype));
  1052     LibmeshPetscCall(VecRestoreArrayAndMemType(x->vec(), &dummyarray));
  1053     if (PetscMemTypeHost(mtype))
  1054       LibmeshPetscCallExternal(HYPRE_SetMemoryLocation, HYPRE_MEMORY_HOST);
  1058   if (this->user_presolve)
  1059     this->user_presolve(this->system());
  1062   if (this->_preconditioner)
  1064       this->_preconditioner->set_matrix(pre_in);
  1065       this->_preconditioner->init();
  1070   if (this->_solver_configuration)
  1071     this->_solver_configuration->configure_solver();
  1085 #if !PETSC_VERSION_LESS_THAN(3,6,0)  1086   LibmeshPetscCall(SNESSetSolution(_snes, x->vec()));
  1088   LibmeshPetscCall(SNESSetUp(_snes));
  1091   LibmeshPetscCall(SNESGetJacobian(_snes, &J, &P,
  1092                                    LIBMESH_PETSC_NULLPTR,
  1093                                    LIBMESH_PETSC_NULLPTR));
  1095 #if !PETSC_VERSION_LESS_THAN(3,8,4)  1102   LibmeshPetscCall(MatSNESMFSetReuseBase(J, PETSC_FALSE));
  1105   LibmeshPetscCall(MatSNESMFSetReuseBase(J, static_cast<PetscBool>(_snesmf_reuse_base)));
  1110   if (this->nullspace || this->nullspace_object)
  1113       this->build_mat_null_space(this->nullspace_object, this->nullspace, msp.
get());
  1116           LibmeshPetscCall(MatSetNullSpace(J, msp));
  1118             LibmeshPetscCall(MatSetNullSpace(P, msp));
  1123   if (this->transpose_nullspace || this->transpose_nullspace_object)
  1125 #if PETSC_VERSION_LESS_THAN(3,6,0)  1126       libmesh_warning(
"MatSetTransposeNullSpace is only supported for PETSc >= 3.6, transpose nullspace will be ignored.");
  1129       this->build_mat_null_space(this->transpose_nullspace_object, this->transpose_nullspace, msp.
get());
  1132           LibmeshPetscCall(MatSetTransposeNullSpace(J, msp));
  1134             LibmeshPetscCall(MatSetTransposeNullSpace(P, msp));
  1140   if (this->nearnullspace || this->nearnullspace_object)
  1143       this->build_mat_null_space(this->nearnullspace_object, this->nearnullspace, msp.
get());
  1147           LibmeshPetscCall(MatSetNearNullSpace(J, msp));
  1149             LibmeshPetscCall(MatSetNearNullSpace(P, msp));
  1153   SNESLineSearch linesearch;
  1154   if (linesearch_object)
  1156     LibmeshPetscCall(SNESGetLineSearch(_snes, &linesearch));
  1157     LibmeshPetscCall(SNESLineSearchSetType(linesearch, SNESLINESEARCHSHELL));
  1158 #if PETSC_RELEASE_GREATER_EQUALS(3, 21, 0)  1165   LibmeshPetscCall(SNESSolve (_snes, LIBMESH_PETSC_NULLPTR, x->vec()));
  1167   LibmeshPetscCall(SNESGetIterationNumber(_snes, &n_iterations));
  1169   LibmeshPetscCall(SNESGetLinearSolveIterations(_snes, &_n_linear_iterations));
  1176   LibmeshPetscCall(SNESGetFunction(_snes, &f, 0, 0));
  1177   LibmeshPetscCall(VecNorm(f, NORM_2, 
pPR(&final_residual_norm)));
  1180   LibmeshPetscCall(SNESGetConvergedReason(_snes, &_reason));
  1183   this->converged = (_reason >= 0);
  1189   return std::make_pair(n_iterations, final_residual_norm);
  1194 template <
typename T>
  1198   libMesh::out << 
"Nonlinear solver convergence/divergence reason: "  1199                << SNESConvergedReasons[this->get_converged_reason()] << std::endl;
  1204 template <
typename T>
  1208     LibmeshPetscCall(SNESGetConvergedReason(_snes, &_reason));
  1213 template <
typename T>
  1216   return _n_linear_iterations;
  1219 template <
typename T>
  1222   if (_default_monitor)
  1227 template <
typename T>
  1230   return this->_reuse_preconditioner;
  1233 template <
typename T>
  1236   return this->_reuse_preconditioner_max_linear_its;
  1239 template <
typename T>
  1245   _setup_reuse = 
false;
  1256 #endif // #ifdef LIBMESH_HAVE_PETSC unsigned _current_nonlinear_iteration_number
Stores the current nonlinear iteration number. 
std::string name(const ElemQuality q)
This function returns a string containing some name for q. 
PetscNonlinearSolver< Number > * solver
SNES snes(const char *name=nullptr)
This class provides a nice interface to PETSc's Vec object. 
PetscErrorCode __libmesh_petsc_snes_jacobian(SNES, Vec x, Mat jac, Mat pc, void *ctx)
void(* residual)(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)
Function that computes the residual R(X) of the nonlinear system at the input iterate X...
virtual unsigned int reuse_preconditioner_max_linear_its() const override
Getter for the maximum iterations flag for preconditioner reuse. 
NonlinearImplicitSystem::ComputeResidualandJacobian * residual_and_jacobian_object
Object that computes either the residual  or the Jacobian  of the nonlinear system at the input itera...
virtual void residual(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)=0
Residual function. 
PetscErrorCode libmesh_petsc_snes_fd_residual(SNES, Vec x, Vec r, void *ctx)
virtual void zero() override
Set all entries to zero. 
PetscNonlinearSolver(sys_type &system)
Constructor. 
PETSC_EXTERN PetscErrorCode DMlibMeshSetSystem(DM, libMesh::NonlinearImplicitSystem &)
Any functional implementation of the DMlibMesh API must compose the following functions with the DM o...
NonlinearImplicitSystem & sys
PetscErrorCode __libmesh_petsc_snes_monitor(SNES, PetscInt its, PetscReal fnorm, void *)
PetscErrorCode libmesh_petsc_preconditioner_apply(PC, Vec x, Vec y)
This function is called by PETSc to actually apply the preconditioner. 
const Parallel::Communicator & comm() const
This base class can be inherited from to provide interfaces to nonlinear solvers from different packa...
static PetscMatrixBase< T > * get_context(Mat mat, const TIMPI::Communicator &comm)
PetscErrorCode libmesh_petsc_snes_postcheck(SNESLineSearch, Vec x, Vec y, Vec w, PetscBool *changed_y, PetscBool *changed_w, void *context)
PetscErrorCode __libmesh_petsc_snes_residual(SNES, Vec x, Vec r, void *ctx)
bool _zero_out_residual
true to zero out residual before going into application level call-back, otherwise false ...
The libMesh namespace provides an interface to certain functionality in the library. 
NonlinearImplicitSystem::ComputeResidual * residual_object
Object that computes the residual R(X) of the nonlinear system at the input iterate X...
void(* jacobian)(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)
Function that computes the Jacobian J(X) of the nonlinear system at the input iterate X...
PetscErrorCode libmesh_petsc_snes_monitor(SNES, PetscInt its, PetscReal fnorm, void *)
PetscErrorCode __libmesh_petsc_snes_mffd_interface(void *ctx, Vec x, Vec r)
virtual void postcheck(const NumericVector< Number > &old_soln, NumericVector< Number > &search_direction, NumericVector< Number > &new_soln, bool &changed_search_direction, bool &changed_new_soln, sys_type &S)=0
This interface, which is inspired by PETSc's, passes the user: .) A constant reference to the "old" s...
virtual void swap(NumericVector< T > &v) override
Swaps the contents of this with v. 
bool snes_mf_reuse_base() const
PetscErrorCode libmesh_petsc_snes_mffd_residual(SNES snes, Vec x, Vec r, void *ctx)
void enforce_constraints_on_residual(const NonlinearImplicitSystem &system, NumericVector< Number > *rhs, NumericVector< Number > const *solution, bool homogeneous=true) const
processor_id_type size() const
const sys_type & system() const
NonlinearImplicitSystem::ComputeJacobian * jacobian_object
Object that computes the Jacobian J(X) of the nonlinear system at the input iterate X...
virtual void zero()=0
Set all entries to 0. 
bool _is_initialized
Flag that tells if init() has been called. 
bool _zero_out_jacobian
true to zero out jacobian before going into application level call-back, otherwise false ...
bool _exact_constraint_enforcement
Whether we should enforce exact constraints globally during a solve. 
virtual void jacobian(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)=0
Jacobian function. 
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values. 
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary. 
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
ResidualContext(PetscNonlinearSolver< Number > *solver_in, NonlinearImplicitSystem &sys_in)
ResidualContext libmesh_petsc_snes_residual_helper(SNES snes, Vec x, void *ctx)
PetscErrorCode __libmesh_petsc_snes_fd_residual(SNES, Vec x, Vec r, void *ctx)
virtual void close() override
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
PetscErrorCode libmesh_petsc_snes_mffd_interface(void *ctx, Vec x, Vec r)
void attach_dof_map(const DofMap &dof_map)
Set a pointer to the DofMap to use. 
virtual void update()
Update the local values to reflect the solution on neighboring processors. 
PetscErrorCode libmesh_petsc_preconditioner_setup(PC)
This function is called by PETSc to initialize the preconditioner. 
PetscErrorCode libmesh_petsc_linesearch_shellfunc(SNESLineSearch linesearch, void *ctx)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::unique_ptr< ComputeLineSearchObject > linesearch_object
A callable object that can be used to specify a custom line-search. 
NonlinearImplicitSystem::ComputePostCheck * postcheck_object
A callable object that is executed after each nonlinear iteration. 
PetscErrorCode libmesh_petsc_snes_jacobian(SNES, Vec x, Mat jac, Mat pc, void *ctx)
PetscErrorCode libmesh_petsc_snes_precheck(SNESLineSearch, Vec X, Vec Y, PetscBool *changed, void *context)
virtual void precheck(const NumericVector< Number > &precheck_soln, NumericVector< Number > &search_direction, bool &changed, sys_type &S)=0
Abstract precheck method that users must override. 
NonlinearImplicitSystem::ComputeResidual * mffd_residual_object
Object that computes the residual R(X) of the nonlinear system at the input iterate X for the purpose...
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand. 
bool initialized()
Checks that library initialization has been done. 
void(* postcheck)(const NumericVector< Number > &old_soln, NumericVector< Number > &search_direction, NumericVector< Number > &new_soln, bool &changed_search_direction, bool &changed_new_soln, sys_type &S)
Function that performs a "check" on the Newton search direction and solution after each nonlinear ste...
PetscErrorCode __libmesh_petsc_snes_postcheck(SNESLineSearch, Vec x, Vec y, Vec w, PetscBool *changed_y, PetscBool *changed_w, void *context)
bool on_command_line(std::string arg)
NonlinearImplicitSystem::ComputePreCheck * precheck_object
PetscFunctionReturn(LIBMESH_PETSC_SUCCESS)
void set_computing_base_vector(bool computing_base_vector)
Set whether we are computing the base vector for matrix-free finite-differencing. ...
const DofMap & get_dof_map() const
const SparseMatrix< Number > & get_system_matrix() const
PetscErrorCode libmesh_petsc_snes_residual(SNES, Vec x, Vec r, void *ctx)
virtual void residual_and_jacobian(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)=0
Residual & Jacobian function, calculated simultaneously. 
PetscErrorCode libmesh_petsc_recalculate_monitor(SNES snes, PetscInt it, PetscReal norm, void *mctx)
bool computing_base_vector() const
void(* matvec)(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)
Function that computes either the residual  or the Jacobian  of the nonlinear system at the input ite...
NonlinearImplicitSystem::ComputeResidual * fd_residual_object
Object that computes the residual R(X) of the nonlinear system at the input iterate X for the purpose...
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh. ...
Callable abstract base class to be used as a callback to provide the solver with a basis for the syst...
void enforce_constraints_on_jacobian(const NonlinearImplicitSystem &system, SparseMatrix< Number > *jac) const