From 87a673d55f0cdef3a5063cfaeb47401c9874de70 Mon Sep 17 00:00:00 2001 From: young Date: Sun, 7 Mar 2010 12:50:06 +0000 Subject: [PATCH] Implementation of simplified PETSc version control in PETScWrappers. git-svn-id: https://svn.dealii.org/trunk@20745 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/petsc_matrix_base.h | 2 ++ .../lac/petsc_parallel_sparse_matrix.h | 1 - deal.II/lac/source/petsc_matrix_base.cc | 30 +++++++------------ .../source/petsc_parallel_sparse_matrix.cc | 10 +++---- deal.II/lac/source/petsc_precondition.cc | 19 ++++-------- deal.II/lac/source/petsc_solver.cc | 11 +++---- deal.II/lac/source/petsc_sparse_matrix.cc | 6 ++-- deal.II/lac/source/petsc_vector_base.cc | 24 +++++++-------- 8 files changed, 43 insertions(+), 60 deletions(-) diff --git a/deal.II/lac/include/lac/petsc_matrix_base.h b/deal.II/lac/include/lac/petsc_matrix_base.h index 2d9e06699f..b4f4d80426 100644 --- a/deal.II/lac/include/lac/petsc_matrix_base.h +++ b/deal.II/lac/include/lac/petsc_matrix_base.h @@ -1096,6 +1096,7 @@ namespace PETScWrappers */ PetscTruth is_symmetric (const double tol = 0.0); +#if DEAL_II_PETSC_VERSION_GTE(2,3,0) /** * Test whether a matrix is Hermitian, * i.e. it is the complex conjugate @@ -1103,6 +1104,7 @@ namespace PETScWrappers * is zero. */ PetscTruth is_hermitian (const double tol = 0.0); +#endif /* * Abstract PETSc object that helps view diff --git a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h index 38ead029a8..188cbdc02e 100644 --- a/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h +++ b/deal.II/lac/include/lac/petsc_parallel_sparse_matrix.h @@ -13,7 +13,6 @@ #ifndef __deal2__petsc_parallel_sparse_matrix_h #define __deal2__petsc_parallel_sparse_matrix_h - #include #ifdef DEAL_II_USE_PETSC diff --git a/deal.II/lac/source/petsc_matrix_base.cc b/deal.II/lac/source/petsc_matrix_base.cc index f19b3944e8..9f1fc2fa50 100644 --- a/deal.II/lac/source/petsc_matrix_base.cc +++ b/deal.II/lac/source/petsc_matrix_base.cc @@ -48,9 +48,7 @@ namespace PETScWrappers // get a representation of the present // row -#if (PETSC_VERSION_MAJOR <= 2) && \ - ((PETSC_VERSION_MINOR < 2) || \ - ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) +#if DEAL_II_PETSC_VERSION_LT(2,2,1) int ncols; int *colnums; PetscScalar *values; @@ -141,9 +139,7 @@ namespace PETScWrappers // now set all the entries of this row to // zero -#if (PETSC_VERSION_MAJOR <= 2) && \ - ((PETSC_VERSION_MINOR < 2) || \ - ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) +#if DEAL_II_PETSC_VERSION_LT(2,2,1) const int petsc_row = row; #else const PetscInt petsc_row = row; @@ -152,7 +148,7 @@ namespace PETScWrappers IS index_set; ISCreateGeneral (get_mpi_communicator(), 1, &petsc_row, &index_set); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = MatZeroRows(matrix, index_set, &new_diag_value); #else @@ -177,9 +173,7 @@ namespace PETScWrappers // now set all the entries of these rows // to zero -#if (PETSC_VERSION_MAJOR <= 2) && \ - ((PETSC_VERSION_MINOR < 2) || \ - ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) +#if DEAL_II_PETSC_VERSION_LT(2,2,1) const std::vector petsc_rows (rows.begin(), rows.end()); #else const std::vector petsc_rows (rows.begin(), rows.end()); @@ -192,7 +186,7 @@ namespace PETScWrappers ISCreateGeneral (get_mpi_communicator(), rows.size(), &petsc_rows[0], &index_set); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = MatZeroRows(matrix, index_set, &new_diag_value); #else @@ -353,9 +347,7 @@ namespace PETScWrappers // get a representation of the present // row - #if (PETSC_VERSION_MAJOR <= 2) && \ - ((PETSC_VERSION_MINOR < 2) || \ - ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) +#if DEAL_II_PETSC_VERSION_LT(2,2,1) int ncols; int *colnums; PetscScalar *values; @@ -426,7 +418,7 @@ namespace PETScWrappers MatrixBase & MatrixBase::operator *= (const PetscScalar a) { -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = MatScale (&a, matrix); #else const int ierr = MatScale (matrix, a); @@ -443,7 +435,7 @@ namespace PETScWrappers { const PetscScalar factor = 1./a; -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = MatScale (&factor, matrix); #else const int ierr = MatScale (matrix, factor); @@ -551,7 +543,7 @@ namespace PETScWrappers { int ierr; -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) ierr = MatTranspose(matrix, PETSC_NULL); #else ierr = MatTranspose(matrix, MAT_REUSE_MATRIX, &matrix); @@ -577,7 +569,7 @@ namespace PETScWrappers // First flush PETSc caches compress (); -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) // avoid warning about unused variables (void) tolerance; @@ -595,7 +587,7 @@ namespace PETScWrappers compress (); // Set options -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) PetscViewerSetFormat (PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_DEFAULT); #else diff --git a/deal.II/lac/source/petsc_parallel_sparse_matrix.cc b/deal.II/lac/source/petsc_parallel_sparse_matrix.cc index 1d998b3e99..02328ba853 100644 --- a/deal.II/lac/source/petsc_parallel_sparse_matrix.cc +++ b/deal.II/lac/source/petsc_parallel_sparse_matrix.cc @@ -192,7 +192,7 @@ namespace PETScWrappers // set symmetric flag, if so requested if (is_symmetric == true) { -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) const int ierr = MatSetOption (matrix, MAT_SYMMETRIC); #else @@ -258,7 +258,7 @@ namespace PETScWrappers // set symmetric flag, if so requested if (is_symmetric == true) { -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) const int ierr = MatSetOption (matrix, MAT_SYMMETRIC); #else @@ -368,9 +368,7 @@ namespace PETScWrappers // available. if we don't have this, we // have to somehow clumsily work around // the whole thing: -#if (PETSC_VERSION_MAJOR <= 2) && \ - ((PETSC_VERSION_MINOR < 2) || \ - ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) +#if DEAL_II_PETSC_VERSION_LT(2,2,1) #ifdef PETSC_USE_64BIT_INDICES std::vector @@ -489,7 +487,7 @@ namespace PETScWrappers // further entries, so PETSc can // internally optimize some data // structures. -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) const int ierr = MatSetOption (matrix, MAT_NO_NEW_NONZERO_LOCATIONS); #else diff --git a/deal.II/lac/source/petsc_precondition.cc b/deal.II/lac/source/petsc_precondition.cc index b2bc95b8f2..7ceeae2f68 100644 --- a/deal.II/lac/source/petsc_precondition.cc +++ b/deal.II/lac/source/petsc_precondition.cc @@ -234,10 +234,7 @@ namespace PETScWrappers AssertThrow (ierr == 0, ExcPETScError(ierr)); // then set flags -#if ((PETSC_VERSION_MAJOR == 2) && \ - ((PETSC_VERSION_MINOR < 3) || \ - ((PETSC_VERSION_MINOR == 3) && \ - (PETSC_VERSION_SUBMINOR < 1)))) +#if DEAL_II_PETSC_VERSION_LT(2,3,1) PCICCSetLevels (pc, additional_data.levels); #else PCFactorSetLevels (pc, additional_data.levels); @@ -277,10 +274,7 @@ namespace PETScWrappers AssertThrow (ierr == 0, ExcPETScError(ierr)); // then set flags -#if ((PETSC_VERSION_MAJOR == 2) && \ - ((PETSC_VERSION_MINOR < 3) || \ - ((PETSC_VERSION_MINOR == 3) && \ - (PETSC_VERSION_SUBMINOR < 1)))) +#if DEAL_II_PETSC_VERSION_LT(2,3,1) PCILUSetLevels (pc, additional_data.levels); #else PCFactorSetLevels (pc, additional_data.levels); @@ -324,17 +318,14 @@ namespace PETScWrappers AssertThrow (ierr == 0, ExcPETScError(ierr)); // set flags as given -#if ((PETSC_VERSION_MAJOR == 2) && \ - ((PETSC_VERSION_MINOR < 3) || \ - ((PETSC_VERSION_MINOR == 3) && \ - (PETSC_VERSION_SUBMINOR < 1)))) +#if DEAL_II_PETSC_VERSION_LT(2,3,1) ierr = PCLUSetPivoting (pc, additional_data.pivoting); #else ierr = PCFactorSetPivoting (pc, additional_data.pivoting); #endif AssertThrow (ierr == 0, ExcPETScError(ierr)); -#if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) ierr = PCLUSetZeroPivot (pc, additional_data.zero_pivot); #else ierr = PCFactorSetZeroPivot (pc, additional_data.zero_pivot); @@ -342,7 +333,7 @@ namespace PETScWrappers AssertThrow (ierr == 0, ExcPETScError(ierr)); -#if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) ierr = PCLUSetDamping (pc, additional_data.damping); #else ierr = PCFactorSetShiftNonzero (pc, additional_data.damping); diff --git a/deal.II/lac/source/petsc_solver.cc b/deal.II/lac/source/petsc_solver.cc index b8e2b7ceb8..cb4aa99173 100644 --- a/deal.II/lac/source/petsc_solver.cc +++ b/deal.II/lac/source/petsc_solver.cc @@ -21,8 +21,8 @@ # include # include -#if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR < 2) -# include +#if DEAL_II_PETSC_VERSION_LT(2,2,0) +#include #endif #include @@ -75,7 +75,8 @@ namespace PETScWrappers // us to work around this by offering two // completely different // implementations. sigh... -#if (PETSC_VERSION_MAJOR == 2) && (PETSC_VERSION_MINOR < 2) +#if DEAL_II_PETSC_VERSION_LT(2,2,0) + // first create a solver object SLES sles; ierr = SLESCreate (mpi_communicator, &sles); @@ -163,7 +164,7 @@ namespace PETScWrappers // checks with the solver_control // object we have in this object for // convergence -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) KSPSetConvergenceTest (solver_data->ksp, &convergence_test, reinterpret_cast(&solver_control)); #else @@ -179,7 +180,7 @@ namespace PETScWrappers // system. unfortunately, the call // sequence is different between PETSc // versions 2.2.0 and 2.2.1 -# if (PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0) +#if DEAL_II_PETSC_VERSION_LT(2,2,1) ierr = KSPSetRhs(solver_data->ksp,b); AssertThrow (ierr == 0, ExcPETScError(ierr)); ierr = KSPSetSolution(solver_data->ksp, x); diff --git a/deal.II/lac/source/petsc_sparse_matrix.cc b/deal.II/lac/source/petsc_sparse_matrix.cc index cd6c2e3796..afe6050a56 100644 --- a/deal.II/lac/source/petsc_sparse_matrix.cc +++ b/deal.II/lac/source/petsc_sparse_matrix.cc @@ -149,7 +149,7 @@ namespace PETScWrappers // set symmetric flag, if so requested if (is_symmetric == true) { -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) const int ierr = MatSetOption (matrix, MAT_SYMMETRIC); #else @@ -194,7 +194,7 @@ namespace PETScWrappers // set symmetric flag, if so requested if (is_symmetric == true) { -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) const int ierr = MatSetOption (matrix, MAT_SYMMETRIC); #else @@ -264,7 +264,7 @@ namespace PETScWrappers // In the end, tell the matrix that // it should not expect any new // entries. -#if (PETSC_VERSION_MAJOR <= 2) +#if DEAL_II_PETSC_VERSION_LT(3,0,0) const int ierr = MatSetOption (matrix, MAT_NO_NEW_NONZERO_LOCATIONS); #else diff --git a/deal.II/lac/source/petsc_vector_base.cc b/deal.II/lac/source/petsc_vector_base.cc index 259e8a1566..9f6550833d 100644 --- a/deal.II/lac/source/petsc_vector_base.cc +++ b/deal.II/lac/source/petsc_vector_base.cc @@ -138,7 +138,7 @@ namespace PETScWrappers // (see test bits/petsc_65) compress (); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecSet (&s, vector); #else const int ierr = VecSet (vector, s); @@ -597,7 +597,7 @@ namespace PETScWrappers Assert (numbers::is_finite(a), ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)")); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecScale (&a, vector); #else const int ierr = VecScale (vector, a); @@ -622,7 +622,7 @@ namespace PETScWrappers Assert (numbers::is_finite(factor), ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)")); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecScale (&factor, vector); #else const int ierr = VecScale (vector, factor); @@ -638,7 +638,7 @@ namespace PETScWrappers VectorBase & VectorBase::operator += (const VectorBase &v) { -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const PetscScalar one = 1.0; const int ierr = VecAXPY (&one, v, vector); #else @@ -655,7 +655,7 @@ namespace PETScWrappers VectorBase & VectorBase::operator -= (const VectorBase &v) { -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const PetscScalar minus_one = -1.0; const int ierr = VecAXPY (&minus_one, v, vector); #else @@ -676,7 +676,7 @@ namespace PETScWrappers Assert (numbers::is_finite(s), ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)")); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecShift (&s, vector); #else const int ierr = VecShift (vector, s); @@ -703,7 +703,7 @@ namespace PETScWrappers Assert (numbers::is_finite(a), ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)")); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecAXPY (&a, v, vector); #else const int ierr = VecAXPY (vector, a, v); @@ -729,7 +729,7 @@ namespace PETScWrappers const PetscScalar weights[2] = {a,b}; Vec addends[2] = {v.vector, w.vector}; -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecMAXPY (2, weights, vector, addends); #else const int ierr = VecMAXPY (vector, 2, weights, addends); @@ -748,7 +748,7 @@ namespace PETScWrappers Assert (numbers::is_finite(s), ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)")); -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecAYPX (&s, v, vector); #else const int ierr = VecAYPX (vector, s, v); @@ -801,7 +801,7 @@ namespace PETScWrappers const PetscScalar weights[2] = {a,b}; Vec addends[2] = {v.vector,w.vector}; -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecMAXPY (2, weights, vector, addends); #else const int ierr = VecMAXPY (vector, 2, weights, addends); @@ -838,7 +838,7 @@ namespace PETScWrappers const PetscScalar weights[3] = {a,b,c}; Vec addends[3] = {v.vector, w.vector, x.vector}; -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecMAXPY (3, weights, vector, addends); #else const int ierr = VecMAXPY (vector, 3, weights, addends); @@ -911,7 +911,7 @@ namespace PETScWrappers VectorBase::ratio (const VectorBase &a, const VectorBase &b) { -#if (PETSC_VERSION_MAJOR <= 2) && (PETSC_VERSION_MINOR < 3) +#if DEAL_II_PETSC_VERSION_LT(2,3,0) const int ierr = VecPointwiseDivide (a, b, vector); #else const int ierr = VecPointwiseDivide (vector, a, b); -- 2.39.5