Merge pull request #355 from bhermanmit/petsc_version

PETSc compatibility for 3.4 and 3.5
This commit is contained in:
Paul Romano 2015-01-30 20:49:55 -05:00
commit 4d63b851af
3 changed files with 43 additions and 5 deletions

View file

@ -195,6 +195,20 @@ if(petsc)
list(INSERT PETSC_PACKAGE_LIBS 0 ${PETSC_RT_LIB})
endif()
# If libssl wasn't found, search /usr/lib64
if(PETSC_SSL_LIB STREQUAL "PETSC_SSL_LIB-NOTFOUND")
find_library(PETSC_SSL_LIB libssl.so /usr/lib64)
list(REMOVE_ITEM PETSC_PACKAGE_LIBS PETSC_SSL_LIB-NOTFOUND)
list(INSERT PETSC_PACKAGE_LIBS 0 ${PETSC_SSL_LIB})
endif()
# If libcrypto wasn't found, search /usr/lib64
if(PETSC_CRYPTO_LIB STREQUAL "PETSC_CRYPTO_LIB-NOTFOUND")
find_library(PETSC_CRYPTO_LIB libcrypto.so /usr/lib64)
list(REMOVE_ITEM PETSC_PACKAGE_LIBS PETSC_CRYPTO_LIB-NOTFOUND)
list(INSERT PETSC_PACKAGE_LIBS 0 ${PETSC_CRYPTO_LIB})
endif()
message("-- Using PETSC: ${libpetsc}")
add_definitions(-DPETSC)
include_directories($ENV{PETSC_DIR}/include)

View file

@ -7,6 +7,7 @@ module solver_interface
#ifdef PETSC
use petscksp
use petscsnes
# include <petscversion.h>
#endif
implicit none
@ -67,6 +68,11 @@ module solver_interface
#ifdef PETSC
integer :: petsc_err ! petsc error code
! Checks for PETSc version to handle 3.5 changes
# if (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR > 4)
# define PETSC_GREATER_34
# endif
#endif
contains
@ -85,8 +91,13 @@ contains
real(8) :: atol = 1.0e-10_8
call KSPCreate(PETSC_COMM_WORLD, self % ksp_, petsc_err)
#ifdef PETSC_GREATER_34
call KSPSetTolerances(self % ksp_, rtol, atol, &
PETSC_DEFAULT_REAL, PETSC_DEFAULT_INTEGER, petsc_err)
#else
call KSPSetTolerances(self % ksp_, rtol, atol, &
PETSC_DEFAULT_DOUBLE_PRECISION, PETSC_DEFAULT_INTEGER, petsc_err)
#endif
call KSPSetType(self % ksp_, 'gmres', petsc_err)
call KSPSetInitialGuessNonzero(self % ksp_, PETSC_TRUE, petsc_err)
call KSPGetPC(self % ksp_, self % pc_, petsc_err)
@ -105,8 +116,13 @@ contains
type(Matrix), intent(inout) :: prec_mat ! preconditioner matrix
type(Matrix), intent(inout) :: mat_in ! coefficient matrix
#ifdef PETSC_GREATER_34
call KSPSetOperators(self % ksp_, mat_in % petsc_mat, prec_mat % petsc_mat, &
petsc_err)
#else
call KSPSetOperators(self % ksp_, mat_in % petsc_mat, prec_mat % petsc_mat, &
SAME_NONZERO_PATTERN, petsc_err)
#endif
call KSPSetUp(self % ksp_, petsc_err)
end subroutine petsc_gmres_set_oper
@ -259,17 +275,25 @@ contains
! PETSC_JFNK_COMPUTE_JACOBIAN buffer routine to user specified jacobian routine
!===============================================================================
#ifdef PETSC_GREATER_34
subroutine petsc_jfnk_compute_jacobian(snes_, x, jac_mf, jac_prec, &
ctx, ierr)
#else
subroutine petsc_jfnk_compute_jacobian(snes_, x, jac_mf, jac_prec, flag, &
ctx, ierr)
#endif
type(snes), intent(inout) :: snes_ ! PETSc snes instance
type(vec), intent(inout) :: x ! PETSc solution vector
type(mat), intent(inout) :: jac_mf ! PETSc matrix free jacobian
type(mat), intent(inout) :: jac_prec ! PETSc matrix jacobian precond.
integer, intent(inout) :: flag ! unused madatory flag
type(Jfnk_ctx), intent(inout) :: ctx ! JFNK context instance
integer, intent(inout) :: ierr ! error code
#ifndef PETSC_GREATER_34
integer, intent(inout) :: flag ! unused madatory flag
#endif
type(Vector) :: xvec ! solution vector
! Again, we use the vector that comes from Petsc to build the Jacobian

View file

@ -42,10 +42,10 @@ parser.add_option("-s", "--script", action="store_true", dest="script",
# Default compiler paths
FC='gfortran'
MPI_DIR='/opt/mpich/3.1-gnu'
HDF5_DIR='/opt/hdf5/1.8.12-gnu'
PHDF5_DIR='/opt/phdf5/1.8.12-gnu'
PETSC_DIR='/opt/petsc/3.4.4-gnu'
MPI_DIR='/opt/mpich/3.1.3-gnu'
HDF5_DIR='/opt/hdf5/1.8.14-gnu'
PHDF5_DIR='/opt/phdf5/1.8.14-gnu'
PETSC_DIR='/opt/petsc/3.5.2-gnu'
# Script mode for extra capability
script_mode = False