Lines Matching refs:snes

36 PetscErrorCode SNESSetErrorIfNotConverged(SNES snes, PetscBool flg)  in SNESSetErrorIfNotConverged()  argument
39 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetErrorIfNotConverged()
40 PetscValidLogicalCollectiveBool(snes, flg, 2); in SNESSetErrorIfNotConverged()
41 snes->errorifnotconverged = flg; in SNESSetErrorIfNotConverged()
60 PetscErrorCode SNESGetErrorIfNotConverged(SNES snes, PetscBool *flag) in SNESGetErrorIfNotConverged() argument
63 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetErrorIfNotConverged()
65 *flag = snes->errorifnotconverged; in SNESGetErrorIfNotConverged()
86 PetscErrorCode SNESSetAlwaysComputesFinalResidual(SNES snes, PetscBool flg) in SNESSetAlwaysComputesFinalResidual() argument
89 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetAlwaysComputesFinalResidual()
90 snes->alwayscomputesfinalresidual = flg; in SNESSetAlwaysComputesFinalResidual()
109 PetscErrorCode SNESGetAlwaysComputesFinalResidual(SNES snes, PetscBool *flg) in SNESGetAlwaysComputesFinalResidual() argument
112 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetAlwaysComputesFinalResidual()
113 *flg = snes->alwayscomputesfinalresidual; in SNESGetAlwaysComputesFinalResidual()
148 PetscErrorCode SNESSetFunctionDomainError(SNES snes) in SNESSetFunctionDomainError() argument
151 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetFunctionDomainError()
152 snes->functiondomainerror = PETSC_TRUE; in SNESSetFunctionDomainError()
187 PetscErrorCode SNESSetObjectiveDomainError(SNES snes) in SNESSetObjectiveDomainError() argument
190 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetObjectiveDomainError()
191 snes->objectivedomainerror = PETSC_TRUE; in SNESSetObjectiveDomainError()
216 PetscErrorCode SNESSetJacobianDomainError(SNES snes) in SNESSetJacobianDomainError() argument
219 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetJacobianDomainError()
220 …PetscCheck(!snes->errorifnotconverged, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "User code indic… in SNESSetJacobianDomainError()
221 snes->jacobiandomainerror = PETSC_TRUE; in SNESSetJacobianDomainError()
244 PetscErrorCode SNESSetCheckJacobianDomainError(SNES snes, PetscBool flg) in SNESSetCheckJacobianDomainError() argument
247 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetCheckJacobianDomainError()
248 snes->checkjacdomainerror = flg; in SNESSetCheckJacobianDomainError()
267 PetscErrorCode SNESGetCheckJacobianDomainError(SNES snes, PetscBool *flg) in SNESGetCheckJacobianDomainError() argument
270 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetCheckJacobianDomainError()
272 *flg = snes->checkjacdomainerror; in SNESGetCheckJacobianDomainError()
293 PetscErrorCode SNESLoad(SNES snes, PetscViewer viewer) in SNESLoad() argument
303 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESLoad()
309 …PetscCheck(classid == SNES_FILE_CLASSID, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_WRONG, … in SNESLoad()
311 PetscCall(SNESSetType(snes, type)); in SNESLoad()
312 PetscTryTypeMethod(snes, load, viewer); in SNESLoad()
313 PetscCall(SNESGetDM(snes, &dm)); in SNESLoad()
316 PetscCall(SNESGetKSP(snes, &ksp)); in SNESLoad()
383 PetscErrorCode SNESView(SNES snes, PetscViewer viewer) in SNESView() argument
395 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESView()
396 if (!viewer) PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)snes), &viewer)); in SNESView()
398 PetscCheckSameComm(snes, 1, viewer, 2); in SNESView()
414 PetscCall(PetscObjectPrintClassNamePrefixType((PetscObject)snes, viewer)); in SNESView()
415 …if (!snes->setupcalled) PetscCall(PetscViewerASCIIPrintf(viewer, " SNES has not been set up so in… in SNESView()
416 if (snes->ops->view) { in SNESView()
418 PetscUseTypeMethod(snes, view, viewer); in SNESView()
421 if (snes->max_funcs == PETSC_UNLIMITED) { in SNESView()
422 … maximum iterations=%" PetscInt_FMT ", maximum function evaluations=unlimited\n", snes->max_its)); in SNESView()
424 …PetscInt_FMT ", maximum function evaluations=%" PetscInt_FMT "\n", snes->max_its, snes->max_funcs)… in SNESView()
426 …s: relative=%g, absolute=%g, solution=%g\n", (double)snes->rtol, (double)snes->abstol, (double)sne… in SNESView()
427 …if (snes->usesksp) PetscCall(PetscViewerASCIIPrintf(viewer, " total number of linear solver itera… in SNESView()
428 …erASCIIPrintf(viewer, " total number of function evaluations=%" PetscInt_FMT "\n", snes->nfuncs)); in SNESView()
429 PetscCall(SNESGetNormSchedule(snes, &normschedule)); in SNESView()
431 …if (snes->gridsequence) PetscCall(PetscViewerASCIIPrintf(viewer, " total number of grid sequence … in SNESView()
432 if (snes->ksp_ewconv) { in SNESView()
433 kctx = (SNESKSPEW *)snes->kspconvctx; in SNESView()
440 if (snes->lagpreconditioner == -1) { in SNESView()
442 } else if (snes->lagpreconditioner > 1) { in SNESView()
443 …r, " Preconditioned is rebuilt every %" PetscInt_FMT " new Jacobians\n", snes->lagpreconditioner)… in SNESView()
445 if (snes->lagjacobian == -1) { in SNESView()
447 } else if (snes->lagjacobian > 1) { in SNESView()
448 …ntf(viewer, " Jacobian is rebuilt every %" PetscInt_FMT " SNES iterations\n", snes->lagjacobian)); in SNESView()
450 PetscCall(SNESGetDM(snes, &dm)); in SNESView()
452 if (snes->mf_operator) { in SNESView()
469 } else if (snes->mf && !snes->mf_operator) { in SNESView()
474 PetscCall(SNESGetType(snes, &type)); in SNESView()
476 PetscTryTypeMethod(snes, view, viewer); in SNESView()
483 PetscCall(PetscObjectGetComm((PetscObject)snes, &comm)); in SNESView()
487 PetscCall(PetscStrncpy(type, ((PetscObject)snes)->type_name, sizeof(type))); in SNESView()
490 PetscTryTypeMethod(snes, view, viewer); in SNESView()
499 PetscCall(PetscStrlcat(str, ((PetscObject)snes)->type_name, sizeof(str))); in SNESView()
503 PetscTryTypeMethod(snes, view, viewer); in SNESView()
509 PetscCall(PetscObjectGetName((PetscObject)snes, &name)); in SNESView()
511 if (!((PetscObject)snes)->amsmem && rank == 0) { in SNESView()
514 PetscCall(PetscObjectViewSAWs((PetscObject)snes, viewer)); in SNESView()
516 PetscCallSAWs(SAWs_Register, (dir, &snes->iter, 1, SAWs_READ, SAWs_INT)); in SNESView()
517 …if (!snes->conv_hist) PetscCall(SNESSetConvergenceHistory(snes, NULL, NULL, PETSC_DECIDE, PETSC_TR… in SNESView()
519 PetscCallSAWs(SAWs_Register, (dir, snes->conv_hist, 10, SAWs_READ, SAWs_DOUBLE)); in SNESView()
523 if (snes->linesearch) { in SNESView()
524 PetscCall(SNESGetLineSearch(snes, &linesearch)); in SNESView()
529 if (snes->npc && snes->usesnpc) { in SNESView()
531 PetscCall(SNESView(snes->npc, viewer)); in SNESView()
535 PetscCall(DMGetDMSNES(snes->dm, &dmsnes)); in SNESView()
538 if (snes->usesksp) { in SNESView()
539 PetscCall(SNESGetKSP(snes, &ksp)); in SNESView()
575 PetscErrorCode SNESAddOptionsChecker(PetscErrorCode (*snescheck)(SNES snes)) in SNESAddOptionsChecker() argument
583 static PetscErrorCode SNESSetUpMatrixFree_Private(SNES snes, PetscBool hasOperator, PetscInt versio… in SNESSetUpMatrixFree_Private() argument
589 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetUpMatrixFree_Private()
591 if (!snes->vec_func && (snes->jacobian || snes->jacobian_pre)) { in SNESSetUpMatrixFree_Private()
592 Mat A = snes->jacobian, B = snes->jacobian_pre; in SNESSetUpMatrixFree_Private()
593 PetscCall(MatCreateVecs(A ? A : B, NULL, &snes->vec_func)); in SNESSetUpMatrixFree_Private()
598 PetscCall(MatCreateSNESMF(snes, &J)); in SNESSetUpMatrixFree_Private()
599 PetscCall(MatMFFDSetOptionsPrefix(J, ((PetscObject)snes)->prefix)); in SNESSetUpMatrixFree_Private()
603 …PetscCheck(snes->vec_func, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "SNESSetFunction() must be c… in SNESSetUpMatrixFree_Private()
605 PetscCall(MatCreateSNESMFMore(snes, snes->vec_func, &J)); in SNESSetUpMatrixFree_Private()
612 if (snes->jacobian) { in SNESSetUpMatrixFree_Private()
613 PetscCall(MatGetNullSpace(snes->jacobian, &nullsp)); in SNESSetUpMatrixFree_Private()
617 …PetscCall(PetscInfo(snes, "Setting default matrix-free operator routines (version %" PetscInt_FMT … in SNESSetUpMatrixFree_Private()
621 PetscCall(SNESSetJacobian(snes, J, NULL, NULL, NULL)); in SNESSetUpMatrixFree_Private()
625 if (snes->npcside == PC_LEFT && snes->npc) { in SNESSetUpMatrixFree_Private()
626 if (!snes->jacobian) PetscCall(SNESSetJacobian(snes, J, NULL, NULL, NULL)); in SNESSetUpMatrixFree_Private()
632 PetscCall(SNESSetJacobian(snes, J, J, MatMFFDComputeJacobian, NULL)); in SNESSetUpMatrixFree_Private()
634 PetscCall(SNESGetKSP(snes, &ksp)); in SNESSetUpMatrixFree_Private()
638 …PetscCall(PetscInfo(snes, "Setting default matrix-free preconditioner routines\nThat is no precond… in SNESSetUpMatrixFree_Private()
649 SNES snes = (SNES)ctx; in DMRestrictHook_SNESVecSol() local
661 if (dmfine == snes->dm) Xfine = snes->vec_sol; in DMRestrictHook_SNESVecSol()
689 SNES snes = (SNES)ctx; in KSPComputeOperators_SNES() local
697 dmsave = snes->dm; in KSPComputeOperators_SNES()
698 PetscCall(KSPGetDM(ksp, &snes->dm)); in KSPComputeOperators_SNES()
699 if (dmsave == snes->dm) X = snes->vec_sol; /* We are on the finest level */ in KSPComputeOperators_SNES()
704 PetscCall(DMHasNamedGlobalVector(snes->dm, "SNESVecSol", &has)); in KSPComputeOperators_SNES()
705 PetscCheck(has, PetscObjectComm((PetscObject)snes->dm), PETSC_ERR_PLIB, "Missing SNESVecSol"); in KSPComputeOperators_SNES()
706 PetscCall(DMGetNamedGlobalVector(snes->dm, "SNESVecSol", &Xnamed)); in KSPComputeOperators_SNES()
708 PetscCall(SNESGetJacobian(snes, NULL, NULL, &jac, &ctxsave)); in KSPComputeOperators_SNES()
710 …if (jac == SNESComputeJacobianDefaultColor) PetscCall(SNESSetJacobian(snes, NULL, NULL, SNESComput… in KSPComputeOperators_SNES()
714 PetscCall(DMGetDMSNES(snes->dm, &sdm)); in KSPComputeOperators_SNES()
718 Vec F, saverhs = snes->vec_rhs; in KSPComputeOperators_SNES()
720 snes->vec_rhs = NULL; in KSPComputeOperators_SNES()
721 PetscCall(DMGetGlobalVector(snes->dm, &F)); in KSPComputeOperators_SNES()
722 PetscCall(SNESComputeFunction(snes, X, F)); in KSPComputeOperators_SNES()
723 PetscCall(DMRestoreGlobalVector(snes->dm, &F)); in KSPComputeOperators_SNES()
724 snes->vec_rhs = saverhs; in KSPComputeOperators_SNES()
725 snes->nfuncs--; /* Do not log coarser level evaluations */ in KSPComputeOperators_SNES()
728 if (!sdm->ops->computejacobian) PetscCall(DMCopyDMSNES(dmsave, snes->dm)); in KSPComputeOperators_SNES()
729 …PetscCall(SNESComputeJacobian(snes, X, A, B)); /* cannot handle previous SNESSetJacobianDomainErro… in KSPComputeOperators_SNES()
732 …if (snes->dm != dmsave && jac == SNESComputeJacobianDefaultColor) PetscCall(SNESSetJacobian(snes, … in KSPComputeOperators_SNES()
734 if (Xnamed) PetscCall(DMRestoreNamedGlobalVector(snes->dm, "SNESVecSol", &Xnamed)); in KSPComputeOperators_SNES()
735 snes->dm = dmsave; in KSPComputeOperators_SNES()
759 PetscErrorCode SNESSetUpMatrices(SNES snes) in SNESSetUpMatrices() argument
765 PetscCall(SNESGetDM(snes, &dm)); in SNESSetUpMatrices()
767 if (!snes->jacobian && snes->mf && !snes->mf_operator && !snes->jacobian_pre) { in SNESSetUpMatrices()
770 PetscCall(MatCreateSNESMF(snes, &J)); in SNESSetUpMatrices()
771 PetscCall(MatMFFDSetOptionsPrefix(J, ((PetscObject)snes)->prefix)); in SNESSetUpMatrices()
773 PetscCall(SNESGetFunction(snes, NULL, NULL, &functx)); in SNESSetUpMatrices()
774 PetscCall(SNESSetJacobian(snes, J, J, NULL, NULL)); in SNESSetUpMatrices()
776 } else if (snes->mf_operator && !snes->jacobian_pre && !snes->jacobian) { in SNESSetUpMatrices()
778 PetscCall(MatCreateSNESMF(snes, &J)); in SNESSetUpMatrices()
779 PetscCall(MatMFFDSetOptionsPrefix(J, ((PetscObject)snes)->prefix)); in SNESSetUpMatrices()
781 PetscCall(DMCreateMatrix(snes->dm, &B)); in SNESSetUpMatrices()
783 PetscCall(SNESSetJacobian(snes, J, B, NULL, NULL)); in SNESSetUpMatrices()
786 } else if (!snes->jacobian_pre) { in SNESSetUpMatrices()
791 J = snes->jacobian; in SNESSetUpMatrices()
795 else if (hasPrec) PetscCall(DMCreateMatrix(snes->dm, &J)); in SNESSetUpMatrices()
796 PetscCall(DMCreateMatrix(snes->dm, &B)); in SNESSetUpMatrices()
797 PetscCall(SNESSetJacobian(snes, J ? J : B, B, NULL, NULL)); in SNESSetUpMatrices()
803 PetscCall(SNESGetKSP(snes, &ksp)); in SNESSetUpMatrices()
804 PetscCall(KSPSetComputeOperators(ksp, KSPComputeOperators_SNES, snes)); in SNESSetUpMatrices()
805 … PetscCall(DMCoarsenHookAdd(snes->dm, DMCoarsenHook_SNESVecSol, DMRestrictHook_SNESVecSol, snes)); in SNESSetUpMatrices()
812 static PetscErrorCode SNESMonitorPauseFinal_Internal(SNES snes) in SNESMonitorPauseFinal_Internal() argument
815 if (!snes->pauseFinal) PetscFunctionReturn(PETSC_SUCCESS); in SNESMonitorPauseFinal_Internal()
816 PetscCall(PetscMonitorPauseFinal_Internal(snes->numbermonitors, snes->monitorcontext)); in SNESMonitorPauseFinal_Internal()
856snes, const char name[], const char help[], const char manual[], PetscErrorCode (*monitor)(SNES sn… in SNESMonitorSetFromOptions() argument
863 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESMonitorSetFromOptions()
868 if (monitorsetup) PetscCall((*monitorsetup)(snes, vf)); in SNESMonitorSetFromOptions()
869 …PetscCall(SNESMonitorSet(snes, (PetscErrorCode (*)(SNES, PetscInt, PetscReal, PetscCtx))monitor, v… in SNESMonitorSetFromOptions()
959 PetscErrorCode SNESSetFromOptions(SNES snes) in SNESSetFromOptions() argument
972 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetFromOptions()
974 PetscObjectOptionsBegin((PetscObject)snes); in SNESSetFromOptions()
975 if (((PetscObject)snes)->type_name) deft = ((PetscObject)snes)->type_name; in SNESSetFromOptions()
978 PetscCall(SNESSetType(snes, type)); in SNESSetFromOptions()
979 } else if (!((PetscObject)snes)->type_name) { in SNESSetFromOptions()
980 PetscCall(SNESSetType(snes, deft)); in SNESSetFromOptions()
983 abstol = snes->abstol; in SNESSetFromOptions()
984 rtol = snes->rtol; in SNESSetFromOptions()
985 stol = snes->stol; in SNESSetFromOptions()
986 max_its = snes->max_its; in SNESSetFromOptions()
987 max_funcs = snes->max_funcs; in SNESSetFromOptions()
988 …tol", "Stop if decrease in function norm less than", "SNESSetTolerances", snes->rtol, &rtol, NULL)… in SNESSetFromOptions()
989 …eal("-snes_atol", "Stop if function norm less than", "SNESSetTolerances", snes->abstol, &abstol, N… in SNESSetFromOptions()
990 …sReal("-snes_stol", "Stop if step length less than", "SNESSetTolerances", snes->stol, &stol, NULL)… in SNESSetFromOptions()
991 …PetscCall(PetscOptionsInt("-snes_max_it", "Maximum iterations", "SNESSetTolerances", snes->max_its… in SNESSetFromOptions()
992 …t("-snes_max_funcs", "Maximum function evaluations", "SNESSetTolerances", snes->max_funcs, &max_fu… in SNESSetFromOptions()
993 PetscCall(SNESSetTolerances(snes, abstol, rtol, stol, max_its, max_funcs)); in SNESSetFromOptions()
995 …dual norm increases by this factor", "SNESSetDivergenceTolerance", snes->divtol, &snes->divtol, &f… in SNESSetFromOptions()
996 if (flg) PetscCall(SNESSetDivergenceTolerance(snes, snes->divtol)); in SNESSetFromOptions()
998 …um nonlinear step failures", "SNESSetMaxNonlinearStepFailures", snes->maxFailures, &snes->maxFailu… in SNESSetFromOptions()
999 if (flg) PetscCall(SNESSetMaxNonlinearStepFailures(snes, snes->maxFailures)); in SNESSetFromOptions()
1001 …n linear solves allowed", "SNESSetMaxLinearSolveFailures", snes->maxLinearSolveFailures, &snes->ma… in SNESSetFromOptions()
1002 if (flg) PetscCall(SNESSetMaxLinearSolveFailures(snes, snes->maxLinearSolveFailures)); in SNESSetFromOptions()
1004 …if solver does not converge", "SNESSetErrorIfNotConverged", snes->errorifnotconverged, &snes->erro… in SNESSetFromOptions()
1005 …ve() to take at least one iteration", "SNESSetForceIteration", snes->forceiteration, &snes->forcei… in SNESSetFromOptions()
1006 …after Jacobian evaluation", "SNESCheckJacobianDomainError", snes->checkjacdomainerror, &snes->chec… in SNESSetFromOptions()
1008 …oner", "How often to rebuild preconditioner", "SNESSetLagPreconditioner", snes->lagpreconditioner,… in SNESSetFromOptions()
1010 …PetscCheck(lag != -1, PetscObjectComm((PetscObject)snes), PETSC_ERR_USER, "Cannot set the lag to -… in SNESSetFromOptions()
1011 PetscCall(SNESSetLagPreconditioner(snes, lag)); in SNESSetFromOptions()
1013 …agging through multiple SNES solves", "SNESSetLagPreconditionerPersists", snes->lagjac_persist, &p… in SNESSetFromOptions()
1014 if (flg) PetscCall(SNESSetLagPreconditionerPersists(snes, persist)); in SNESSetFromOptions()
1015 …nes_lag_jacobian", "How often to rebuild Jacobian", "SNESSetLagJacobian", snes->lagjacobian, &lag,… in SNESSetFromOptions()
1017 …PetscCheck(lag != -1, PetscObjectComm((PetscObject)snes), PETSC_ERR_USER, "Cannot set the lag to -… in SNESSetFromOptions()
1018 PetscCall(SNESSetLagJacobian(snes, lag)); in SNESSetFromOptions()
1020 …bian lagging through multiple SNES solves", "SNESSetLagJacobianPersists", snes->lagjac_persist, &p… in SNESSetFromOptions()
1021 if (flg) PetscCall(SNESSetLagJacobianPersists(snes, persist)); in SNESSetFromOptions()
1023 …, "Use grid sequencing to generate initial guess", "SNESSetGridSequence", snes->gridsequence, &gri… in SNESSetFromOptions()
1024 if (flg) PetscCall(SNESSetGridSequence(snes, grids)); in SNESSetFromOptions()
1030 PetscCall(SNESSetConvergenceTest(snes, SNESConvergedDefault, NULL, NULL)); in SNESSetFromOptions()
1033 PetscCall(SNESSetConvergenceTest(snes, SNESConvergedSkip, NULL, NULL)); in SNESSetFromOptions()
1036 PetscCall(SNESSetConvergenceTest(snes, SNESConvergedCorrectPressure, NULL, NULL)); in SNESSetFromOptions()
1042 if (flg) PetscCall(SNESSetNormSchedule(snes, (SNESNormSchedule)indx)); in SNESSetFromOptions()
1045 if (flg) PetscCall(SNESSetFunctionType(snes, (SNESFunctionType)indx)); in SNESSetFromOptions()
1047 kctx = (SNESKSPEW *)snes->kspconvctx; in SNESSetFromOptions()
1049 …entat-Walker linear system convergence test", "SNESKSPSetUseEW", snes->ksp_ewconv, &snes->ksp_ewco… in SNESSetFromOptions()
1051 PetscCall(SNESGetOptionsPrefix(snes, &optionsprefix)); in SNESSetFromOptions()
1053 …PetscCall(SNESEWSetFromOptions_Private(kctx, PETSC_TRUE, PetscObjectComm((PetscObject)snes), ewpre… in SNESSetFromOptions()
1057 if (set && flg) PetscCall(SNESMonitorCancel(snes)); in SNESSetFromOptions()
1059 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor", "Monitor norm of function", "SNESMonito… in SNESSetFromOptions()
1060 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_short", "Monitor norm of function with fe… in SNESSetFromOptions()
1061 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_range", "Monitor range of elements of fun… in SNESSetFromOptions()
1063 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_ratio", "Monitor ratios of the norm of fu… in SNESSetFromOptions()
1064 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_field", "Monitor norm of function (split … in SNESSetFromOptions()
1065 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_solution", "View solution at each iterati… in SNESSetFromOptions()
1066 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_solution_update", "View correction at eac… in SNESSetFromOptions()
1067 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_residual", "View residual at each iterati… in SNESSetFromOptions()
1068 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_jacupdate_spectrum", "Print the change in… in SNESSetFromOptions()
1069 …PetscCall(SNESMonitorSetFromOptions(snes, "-snes_monitor_fields", "Monitor norm of function per fi… in SNESSetFromOptions()
1070 …rs at the final iterate", "SNESMonitorPauseFinal_Internal", PETSC_FALSE, &snes->pauseFinal, NULL)); in SNESSetFromOptions()
1073 if (flg) PetscCall(PetscPythonMonitorSet((PetscObject)snes, monfilename)); in SNESSetFromOptions()
1080 …PetscCall(PetscViewerDrawOpen(PetscObjectComm((PetscObject)snes), NULL, NULL, PETSC_DECIDE, PETSC_… in SNESSetFromOptions()
1081 … PetscCall(SNESMonitorSet(snes, SNESMonitorLGRange, ctx, (PetscCtxDestroyFn *)PetscViewerDestroy)); in SNESSetFromOptions()
1084 PetscCall(PetscViewerDestroy(&snes->convergedreasonviewer)); in SNESSetFromOptions()
1085 …(PetscObject)snes), ((PetscObject)snes)->options, ((PetscObject)snes)->prefix, "-snes_converged_re… in SNESSetFromOptions()
1088 if (set && flg) PetscCall(SNESConvergedReasonViewCancel(snes)); in SNESSetFromOptions()
1095 PetscCall(SNESGetDM(snes, &dm)); in SNESSetFromOptions()
1097 PetscCall(SNESGetFunction(snes, NULL, NULL, &functx)); in SNESSetFromOptions()
1098 …PetscCall(SNESSetJacobian(snes, snes->jacobian, snes->jacobian_pre, SNESComputeJacobianDefault, fu… in SNESSetFromOptions()
1099 PetscCall(PetscInfo(snes, "Setting default finite difference Jacobian matrix\n")); in SNESSetFromOptions()
1104 if (flg) PetscCall(SNESSetFunction(snes, NULL, SNESObjectiveComputeFunctionDefaultFD, NULL)); in SNESSetFromOptions()
1110 PetscCall(SNESGetDM(snes, &dm)); in SNESSetFromOptions()
1112 …PetscCall(SNESSetJacobian(snes, snes->jacobian, snes->jacobian_pre, SNESComputeJacobianDefaultColo… in SNESSetFromOptions()
1113 PetscCall(PetscInfo(snes, "Setting default finite difference coloring Jacobian matrix\n")); in SNESSetFromOptions()
1117 … for computing the preconditioner", "SNESSetUseMatrixFree", PETSC_FALSE, &snes->mf_operator, &flg)… in SNESSetFromOptions()
1118 if (flg && snes->mf_operator) { in SNESSetFromOptions()
1119 snes->mf_operator = PETSC_TRUE; in SNESSetFromOptions()
1120 snes->mf = PETSC_TRUE; in SNESSetFromOptions()
1123 …o matrix for computing the preconditioner", "SNESSetUseMatrixFree", PETSC_FALSE, &snes->mf, &flg)); in SNESSetFromOptions()
1124 if (!flg && snes->mf_operator) snes->mf = PETSC_TRUE; in SNESSetFromOptions()
1125 …snes_mf_version", "Matrix-Free routines version 1 or 2", "None", snes->mf_version, &snes->mf_versi… in SNESSetFromOptions()
1127 …es_test_function", "Compare hand-coded and finite difference functions", "None", &snes->testFunc)); in SNESSetFromOptions()
1128 …nes_test_jacobian", "Compare hand-coded and finite difference Jacobians", "None", &snes->testJac)); in SNESSetFromOptions()
1131 PetscCall(SNESGetNPCSide(snes, &pcside)); in SNESSetFromOptions()
1133 if (flg) PetscCall(SNESSetNPCSide(snes, pcside)); in SNESSetFromOptions()
1143 PetscCall(SNESMonitorSAWsCreate(snes, &ctx)); in SNESSetFromOptions()
1144 PetscCall(SNESMonitorSet(snes, SNESMonitorSAWs, ctx, SNESMonitorSAWsDestroy)); in SNESSetFromOptions()
1151 …lock for SAWs at end of SNESSolve", "PetscObjectSAWsBlock", ((PetscObject)snes)->amspublishblock, … in SNESSetFromOptions()
1152 if (set) PetscCall(PetscObjectSAWsSetBlock((PetscObject)snes, flg)); in SNESSetFromOptions()
1156 for (i = 0; i < numberofsetfromoptions; i++) PetscCall((*othersetfromoptions[i])(snes)); in SNESSetFromOptions()
1158 PetscTryTypeMethod(snes, setfromoptions, PetscOptionsObject); in SNESSetFromOptions()
1161 PetscCall(PetscObjectProcessOptionsHandlers((PetscObject)snes, PetscOptionsObject)); in SNESSetFromOptions()
1164 if (snes->linesearch) { in SNESSetFromOptions()
1165 PetscCall(SNESGetLineSearch(snes, &snes->linesearch)); in SNESSetFromOptions()
1166 PetscCall(SNESLineSearchSetFromOptions(snes->linesearch)); in SNESSetFromOptions()
1169 if (snes->usesksp) { in SNESSetFromOptions()
1170 if (!snes->ksp) PetscCall(SNESGetKSP(snes, &snes->ksp)); in SNESSetFromOptions()
1171 PetscCall(KSPSetOperators(snes->ksp, snes->jacobian, snes->jacobian_pre)); in SNESSetFromOptions()
1172 PetscCall(KSPSetFromOptions(snes->ksp)); in SNESSetFromOptions()
1176 PetscCall(SNESGetOptionsPrefix(snes, &optionsprefix)); in SNESSetFromOptions()
1177 …PetscCall(PetscOptionsHasName(((PetscObject)snes)->options, optionsprefix, "-npc_snes_type", &pcse… in SNESSetFromOptions()
1178 if (pcset && (!snes->npc)) PetscCall(SNESGetNPC(snes, &snes->npc)); in SNESSetFromOptions()
1179 if (snes->npc) PetscCall(SNESSetFromOptions(snes->npc)); in SNESSetFromOptions()
1180 snes->setfromoptionscalled++; in SNESSetFromOptions()
1196 PetscErrorCode SNESResetFromOptions(SNES snes) in SNESResetFromOptions() argument
1199 if (snes->setfromoptionscalled) PetscCall(SNESSetFromOptions(snes)); in SNESResetFromOptions()
1227 PetscErrorCode SNESSetComputeApplicationContext(SNES snes, PetscErrorCode (*compute)(SNES snes, Pet… in SNESSetComputeApplicationContext() argument
1230 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetComputeApplicationContext()
1231 snes->ops->ctxcompute = compute; in SNESSetComputeApplicationContext()
1232 snes->ops->ctxdestroy = destroy; in SNESSetComputeApplicationContext()
1260 PetscErrorCode SNESSetApplicationContext(SNES snes, PetscCtx ctx) in SNESSetApplicationContext() argument
1265 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetApplicationContext()
1266 PetscCall(SNESGetKSP(snes, &ksp)); in SNESSetApplicationContext()
1268 snes->ctx = ctx; in SNESSetApplicationContext()
1294 PetscErrorCode SNESGetApplicationContext(SNES snes, PetscCtxRt ctx) in SNESGetApplicationContext() argument
1297 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetApplicationContext()
1298 *(void **)ctx = snes->ctx; in SNESGetApplicationContext()
1328 PetscErrorCode SNESSetUseMatrixFree(SNES snes, PetscBool mf_operator, PetscBool mf) in SNESSetUseMatrixFree() argument
1331 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetUseMatrixFree()
1332 PetscValidLogicalCollectiveBool(snes, mf_operator, 2); in SNESSetUseMatrixFree()
1333 PetscValidLogicalCollectiveBool(snes, mf, 3); in SNESSetUseMatrixFree()
1334 snes->mf = mf_operator ? PETSC_TRUE : mf; in SNESSetUseMatrixFree()
1335 snes->mf_operator = mf_operator; in SNESSetUseMatrixFree()
1355 PetscErrorCode SNESGetUseMatrixFree(SNES snes, PetscBool *mf_operator, PetscBool *mf) in SNESGetUseMatrixFree() argument
1358 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetUseMatrixFree()
1359 if (mf) *mf = snes->mf; in SNESGetUseMatrixFree()
1360 if (mf_operator) *mf_operator = snes->mf_operator; in SNESGetUseMatrixFree()
1395 PetscErrorCode SNESGetIterationNumber(SNES snes, PetscInt *iter) in SNESGetIterationNumber() argument
1398 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetIterationNumber()
1400 *iter = snes->iter; in SNESGetIterationNumber()
1420 PetscErrorCode SNESSetIterationNumber(SNES snes, PetscInt iter) in SNESSetIterationNumber() argument
1423 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetIterationNumber()
1424 PetscCall(PetscObjectSAWsTakeAccess((PetscObject)snes)); in SNESSetIterationNumber()
1425 snes->iter = iter; in SNESSetIterationNumber()
1426 PetscCall(PetscObjectSAWsGrantAccess((PetscObject)snes)); in SNESSetIterationNumber()
1458 PetscErrorCode SNESGetNonlinearStepFailures(SNES snes, PetscInt *nfails) in SNESGetNonlinearStepFailures() argument
1461 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetNonlinearStepFailures()
1463 *nfails = snes->numFailures; in SNESGetNonlinearStepFailures()
1495 PetscErrorCode SNESSetMaxNonlinearStepFailures(SNES snes, PetscInt maxFails) in SNESSetMaxNonlinearStepFailures() argument
1498 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetMaxNonlinearStepFailures()
1501 snes->maxFailures = PETSC_INT_MAX; in SNESSetMaxNonlinearStepFailures()
1503 …PetscCheck(maxFails >= 0, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE, "Cannot ha… in SNESSetMaxNonlinearStepFailures()
1504 snes->maxFailures = maxFails; in SNESSetMaxNonlinearStepFailures()
1526 PetscErrorCode SNESGetMaxNonlinearStepFailures(SNES snes, PetscInt *maxFails) in SNESGetMaxNonlinearStepFailures() argument
1529 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetMaxNonlinearStepFailures()
1531 *maxFails = snes->maxFailures; in SNESGetMaxNonlinearStepFailures()
1554 PetscErrorCode SNESGetNumberFunctionEvals(SNES snes, PetscInt *nfuncs) in SNESGetNumberFunctionEvals() argument
1557 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetNumberFunctionEvals()
1559 *nfuncs = snes->nfuncs; in SNESGetNumberFunctionEvals()
1585 PetscErrorCode SNESGetLinearSolveFailures(SNES snes, PetscInt *nfails) in SNESGetLinearSolveFailures() argument
1588 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetLinearSolveFailures()
1590 *nfails = snes->numLinearSolveFailures; in SNESGetLinearSolveFailures()
1617 PetscErrorCode SNESSetMaxLinearSolveFailures(SNES snes, PetscInt maxFails) in SNESSetMaxLinearSolveFailures() argument
1620 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetMaxLinearSolveFailures()
1621 PetscValidLogicalCollectiveInt(snes, maxFails, 2); in SNESSetMaxLinearSolveFailures()
1624 snes->maxLinearSolveFailures = PETSC_INT_MAX; in SNESSetMaxLinearSolveFailures()
1626 …PetscCheck(maxFails >= 0, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE, "Cannot ha… in SNESSetMaxLinearSolveFailures()
1627 snes->maxLinearSolveFailures = maxFails; in SNESSetMaxLinearSolveFailures()
1651 PetscErrorCode SNESGetMaxLinearSolveFailures(SNES snes, PetscInt *maxFails) in SNESGetMaxLinearSolveFailures() argument
1654 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetMaxLinearSolveFailures()
1656 *maxFails = snes->maxLinearSolveFailures; in SNESGetMaxLinearSolveFailures()
1682 PetscErrorCode SNESGetLinearSolveIterations(SNES snes, PetscInt *lits) in SNESGetLinearSolveIterations() argument
1685 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetLinearSolveIterations()
1687 *lits = snes->linear_its; in SNESGetLinearSolveIterations()
1705 PetscErrorCode SNESSetCountersReset(SNES snes, PetscBool reset) in SNESSetCountersReset() argument
1708 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetCountersReset()
1709 PetscValidLogicalCollectiveBool(snes, reset, 2); in SNESSetCountersReset()
1710 snes->counters_reset = reset; in SNESSetCountersReset()
1729 PetscErrorCode SNESResetCounters(SNES snes) in SNESResetCounters() argument
1732 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESResetCounters()
1733 if (snes->counters_reset) { in SNESResetCounters()
1734 snes->nfuncs = 0; in SNESResetCounters()
1735 snes->linear_its = 0; in SNESResetCounters()
1736 snes->numFailures = 0; in SNESResetCounters()
1761 PetscErrorCode SNESSetKSP(SNES snes, KSP ksp) in SNESSetKSP() argument
1764 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetKSP()
1766 PetscCheckSameComm(snes, 1, ksp, 2); in SNESSetKSP()
1768 if (snes->ksp) PetscCall(PetscObjectDereference((PetscObject)snes->ksp)); in SNESSetKSP()
1769 snes->ksp = ksp; in SNESSetKSP()
1790 PetscErrorCode SNESParametersInitialize(SNES snes) in SNESParametersInitialize() argument
1792 PetscObjectParameterSetDefault(snes, max_its, 50); in SNESParametersInitialize()
1793 PetscObjectParameterSetDefault(snes, max_funcs, 10000); in SNESParametersInitialize()
1794 PetscObjectParameterSetDefault(snes, rtol, PetscDefined(USE_REAL_SINGLE) ? 1.e-5 : 1.e-8); in SNESParametersInitialize()
1795 PetscObjectParameterSetDefault(snes, abstol, PetscDefined(USE_REAL_SINGLE) ? 1.e-25 : 1.e-50); in SNESParametersInitialize()
1796 PetscObjectParameterSetDefault(snes, stol, PetscDefined(USE_REAL_SINGLE) ? 1.e-5 : 1.e-8); in SNESParametersInitialize()
1797 PetscObjectParameterSetDefault(snes, divtol, 1.e4); in SNESParametersInitialize()
1835 SNES snes; in SNESCreate() local
1842 …PetscCall(PetscHeaderCreate(snes, SNES_CLASSID, "SNES", "Nonlinear solver", "SNES", comm, SNESDest… in SNESCreate()
1843 snes->ops->converged = SNESConvergedDefault; in SNESCreate()
1844 snes->usesksp = PETSC_TRUE; in SNESCreate()
1845 snes->norm = 0.0; in SNESCreate()
1846 snes->xnorm = 0.0; in SNESCreate()
1847 snes->ynorm = 0.0; in SNESCreate()
1848 snes->normschedule = SNES_NORM_ALWAYS; in SNESCreate()
1849 snes->functype = SNES_FUNCTION_DEFAULT; in SNESCreate()
1850 snes->ttol = 0.0; in SNESCreate()
1852 snes->rnorm0 = 0; in SNESCreate()
1853 snes->nfuncs = 0; in SNESCreate()
1854 snes->numFailures = 0; in SNESCreate()
1855 snes->maxFailures = 1; in SNESCreate()
1856 snes->linear_its = 0; in SNESCreate()
1857 snes->lagjacobian = 1; in SNESCreate()
1858 snes->jac_iter = 0; in SNESCreate()
1859 snes->lagjac_persist = PETSC_FALSE; in SNESCreate()
1860 snes->lagpreconditioner = 1; in SNESCreate()
1861 snes->pre_iter = 0; in SNESCreate()
1862 snes->lagpre_persist = PETSC_FALSE; in SNESCreate()
1863 snes->numbermonitors = 0; in SNESCreate()
1864 snes->numberreasonviews = 0; in SNESCreate()
1865 snes->data = NULL; in SNESCreate()
1866 snes->setupcalled = PETSC_FALSE; in SNESCreate()
1867 snes->ksp_ewconv = PETSC_FALSE; in SNESCreate()
1868 snes->nwork = 0; in SNESCreate()
1869 snes->work = NULL; in SNESCreate()
1870 snes->nvwork = 0; in SNESCreate()
1871 snes->vwork = NULL; in SNESCreate()
1872 snes->conv_hist_len = 0; in SNESCreate()
1873 snes->conv_hist_max = 0; in SNESCreate()
1874 snes->conv_hist = NULL; in SNESCreate()
1875 snes->conv_hist_its = NULL; in SNESCreate()
1876 snes->conv_hist_reset = PETSC_TRUE; in SNESCreate()
1877 snes->counters_reset = PETSC_TRUE; in SNESCreate()
1878 snes->vec_func_init_set = PETSC_FALSE; in SNESCreate()
1879 snes->reason = SNES_CONVERGED_ITERATING; in SNESCreate()
1880 snes->npcside = PC_RIGHT; in SNESCreate()
1881 snes->setfromoptionscalled = 0; in SNESCreate()
1883 snes->mf = PETSC_FALSE; in SNESCreate()
1884 snes->mf_operator = PETSC_FALSE; in SNESCreate()
1885 snes->mf_version = 1; in SNESCreate()
1887 snes->numLinearSolveFailures = 0; in SNESCreate()
1888 snes->maxLinearSolveFailures = 1; in SNESCreate()
1890 snes->vizerotolerance = 1.e-8; in SNESCreate()
1891 snes->checkjacdomainerror = PetscDefined(USE_DEBUG) ? PETSC_TRUE : PETSC_FALSE; in SNESCreate()
1894 snes->alwayscomputesfinalresidual = PETSC_FALSE; in SNESCreate()
1899 snes->kspconvctx = kctx; in SNESCreate()
1923 PetscCall(SNESParametersInitialize(snes)); in SNESCreate()
1924 *outsnes = snes; in SNESCreate()
1946 PetscErrorCode SNESSetFunction(SNES snes, Vec r, SNESFunctionFn *f, PetscCtx ctx) in SNESSetFunction() argument
1951 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetFunction()
1954 PetscCheckSameComm(snes, 1, r, 2); in SNESSetFunction()
1956 PetscCall(VecDestroy(&snes->vec_func)); in SNESSetFunction()
1957 snes->vec_func = r; in SNESSetFunction()
1959 PetscCall(SNESGetDM(snes, &dm)); in SNESSetFunction()
1983 PetscErrorCode SNESSetInitialFunction(SNES snes, Vec f) in SNESSetInitialFunction() argument
1988 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetInitialFunction()
1990 PetscCheckSameComm(snes, 1, f, 2); in SNESSetInitialFunction()
1991 if (snes->npcside == PC_LEFT && snes->functype == SNES_FUNCTION_PRECONDITIONED) { in SNESSetInitialFunction()
1992 snes->vec_func_init_set = PETSC_FALSE; in SNESSetInitialFunction()
1995 PetscCall(SNESGetFunction(snes, &vec_func, NULL, NULL)); in SNESSetInitialFunction()
1998 snes->vec_func_init_set = PETSC_TRUE; in SNESSetInitialFunction()
2028 PetscErrorCode SNESSetNormSchedule(SNES snes, SNESNormSchedule normschedule) in SNESSetNormSchedule() argument
2031 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetNormSchedule()
2032 snes->normschedule = normschedule; in SNESSetNormSchedule()
2050 PetscErrorCode SNESGetNormSchedule(SNES snes, SNESNormSchedule *normschedule) in SNESGetNormSchedule() argument
2053 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetNormSchedule()
2054 *normschedule = snes->normschedule; in SNESGetNormSchedule()
2071 PetscErrorCode SNESSetFunctionNorm(SNES snes, PetscReal norm) in SNESSetFunctionNorm() argument
2074 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetFunctionNorm()
2075 snes->norm = norm; in SNESSetFunctionNorm()
2094 PetscErrorCode SNESGetFunctionNorm(SNES snes, PetscReal *norm) in SNESGetFunctionNorm() argument
2097 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetFunctionNorm()
2099 *norm = snes->norm; in SNESGetFunctionNorm()
2121 PetscErrorCode SNESGetUpdateNorm(SNES snes, PetscReal *ynorm) in SNESGetUpdateNorm() argument
2124 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetUpdateNorm()
2126 *ynorm = snes->ynorm; in SNESGetUpdateNorm()
2145 PetscErrorCode SNESGetSolutionNorm(SNES snes, PetscReal *xnorm) in SNESGetSolutionNorm() argument
2148 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetSolutionNorm()
2150 *xnorm = snes->xnorm; in SNESGetSolutionNorm()
2176 PetscErrorCode SNESSetFunctionType(SNES snes, SNESFunctionType type) in SNESSetFunctionType() argument
2179 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetFunctionType()
2180 snes->functype = type; in SNESSetFunctionType()
2198 PetscErrorCode SNESGetFunctionType(SNES snes, SNESFunctionType *type) in SNESGetFunctionType() argument
2201 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetFunctionType()
2202 *type = snes->functype; in SNESGetFunctionType()
2223 PetscErrorCode SNESSetNGS(SNES snes, SNESNGSFn *f, PetscCtx ctx) in SNESSetNGS() argument
2228 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetNGS()
2229 PetscCall(SNESGetDM(snes, &dm)); in SNESSetNGS()
2238 PetscErrorCode SNESPicardComputeMFFunction(SNES snes, Vec x, Vec f, PetscCtx ctx) in SNESPicardComputeMFFunction() argument
2244 PetscCall(SNESGetDM(snes, &dm)); in SNESPicardComputeMFFunction()
2248 …PetscCallBack("SNES Picard callback function", (*sdm->ops->computepfunction)(snes, x, f, sdm->pctx… in SNESPicardComputeMFFunction()
2251 …if (!snes->picard) PetscCall(MatDuplicate(snes->jacobian_pre, MAT_DO_NOT_COPY_VALUES, &snes->picar… in SNESPicardComputeMFFunction()
2252 …"SNES Picard callback Jacobian", (*sdm->ops->computepjacobian)(snes, x, snes->picard, snes->picard… in SNESPicardComputeMFFunction()
2253 PetscCall(MatMultAdd(snes->picard, x, f, f)); in SNESPicardComputeMFFunction()
2255 …"SNES Picard callback Jacobian", (*sdm->ops->computepjacobian)(snes, x, snes->picard, snes->picard… in SNESPicardComputeMFFunction()
2256 PetscCall(MatMult(snes->picard, x, f)); in SNESPicardComputeMFFunction()
2261 PetscErrorCode SNESPicardComputeFunction(SNES snes, Vec x, Vec f, PetscCtx ctx) in SNESPicardComputeFunction() argument
2267 PetscCall(SNESGetDM(snes, &dm)); in SNESPicardComputeFunction()
2271 …PetscCallBack("SNES Picard callback function", (*sdm->ops->computepfunction)(snes, x, f, sdm->pctx… in SNESPicardComputeFunction()
2273 …SNES Picard callback Jacobian", (*sdm->ops->computepjacobian)(snes, x, snes->jacobian, snes->jacob… in SNESPicardComputeFunction()
2274 PetscCall(MatMultAdd(snes->jacobian_pre, x, f, f)); in SNESPicardComputeFunction()
2276 …SNES Picard callback Jacobian", (*sdm->ops->computepjacobian)(snes, x, snes->jacobian, snes->jacob… in SNESPicardComputeFunction()
2277 PetscCall(MatMult(snes->jacobian_pre, x, f)); in SNESPicardComputeFunction()
2282 PetscErrorCode SNESPicardComputeJacobian(SNES snes, Vec x1, Mat J, Mat B, PetscCtx ctx) in SNESPicardComputeJacobian() argument
2339 PetscErrorCode SNESSetPicard(SNES snes, Vec r, SNESFunctionFn *bp, Mat Amat, Mat Pmat, SNESJacobian… in SNESSetPicard() argument
2344 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetPicard()
2345 PetscCall(SNESGetDM(snes, &dm)); in SNESSetPicard()
2348 PetscCall(SNESSetFunction(snes, r, SNESPicardComputeFunction, ctx)); in SNESSetPicard()
2349 PetscCall(SNESSetJacobian(snes, Amat, Pmat, SNESPicardComputeJacobian, ctx)); in SNESSetPicard()
2373 PetscErrorCode SNESGetPicard(SNES snes, Vec *r, SNESFunctionFn **f, Mat *Amat, Mat *Pmat, SNESJacob… in SNESGetPicard() argument
2378 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetPicard()
2379 PetscCall(SNESGetFunction(snes, r, NULL, NULL)); in SNESGetPicard()
2380 PetscCall(SNESGetJacobian(snes, Amat, Pmat, NULL, NULL)); in SNESGetPicard()
2381 PetscCall(SNESGetDM(snes, &dm)); in SNESGetPicard()
2401 PetscErrorCode SNESSetComputeInitialGuess(SNES snes, SNESInitialGuessFn *func, PetscCtx ctx) in SNESSetComputeInitialGuess() argument
2404 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetComputeInitialGuess()
2405 if (func) snes->ops->computeinitialguess = func; in SNESSetComputeInitialGuess()
2406 if (ctx) snes->initialguessP = ctx; in SNESSetComputeInitialGuess()
2426 PetscErrorCode SNESGetRhs(SNES snes, Vec *rhs) in SNESGetRhs() argument
2429 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetRhs()
2431 *rhs = snes->vec_rhs; in SNESGetRhs()
2465 PetscErrorCode SNESComputeFunction(SNES snes, Vec x, Vec f) in SNESComputeFunction() argument
2471 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESComputeFunction()
2474 PetscCheckSameComm(snes, 1, x, 2); in SNESComputeFunction()
2475 PetscCheckSameComm(snes, 1, f, 3); in SNESComputeFunction()
2478 PetscCall(SNESGetDM(snes, &dm)); in SNESComputeFunction()
2480 …PetscCheck(sdm->ops->computefunction || snes->vec_rhs, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, … in SNESComputeFunction()
2482 …ObjectiveComputeFunctionDefaultFD) PetscCall(PetscLogEventBegin(SNES_FunctionEval, snes, x, f, 0)); in SNESComputeFunction()
2485 snes->functiondomainerror = PETSC_FALSE; in SNESComputeFunction()
2490 PetscCallBack("SNES callback function", (*computefunction)(snes, x, f, ctx)); in SNESComputeFunction()
2493 …ESObjectiveComputeFunctionDefaultFD) PetscCall(PetscLogEventEnd(SNES_FunctionEval, snes, x, f, 0)); in SNESComputeFunction()
2495 PetscCall(MatMult(snes->jacobian, x, f)); in SNESComputeFunction()
2497 if (snes->vec_rhs) PetscCall(VecAXPY(f, -1.0, snes->vec_rhs)); in SNESComputeFunction()
2498 snes->nfuncs++; in SNESComputeFunction()
2503 PetscCall(VecFlag(f, snes->functiondomainerror)); in SNESComputeFunction()
2531 PetscErrorCode SNESComputeMFFunction(SNES snes, Vec x, Vec y) in SNESComputeMFFunction() argument
2537 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESComputeMFFunction()
2540 PetscCheckSameComm(snes, 1, x, 2); in SNESComputeMFFunction()
2541 PetscCheckSameComm(snes, 1, y, 3); in SNESComputeMFFunction()
2544 PetscCall(SNESGetDM(snes, &dm)); in SNESComputeMFFunction()
2546 PetscCall(PetscLogEventBegin(SNES_FunctionEval, snes, x, y, 0)); in SNESComputeMFFunction()
2549 snes->functiondomainerror = PETSC_FALSE; in SNESComputeMFFunction()
2550 …PetscCallBack("SNES callback function", (*sdm->ops->computemffunction)(snes, x, y, sdm->mffunction… in SNESComputeMFFunction()
2552 PetscCall(PetscLogEventEnd(SNES_FunctionEval, snes, x, y, 0)); in SNESComputeMFFunction()
2553 snes->nfuncs++; in SNESComputeMFFunction()
2558 PetscCall(VecFlag(y, snes->functiondomainerror)); in SNESComputeMFFunction()
2584 PetscErrorCode SNESComputeNGS(SNES snes, Vec b, Vec x) in SNESComputeNGS() argument
2590 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESComputeNGS()
2593 PetscCheckSameComm(snes, 1, x, 3); in SNESComputeNGS()
2594 if (b) PetscCheckSameComm(snes, 1, b, 2); in SNESComputeNGS()
2596 PetscCall(PetscLogEventBegin(SNES_NGSEval, snes, x, b, 0)); in SNESComputeNGS()
2597 PetscCall(SNESGetDM(snes, &dm)); in SNESComputeNGS()
2601 PetscCallBack("SNES callback NGS", (*sdm->ops->computegs)(snes, x, b, sdm->gsctx)); in SNESComputeNGS()
2603 PetscCall(PetscLogEventEnd(SNES_NGSEval, snes, x, b, 0)); in SNESComputeNGS()
2607 static PetscErrorCode SNESComputeFunction_FD(SNES snes, Vec Xin, Vec G) in SNESComputeFunction_FD() argument
2617 …PetscCall(PetscOptionsGetReal(((PetscObject)snes)->options, ((PetscObject)snes)->prefix, "-snes_fd… in SNESComputeFunction_FD()
2628 PetscCall(SNESComputeObjective(snes, X, &f)); in SNESComputeFunction_FD()
2632 PetscCall(SNESComputeObjective(snes, X, &f2)); in SNESComputeFunction_FD()
2659 PetscErrorCode SNESTestFunction(SNES snes) in SNESTestFunction() argument
2673 PetscCall(SNESGetObjective(snes, &objective, NULL)); in SNESTestFunction()
2676 PetscObjectOptionsBegin((PetscObject)snes); in SNESTestFunction()
2680 PetscCall(PetscObjectGetComm((PetscObject)snes, &comm)); in SNESTestFunction()
2683 PetscCall(PetscViewerASCIISetTab(viewer, ((PetscObject)snes)->tablevel)); in SNESTestFunction()
2696 PetscCall(SNESGetSolution(snes, &x)); in SNESTestFunction()
2700 …PetscCall(SNESComputeFunction(snes, x, g1)); /* does not handle use of SNESSetFunctionDomainError(… in SNESTestFunction()
2701 PetscCall(SNESComputeFunction_FD(snes, x, g2)); in SNESTestFunction()
2759 PetscErrorCode SNESTestJacobian(SNES snes, PetscReal *Jnorm, PetscReal *diffNorm) in SNESTestJacobian() argument
2762 Vec x = snes->vec_sol, f; in SNESTestJacobian()
2777 PetscObjectOptionsBegin((PetscObject)snes); in SNESTestJacobian()
2785 PetscCall(PetscObjectGetComm((PetscObject)snes, &comm)); in SNESTestJacobian()
2788 PetscCall(PetscViewerASCIISetTab(viewer, ((PetscObject)snes)->tablevel)); in SNESTestJacobian()
2801 PetscCall(PetscObjectTypeCompare((PetscObject)snes->jacobian, MATMFFD, &flg)); in SNESTestJacobian()
2802 if (!flg) jacobian = snes->jacobian; in SNESTestJacobian()
2803 else jacobian = snes->jacobian_pre; in SNESTestJacobian()
2810 PetscCall(SNESComputeFunction(snes, x, f)); in SNESTestJacobian()
2812 PetscCall(PetscObjectTypeCompare((PetscObject)snes, SNESKSPTRANSPOSEONLY, &istranspose)); in SNESTestJacobian()
2839 PetscCall(SNESGetFunction(snes, NULL, NULL, &functx)); in SNESTestJacobian()
2840 PetscCall(SNESComputeJacobianDefault(snes, x, B, B, functx)); in SNESTestJacobian()
2896 if (jacobian != snes->jacobian_pre) { in SNESTestJacobian()
2897 jacobian = snes->jacobian_pre; in SNESTestJacobian()
2954 PetscErrorCode SNESComputeJacobian(SNES snes, Vec X, Mat A, Mat B) in SNESComputeJacobian() argument
2962 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESComputeJacobian()
2964 PetscCheckSameComm(snes, 1, X, 2); in SNESComputeJacobian()
2966 PetscCall(SNESGetDM(snes, &dm)); in SNESComputeJacobian()
2970 if (snes->lagjacobian == -2) { in SNESComputeJacobian()
2971 snes->lagjacobian = -1; in SNESComputeJacobian()
2973 …PetscCall(PetscInfo(snes, "Recomputing Jacobian/preconditioner because lag is -2 (means compute Ja… in SNESComputeJacobian()
2974 } else if (snes->lagjacobian == -1) { in SNESComputeJacobian()
2975 PetscCall(PetscInfo(snes, "Reusing Jacobian/preconditioner because lag is -1\n")); in SNESComputeJacobian()
2982 } else if (snes->lagjacobian > 1 && (snes->iter + snes->jac_iter) % snes->lagjacobian) { in SNESComputeJacobian()
2983 …scInfo(snes, "Reusing Jacobian/preconditioner because lag is %" PetscInt_FMT " and SNES iteration … in SNESComputeJacobian()
2991 if (snes->npc && snes->npcside == PC_LEFT) { in SNESComputeJacobian()
2997 PetscCall(PetscLogEventBegin(SNES_JacobianEval, snes, X, A, B)); in SNESComputeJacobian()
3003 PetscCallBack("SNES callback Jacobian", (*J)(snes, X, A, B, ctx)); in SNESComputeJacobian()
3006 PetscCall(PetscLogEventEnd(SNES_JacobianEval, snes, X, A, B)); in SNESComputeJacobian()
3012 PetscCall(SNESGetKSP(snes, &ksp)); in SNESComputeJacobian()
3013 if (snes->lagpreconditioner == -2) { in SNESComputeJacobian()
3014 PetscCall(PetscInfo(snes, "Rebuilding preconditioner exactly once since lag is -2\n")); in SNESComputeJacobian()
3015 PetscCall(KSPSetReusePreconditioner(snes->ksp, PETSC_FALSE)); in SNESComputeJacobian()
3016 snes->lagpreconditioner = -1; in SNESComputeJacobian()
3017 } else if (snes->lagpreconditioner == -1) { in SNESComputeJacobian()
3018 PetscCall(PetscInfo(snes, "Reusing preconditioner because lag is -1\n")); in SNESComputeJacobian()
3019 PetscCall(KSPSetReusePreconditioner(snes->ksp, PETSC_TRUE)); in SNESComputeJacobian()
3020 …} else if (snes->lagpreconditioner > 1 && (snes->iter + snes->pre_iter) % snes->lagpreconditioner)… in SNESComputeJacobian()
3021 …tscInfo(snes, "Reusing preconditioner because lag is %" PetscInt_FMT " and SNES iteration is %" Pe… in SNESComputeJacobian()
3022 PetscCall(KSPSetReusePreconditioner(snes->ksp, PETSC_TRUE)); in SNESComputeJacobian()
3024 PetscCall(PetscInfo(snes, "Rebuilding preconditioner\n")); in SNESComputeJacobian()
3025 PetscCall(KSPSetReusePreconditioner(snes->ksp, PETSC_FALSE)); in SNESComputeJacobian()
3031 Vec xsave = snes->vec_sol; in SNESComputeJacobian()
3032 Mat jacobiansave = snes->jacobian; in SNESComputeJacobian()
3033 Mat jacobian_presave = snes->jacobian_pre; in SNESComputeJacobian()
3035 snes->vec_sol = X; in SNESComputeJacobian()
3036 snes->jacobian = A; in SNESComputeJacobian()
3037 snes->jacobian_pre = B; in SNESComputeJacobian()
3038 if (snes->testFunc) PetscCall(SNESTestFunction(snes)); in SNESComputeJacobian()
3039 if (snes->testJac) PetscCall(SNESTestJacobian(snes, NULL, NULL)); in SNESComputeJacobian()
3041 snes->vec_sol = xsave; in SNESComputeJacobian()
3042 snes->jacobian = jacobiansave; in SNESComputeJacobian()
3043 snes->jacobian_pre = jacobian_presave; in SNESComputeJacobian()
3048 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3049 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3050 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3051 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3070 PetscCall(SNESComputeJacobianDefault(snes, X, FDexp, FDexp, NULL)); in SNESComputeJacobian()
3071 PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)snes), &vstdout)); in SNESComputeJacobian()
3073 …PetscCall(PetscViewerDrawOpen(PetscObjectComm((PetscObject)snes), NULL, "Explicit Jacobians", PETS… in SNESComputeJacobian()
3099 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3100 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3101 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3102 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3103 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESComputeJacobian()
3105 …PetscCall(PetscOptionsGetReal(((PetscObject)snes)->options, ((PetscObject)snes)->prefix, "-snes_co… in SNESComputeJacobian()
3106 …PetscCall(PetscOptionsGetReal(((PetscObject)snes)->options, ((PetscObject)snes)->prefix, "-snes_co… in SNESComputeJacobian()
3130 PetscCall(SNESGetFunction(snes, NULL, &func, &funcctx)); in SNESComputeJacobian()
3132 … PetscCall(PetscObjectSetOptionsPrefix((PetscObject)matfdcoloring, ((PetscObject)snes)->prefix)); in SNESComputeJacobian()
3135 PetscCall(MatFDColoringApply(Bfd, matfdcoloring, X, snes)); in SNESComputeJacobian()
3138 PetscCall(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)snes), &vstdout)); in SNESComputeJacobian()
3140 …PetscCall(PetscViewerDrawOpen(PetscObjectComm((PetscObject)snes), NULL, "Colored Jacobians", PETSC… in SNESComputeJacobian()
3241 PetscErrorCode SNESSetJacobian(SNES snes, Mat Amat, Mat Pmat, SNESJacobianFn *J, PetscCtx ctx) in SNESSetJacobian() argument
3246 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetJacobian()
3249 if (Amat) PetscCheckSameComm(snes, 1, Amat, 2); in SNESSetJacobian()
3250 if (Pmat) PetscCheckSameComm(snes, 1, Pmat, 3); in SNESSetJacobian()
3251 PetscCall(SNESGetDM(snes, &dm)); in SNESSetJacobian()
3255 PetscCall(MatDestroy(&snes->jacobian)); in SNESSetJacobian()
3257 snes->jacobian = Amat; in SNESSetJacobian()
3261 PetscCall(MatDestroy(&snes->jacobian_pre)); in SNESSetJacobian()
3263 snes->jacobian_pre = Pmat; in SNESSetJacobian()
3287 PetscErrorCode SNESGetJacobian(SNES snes, Mat *Amat, Mat *Pmat, SNESJacobianFn **J, PetscCtxRt ctx) in SNESGetJacobian() argument
3292 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetJacobian()
3293 if (Amat) *Amat = snes->jacobian; in SNESGetJacobian()
3294 if (Pmat) *Pmat = snes->jacobian_pre; in SNESGetJacobian()
3295 PetscCall(SNESGetDM(snes, &dm)); in SNESGetJacobian()
3300 static PetscErrorCode SNESSetDefaultComputeJacobian(SNES snes) in SNESSetDefaultComputeJacobian() argument
3306 PetscCall(SNESGetDM(snes, &dm)); in SNESSetDefaultComputeJacobian()
3308 if (!sdm->ops->computejacobian && snes->jacobian_pre) { in SNESSetDefaultComputeJacobian()
3312 PetscCall(SNESGetDM(snes, &dm)); in SNESSetDefaultComputeJacobian()
3313 …PetscCall(PetscObjectTypeCompareAny((PetscObject)snes->jacobian_pre, &isdense, MATSEQDENSE, MATMPI… in SNESSetDefaultComputeJacobian()
3314 …PetscCall(PetscObjectTypeCompareAny((PetscObject)snes->jacobian_pre, &ismf, MATMFFD, MATSHELL, NUL… in SNESSetDefaultComputeJacobian()
3344 PetscErrorCode SNESSetUp(SNES snes) in SNESSetUp() argument
3361 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetUp()
3362 if (snes->setupcalled) PetscFunctionReturn(PETSC_SUCCESS); in SNESSetUp()
3363 PetscCall(PetscLogEventBegin(SNES_SetUp, snes, 0, 0, 0)); in SNESSetUp()
3365 if (!((PetscObject)snes)->type_name) PetscCall(SNESSetType(snes, SNESNEWTONLS)); in SNESSetUp()
3367 PetscCall(SNESGetFunction(snes, &snes->vec_func, NULL, NULL)); in SNESSetUp()
3369 PetscCall(SNESGetDM(snes, &dm)); in SNESSetUp()
3371 PetscCall(SNESSetDefaultComputeJacobian(snes)); in SNESSetUp()
3373 if (!snes->vec_func) PetscCall(DMCreateGlobalVector(dm, &snes->vec_func)); in SNESSetUp()
3375 if (!snes->ksp) PetscCall(SNESGetKSP(snes, &snes->ksp)); in SNESSetUp()
3377 if (snes->linesearch) { in SNESSetUp()
3378 PetscCall(SNESGetLineSearch(snes, &snes->linesearch)); in SNESSetUp()
3379 PetscCall(SNESLineSearchSetFunction(snes->linesearch, SNESComputeFunction)); in SNESSetUp()
3382 PetscCall(SNESGetUseMatrixFree(snes, &mf_operator, &mf)); in SNESSetUp()
3383 if (snes->npc && snes->npcside == PC_LEFT) { in SNESSetUp()
3384 snes->mf = PETSC_TRUE; in SNESSetUp()
3385 snes->mf_operator = PETSC_FALSE; in SNESSetUp()
3388 if (snes->npc) { in SNESSetUp()
3390 PetscCall(SNESGetDM(snes, &dm)); in SNESSetUp()
3391 PetscCall(SNESSetDM(snes->npc, dm)); in SNESSetUp()
3393 PetscCall(SNESGetFunction(snes, &f, &func, &funcctx)); in SNESSetUp()
3395 PetscCall(SNESSetFunction(snes->npc, fpc, func, funcctx)); in SNESSetUp()
3396 PetscCall(SNESGetJacobian(snes, &j, &jpre, &jac, &jacctx)); in SNESSetUp()
3397 PetscCall(SNESSetJacobian(snes->npc, j, jpre, jac, jacctx)); in SNESSetUp()
3398 PetscCall(SNESGetApplicationContext(snes, &appctx)); in SNESSetUp()
3399 PetscCall(SNESSetApplicationContext(snes->npc, appctx)); in SNESSetUp()
3400 PetscCall(SNESSetUseMatrixFree(snes->npc, mf_operator, mf)); in SNESSetUp()
3404 PetscCall(PetscObjectCopyFortranFunctionPointers((PetscObject)snes, (PetscObject)snes->npc)); in SNESSetUp()
3407 PetscCall(SNESSetTolerances(snes->npc, 0.0, 0.0, 0.0, 1, snes->npc->max_funcs)); in SNESSetUp()
3408 if (snes->npcside == PC_RIGHT) { in SNESSetUp()
3409 PetscCall(SNESSetNormSchedule(snes->npc, SNES_NORM_FINAL_ONLY)); in SNESSetUp()
3411 PetscCall(SNESSetNormSchedule(snes->npc, SNES_NORM_NONE)); in SNESSetUp()
3413 PetscCall(SNESSetFromOptions(snes->npc)); in SNESSetUp()
3416 if (snes->linesearch && snes->npc->linesearch) { in SNESSetUp()
3417 PetscCall(SNESGetLineSearch(snes, &linesearch)); in SNESSetUp()
3418 PetscCall(SNESGetLineSearch(snes->npc, &pclinesearch)); in SNESSetUp()
3426 if (snes->mf) PetscCall(SNESSetUpMatrixFree_Private(snes, snes->mf_operator, snes->mf_version)); in SNESSetUp()
3427 …if (snes->ops->ctxcompute && !snes->ctx) PetscCallBack("SNES callback compute application context"… in SNESSetUp()
3429 snes->jac_iter = 0; in SNESSetUp()
3430 snes->pre_iter = 0; in SNESSetUp()
3432 PetscTryTypeMethod(snes, setup); in SNESSetUp()
3434 PetscCall(SNESSetDefaultComputeJacobian(snes)); in SNESSetUp()
3436 if (snes->npc && snes->npcside == PC_LEFT) { in SNESSetUp()
3437 if (snes->functype == SNES_FUNCTION_PRECONDITIONED) { in SNESSetUp()
3438 if (snes->linesearch) { in SNESSetUp()
3439 PetscCall(SNESGetLineSearch(snes, &linesearch)); in SNESSetUp()
3444 PetscCall(PetscLogEventEnd(SNES_SetUp, snes, 0, 0, 0)); in SNESSetUp()
3445 snes->setupcalled = PETSC_TRUE; in SNESSetUp()
3468 PetscErrorCode SNESReset(SNES snes) in SNESReset() argument
3471 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESReset()
3472 if (snes->ops->ctxdestroy && snes->ctx) { in SNESReset()
3473 … PetscCallBack("SNES callback destroy application context", (*snes->ops->ctxdestroy)(&snes->ctx)); in SNESReset()
3474 snes->ctx = NULL; in SNESReset()
3476 if (snes->npc) PetscCall(SNESReset(snes->npc)); in SNESReset()
3478 PetscTryTypeMethod(snes, reset); in SNESReset()
3479 if (snes->ksp) PetscCall(KSPReset(snes->ksp)); in SNESReset()
3481 if (snes->linesearch) PetscCall(SNESLineSearchReset(snes->linesearch)); in SNESReset()
3483 PetscCall(VecDestroy(&snes->vec_rhs)); in SNESReset()
3484 PetscCall(VecDestroy(&snes->vec_sol)); in SNESReset()
3485 PetscCall(VecDestroy(&snes->vec_sol_update)); in SNESReset()
3486 PetscCall(VecDestroy(&snes->vec_func)); in SNESReset()
3487 PetscCall(MatDestroy(&snes->jacobian)); in SNESReset()
3488 PetscCall(MatDestroy(&snes->jacobian_pre)); in SNESReset()
3489 PetscCall(MatDestroy(&snes->picard)); in SNESReset()
3490 PetscCall(VecDestroyVecs(snes->nwork, &snes->work)); in SNESReset()
3491 PetscCall(VecDestroyVecs(snes->nvwork, &snes->vwork)); in SNESReset()
3493 snes->alwayscomputesfinalresidual = PETSC_FALSE; in SNESReset()
3495 snes->nwork = snes->nvwork = 0; in SNESReset()
3496 snes->setupcalled = PETSC_FALSE; in SNESReset()
3513 PetscErrorCode SNESConvergedReasonViewCancel(SNES snes) in SNESConvergedReasonViewCancel() argument
3518 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESConvergedReasonViewCancel()
3519 for (i = 0; i < snes->numberreasonviews; i++) { in SNESConvergedReasonViewCancel()
3520 …if (snes->reasonviewdestroy[i]) PetscCall((*snes->reasonviewdestroy[i])(&snes->reasonviewcontext[i… in SNESConvergedReasonViewCancel()
3522 snes->numberreasonviews = 0; in SNESConvergedReasonViewCancel()
3523 PetscCall(PetscViewerDestroy(&snes->convergedreasonviewer)); in SNESConvergedReasonViewCancel()
3540 PetscErrorCode SNESDestroy(SNES *snes) in SNESDestroy() argument
3545 if (!*snes) PetscFunctionReturn(PETSC_SUCCESS); in SNESDestroy()
3546 PetscValidHeaderSpecific(*snes, SNES_CLASSID, 1); in SNESDestroy()
3547 if (--((PetscObject)*snes)->refct > 0) { in SNESDestroy()
3548 *snes = NULL; in SNESDestroy()
3552 PetscCall(SNESReset(*snes)); in SNESDestroy()
3553 PetscCall(SNESDestroy(&(*snes)->npc)); in SNESDestroy()
3556 PetscCall(PetscObjectSAWsViewOff((PetscObject)*snes)); in SNESDestroy()
3557 PetscTryTypeMethod(*snes, destroy); in SNESDestroy()
3559 dm = (*snes)->dm; in SNESDestroy()
3561 PetscCall(DMCoarsenHookRemove(dm, DMCoarsenHook_SNESVecSol, DMRestrictHook_SNESVecSol, *snes)); in SNESDestroy()
3565 PetscCall(DMDestroy(&(*snes)->dm)); in SNESDestroy()
3566 PetscCall(KSPDestroy(&(*snes)->ksp)); in SNESDestroy()
3567 PetscCall(SNESLineSearchDestroy(&(*snes)->linesearch)); in SNESDestroy()
3569 PetscCall(PetscFree((*snes)->kspconvctx)); in SNESDestroy()
3570 if ((*snes)->ops->convergeddestroy) PetscCall((*(*snes)->ops->convergeddestroy)(&(*snes)->cnvP)); in SNESDestroy()
3571 if ((*snes)->conv_hist_alloc) PetscCall(PetscFree2((*snes)->conv_hist, (*snes)->conv_hist_its)); in SNESDestroy()
3572 PetscCall(SNESMonitorCancel(*snes)); in SNESDestroy()
3573 PetscCall(SNESConvergedReasonViewCancel(*snes)); in SNESDestroy()
3574 PetscCall(PetscHeaderDestroy(snes)); in SNESDestroy()
3608 PetscErrorCode SNESSetLagPreconditioner(SNES snes, PetscInt lag) in SNESSetLagPreconditioner() argument
3611 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetLagPreconditioner()
3614 PetscValidLogicalCollectiveInt(snes, lag, 2); in SNESSetLagPreconditioner()
3615 snes->lagpreconditioner = lag; in SNESSetLagPreconditioner()
3641 PetscErrorCode SNESSetGridSequence(SNES snes, PetscInt steps) in SNESSetGridSequence() argument
3644 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetGridSequence()
3645 PetscValidLogicalCollectiveInt(snes, steps, 2); in SNESSetGridSequence()
3646 snes->gridsequence = steps; in SNESSetGridSequence()
3665 PetscErrorCode SNESGetGridSequence(SNES snes, PetscInt *steps) in SNESGetGridSequence() argument
3668 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetGridSequence()
3669 *steps = snes->gridsequence; in SNESGetGridSequence()
3694 PetscErrorCode SNESGetLagPreconditioner(SNES snes, PetscInt *lag) in SNESGetLagPreconditioner() argument
3697 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetLagPreconditioner()
3698 *lag = snes->lagpreconditioner; in SNESGetLagPreconditioner()
3731 PetscErrorCode SNESSetLagJacobian(SNES snes, PetscInt lag) in SNESSetLagJacobian() argument
3734 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetLagJacobian()
3737 PetscValidLogicalCollectiveInt(snes, lag, 2); in SNESSetLagJacobian()
3738 snes->lagjacobian = lag; in SNESSetLagJacobian()
3764 PetscErrorCode SNESGetLagJacobian(SNES snes, PetscInt *lag) in SNESGetLagJacobian() argument
3767 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetLagJacobian()
3768 *lag = snes->lagjacobian; in SNESGetLagJacobian()
3798 PetscErrorCode SNESSetLagJacobianPersists(SNES snes, PetscBool flg) in SNESSetLagJacobianPersists() argument
3801 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetLagJacobianPersists()
3802 PetscValidLogicalCollectiveBool(snes, flg, 2); in SNESSetLagJacobianPersists()
3803 snes->lagjac_persist = flg; in SNESSetLagJacobianPersists()
3833 PetscErrorCode SNESSetLagPreconditionerPersists(SNES snes, PetscBool flg) in SNESSetLagPreconditionerPersists() argument
3836 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetLagPreconditionerPersists()
3837 PetscValidLogicalCollectiveBool(snes, flg, 2); in SNESSetLagPreconditionerPersists()
3838 snes->lagpre_persist = flg; in SNESSetLagPreconditionerPersists()
3861 PetscErrorCode SNESSetForceIteration(SNES snes, PetscBool force) in SNESSetForceIteration() argument
3864 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetForceIteration()
3865 snes->forceiteration = force; in SNESSetForceIteration()
3884 PetscErrorCode SNESGetForceIteration(SNES snes, PetscBool *force) in SNESGetForceIteration() argument
3887 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetForceIteration()
3888 *force = snes->forceiteration; in SNESGetForceIteration()
3927 PetscErrorCode SNESSetTolerances(SNES snes, PetscReal abstol, PetscReal rtol, PetscReal stol, Petsc… in SNESSetTolerances() argument
3930 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetTolerances()
3931 PetscValidLogicalCollectiveReal(snes, abstol, 2); in SNESSetTolerances()
3932 PetscValidLogicalCollectiveReal(snes, rtol, 3); in SNESSetTolerances()
3933 PetscValidLogicalCollectiveReal(snes, stol, 4); in SNESSetTolerances()
3934 PetscValidLogicalCollectiveInt(snes, maxit, 5); in SNESSetTolerances()
3935 PetscValidLogicalCollectiveInt(snes, maxf, 6); in SNESSetTolerances()
3938 snes->abstol = snes->default_abstol; in SNESSetTolerances()
3940 …PetscCheck(abstol >= 0.0, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE, "Absolute … in SNESSetTolerances()
3941 snes->abstol = abstol; in SNESSetTolerances()
3945 snes->rtol = snes->default_rtol; in SNESSetTolerances()
3947 …PetscCheck(rtol >= 0.0 && 1.0 > rtol, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE… in SNESSetTolerances()
3948 snes->rtol = rtol; in SNESSetTolerances()
3952 snes->stol = snes->default_stol; in SNESSetTolerances()
3954 …PetscCheck(stol >= 0.0, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE, "Step tolera… in SNESSetTolerances()
3955 snes->stol = stol; in SNESSetTolerances()
3959 snes->max_its = snes->default_max_its; in SNESSetTolerances()
3961 snes->max_its = PETSC_INT_MAX; in SNESSetTolerances()
3963 …PetscCheck(maxit >= 0, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE, "Maximum numb… in SNESSetTolerances()
3964 snes->max_its = maxit; in SNESSetTolerances()
3968 snes->max_funcs = snes->default_max_funcs; in SNESSetTolerances()
3970 snes->max_funcs = PETSC_UNLIMITED; in SNESSetTolerances()
3972 …PetscCheck(maxf >= 0, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE, "Maximum numbe… in SNESSetTolerances()
3973 snes->max_funcs = maxf; in SNESSetTolerances()
4001 PetscErrorCode SNESSetDivergenceTolerance(SNES snes, PetscReal divtol) in SNESSetDivergenceTolerance() argument
4004 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetDivergenceTolerance()
4005 PetscValidLogicalCollectiveReal(snes, divtol, 2); in SNESSetDivergenceTolerance()
4008 snes->divtol = snes->default_divtol; in SNESSetDivergenceTolerance()
4010 snes->divtol = PETSC_UNLIMITED; in SNESSetDivergenceTolerance()
4012 …PetscCheck(divtol >= 1.0, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_OUTOFRANGE, "Divergenc… in SNESSetDivergenceTolerance()
4013 snes->divtol = divtol; in SNESSetDivergenceTolerance()
4042 PetscErrorCode SNESGetTolerances(SNES snes, PetscReal *atol, PetscReal *rtol, PetscReal *stol, Pets… in SNESGetTolerances() argument
4045 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetTolerances()
4046 if (atol) *atol = snes->abstol; in SNESGetTolerances()
4047 if (rtol) *rtol = snes->rtol; in SNESGetTolerances()
4048 if (stol) *stol = snes->stol; in SNESGetTolerances()
4049 if (maxit) *maxit = snes->max_its; in SNESGetTolerances()
4050 if (maxf) *maxf = snes->max_funcs; in SNESGetTolerances()
4067 PetscErrorCode SNESGetDivergenceTolerance(SNES snes, PetscReal *divtol) in SNESGetDivergenceTolerance() argument
4070 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetDivergenceTolerance()
4071 if (divtol) *divtol = snes->divtol; in SNESGetDivergenceTolerance()
4077 PetscErrorCode SNESMonitorLGRange(SNES snes, PetscInt n, PetscReal rnorm, void *monctx) in SNESMonitorLGRange() argument
4095 if (n < 20 || !(n % 5) || snes->reason) { in SNESMonitorLGRange()
4104 PetscCall(SNESMonitorRange_Private(snes, n, &per)); in SNESMonitorLGRange()
4108 if (n < 20 || !(n % 5) || snes->reason) { in SNESMonitorLGRange()
4123 if (n < 20 || !(n % 5) || snes->reason) { in SNESMonitorLGRange()
4137 if (n < 20 || !(n % 5) || snes->reason) { in SNESMonitorLGRange()
4165 PetscErrorCode SNESConverged(SNES snes, PetscInt it, PetscReal xnorm, PetscReal snorm, PetscReal fn… in SNESConverged() argument
4168 if (!snes->reason) { in SNESConverged()
4169 …if (snes->normschedule == SNES_NORM_ALWAYS) PetscUseTypeMethod(snes, converged, it, xnorm, snorm, … in SNESConverged()
4170 if (it == snes->max_its && !snes->reason) { in SNESConverged()
4171 if (snes->normschedule == SNES_NORM_ALWAYS) { in SNESConverged()
4172 …PetscCall(PetscInfo(snes, "Maximum number of iterations has been reached: %" PetscInt_FMT "\n", sn… in SNESConverged()
4173 snes->reason = SNES_DIVERGED_MAX_IT; in SNESConverged()
4174 } else snes->reason = SNES_CONVERGED_ITS; in SNESConverged()
4198 PetscErrorCode SNESMonitor(SNES snes, PetscInt iter, PetscReal rnorm) in SNESMonitor() argument
4200 PetscInt i, n = snes->numbermonitors; in SNESMonitor()
4203 PetscCall(VecLockReadPush(snes->vec_sol)); in SNESMonitor()
4204 …for (i = 0; i < n; i++) PetscCall((*snes->monitor[i])(snes, iter, rnorm, snes->monitorcontext[i])); in SNESMonitor()
4205 PetscCall(VecLockReadPop(snes->vec_sol)); in SNESMonitor()
4262 PetscErrorCode SNESMonitorSet(SNES snes, PetscErrorCode (*f)(SNES, PetscInt, PetscReal, PetscCtx), … in SNESMonitorSet() argument
4265 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESMonitorSet()
4266 for (PetscInt i = 0; i < snes->numbermonitors; i++) { in SNESMonitorSet()
4269 …tordestroy, (PetscErrorCode (*)(void))(PetscVoidFn *)snes->monitor[i], snes->monitorcontext[i], sn… in SNESMonitorSet()
4272 …PetscCheck(snes->numbermonitors < MAXSNESMONITORS, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Too… in SNESMonitorSet()
4273 snes->monitor[snes->numbermonitors] = f; in SNESMonitorSet()
4274 snes->monitordestroy[snes->numbermonitors] = monitordestroy; in SNESMonitorSet()
4275 snes->monitorcontext[snes->numbermonitors++] = mctx; in SNESMonitorSet()
4299 PetscErrorCode SNESMonitorCancel(SNES snes) in SNESMonitorCancel() argument
4304 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESMonitorCancel()
4305 for (i = 0; i < snes->numbermonitors; i++) { in SNESMonitorCancel()
4306 if (snes->monitordestroy[i]) PetscCall((*snes->monitordestroy[i])(&snes->monitorcontext[i])); in SNESMonitorCancel()
4308 snes->numbermonitors = 0; in SNESMonitorCancel()
4353 PetscErrorCode SNESSetConvergenceTest(SNES snes, PetscErrorCode (*SNESConvergenceTestFunction)(SNES… in SNESSetConvergenceTest() argument
4356 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetConvergenceTest()
4358 if (snes->ops->convergeddestroy) PetscCall((*snes->ops->convergeddestroy)(&snes->cnvP)); in SNESSetConvergenceTest()
4359 snes->ops->converged = SNESConvergenceTestFunction; in SNESSetConvergenceTest()
4360 snes->ops->convergeddestroy = destroy; in SNESSetConvergenceTest()
4361 snes->cnvP = ctx; in SNESSetConvergenceTest()
4386 PetscErrorCode SNESGetConvergedReason(SNES snes, SNESConvergedReason *reason) in SNESGetConvergedReason() argument
4389 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetConvergedReason()
4391 *reason = snes->reason; in SNESGetConvergedReason()
4410 PetscErrorCode SNESGetConvergedReasonString(SNES snes, const char **strreason) in SNESGetConvergedReasonString() argument
4413 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetConvergedReasonString()
4415 *strreason = SNESConvergedReasons[snes->reason]; in SNESGetConvergedReasonString()
4436 PetscErrorCode SNESSetConvergedReason(SNES snes, SNESConvergedReason reason) in SNESSetConvergedReason() argument
4439 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetConvergedReason()
4440 …PetscCheck(!snes->errorifnotconverged || reason > 0, PetscObjectComm((PetscObject)snes), PETSC_ERR… in SNESSetConvergedReason()
4441 snes->reason = reason; in SNESSetConvergedReason()
4472 PetscErrorCode SNESSetConvergenceHistory(SNES snes, PetscReal a[], PetscInt its[], PetscInt na, Pet… in SNESSetConvergenceHistory() argument
4475 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetConvergenceHistory()
4481 snes->conv_hist_alloc = PETSC_TRUE; in SNESSetConvergenceHistory()
4483 snes->conv_hist = a; in SNESSetConvergenceHistory()
4484 snes->conv_hist_its = its; in SNESSetConvergenceHistory()
4485 snes->conv_hist_max = (size_t)na; in SNESSetConvergenceHistory()
4486 snes->conv_hist_len = 0; in SNESSetConvergenceHistory()
4487 snes->conv_hist_reset = reset; in SNESSetConvergenceHistory()
4495 PETSC_EXTERN mxArray *SNESGetConvergenceHistoryMatlab(SNES snes) in SNESGetConvergenceHistoryMatlab() argument
4501 mat = mxCreateDoubleMatrix(snes->conv_hist_len, 1, mxREAL); in SNESGetConvergenceHistoryMatlab()
4503 for (i = 0; i < snes->conv_hist_len; i++) ar[i] = snes->conv_hist[i]; in SNESGetConvergenceHistoryMatlab()
4540 PetscErrorCode SNESGetConvergenceHistory(SNES snes, PetscReal *a[], PetscInt *its[], PetscInt *na) in SNESGetConvergenceHistory() argument
4543 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetConvergenceHistory()
4544 if (a) *a = snes->conv_hist; in SNESGetConvergenceHistory()
4545 if (its) *its = snes->conv_hist_its; in SNESGetConvergenceHistory()
4546 if (na) *na = (PetscInt)snes->conv_hist_len; in SNESGetConvergenceHistory()
4594 PetscErrorCode SNESSetUpdate(SNES snes, SNESUpdateFn *func) in SNESSetUpdate() argument
4597 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetUpdate()
4598 snes->ops->update = func; in SNESSetUpdate()
4626 PetscErrorCode SNESConvergedReasonView(SNES snes, PetscViewer viewer) in SNESConvergedReasonView() argument
4632 if (!viewer) viewer = PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)snes)); in SNESConvergedReasonView()
4636 PetscCall(PetscViewerASCIIAddTab(viewer, ((PetscObject)snes)->tablevel + 1)); in SNESConvergedReasonView()
4646 PetscCall(SNESGetDM(snes, &dm)); in SNESConvergedReasonView()
4647 PetscCall(SNESGetSolution(snes, &u)); in SNESConvergedReasonView()
4657 if (snes->reason > 0 && format != PETSC_VIEWER_FAILED) { in SNESConvergedReasonView()
4658 if (((PetscObject)snes)->prefix) { in SNESConvergedReasonView()
4659 …s iterations %" PetscInt_FMT "\n", ((PetscObject)snes)->prefix, SNESConvergedReasons[snes->reason]… in SNESConvergedReasonView()
4661 …verged due to %s iterations %" PetscInt_FMT "\n", SNESConvergedReasons[snes->reason], snes->iter)); in SNESConvergedReasonView()
4663 } else if (snes->reason <= 0) { in SNESConvergedReasonView()
4664 if (((PetscObject)snes)->prefix) { in SNESConvergedReasonView()
4665 …s iterations %" PetscInt_FMT "\n", ((PetscObject)snes)->prefix, SNESConvergedReasons[snes->reason]… in SNESConvergedReasonView()
4667 …nverge due to %s iterations %" PetscInt_FMT "\n", SNESConvergedReasons[snes->reason], snes->iter)); in SNESConvergedReasonView()
4670 PetscCall(PetscViewerASCIISubtractTab(viewer, ((PetscObject)snes)->tablevel + 1)); in SNESConvergedReasonView()
4706 PetscErrorCode SNESConvergedReasonViewSet(SNES snes, PetscErrorCode (*f)(SNES snes, void *vctx), vo… in SNESConvergedReasonViewSet() argument
4709 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESConvergedReasonViewSet()
4710 for (PetscInt i = 0; i < snes->numberreasonviews; i++) { in SNESConvergedReasonViewSet()
4713 …destroy, (PetscErrorCode (*)(void))(PetscVoidFn *)snes->reasonview[i], snes->reasonviewcontext[i],… in SNESConvergedReasonViewSet()
4716 …PetscCheck(snes->numberreasonviews < MAXSNESREASONVIEWS, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE… in SNESConvergedReasonViewSet()
4717 snes->reasonview[snes->numberreasonviews] = f; in SNESConvergedReasonViewSet()
4718 snes->reasonviewdestroy[snes->numberreasonviews] = reasonviewdestroy; in SNESConvergedReasonViewSet()
4719 snes->reasonviewcontext[snes->numberreasonviews++] = vctx; in SNESConvergedReasonViewSet()
4737 PetscErrorCode SNESConvergedReasonViewFromOptions(SNES snes) in SNESConvergedReasonViewFromOptions() argument
4746 …for (PetscInt i = 0; i < snes->numberreasonviews; i++) PetscCall((*snes->reasonview[i])(snes, snes in SNESConvergedReasonViewFromOptions()
4749 if (snes->convergedreasonviewer) { in SNESConvergedReasonViewFromOptions()
4750 PetscCall(PetscViewerPushFormat(snes->convergedreasonviewer, snes->convergedreasonformat)); in SNESConvergedReasonViewFromOptions()
4751 PetscCall(SNESConvergedReasonView(snes, snes->convergedreasonviewer)); in SNESConvergedReasonViewFromOptions()
4752 PetscCall(PetscViewerPopFormat(snes->convergedreasonviewer)); in SNESConvergedReasonViewFromOptions()
4778 PetscErrorCode SNESSolve(SNES snes, Vec b, Vec x) in SNESSolve() argument
4786 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSolve()
4788 if (x) PetscCheckSameComm(snes, 1, x, 3); in SNESSolve()
4790 if (b) PetscCheckSameComm(snes, 1, b, 2); in SNESSolve()
4802 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESSolve()
4810 PetscCall(SNESGetDM(snes, &dm)); in SNESSolve()
4813 PetscCall(PetscConvEstCreate(PetscObjectComm((PetscObject)snes), &conv)); in SNESSolve()
4814 PetscCall(PetscConvEstSetSolver(conv, (PetscObject)snes)); in SNESSolve()
4828 …PetscCall(PetscOptionsGetInt(NULL, ((PetscObject)snes)->prefix, "-snes_adapt_initial", &num, &flg)… in SNESSolve()
4833 PetscCall(DMAdaptorCreate(PetscObjectComm((PetscObject)snes), &adaptor)); in SNESSolve()
4834 PetscCall(DMAdaptorSetSolver(adaptor, snes)); in SNESSolve()
4844 …PetscCall(PetscOptionsGetInt(NULL, ((PetscObject)snes)->prefix, "-snes_adapt_sequence", &num, NULL… in SNESSolve()
4850 PetscCall(DMAdaptorCreate(PetscObjectComm((PetscObject)snes), &adaptor)); in SNESSolve()
4851 PetscCall(SNESGetOptionsPrefix(snes, &prefix)); in SNESSolve()
4853 PetscCall(DMAdaptorSetSolver(adaptor, snes)); in SNESSolve()
4864 if (!x) x = snes->vec_sol; in SNESSolve()
4866 PetscCall(SNESGetDM(snes, &dm)); in SNESSolve()
4870 PetscCall(SNESViewFromOptions(snes, NULL, "-snes_view_pre")); in SNESSolve()
4872 …(grid = 0; grid < snes->gridsequence; grid++) PetscCall(PetscViewerASCIIPushTab(PETSC_VIEWER_STDOU… in SNESSolve()
4873 for (grid = 0; grid < snes->gridsequence + 1; grid++) { in SNESSolve()
4876 PetscCall(VecDestroy(&snes->vec_sol)); in SNESSolve()
4877 snes->vec_sol = x; in SNESSolve()
4878 PetscCall(SNESGetDM(snes, &dm)); in SNESSolve()
4882 PetscCall(VecDestroy(&snes->vec_rhs)); in SNESSolve()
4883 snes->vec_rhs = b; in SNESSolve()
4885 …if (snes->vec_rhs) PetscCheck(snes->vec_func != snes->vec_rhs, PETSC_COMM_SELF, PETSC_ERR_ARG_IDN,… in SNESSolve()
4886 …PetscCheck(snes->vec_func != snes->vec_sol, PETSC_COMM_SELF, PETSC_ERR_ARG_IDN, "Solution vector c… in SNESSolve()
4887 …PetscCheck(snes->vec_rhs != snes->vec_sol, PETSC_COMM_SELF, PETSC_ERR_ARG_IDN, "Solution vector ca… in SNESSolve()
4888 …if (!snes->vec_sol_update /* && snes->vec_sol */) PetscCall(VecDuplicate(snes->vec_sol, &snes->vec… in SNESSolve()
4889 PetscCall(DMShellSetGlobalVector(dm, snes->vec_sol)); in SNESSolve()
4890 PetscCall(SNESSetUp(snes)); in SNESSolve()
4893 …if (snes->ops->computeinitialguess) PetscCallBack("SNES callback compute initial guess", (*snes->o… in SNESSolve()
4896 if (snes->conv_hist_reset) snes->conv_hist_len = 0; in SNESSolve()
4897 PetscCall(SNESResetCounters(snes)); in SNESSolve()
4898 snes->reason = SNES_CONVERGED_ITERATING; in SNESSolve()
4899 PetscCall(PetscLogEventBegin(SNES_Solve, snes, 0, 0, 0)); in SNESSolve()
4900 PetscUseTypeMethod(snes, solve); in SNESSolve()
4901 PetscCall(PetscLogEventEnd(SNES_Solve, snes, 0, 0, 0)); in SNESSolve()
4902 …scCheck(snes->reason, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Internal error, solver %s returned without… in SNESSolve()
4903 snes->functiondomainerror = PETSC_FALSE; /* clear the flag if it has been set */ in SNESSolve()
4904 snes->objectivedomainerror = PETSC_FALSE; /* clear the flag if it has been set */ in SNESSolve()
4905 snes->jacobiandomainerror = PETSC_FALSE; /* clear the flag if it has been set */ in SNESSolve()
4907 if (snes->lagjac_persist) snes->jac_iter += snes->iter; in SNESSolve()
4908 if (snes->lagpre_persist) snes->pre_iter += snes->iter; in SNESSolve()
4910 …OptionsCreateViewer(PetscObjectComm((PetscObject)snes), ((PetscObject)snes)->options, ((PetscObjec… in SNESSolve()
4911 if (flg && !PetscPreLoadingOn) PetscCall(SNESTestLocalMin(snes)); in SNESSolve()
4913 PetscCall(SNESConvergedReasonViewFromOptions(snes)); in SNESSolve()
4915 if (snes->errorifnotconverged) { in SNESSolve()
4916 if (snes->reason < 0) PetscCall(SNESMonitorCancel(snes)); in SNESSolve()
4917 …PetscCheck(snes->reason >= 0, PetscObjectComm((PetscObject)snes), PETSC_ERR_NOT_CONVERGED, "SNESSo… in SNESSolve()
4919 if (snes->reason < 0) break; in SNESSolve()
4920 if (grid < snes->gridsequence) { in SNESSolve()
4925 PetscCall(DMRefine(snes->dm, PetscObjectComm((PetscObject)snes), &fine)); in SNESSolve()
4926 …PetscCheck(fine, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_INCOMP, "DMRefine() did not per… in SNESSolve()
4928 PetscCall(DMCreateInterpolation(snes->dm, fine, &interp, NULL)); in SNESSolve()
4931 PetscCall(DMInterpolate(snes->dm, interp, fine)); in SNESSolve()
4935 PetscCall(SNESReset(snes)); in SNESSolve()
4936 PetscCall(SNESSetDM(snes, fine)); in SNESSolve()
4937 PetscCall(SNESResetFromOptions(snes)); in SNESSolve()
4939 PetscCall(PetscViewerASCIIPopTab(PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)snes)))); in SNESSolve()
4942 PetscCall(SNESViewFromOptions(snes, NULL, "-snes_view")); in SNESSolve()
4943 PetscCall(VecViewFromOptions(snes->vec_sol, (PetscObject)snes, "-snes_view_solution")); in SNESSolve()
4944 PetscCall(DMMonitor(snes->dm)); in SNESSolve()
4945 PetscCall(SNESMonitorPauseFinal_Internal(snes)); in SNESSolve()
4948 PetscCall(PetscObjectSAWsBlock((PetscObject)snes)); in SNESSolve()
4993 PetscErrorCode SNESSetType(SNES snes, SNESType type) in SNESSetType() argument
4999 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetType()
5002 PetscCall(PetscObjectTypeCompare((PetscObject)snes, type, &match)); in SNESSetType()
5006 …PetscCheck(r, PetscObjectComm((PetscObject)snes), PETSC_ERR_ARG_UNKNOWN_TYPE, "Unable to find requ… in SNESSetType()
5008 PetscTryTypeMethod(snes, destroy); in SNESSetType()
5010 snes->ops->reset = NULL; in SNESSetType()
5011 snes->ops->setup = NULL; in SNESSetType()
5012 snes->ops->solve = NULL; in SNESSetType()
5013 snes->ops->view = NULL; in SNESSetType()
5014 snes->ops->setfromoptions = NULL; in SNESSetType()
5015 snes->ops->destroy = NULL; in SNESSetType()
5018 if (((PetscObject)snes)->type_name) PetscCall(SNESLineSearchDestroy(&snes->linesearch)); in SNESSetType()
5021 snes->setupcalled = PETSC_FALSE; in SNESSetType()
5023 PetscCall(PetscObjectChangeTypeName((PetscObject)snes, type)); in SNESSetType()
5024 PetscCall((*r)(snes)); in SNESSetType()
5043 PetscErrorCode SNESGetType(SNES snes, SNESType *type) in SNESGetType() argument
5046 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetType()
5048 *type = ((PetscObject)snes)->type_name; in SNESGetType()
5065 PetscErrorCode SNESSetSolution(SNES snes, Vec u) in SNESSetSolution() argument
5070 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetSolution()
5073 PetscCall(VecDestroy(&snes->vec_sol)); in SNESSetSolution()
5075 snes->vec_sol = u; in SNESSetSolution()
5077 PetscCall(SNESGetDM(snes, &dm)); in SNESSetSolution()
5098 PetscErrorCode SNESGetSolution(SNES snes, Vec *x) in SNESGetSolution() argument
5101 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetSolution()
5103 *x = snes->vec_sol; in SNESGetSolution()
5123 PetscErrorCode SNESGetSolutionUpdate(SNES snes, Vec *x) in SNESGetSolutionUpdate() argument
5126 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetSolutionUpdate()
5128 *x = snes->vec_sol_update; in SNESGetSolutionUpdate()
5152 PetscErrorCode SNESGetFunction(SNES snes, Vec *r, SNESFunctionFn **f, PetscCtxRt ctx) in SNESGetFunction() argument
5157 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetFunction()
5159 if (!snes->vec_func) { in SNESGetFunction()
5160 if (snes->vec_rhs) { in SNESGetFunction()
5161 PetscCall(VecDuplicate(snes->vec_rhs, &snes->vec_func)); in SNESGetFunction()
5162 } else if (snes->vec_sol) { in SNESGetFunction()
5163 PetscCall(VecDuplicate(snes->vec_sol, &snes->vec_func)); in SNESGetFunction()
5164 } else if (snes->dm) { in SNESGetFunction()
5165 PetscCall(DMCreateGlobalVector(snes->dm, &snes->vec_func)); in SNESGetFunction()
5168 *r = snes->vec_func; in SNESGetFunction()
5170 PetscCall(SNESGetDM(snes, &dm)); in SNESGetFunction()
5189 PetscErrorCode SNESGetNGS(SNES snes, SNESNGSFn **f, PetscCtxRt ctx) in SNESGetNGS() argument
5194 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetNGS()
5195 PetscCall(SNESGetDM(snes, &dm)); in SNESGetNGS()
5218 PetscErrorCode SNESSetOptionsPrefix(SNES snes, const char prefix[]) in SNESSetOptionsPrefix() argument
5221 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetOptionsPrefix()
5222 PetscCall(PetscObjectSetOptionsPrefix((PetscObject)snes, prefix)); in SNESSetOptionsPrefix()
5223 if (!snes->ksp) PetscCall(SNESGetKSP(snes, &snes->ksp)); in SNESSetOptionsPrefix()
5224 if (snes->linesearch) { in SNESSetOptionsPrefix()
5225 PetscCall(SNESGetLineSearch(snes, &snes->linesearch)); in SNESSetOptionsPrefix()
5226 PetscCall(PetscObjectSetOptionsPrefix((PetscObject)snes->linesearch, prefix)); in SNESSetOptionsPrefix()
5228 PetscCall(KSPSetOptionsPrefix(snes->ksp, prefix)); in SNESSetOptionsPrefix()
5250 PetscErrorCode SNESAppendOptionsPrefix(SNES snes, const char prefix[]) in SNESAppendOptionsPrefix() argument
5253 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESAppendOptionsPrefix()
5254 PetscCall(PetscObjectAppendOptionsPrefix((PetscObject)snes, prefix)); in SNESAppendOptionsPrefix()
5255 if (!snes->ksp) PetscCall(SNESGetKSP(snes, &snes->ksp)); in SNESAppendOptionsPrefix()
5256 if (snes->linesearch) { in SNESAppendOptionsPrefix()
5257 PetscCall(SNESGetLineSearch(snes, &snes->linesearch)); in SNESAppendOptionsPrefix()
5258 PetscCall(PetscObjectAppendOptionsPrefix((PetscObject)snes->linesearch, prefix)); in SNESAppendOptionsPrefix()
5260 PetscCall(KSPAppendOptionsPrefix(snes->ksp, prefix)); in SNESAppendOptionsPrefix()
5280 PetscErrorCode SNESGetOptionsPrefix(SNES snes, const char *prefix[]) in SNESGetOptionsPrefix() argument
5283 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetOptionsPrefix()
5284 PetscCall(PetscObjectGetOptionsPrefix((PetscObject)snes, prefix)); in SNESGetOptionsPrefix()
5326 PetscErrorCode SNESTestLocalMin(SNES snes) in SNESTestLocalMin() argument
5334 PetscCall(SNESGetSolution(snes, &u)); in SNESTestLocalMin()
5339 …PetscCall(PetscPrintf(PetscObjectComm((PetscObject)snes), "Testing FormFunction() for local min\n"… in SNESTestLocalMin()
5343 PetscCall(PetscPrintf(PetscObjectComm((PetscObject)snes), "i = %" PetscInt_FMT "\n", i)); in SNESTestLocalMin()
5347 PetscCall(SNESComputeFunction(snes, uh, fh)); in SNESTestLocalMin()
5349 …PetscCall(PetscPrintf(PetscObjectComm((PetscObject)snes), " j norm %" PetscInt_FMT " %18.16e… in SNESTestLocalMin()
5379 PetscErrorCode SNESGetLineSearch(SNES snes, SNESLineSearch *linesearch) in SNESGetLineSearch() argument
5384 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetLineSearch()
5386 if (!snes->linesearch) { in SNESGetLineSearch()
5387 PetscCall(SNESGetOptionsPrefix(snes, &optionsprefix)); in SNESGetLineSearch()
5388 PetscCall(SNESLineSearchCreate(PetscObjectComm((PetscObject)snes), &snes->linesearch)); in SNESGetLineSearch()
5389 PetscCall(SNESLineSearchSetSNES(snes->linesearch, snes)); in SNESGetLineSearch()
5390 PetscCall(SNESLineSearchAppendOptionsPrefix(snes->linesearch, optionsprefix)); in SNESGetLineSearch()
5391 PetscCall(PetscObjectIncrementTabLevel((PetscObject)snes->linesearch, (PetscObject)snes, 1)); in SNESGetLineSearch()
5393 *linesearch = snes->linesearch; in SNESGetLineSearch()
5429 PetscErrorCode SNESKSPSetUseEW(SNES snes, PetscBool flag) in SNESKSPSetUseEW() argument
5432 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESKSPSetUseEW()
5433 PetscValidLogicalCollectiveBool(snes, flag, 2); in SNESKSPSetUseEW()
5434 snes->ksp_ewconv = flag; in SNESKSPSetUseEW()
5455 PetscErrorCode SNESKSPGetUseEW(SNES snes, PetscBool *flag) in SNESKSPGetUseEW() argument
5458 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESKSPGetUseEW()
5460 *flag = snes->ksp_ewconv; in SNESKSPGetUseEW()
5491 PetscErrorCode SNESKSPSetParametersEW(SNES snes, PetscInt version, PetscReal rtol_0, PetscReal rtol… in SNESKSPSetParametersEW() argument
5496 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESKSPSetParametersEW()
5497 kctx = (SNESKSPEW *)snes->kspconvctx; in SNESKSPSetParametersEW()
5499 PetscValidLogicalCollectiveInt(snes, version, 2); in SNESKSPSetParametersEW()
5500 PetscValidLogicalCollectiveReal(snes, rtol_0, 3); in SNESKSPSetParametersEW()
5501 PetscValidLogicalCollectiveReal(snes, rtol_max, 4); in SNESKSPSetParametersEW()
5502 PetscValidLogicalCollectiveReal(snes, gamma, 5); in SNESKSPSetParametersEW()
5503 PetscValidLogicalCollectiveReal(snes, alpha, 6); in SNESKSPSetParametersEW()
5504 PetscValidLogicalCollectiveReal(snes, alpha2, 7); in SNESKSPSetParametersEW()
5505 PetscValidLogicalCollectiveReal(snes, threshold, 8); in SNESKSPSetParametersEW()
5547 PetscErrorCode SNESKSPGetParametersEW(SNES snes, PetscInt *version, PetscReal *rtol_0, PetscReal *r… in SNESKSPGetParametersEW() argument
5552 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESKSPGetParametersEW()
5553 kctx = (SNESKSPEW *)snes->kspconvctx; in SNESKSPGetParametersEW()
5567 SNES snes = (SNES)ctx; in KSPPreSolve_SNESEW() local
5568 SNESKSPEW *kctx = (SNESKSPEW *)snes->kspconvctx; in KSPPreSolve_SNESEW()
5572 if (!snes->ksp_ewconv) PetscFunctionReturn(PETSC_SUCCESS); in KSPPreSolve_SNESEW()
5573 if (!snes->iter) { in KSPPreSolve_SNESEW()
5575 PetscCall(VecNorm(snes->vec_func, NORM_2, &kctx->norm_first)); in KSPPreSolve_SNESEW()
5579 rtol = PetscAbsReal(snes->norm - kctx->lresid_last) / kctx->norm_last; in KSPPreSolve_SNESEW()
5583 rtol = kctx->gamma * PetscPowReal(snes->norm / kctx->norm_last, kctx->alpha); in KSPPreSolve_SNESEW()
5587 rtol = kctx->gamma * PetscPowReal(snes->norm / kctx->norm_last, kctx->alpha); in KSPPreSolve_SNESEW()
5593 stol = kctx->gamma * (kctx->norm_first * snes->rtol) / snes->norm; in KSPPreSolve_SNESEW()
5598 PetscReal ared = PetscAbsReal(kctx->norm_last - snes->norm); in KSPPreSolve_SNESEW()
5615 …PetscCall(PetscInfo(snes, "iter %" PetscInt_FMT ", Eisenstat-Walker (version %" PetscInt_FMT ") KS… in KSPPreSolve_SNESEW()
5621 SNES snes = (SNES)ctx; in KSPPostSolve_SNESEW() local
5622 SNESKSPEW *kctx = (SNESKSPEW *)snes->kspconvctx; in KSPPostSolve_SNESEW()
5627 if (!snes->ksp_ewconv) PetscFunctionReturn(PETSC_SUCCESS); in KSPPostSolve_SNESEW()
5629 kctx->norm_last = snes->norm; in KSPPostSolve_SNESEW()
5682 PetscErrorCode SNESGetKSP(SNES snes, KSP *ksp) in SNESGetKSP() argument
5685 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetKSP()
5688 if (!snes->ksp) { in SNESGetKSP()
5689 PetscCall(KSPCreate(PetscObjectComm((PetscObject)snes), &snes->ksp)); in SNESGetKSP()
5690 PetscCall(PetscObjectIncrementTabLevel((PetscObject)snes->ksp, (PetscObject)snes, 1)); in SNESGetKSP()
5692 PetscCall(KSPSetPreSolve(snes->ksp, KSPPreSolve_SNESEW, snes)); in SNESGetKSP()
5693 PetscCall(KSPSetPostSolve(snes->ksp, KSPPostSolve_SNESEW, snes)); in SNESGetKSP()
5695 …PetscCall(KSPMonitorSetFromOptions(snes->ksp, "-snes_monitor_ksp", "snes_preconditioned_residual",… in SNESGetKSP()
5696 PetscCall(PetscObjectSetOptions((PetscObject)snes->ksp, ((PetscObject)snes)->options)); in SNESGetKSP()
5698 *ksp = snes->ksp; in SNESGetKSP()
5721 PetscErrorCode SNESSetDM(SNES snes, DM dm) in SNESSetDM() argument
5727 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetDM()
5730 if (snes->dm) { /* Move the DMSNES context over to the new DM unless the new DM already has one */ in SNESSetDM()
5731 if (snes->dm->dmsnes && !dm->dmsnes) { in SNESSetDM()
5732 PetscCall(DMCopyDMSNES(snes->dm, dm)); in SNESSetDM()
5733 PetscCall(DMGetDMSNES(snes->dm, &sdm)); in SNESSetDM()
5734 …if (sdm->originaldm == snes->dm) sdm->originaldm = dm; /* Grant write privileges to the replacemen… in SNESSetDM()
5736 …PetscCall(DMCoarsenHookRemove(snes->dm, DMCoarsenHook_SNESVecSol, DMRestrictHook_SNESVecSol, snes)… in SNESSetDM()
5737 PetscCall(DMDestroy(&snes->dm)); in SNESSetDM()
5739 snes->dm = dm; in SNESSetDM()
5740 snes->dmAuto = PETSC_FALSE; in SNESSetDM()
5742 PetscCall(SNESGetKSP(snes, &ksp)); in SNESSetDM()
5745 if (snes->npc) { in SNESSetDM()
5746 PetscCall(SNESSetDM(snes->npc, snes->dm)); in SNESSetDM()
5747 PetscCall(SNESSetNPCSide(snes, snes->npcside)); in SNESSetDM()
5767 PetscErrorCode SNESGetDM(SNES snes, DM *dm) in SNESGetDM() argument
5770 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetDM()
5771 if (!snes->dm) { in SNESGetDM()
5772 PetscCall(DMShellCreate(PetscObjectComm((PetscObject)snes), &snes->dm)); in SNESGetDM()
5773 snes->dmAuto = PETSC_TRUE; in SNESGetDM()
5775 *dm = snes->dm; in SNESGetDM()
5800 PetscErrorCode SNESSetNPC(SNES snes, SNES npc) in SNESSetNPC() argument
5803 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetNPC()
5805 PetscCheckSameComm(snes, 1, npc, 2); in SNESSetNPC()
5807 PetscCall(SNESDestroy(&snes->npc)); in SNESSetNPC()
5808 snes->npc = npc; in SNESSetNPC()
5839 PetscErrorCode SNESGetNPC(SNES snes, SNES *pc) in SNESGetNPC() argument
5844 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetNPC()
5846 if (!snes->npc) { in SNESGetNPC()
5849 PetscCall(SNESCreate(PetscObjectComm((PetscObject)snes), &snes->npc)); in SNESGetNPC()
5850 PetscCall(PetscObjectIncrementTabLevel((PetscObject)snes->npc, (PetscObject)snes, 1)); in SNESGetNPC()
5851 PetscCall(SNESGetOptionsPrefix(snes, &optionsprefix)); in SNESGetNPC()
5852 PetscCall(SNESSetOptionsPrefix(snes->npc, optionsprefix)); in SNESGetNPC()
5853 PetscCall(SNESAppendOptionsPrefix(snes->npc, "npc_")); in SNESGetNPC()
5854 if (snes->ops->ctxcompute) { in SNESGetNPC()
5855 … PetscCall(SNESSetComputeApplicationContext(snes, snes->ops->ctxcompute, snes->ops->ctxdestroy)); in SNESGetNPC()
5857 PetscCall(SNESGetApplicationContext(snes, &ctx)); in SNESGetNPC()
5858 PetscCall(SNESSetApplicationContext(snes->npc, ctx)); in SNESGetNPC()
5860 PetscCall(SNESSetCountersReset(snes->npc, PETSC_FALSE)); in SNESGetNPC()
5862 *pc = snes->npc; in SNESGetNPC()
5881 PetscErrorCode SNESHasNPC(SNES snes, PetscBool *has_npc) in SNESHasNPC() argument
5884 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESHasNPC()
5886 *has_npc = snes->npc ? PETSC_TRUE : PETSC_FALSE; in SNESHasNPC()
5915 PetscErrorCode SNESSetNPCSide(SNES snes, PCSide side) in SNESSetNPCSide() argument
5918 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetNPCSide()
5919 PetscValidLogicalCollectiveEnum(snes, side, 2); in SNESSetNPCSide()
5921 …PetscCheck((side == PC_LEFT) || (side == PC_RIGHT), PetscObjectComm((PetscObject)snes), PETSC_ERR_… in SNESSetNPCSide()
5922 snes->npcside = side; in SNESSetNPCSide()
5945 PetscErrorCode SNESGetNPCSide(SNES snes, PCSide *side) in SNESGetNPCSide() argument
5948 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESGetNPCSide()
5950 *side = snes->npcside; in SNESGetNPCSide()
5971 PetscErrorCode SNESSetLineSearch(SNES snes, SNESLineSearch linesearch) in SNESSetLineSearch() argument
5974 PetscValidHeaderSpecific(snes, SNES_CLASSID, 1); in SNESSetLineSearch()
5976 PetscCheckSameComm(snes, 1, linesearch, 2); in SNESSetLineSearch()
5978 PetscCall(SNESLineSearchDestroy(&snes->linesearch)); in SNESSetLineSearch()
5980 snes->linesearch = linesearch; in SNESSetLineSearch()