Commit 3bf42ab2 authored by Christophe Geuzaine's avatar Christophe Geuzaine

simplify petsc/slepc version checks

parent becdc47c
Pipeline #2117 passed with stage
in 12 minutes 31 seconds
......@@ -308,7 +308,7 @@ static void _storeEigenVectors(struct DofData *DofData_P, int nconv, EPS eps,
Current.TimeStep += 1.;
}
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
_try(VecDestroy(&xr));
_try(VecDestroy(&xi));
if(Message::GetCommSize() > 1){
......@@ -379,7 +379,7 @@ static void _linearEVP(struct DofData * DofData_P, int numEigenValues,
_try(PCSetType(pc, PCLU));
#if defined(PETSC_HAVE_MUMPS)
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9)
_try(PCFactorSetMatSolverType(pc, "mumps"));
#elif (PETSC_VERSION_MAJOR > 2)
_try(PCFactorSetMatSolverPackage(pc, "mumps"));
......@@ -417,7 +417,7 @@ static void _linearEVP(struct DofData * DofData_P, int numEigenValues,
Message::Error("SLEPc diverged after %d iterations", its);
else if(reason == EPS_DIVERGED_BREAKDOWN)
Message::Error("SLEPc generic breakdown in method");
#if !(PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
#if !((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
else if(reason == EPS_DIVERGED_NONSYMMETRIC)
Message::Error("The operator is nonsymmetric");
#endif
......@@ -433,7 +433,7 @@ static void _linearEVP(struct DofData * DofData_P, int numEigenValues,
// print eigenvalues and store eigenvectors in DofData
_storeEigenVectors(DofData_P, nconv, eps, PETSC_NULL,PETSC_NULL , filterExpressionIndex);
#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
_try(EPSDestroy(&eps));
#else
_try(EPSDestroy(eps));
......@@ -501,7 +501,7 @@ static void _quadraticEVP(struct DofData * DofData_P, int numEigenValues,
_try(KSPGetPC(ksp, &pc));
_try(PCSetType(pc, PCLU));
#if defined(PETSC_HAVE_MUMPS)
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9)
_try(PCFactorSetMatSolverType(pc, "mumps"));
#elif (PETSC_VERSION_MAJOR > 2)
_try(PCFactorSetMatSolverPackage(pc, "mumps"));
......@@ -554,7 +554,7 @@ static void _quadraticEVP(struct DofData * DofData_P, int numEigenValues,
// print eigenvalues and store eigenvectors in DofData
_storeEigenVectors(DofData_P, nconv, PETSC_NULL, qep, PETSC_NULL, filterExpressionIndex);
#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
_try(QEPDestroy(&qep));
#else
_try(QEPDestroy(qep));
......@@ -623,7 +623,7 @@ static void _quadraticEVP(struct DofData * DofData_P, int numEigenValues,
_try(KSPGetPC(ksp, &pc));
_try(PCSetType(pc, PCLU));
#if defined(PETSC_HAVE_MUMPS)
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9)
_try(PCFactorSetMatSolverType(pc, "mumps"));
#elif (PETSC_VERSION_MAJOR > 2)
_try(PCFactorSetMatSolverPackage(pc, "mumps"));
......@@ -794,9 +794,7 @@ static void _nonlinearEVP(struct DofData * DofData_P, int numEigenValues,
double shift_r, double shift_i, int filterExpressionIndex,
List_T *RationalCoefsNum, List_T *RationalCoefsDen)
{
// #if (PETSC_VERSION_RELEASE != 0)
// Message::Error("You need PETSc/SLEPc dev for nonlinear EVP support!");
// #else
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 8)
NEP nep;
NEPType type;
int max_Nchar = 1000;
......@@ -992,7 +990,9 @@ static void _nonlinearEVP(struct DofData * DofData_P, int numEigenValues,
_storeEigenVectors(DofData_P, nconv, PETSC_NULL, PETSC_NULL, nep, filterExpressionIndex);
_try(NEPDestroy(&nep));
// #endif
#else
Msg::Error("Nonlinear eigenvalue solver requires PETSc/SLEPc >= 3.8");
#endif
}
void EigenSolve_SLEPC(struct DofData * DofData_P, int numEigenValues,
......
......@@ -71,7 +71,7 @@ static void _try(int ierr)
static int SolverInitialized = 0;
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 7))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 7)
#define PetscTruth PetscBool
#define PetscOptionsGetTruth(A, B, C, D) PetscOptionsGetBool(A, NULL, B, C, D)
#define PetscOptionsInsertFile(A, B, C) PetscOptionsInsertFile(A, NULL, B, C)
......@@ -84,6 +84,10 @@ static int SolverInitialized = 0;
#define PetscOptionsGetTruth PetscOptionsGetBool
#endif
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9)
#define PCFactorSetMatSolverPackage PCFactorSetMatSolverType
#endif
void LinAlg_InitializeSolver(int* argc, char*** argv)
{
if(SolverInitialized) return;
......@@ -186,7 +190,7 @@ void _fillseq(Vec &V, Vec &Vseq)
VecScatterEnd(ctx, V, Vseq, INSERT_VALUES, SCATTER_FORWARD);
#endif
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
VecScatterDestroy(&ctx);
#else
VecScatterDestroy(ctx);
......@@ -269,7 +273,7 @@ void LinAlg_CreateMatrix(gMatrix *M, gSolver *Solver, int n, int m)
void LinAlg_DestroySolver(gSolver *Solver)
{
for(int i = 0; i < 10; i++){
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
if(Solver->ksp[i]) _try(KSPDestroy(&Solver->ksp[i]));
if(Solver->snes[i]) _try(SNESDestroy(&Solver->snes[i]));
#else
......@@ -281,7 +285,7 @@ void LinAlg_DestroySolver(gSolver *Solver)
void LinAlg_DestroyVector(gVector *V)
{
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
_try(VecDestroy(&V->V));
if(V->haveSeq) _try(VecDestroy(&V->Vseq));
#else
......@@ -292,7 +296,7 @@ void LinAlg_DestroyVector(gVector *V)
void LinAlg_DestroyMatrix(gMatrix *M)
{
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
_try(MatDestroy(&M->M));
#else
_try(MatDestroy(M->M));
......@@ -436,7 +440,7 @@ void LinAlg_PrintVector(FILE *file, gVector *V, bool matlab,
_try(PetscViewerSetFormat(fd, PETSC_VIEWER_ASCII_MATLAB));
_try(PetscObjectSetName((PetscObject)V->V, varName));
_try(VecView(V->V, fd));
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
_try(PetscViewerDestroy(&fd));
#else
_try(PetscViewerDestroy(fd));
......@@ -480,7 +484,7 @@ void LinAlg_PrintMatrix(FILE *file, gMatrix *M, bool matlab,
_try(PetscViewerSetFormat(fd2, PETSC_VIEWER_DEFAULT));
_try(MatView(M->M, fd2));
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)
_try(PetscViewerDestroy(&fd));
_try(PetscViewerDestroy(&fd2));
#else
......@@ -1276,7 +1280,7 @@ static void _solve(gMatrix *A, gVector *B, gSolver *Solver, gVector *X,
if(!Solver->ksp[kspIndex]) {
_try(KSPCreate(MyComm, &Solver->ksp[kspIndex]));
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 5))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 5)
_try(KSPSetOperators(Solver->ksp[kspIndex], A->M, A->M));
#else
_try(KSPSetOperators(Solver->ksp[kspIndex], A->M, A->M, DIFFERENT_NONZERO_PATTERN));
......@@ -1289,9 +1293,7 @@ static void _solve(gMatrix *A, gVector *B, gSolver *Solver, gVector *X,
// native PETSc LU)
_try(KSPSetType(Solver->ksp[kspIndex], "preonly"));
_try(PCSetType(pc, PCLU));
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9))
_try(PCFactorSetMatSolverType(pc, "mumps"));
#elif (PETSC_VERSION_MAJOR > 2) && defined(PETSC_HAVE_MUMPS)
#if (PETSC_VERSION_MAJOR > 2) && defined(PETSC_HAVE_MUMPS)
_try(PCFactorSetMatSolverPackage(pc, "mumps"));
#elif (PETSC_VERSION_MAJOR > 2) && defined(PETSC_HAVE_MKL_PARDISO)
_try(PCFactorSetMatSolverPackage(pc, "mkl_pardiso"));
......@@ -1314,7 +1316,7 @@ static void _solve(gMatrix *A, gVector *B, gSolver *Solver, gVector *X,
// either we are on parallel (!GetIsCommWorld) or in sequential with rank
// = 0 (GetIsCommWorld)
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 4))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 4)
const char *ksptype = "";
_try(KSPGetType(Solver->ksp[kspIndex], &ksptype));
const char *pctype = "";
......@@ -1326,7 +1328,7 @@ static void _solve(gMatrix *A, gVector *B, gSolver *Solver, gVector *X,
_try(PCGetType(pc, &pctype));
#endif
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9)
MatSolverType stype;
_try(PCFactorGetMatSolverType(pc, &stype));
#elif (PETSC_VERSION_MAJOR > 2)
......@@ -1339,7 +1341,7 @@ static void _solve(gMatrix *A, gVector *B, gSolver *Solver, gVector *X,
}
}
else if(precond){
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 5))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 5)
_try(KSPSetReusePreconditioner(Solver->ksp[kspIndex], PETSC_FALSE));
_try(KSPSetOperators(Solver->ksp[kspIndex], A->M, A->M));
#else
......@@ -1347,7 +1349,7 @@ static void _solve(gMatrix *A, gVector *B, gSolver *Solver, gVector *X,
#endif
}
else{
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 5))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 5)
_try(KSPSetReusePreconditioner(Solver->ksp[kspIndex], PETSC_TRUE));
#endif
}
......@@ -1512,7 +1514,7 @@ static void _solveNL(gMatrix *A, gVector *B, gMatrix *J, gVector *R, gSolver *So
if (fd_jacobian || snes_fd) {
// Message::Error("Finite Difference Jacobian not yet implemented");
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 4))
#if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 4)
_try(SNESSetJacobian(Solver->snes[solverIndex], J->M, J->M,
SNESComputeJacobianDefault, PETSC_NULL));
#else
......@@ -1535,9 +1537,7 @@ static void _solveNL(gMatrix *A, gVector *B, gMatrix *J, gVector *R, gSolver *So
_try(KSPGetPC(ksp, &pc));
_try(KSPSetType(ksp, "preonly"));
_try(PCSetType(pc, PCLU));
#if (PETSC_VERSION_RELEASE == 0) || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 9))
_try(PCFactorSetMatSolverType(pc, "mumps"));
#elif (PETSC_VERSION_MAJOR > 2) && defined(PETSC_HAVE_MUMPS)
#if (PETSC_VERSION_MAJOR > 2) && defined(PETSC_HAVE_MUMPS)
_try(PCFactorSetMatSolverPackage(pc, "mumps"));
#endif
_try(SNESSolve(Solver->snes[solverIndex], PETSC_NULL, X->V));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment