From eaa43d847d34f14e81a3f363fe130e28052cfad5 Mon Sep 17 00:00:00 2001 From: Nuno Nobre Date: Mon, 28 Oct 2024 23:21:18 +0000 Subject: [PATCH] Replace LIBMESH_CHKERR with LibmeshPetscCallQ (#28929) --- framework/src/utils/SlepcSupport.C | 51 +++++++++--------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/framework/src/utils/SlepcSupport.C b/framework/src/utils/SlepcSupport.C index 1623461514dc..4930cfae82c3 100644 --- a/framework/src/utils/SlepcSupport.C +++ b/framework/src/utils/SlepcSupport.C @@ -1216,12 +1216,10 @@ mooseSlepcStoppingTest(EPS eps, EPSConvergedReason * reason, void * ctx) { - PetscErrorCode ierr; EigenProblem * eigen_problem = static_cast(ctx); PetscFunctionBegin; - ierr = EPSStoppingBasic(eps, its, max_it, nconv, nev, reason, NULL); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(EPSStoppingBasic(eps, its, max_it, nconv, nev, reason, NULL)); // If we do free power iteration, we need to mark the solver as converged. // It is because SLEPc does not offer a way to copy unconverged solution. @@ -1240,24 +1238,20 @@ mooseSlepcStoppingTest(EPS eps, PetscErrorCode mooseSlepcEPSGetSNES(EPS eps, SNES * snes) { - PetscErrorCode ierr; PetscBool same, nonlinear; PetscFunctionBegin; - ierr = PetscObjectTypeCompare((PetscObject)eps, EPSPOWER, &same); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(PetscObjectTypeCompare((PetscObject)eps, EPSPOWER, &same)); if (!same) mooseError("It is not eps power, and there is no snes"); - ierr = EPSPowerGetNonlinear(eps, &nonlinear); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(EPSPowerGetNonlinear(eps, &nonlinear)); if (!nonlinear) mooseError("It is not a nonlinear eigen solver"); - ierr = EPSPowerGetSNES(eps, snes); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(EPSPowerGetSNES(eps, snes)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1265,21 +1259,17 @@ mooseSlepcEPSGetSNES(EPS eps, SNES * snes) PetscErrorCode mooseSlepcEPSSNESSetUpOptionPrefix(EPS eps) { - PetscErrorCode ierr; SNES snes; const char * prefix = nullptr; PetscFunctionBegin; - ierr = mooseSlepcEPSGetSNES(eps, &snes); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(mooseSlepcEPSGetSNES(eps, &snes)); // There is an extra "eps_power" in snes that users do not like it. // Let us remove that from snes. // Retrieve option prefix from EPS - ierr = PetscObjectGetOptionsPrefix((PetscObject)eps, &prefix); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(PetscObjectGetOptionsPrefix((PetscObject)eps, &prefix)); // Set option prefix to SNES - ierr = SNESSetOptionsPrefix(snes, prefix); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(SNESSetOptionsPrefix(snes, prefix)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1287,41 +1277,33 @@ mooseSlepcEPSSNESSetUpOptionPrefix(EPS eps) PetscErrorCode mooseSlepcEPSSNESSetCustomizePC(EPS eps) { - PetscErrorCode ierr; SNES snes; KSP ksp; PC pc; PetscFunctionBegin; // Get SNES from EPS - ierr = mooseSlepcEPSGetSNES(eps, &snes); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(mooseSlepcEPSGetSNES(eps, &snes)); // Get KSP from SNES - ierr = SNESGetKSP(snes, &ksp); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(SNESGetKSP(snes, &ksp)); // Get PC from KSP - ierr = KSPGetPC(ksp, &pc); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(KSPGetPC(ksp, &pc)); // Set PC type - ierr = PCSetType(pc, "moosepc"); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(PCSetType(pc, "moosepc")); PetscFunctionReturn(PETSC_SUCCESS); } PetscErrorCode mooseSlepcEPSSNESKSPSetPCSide(FEProblemBase & problem, EPS eps) { - PetscErrorCode ierr; SNES snes; KSP ksp; PetscFunctionBegin; // Get SNES from EPS - ierr = mooseSlepcEPSGetSNES(eps, &snes); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(mooseSlepcEPSGetSNES(eps, &snes)); // Get KSP from SNES - ierr = SNESGetKSP(snes, &ksp); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(SNESGetKSP(snes, &ksp)); Moose::PetscSupport::petscSetDefaultPCSide(problem, ksp); @@ -1340,7 +1322,6 @@ mooseSlepcEPSMonitor(EPS eps, void * mctx) { ST st; - auto ierr = (PetscErrorCode)0; PetscScalar eigenr, eigeni; PetscFunctionBegin; @@ -1348,13 +1329,11 @@ mooseSlepcEPSMonitor(EPS eps, auto & console = eigen_problem->console(); auto inverse = eigen_problem->outputInverseEigenvalue(); - ierr = EPSGetST(eps, &st); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(EPSGetST(eps, &st)); eigenr = eigr[0]; eigeni = eigi[0]; // Make the eigenvalue consistent with shift type - ierr = STBackTransform(st, 1, &eigenr, &eigeni); - LIBMESH_CHKERR(ierr); + LibmeshPetscCallQ(STBackTransform(st, 1, &eigenr, &eigeni)); auto eigenvalue = inverse ? 1.0 / eigenr : eigenr;