diff --git a/Makefile b/Makefile index 7a83732..3fcd41a 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ OBJS := $(OBJS) $(SRCDIR)/PETSc_Helper.o \ $(SRCDIR)/PCPFLAREINV.o # Define a variable containing all the tests -export TEST_TARGETS = ex12f ex6f ex6f_getcoeffs ex6 adv_1d adv_diff_2d ex6_cf_splitting adv_diff_cg_supg matrandom +export TEST_TARGETS = ex12f ex6f ex6f_getcoeffs ex6 adv_1d adv_diff_2d ex6_cf_splitting adv_diff_cg_supg matrandom matrandom_check_reset # Include kokkos examples ifeq ($(PETSC_HAVE_KOKKOS),1) export TEST_TARGETS := $(TEST_TARGETS) adv_1dk diff --git a/src/C_PETSc_Interfaces.F90 b/src/C_PETSc_Interfaces.F90 index 2a11959..2619d6e 100644 --- a/src/C_PETSc_Interfaces.F90 +++ b/src/C_PETSc_Interfaces.F90 @@ -250,6 +250,16 @@ end subroutine PCGetSetupCalled_c end interface + interface + + subroutine PCMarkNotSetUp_c(A_array) & + bind(c, name="PCMarkNotSetUp_c") + use iso_c_binding + integer(c_long_long) :: A_array + end subroutine PCMarkNotSetUp_c + + end interface + interface subroutine MatGetDiagonalOnly_c(A_array, diag_only) & diff --git a/src/C_PETSc_Routines.c b/src/C_PETSc_Routines.c index 26d2cec..e3cacdf 100644 --- a/src/C_PETSc_Routines.c +++ b/src/C_PETSc_Routines.c @@ -470,6 +470,12 @@ PETSC_INTERN void PCGetSetupCalled_c(PC *pc, PetscInt *setupcalled) *setupcalled = (*pc)->setupcalled; } +// Mark that we need to do setup again (e.g. after a reset) +PETSC_INTERN void PCMarkNotSetUp_c(PC *pc) +{ + (*pc)->setupcalled = PETSC_FALSE; +} + // Gets the number of nonzeros in the local PETSC_INTERN PetscErrorCode MatGetNNZs_local_c(Mat *A, PetscInt *nnzs) { diff --git a/src/PCAIR.c b/src/PCAIR.c index 252ef55..0f1ed4a 100644 --- a/src/PCAIR.c +++ b/src/PCAIR.c @@ -491,10 +491,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetPrintStatsTimings(PC pc, PetscBool input_boo PETSC_EXTERN PetscErrorCode PCAIRSetMaxLevels(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetMaxLevels(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMaxLevels_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -504,10 +500,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMaxLevels(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetCoarseEqLimit(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCoarseEqLimit(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarseEqLimit_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -518,10 +510,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarseEqLimit(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateStartLevel(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetAutoTruncateStartLevel(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetAutoTruncateStartLevel_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -531,10 +519,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateStartLevel(PC pc, PetscInt input PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateTol(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetAutoTruncateTol(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetAutoTruncateTol_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -549,10 +533,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateTol(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglom(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetProcessorAgglom(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessorAgglom_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -563,10 +543,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglom(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomRatio(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetProcessorAgglomRatio(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessorAgglomRatio_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -577,10 +553,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomRatio(PC pc, PetscReal input_ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomFactor(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetProcessorAgglomFactor(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessorAgglomFactor_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -591,10 +563,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomFactor(PC pc, PetscInt input_ PETSC_EXTERN PetscErrorCode PCAIRSetProcessEqLimit(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetProcessEqLimit(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessEqLimit_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -618,10 +586,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetSubcomm(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetStrongThreshold(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetStrongThreshold(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetStrongThreshold_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -631,10 +595,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetStrongThreshold(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetDDCIts(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetDDCIts(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetDDCIts_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -645,10 +605,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetDDCIts(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetMaxDDRatio(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetMaxDDRatio(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMaxDDRatio_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -658,11 +614,7 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMaxDDRatio(PC pc, PetscReal input_real) // -pc_air_ddc_fraction PETSC_EXTERN PetscErrorCode PCAIRSetDDCFraction(PC pc, PetscReal input_real) { - PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetDDCFraction(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); + PetscFunctionBegin; PCAIRSetDDCFraction_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -675,10 +627,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetDDCFraction(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetCFSplittingType(PC pc, CFSplittingType input_int) { PetscFunctionBegin; - CFSplittingType old_int; - PetscCall(PCAIRGetCFSplittingType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCFSplittingType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -690,10 +638,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCFSplittingType(PC pc, CFSplittingType input PETSC_EXTERN PetscErrorCode PCAIRSetMaxLubySteps(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetMaxLubySteps(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMaxLubySteps_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -703,10 +647,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMaxLubySteps(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetSmoothType(PC pc, const char* input_string) { PetscFunctionBegin; - char old_string[PETSC_MAX_PATH_LEN]; - PetscCall(PCAIRGetSmoothType(pc, old_string)); - if (strcmp(input_string, old_string) == 0) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetSmoothType_c(&pc, input_string); PetscFunctionReturn(PETSC_SUCCESS); } @@ -716,10 +656,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetSmoothType(PC pc, const char* input_string) PETSC_EXTERN PetscErrorCode PCAIRSetMatrixFreePolys(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetMatrixFreePolys(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMatrixFreePolys_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -729,10 +665,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMatrixFreePolys(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetOnePointClassicalProlong(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetOnePointClassicalProlong(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetOnePointClassicalProlong_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -742,10 +674,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetOnePointClassicalProlong(PC pc, PetscBool in PETSC_EXTERN PetscErrorCode PCAIRSetFullSmoothingUpAndDown(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetFullSmoothingUpAndDown(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetFullSmoothingUpAndDown_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -755,10 +683,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetFullSmoothingUpAndDown(PC pc, PetscBool inpu PETSC_EXTERN PetscErrorCode PCAIRSetSymmetric(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetSymmetric(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetSymmetric_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -772,10 +696,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetSymmetric(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetConstrainW(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetConstrainW(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetConstrainW_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -789,10 +709,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetConstrainW(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetConstrainZ(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetConstrainZ(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetConstrainZ_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -803,10 +719,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetConstrainZ(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetImproveWIts(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetImproveWIts(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetImproveWIts_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -817,10 +729,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetImproveWIts(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetImproveZIts(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetImproveZIts(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetImproveZIts_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -833,10 +741,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetImproveZIts(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetStrongRThreshold(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetStrongRThreshold(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetStrongRThreshold_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -857,10 +761,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetStrongRThreshold(PC pc, PetscReal input_real PETSC_EXTERN PetscErrorCode PCAIRSetInverseType(PC pc, PCPFLAREINVType input_int) { PetscFunctionBegin; - PCPFLAREINVType old_int; - PetscCall(PCAIRGetInverseType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetInverseType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -871,10 +771,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetInverseType(PC pc, PCPFLAREINVType input_int PETSC_EXTERN PetscErrorCode PCAIRSetCInverseType(PC pc, PCPFLAREINVType input_int) { PetscFunctionBegin; - PCPFLAREINVType old_int; - PetscCall(PCAIRGetCInverseType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCInverseType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -887,10 +783,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCInverseType(PC pc, PCPFLAREINVType input_in PETSC_EXTERN PetscErrorCode PCAIRSetZType(PC pc, PCAIRZType input_int) { PetscFunctionBegin; - PCAIRZType old_int; - PetscCall(PCAIRGetZType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetZType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -903,10 +795,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetZType(PC pc, PCAIRZType input_int) PETSC_EXTERN PetscErrorCode PCAIRSetLairDistance(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetLairDistance(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetLairDistance_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -917,10 +805,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetLairDistance(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetPolyOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetPolyOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetPolyOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -932,10 +816,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetPolyOrder(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetInverseSparsityOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetInverseSparsityOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetInverseSparsityOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -947,10 +827,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetInverseSparsityOrder(PC pc, PetscInt input_i PETSC_EXTERN PetscErrorCode PCAIRSetCPolyOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCPolyOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCPolyOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -962,10 +838,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCPolyOrder(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetCInverseSparsityOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCInverseSparsityOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCInverseSparsityOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -975,10 +847,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCInverseSparsityOrder(PC pc, PetscInt input_ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseType(PC pc, PCPFLAREINVType input_int) { PetscFunctionBegin; - PCPFLAREINVType old_int; - PetscCall(PCAIRGetCoarsestInverseType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestInverseType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -988,10 +856,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseType(PC pc, PCPFLAREINVType i PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestPolyOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCoarsestPolyOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestPolyOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1001,10 +865,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestPolyOrder(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseSparsityOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCoarsestInverseSparsityOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestInverseSparsityOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1014,10 +874,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseSparsityOrder(PC pc, PetscInt PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestMatrixFreePolys(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetCoarsestMatrixFreePolys(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestMatrixFreePolys_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1037,10 +893,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestSubcomm(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetRDrop(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetRDrop(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetRDrop_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1050,10 +902,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetRDrop(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetADrop(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetADrop(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetADrop_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1063,10 +911,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetADrop(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetALump(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetALump(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetALump_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/src/PCAIR_Interfaces.F90 b/src/PCAIR_Interfaces.F90 index c828059..c54f491 100644 --- a/src/PCAIR_Interfaces.F90 +++ b/src/PCAIR_Interfaces.F90 @@ -93,7 +93,33 @@ subroutine PCAIRGetOptions(pc, options) ! Return the options options => pc_air_data%air_data%options - end subroutine PCAIRGetOptions + end subroutine PCAIRGetOptions + +! ------------------------------------------------------------------------------------------------------------------------------- + + subroutine PCAIRGetOptionsAndShell(pc, options, pc_shell) + + ! Gets the air options and PCSHELL that lives in our PCAIR + + ! ~~~~~~~~ + type(tPC), intent(inout) :: pc + type(air_options), pointer, intent(inout) :: options + type(tPC), intent(inout) :: pc_shell + + type(pc_air_multigrid_data), pointer :: pc_air_data=>null() + PetscErrorCode :: ierr + ! ~~~~~~~~ + + ! Get the underlying PCShell + call PCAIRGetPCShell(pc, pc_shell) + + ! Get the PC shell context + call PCShellGetContext(pc_shell, pc_air_data, ierr) + + ! Return the options + options => pc_air_data%air_data%options + + end subroutine PCAIRGetOptionsAndShell ! ------------------------------------------------------------------------------------------------------------------------------- @@ -1204,10 +1230,27 @@ subroutine PCAIRSetMaxLevels(pc, max_levels, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetMaxLevels(pc, old_int, ierr) + if (old_int == max_levels) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + ! Call the underlying reset - this won't touch the context + ! in our pcshell though as pcshell doesn't offer a way to + ! give a custom reset function + call PCReset(pc_shell, ierr) + ! Call the destroy routine + call PCReset_AIR_Shell(pc_shell, ierr) + ! Have to mark that the outer setup must be called again + call PCMarkNotSetUp_c(pc%v) + options%max_levels = int(max_levels) ierr = 0 @@ -1223,10 +1266,22 @@ subroutine PCAIRSetCoarseEqLimit(pc, coarse_eq_limit, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCoarseEqLimit(pc, old_int, ierr) + if (old_int == coarse_eq_limit) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%coarse_eq_limit = coarse_eq_limit ierr = 0 @@ -1242,10 +1297,22 @@ subroutine PCAIRSetAutoTruncateStartLevel(pc, start_level, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetAutoTruncateStartLevel(pc, old_int, ierr) + if (old_int == start_level) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%auto_truncate_start_level = int(start_level) ierr = 0 @@ -1261,10 +1328,22 @@ subroutine PCAIRSetAutoTruncateTol(pc, tol, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetAutoTruncateTol(pc, old_real, ierr) + if (old_real == tol) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%auto_truncate_tol = tol ierr = 0 @@ -1280,10 +1359,22 @@ subroutine PCAIRSetProcessorAgglom(pc, processor_agglom, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetProcessorAgglom(pc, old_bool, ierr) + if (old_bool .eqv. processor_agglom) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%processor_agglom = processor_agglom ierr = 0 @@ -1299,10 +1390,22 @@ subroutine PCAIRSetProcessorAgglomRatio(pc, ratio, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetProcessorAgglomRatio(pc, old_real, ierr) + if (old_real == ratio) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%processor_agglom_ratio = ratio ierr = 0 @@ -1318,10 +1421,22 @@ subroutine PCAIRSetProcessorAgglomFactor(pc, factor, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetProcessorAgglomFactor(pc, old_int, ierr) + if (old_int == factor) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%processor_agglom_factor = int(factor) ierr = 0 @@ -1337,10 +1452,22 @@ subroutine PCAIRSetProcessEqLimit(pc, limit, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetProcessEqLimit(pc, old_int, ierr) + if (old_int == limit) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%process_eq_limit = limit ierr = 0 @@ -1375,10 +1502,22 @@ subroutine PCAIRSetStrongThreshold(pc, thresh, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetStrongThreshold(pc, old_real, ierr) + if (old_real == thresh) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%strong_threshold = thresh ierr = 0 @@ -1394,10 +1533,22 @@ subroutine PCAIRSetDDCIts(pc, its, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetDDCIts(pc, old_int, ierr) + if (old_int == its) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%ddc_its = int(its) ierr = 0 @@ -1413,10 +1564,22 @@ subroutine PCAIRSetMaxDDRatio(pc, ratio, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetMaxDDRatio(pc, old_real, ierr) + if (old_real == ratio) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%max_dd_ratio = ratio ierr = 0 @@ -1432,10 +1595,22 @@ subroutine PCAIRSetDDCFraction(pc, frac, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetDDCFraction(pc, old_real, ierr) + if (old_real == frac) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%ddc_fraction = frac ierr = 0 @@ -1451,10 +1626,22 @@ subroutine PCAIRSetCFSplittingType(pc, algo, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + CFSplittingType :: old_type ! ~~~~~~~~ + call PCAIRGetCFSplittingType(pc, old_type, ierr) + if (old_type == algo) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%cf_splitting_type = int(algo) ierr = 0 @@ -1470,10 +1657,22 @@ subroutine PCAIRSetMaxLubySteps(pc, steps, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetMaxLubySteps(pc, old_int, ierr) + if (old_int == steps) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%max_luby_steps = int(steps) ierr = 0 @@ -1489,13 +1688,24 @@ subroutine PCAIRSetSmoothType(pc, input_string, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell character(len = 1) :: current_char, old_char + character(len = PETSC_MAX_PATH_LEN) :: old_string integer :: smooth_order_index integer :: errorcode, n, i ! ~~~~~~~~ + call PCAIRGetSmoothType(pc, old_string, ierr) + if (trim(old_string) == trim(input_string)) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) n = len_trim(input_string) if (n == 0) then @@ -1598,10 +1808,22 @@ subroutine PCAIRSetMatrixFreePolys(pc, mf, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetMatrixFreePolys(pc, old_bool, ierr) + if (old_bool .eqv. mf) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%matrix_free_polys = mf ierr = 0 @@ -1617,10 +1839,22 @@ subroutine PCAIRSetOnePointClassicalProlong(pc, onep, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetOnePointClassicalProlong(pc, old_bool, ierr) + if (old_bool .eqv. onep) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%one_point_classical_prolong = onep ierr = 0 @@ -1636,10 +1870,22 @@ subroutine PCAIRSetFullSmoothingUpAndDown(pc, full, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetFullSmoothingUpAndDown(pc, old_bool, ierr) + if (old_bool .eqv. full) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%full_smoothing_up_and_down = full ierr = 0 @@ -1655,10 +1901,22 @@ subroutine PCAIRSetSymmetric(pc, sym, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetSymmetric(pc, old_bool, ierr) + if (old_bool .eqv. sym) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%symmetric = sym ierr = 0 @@ -1674,10 +1932,22 @@ subroutine PCAIRSetConstrainW(pc, constrain, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetConstrainW(pc, old_bool, ierr) + if (old_bool .eqv. constrain) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%constrain_w = constrain ierr = 0 @@ -1693,10 +1963,22 @@ subroutine PCAIRSetConstrainZ(pc, constrain, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetConstrainZ(pc, old_bool, ierr) + if (old_bool .eqv. constrain) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%constrain_z = constrain ierr = 0 @@ -1712,10 +1994,22 @@ subroutine PCAIRSetImproveWIts(pc, its, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetImproveWIts(pc, old_int, ierr) + if (old_int == its) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%improve_w_its = int(its) ierr = 0 @@ -1731,10 +2025,22 @@ subroutine PCAIRSetImproveZIts(pc, its, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetImproveZIts(pc, old_int, ierr) + if (old_int == its) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%improve_z_its = int(its) ierr = 0 @@ -1750,10 +2056,22 @@ subroutine PCAIRSetStrongRThreshold(pc, thresh, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetStrongRThreshold(pc, old_real, ierr) + if (old_real == thresh) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%strong_r_threshold = thresh ierr = 0 @@ -1769,10 +2087,22 @@ subroutine PCAIRSetInverseType(pc, inv_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCPFLAREINVType :: old_type ! ~~~~~~~~ + call PCAIRGetInverseType(pc, old_type, ierr) + if (old_type == inv_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%inverse_type = inv_type ierr = 0 @@ -1788,10 +2118,22 @@ subroutine PCAIRSetCInverseType(pc, inv_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCPFLAREINVType :: old_type ! ~~~~~~~~ + call PCAIRGetCInverseType(pc, old_type, ierr) + if (old_type == inv_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%c_inverse_type = inv_type ierr = 0 @@ -1807,10 +2149,22 @@ subroutine PCAIRSetZType(pc, z_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCAIRZType :: old_type ! ~~~~~~~~ + call PCAIRGetZType(pc, old_type, ierr) + if (old_type == z_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%z_type = z_type ierr = 0 @@ -1826,10 +2180,22 @@ subroutine PCAIRSetLairDistance(pc, distance, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetLairDistance(pc, old_int, ierr) + if (old_int == distance) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%lair_distance = int(distance) ierr = 0 @@ -1845,10 +2211,22 @@ subroutine PCAIRSetPolyOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetPolyOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%poly_order = int(order) ierr = 0 @@ -1864,10 +2242,22 @@ subroutine PCAIRSetInverseSparsityOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetInverseSparsityOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%inverse_sparsity_order = int(order) ierr = 0 @@ -1883,10 +2273,22 @@ subroutine PCAIRSetCPolyOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCPolyOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%c_poly_order = int(order) ierr = 0 @@ -1902,10 +2304,22 @@ subroutine PCAIRSetCInverseSparsityOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCInverseSparsityOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%c_inverse_sparsity_order = int(order) ierr = 0 @@ -1921,10 +2335,22 @@ subroutine PCAIRSetCoarsestInverseType(pc, inv_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCPFLAREINVType :: old_type ! ~~~~~~~~ + call PCAIRGetCoarsestInverseType(pc, old_type, ierr) + if (old_type == inv_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%coarsest_inverse_type = inv_type ierr = 0 @@ -1940,10 +2366,22 @@ subroutine PCAIRSetCoarsestPolyOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCoarsestPolyOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%coarsest_poly_order = int(order) ierr = 0 @@ -1959,10 +2397,22 @@ subroutine PCAIRSetCoarsestInverseSparsityOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCoarsestInverseSparsityOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%coarsest_inverse_sparsity_order = int(order) ierr = 0 @@ -1978,10 +2428,22 @@ subroutine PCAIRSetCoarsestMatrixFreePolys(pc, mf, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetCoarsestMatrixFreePolys(pc, old_bool, ierr) + if (old_bool .eqv. mf) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%coarsest_matrix_free_polys = mf ierr = 0 @@ -2016,10 +2478,22 @@ subroutine PCAIRSetRDrop(pc, rdrop, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetRDrop(pc, old_real, ierr) + if (old_real == rdrop) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%r_drop = rdrop ierr = 0 @@ -2035,10 +2509,22 @@ subroutine PCAIRSetADrop(pc, adrop, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetADrop(pc, old_real, ierr) + if (old_real == adrop) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%a_drop = adrop ierr = 0 @@ -2054,10 +2540,22 @@ subroutine PCAIRSetALump(pc, lump, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetALump(pc, old_bool, ierr) + if (old_bool .eqv. lump) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) + options%a_lump = lump ierr = 0 diff --git a/src/PCPFLAREINV.c b/src/PCPFLAREINV.c index 8c0b716..b7f3a8e 100644 --- a/src/PCPFLAREINV.c +++ b/src/PCPFLAREINV.c @@ -164,7 +164,8 @@ PetscErrorCode PCPFLAREINVSetOrder(PC pc, PetscInt poly_order) PetscCall(PCPFLAREINVGetOrder(pc, &old_order)); if (old_order == poly_order) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); - inv_data->poly_order = (int)poly_order; + inv_data->poly_order = (int)poly_order; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } @@ -190,7 +191,8 @@ PetscErrorCode PCPFLAREINVSetSparsityOrder(PC pc, PetscInt inverse_sparsity_orde PetscCall(PCPFLAREINVGetSparsityOrder(pc, &old_order)); if (old_order == inverse_sparsity_order) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); - inv_data->inverse_sparsity_order = (int)inverse_sparsity_order; + inv_data->inverse_sparsity_order = (int)inverse_sparsity_order; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } @@ -217,6 +219,7 @@ PetscErrorCode PCPFLAREINVSetType(PC pc, PCPFLAREINVType type) if (old_type == type) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); inv_data->inverse_type = type; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } @@ -244,6 +247,7 @@ static PetscErrorCode PCPFLAREINVSetMatrixFree_PFLAREINV(PC pc, PetscBool flg) if (old_flag == flg) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); inv_data->matrix_free = flg; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/tests/Makefile b/tests/Makefile index 3b5b1ba..5dd2e45 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -165,6 +165,11 @@ run_tests_no_load_serial: @echo "Test AIRG with random diagonally dominant matrix" ./matrandom -ksp_max_it 5 @echo "" + @echo "Test AIRG with parameter resets on random diagonally dominant matrix" + ./matrandom_check_reset -ksp_max_it 7 + @echo "Test PCPFLAREINV with parameter resets on random diagonally dominant matrix" + ./matrandom_check_reset -ksp_max_it 12 -check_airg 0 + @echo "" @echo "Test AIRG with SUPG CG FEM in 2D" ./adv_diff_cg_supg -adv_diff_petscspace_degree 1 -dm_plex_simplex 0 -dm_refine 1 -pc_type air -pc_air_a_drop 1e-3 -pc_air_inverse_type power \ -ksp_type richardson -ksp_norm_type unpreconditioned -ksp_max_it 4 diff --git a/tests/matrandom_check_reset.F90 b/tests/matrandom_check_reset.F90 new file mode 100644 index 0000000..8ee8037 --- /dev/null +++ b/tests/matrandom_check_reset.F90 @@ -0,0 +1,92 @@ +#include +#include "finclude/pflare.h" + use petscksp + implicit none + +! Test changing parameters after a solve triggers a reset + + PetscErrorCode :: ierr + Mat :: A + PetscInt :: m, n, nnzs + PetscInt, parameter :: one = 1, two = 2, three = 3, nine = 9 + Vec :: x,b + KSP :: ksp + PC :: pc + PetscBool :: flg, check_airg, check + KSPConvergedReason reason + + call PetscInitialize(PETSC_NULL_CHARACTER,ierr) + ! Register the pflare types + call PCRegister_PFLARE() + + m = 5 + n = 5 + call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-m',m,flg,ierr) + call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr) + check_airg = PETSC_TRUE + call PetscOptionsGetBool(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER, & + '-check_airg', check,flg,ierr) + if (flg) check_airg = check + + ! Create matrix + call MatCreate(PETSC_COMM_WORLD,A,ierr) + call MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n,ierr) + call MatSetFromOptions(A,ierr) + nnzs = m * 2; + call MatSeqAIJSetPreallocation(A, nnzs, PETSC_NULL_INTEGER_ARRAY, ierr) + call MatMPIAIJSetPreallocation(A, nnzs, PETSC_NULL_INTEGER_ARRAY, nnzs, PETSC_NULL_INTEGER_ARRAY, ierr) + call MatSetUp(A,ierr) + + call MatCreateVecs(A,b,x,ierr) + call VecSet(x, 0d0, ierr) + call VecSet(b, 2d0, ierr) + + ! Set random values in matrix + call MatSetRandom(A, PETSC_NULL_RANDOM, ierr) + call MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE, ierr) + call MatDiagonalSet(A, b, ADD_VALUES, ierr) ! make it diagonally dominant + + call KSPCreate(PETSC_COMM_WORLD,ksp,ierr) + call KSPSetOperators(ksp,A,A,ierr) + call KSPGetPC(ksp,pc,ierr) + ! Set AIRG as pc + if (check_airg) then + call PCSetType(pc, PCAIR, ierr) + ! Set an initial option to test it persists after reset + call PCAIRSetCoarseEqLimit(pc, nine, ierr) + else + call PCSetType(pc, PCPFLAREINV, ierr) + call PCPFLAREINVSetOrder(pc, two, ierr) + end if + + call KSPSetPC(ksp, pc, ierr) + call KSPSetFromOptions(ksp,ierr) + call KSPSetUp(ksp,ierr) + + ! Do the solve + call KSPSolve(ksp,b,x,ierr) + call KSPGetConvergedReason(ksp, reason, ierr) + if (reason%v < 0) then + error stop 1 + end if + + ! Do a second solve with some changed parameters to test reset + if (check_airg) then + call PCAIRSetMaxLevels(pc, two, ierr) + call PCAIRSetStrongThreshold(pc, 0.4d0, ierr) + else + call PCPFLAREINVSetMatrixFree(pc, PETSC_TRUE, ierr) + end if + call VecSet(x, 0d0, ierr) + call KSPSolve(ksp,b,x,ierr) + call KSPGetConvergedReason(ksp, reason, ierr) + if (reason%v < 0) then + error stop 1 + end if + + call MatDestroy(A, ierr) + call VecDestroy(b, ierr) + call VecDestroy(x, ierr) + call KSPDestroy(ksp, ierr) + call PetscFinalize(ierr) + end \ No newline at end of file