diff --git a/CMakeLists.txt b/CMakeLists.txt index bcc3c4d..b72d48a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,10 @@ else(IS_CLUSTER) set(ITK_DIR ${MY_HOME}/Documents/softwares/ITK-build) message("setting up for delorme") endif(IS_CLUSTER) - +MESSAGE("The directory is: ${CMAKE_SOURCE_DIR}") #add cmake modules path to the default one: -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${MY_HOME}/cmakeModules/petsc") +#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${MY_HOME}/cmakeModules/petsc") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") #Find the external library for Petsc find_package(PETSc COMPONENTS CXX REQUIRED) diff --git a/cmake/Modules/FindPETSc.cmake b/cmake/Modules/FindPETSc.cmake index e5187a7..1caa82a 100644 --- a/cmake/Modules/FindPETSc.cmake +++ b/cmake/Modules/FindPETSc.cmake @@ -1,322 +1,304 @@ # - Try to find PETSc # Once done this will define # -# PETSC_FOUND - system has PETSc -# PETSC_INCLUDES - the PETSc include directories -# PETSC_LIBRARIES - Link these to use PETSc -# PETSC_COMPILER - Compiler used by PETSc, helpful to find a compatible MPI -# PETSC_DEFINITIONS - Compiler switches for using PETSc -# PETSC_MPIEXEC - Executable for running MPI programs -# PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR) +# PETSC_FOUND - system has PETSc +# PETSC_INCLUDES - the PETSc include directories +# PETSC_LIBRARIES - Link these to use PETSc +# PETSC_COMPILER - Compiler used by PETSc, helpful to find a compatible MPI +# PETSC_DEFINITIONS - Compiler switches for using PETSc +# PETSC_MPIEXEC - Executable for running MPI programs +# PETSC_VERSION - Version string (MAJOR.MINOR.SUBMINOR) # -# Usage: -# find_package(PETSc COMPONENTS CXX) - required if build --with-clanguage=C++ --with-c-support=0 -# find_package(PETSc COMPONENTS C) - standard behavior of checking build using a C compiler -# find_package(PETSc) - same as above +# Usage: +# find_package(PETSc COMPONENTS CXX) - required if build --with-clanguage=C++ --with-c-support=0 +# find_package(PETSc COMPONENTS C) - standard behavior of checking build using a C compiler +# find_package(PETSc) - same as above # # Setting these changes the behavior of the search -# PETSC_DIR - directory in which PETSc resides -# PETSC_ARCH - build architecture +# PETSC_DIR - directory in which PETSc resides +# PETSC_ARCH - build architecture # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # - set(PETSC_VALID_COMPONENTS - C - CXX) - +C +CXX) if(NOT PETSc_FIND_COMPONENTS) - set(PETSC_LANGUAGE_BINDINGS "C") +set(PETSC_LANGUAGE_BINDINGS "C") else() - # Right now, this is designed for compatability with the --with-clanguage option, so - # only allow one item in the components list. - list(LENGTH ${PETSc_FIND_COMPONENTS} components_length) - if(${components_length} GREATER 1) - message(FATAL_ERROR "Only one component for PETSc is allowed to be specified") - endif() - # This is a stub for allowing multiple components should that time ever come. Perhaps - # to also test Fortran bindings? - foreach(component ${PETSc_FIND_COMPONENTS}) - list(FIND PETSC_VALID_COMPONENTS ${component} component_location) - if(${component_location} EQUAL -1) - message(FATAL_ERROR "\"${component}\" is not a valid PETSc component.") - else() - list(APPEND PETSC_LANGUAGE_BINDINGS ${component}) - endif() - endforeach() +# Right now, this is designed for compatability with the --with-clanguage option, so +# only allow one item in the components list. +list(LENGTH ${PETSc_FIND_COMPONENTS} components_length) +if(${components_length} GREATER 1) +message(FATAL_ERROR "Only one component for PETSc is allowed to be specified") +endif() +# This is a stub for allowing multiple components should that time ever come. Perhaps +# to also test Fortran bindings? +foreach(component ${PETSc_FIND_COMPONENTS}) +list(FIND PETSC_VALID_COMPONENTS ${component} component_location) +if(${component_location} EQUAL -1) +message(FATAL_ERROR "\"${component}\" is not a valid PETSc component.") +else() +list(APPEND PETSC_LANGUAGE_BINDINGS ${component}) +endif() +endforeach() endif() - function (petsc_get_version) - if (EXISTS "${PETSC_DIR}/include/petscversion.h") - file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") - foreach (line ${vstrings}) - string (REGEX REPLACE " +" ";" fields ${line}) # break line into three fields (the first is always "#define") - list (GET fields 1 var) - list (GET fields 2 val) - set (${var} ${val} PARENT_SCOPE) - set (${var} ${val}) # Also in local scope so we have access below - endforeach () - if (PETSC_VERSION_RELEASE) - set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}p${PETSC_VERSION_PATCH}" PARENT_SCOPE) - else () - # make dev version compare higher than any patch level of a released version - set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}.99" PARENT_SCOPE) - endif () - else () - message (SEND_ERROR "PETSC_DIR can not be used, ${PETSC_DIR}/include/petscversion.h does not exist") - endif () +if (EXISTS "${PETSC_DIR}/include/petscversion.h") +file (STRINGS "${PETSC_DIR}/include/petscversion.h" vstrings REGEX "#define PETSC_VERSION_(RELEASE|MAJOR|MINOR|SUBMINOR|PATCH) ") +foreach (line ${vstrings}) +string (REGEX REPLACE " +" ";" fields ${line}) # break line into three fields (the first is always "#define") +list (GET fields 1 var) +list (GET fields 2 val) +set (${var} ${val} PARENT_SCOPE) +set (${var} ${val}) # Also in local scope so we have access below +endforeach () +if (PETSC_VERSION_RELEASE) +set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}p${PETSC_VERSION_PATCH}" PARENT_SCOPE) +else () +# make dev version compare higher than any patch level of a released version +set (PETSC_VERSION "${PETSC_VERSION_MAJOR}.${PETSC_VERSION_MINOR}.${PETSC_VERSION_SUBMINOR}.99" PARENT_SCOPE) +endif () +else () +message (SEND_ERROR "PETSC_DIR can not be used, ${PETSC_DIR}/include/petscversion.h does not exist") +endif () endfunction () - find_path (PETSC_DIR include/petsc.h - HINTS ENV PETSC_DIR - PATHS - # Debian paths - /usr/lib/petscdir/3.3 /usr/lib/petscdir/3.2 /usr/lib/petscdir/3.1 - /usr/lib/petscdir/3.0.0 /usr/lib/petscdir/2.3.3 /usr/lib/petscdir/2.3.2 - $ENV{HOME}/petsc - DOC "PETSc Directory") - +HINTS ENV PETSC_DIR +PATHS +# Debian paths +/usr/lib/petscdir/3.5.1 /usr/lib/petscdir/3.5 +/usr/lib/petscdir/3.4.2 /usr/lib/petscdir/3.4 +/usr/lib/petscdir/3.3 /usr/lib/petscdir/3.2 /usr/lib/petscdir/3.1 +/usr/lib/petscdir/3.0.0 /usr/lib/petscdir/2.3.3 /usr/lib/petscdir/2.3.2 +# MacPorts path +/opt/local/lib/petsc +$ENV{HOME}/petsc +DOC "PETSc Directory") find_program (MAKE_EXECUTABLE NAMES make gmake) - if (PETSC_DIR AND NOT PETSC_ARCH) - set (_petsc_arches - $ENV{PETSC_ARCH} # If set, use environment variable first - linux-gnu-c-debug linux-gnu-c-opt # Debian defaults - x86_64-unknown-linux-gnu i386-unknown-linux-gnu) - set (petscconf "NOTFOUND" CACHE FILEPATH "Cleared" FORCE) - foreach (arch ${_petsc_arches}) - if (NOT PETSC_ARCH) - find_path (petscconf petscconf.h - HINTS ${PETSC_DIR} - PATH_SUFFIXES ${arch}/include bmake/${arch} - NO_DEFAULT_PATH) - if (petscconf) - set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture") - endif (petscconf) - endif (NOT PETSC_ARCH) - endforeach (arch) - set (petscconf "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE) +set (_petsc_arches +$ENV{PETSC_ARCH} # If set, use environment variable first +linux-gnu-c-debug linux-gnu-c-opt # Debian defaults +x86_64-unknown-linux-gnu i386-unknown-linux-gnu) +set (petscconf "NOTFOUND" CACHE FILEPATH "Cleared" FORCE) +foreach (arch ${_petsc_arches}) +if (NOT PETSC_ARCH) +find_path (petscconf petscconf.h +HINTS ${PETSC_DIR} +PATH_SUFFIXES ${arch}/include bmake/${arch} +NO_DEFAULT_PATH) +if (petscconf) +set (PETSC_ARCH "${arch}" CACHE STRING "PETSc build architecture") +endif (petscconf) +endif (NOT PETSC_ARCH) +endforeach (arch) +set (petscconf "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE) endif (PETSC_DIR AND NOT PETSC_ARCH) - set (petsc_slaves LIBRARIES_SYS LIBRARIES_VEC LIBRARIES_MAT LIBRARIES_DM LIBRARIES_KSP LIBRARIES_SNES LIBRARIES_TS - INCLUDE_DIR INCLUDE_CONF) +INCLUDE_DIR INCLUDE_CONF) include (FindPackageMultipass) find_package_multipass (PETSc petsc_config_current - STATES DIR ARCH - DEPENDENTS INCLUDES LIBRARIES COMPILER MPIEXEC ${petsc_slaves}) - +STATES DIR ARCH +DEPENDENTS INCLUDES LIBRARIES COMPILER MPIEXEC ${petsc_slaves}) # Determine whether the PETSc layout is old-style (through 2.3.3) or # new-style (>= 3.0.0) -if (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h") # > 2.3.3 - set (petsc_conf_rules "${PETSC_DIR}/conf/rules") - set (petsc_conf_variables "${PETSC_DIR}/conf/variables") +if (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables") # > 3.5 +set (petsc_conf_rules "${PETSC_DIR}/lib/petsc/conf/rules") +set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables") +elseif (EXISTS "${PETSC_DIR}/${PETSC_ARCH}/include/petscconf.h") # > 2.3.3 +set (petsc_conf_rules "${PETSC_DIR}/conf/rules") +set (petsc_conf_variables "${PETSC_DIR}/conf/variables") elseif (EXISTS "${PETSC_DIR}/bmake/${PETSC_ARCH}/petscconf.h") # <= 2.3.3 - set (petsc_conf_rules "${PETSC_DIR}/bmake/common/rules") - set (petsc_conf_variables "${PETSC_DIR}/bmake/common/variables") +set (petsc_conf_rules "${PETSC_DIR}/bmake/common/rules") +set (petsc_conf_variables "${PETSC_DIR}/bmake/common/variables") elseif (PETSC_DIR) - message (SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation") +message (SEND_ERROR "The pair PETSC_DIR=${PETSC_DIR} PETSC_ARCH=${PETSC_ARCH} do not specify a valid PETSc installation") endif () - if (petsc_conf_rules AND petsc_conf_variables AND NOT petsc_config_current) - petsc_get_version() - - # Put variables into environment since they are needed to get - # configuration (petscvariables) in the PETSc makefile - set (ENV{PETSC_DIR} "${PETSC_DIR}") - set (ENV{PETSC_ARCH} "${PETSC_ARCH}") - - # A temporary makefile to probe the PETSc configuration - set (petsc_config_makefile "${PROJECT_BINARY_DIR}/Makefile.petsc") - file (WRITE "${petsc_config_makefile}" +petsc_get_version() +# Put variables into environment since they are needed to get +# configuration (petscvariables) in the PETSc makefile +set (ENV{PETSC_DIR} "${PETSC_DIR}") +set (ENV{PETSC_ARCH} "${PETSC_ARCH}") +# A temporary makefile to probe the PETSc configuration +set (petsc_config_makefile "${PROJECT_BINARY_DIR}/Makefile.petsc") +file (WRITE "${petsc_config_makefile}" "## This file was autogenerated by FindPETSc.cmake -# PETSC_DIR = ${PETSC_DIR} +# PETSC_DIR = ${PETSC_DIR} # PETSC_ARCH = ${PETSC_ARCH} include ${petsc_conf_rules} include ${petsc_conf_variables} show : - -@echo -n \${\${VARIABLE}} +\t-@echo -n \${\${VARIABLE}} ") - - macro (PETSC_GET_VARIABLE name var) - set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) - execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} show VARIABLE=${name} - OUTPUT_VARIABLE ${var} - RESULT_VARIABLE petsc_return) - endmacro (PETSC_GET_VARIABLE) - petsc_get_variable (PETSC_LIB_DIR petsc_lib_dir) - petsc_get_variable (PETSC_EXTERNAL_LIB_BASIC petsc_libs_external) - petsc_get_variable (PETSC_CCPPFLAGS petsc_cpp_line) - petsc_get_variable (PETSC_INCLUDE petsc_include) - petsc_get_variable (PCC petsc_cc) - petsc_get_variable (PCC_FLAGS petsc_cc_flags) - petsc_get_variable (MPIEXEC petsc_mpiexec) - # We are done with the temporary Makefile, calling PETSC_GET_VARIABLE after this point is invalid! - file (REMOVE ${petsc_config_makefile}) - - include (ResolveCompilerPaths) - # Extract include paths and libraries from compile command line - resolve_includes (petsc_includes_all "${petsc_cpp_line}") - - #on windows we need to make sure we're linking against the right - #runtime library - if (WIN32) - if (petsc_cc_flags MATCHES "-MT") - set(using_md False) - foreach(flag_var - CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MD") - set(using_md True) - endif(${flag_var} MATCHES "/MD") - endforeach(flag_var) - if(${using_md} MATCHES "True") - message(WARNING "PETSc was built with /MT, but /MD is currently set. - See http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F") - endif(${using_md} MATCHES "True") - endif (petsc_cc_flags MATCHES "-MT") - endif (WIN32) - - include (CorrectWindowsPaths) - convert_cygwin_path(petsc_lib_dir) - message (STATUS "petsc_lib_dir ${petsc_lib_dir}") - - macro (PETSC_FIND_LIBRARY suffix name) - set (PETSC_LIBRARY_${suffix} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # Clear any stale value, if we got here, we need to find it again - if (WIN32) - set (libname lib${name}) #windows expects "libfoo", linux expects "foo" - else (WIN32) - set (libname ${name}) - endif (WIN32) - find_library (PETSC_LIBRARY_${suffix} NAMES ${libname} HINTS ${petsc_lib_dir} NO_DEFAULT_PATH) - set (PETSC_LIBRARIES_${suffix} "${PETSC_LIBRARY_${suffix}}") - mark_as_advanced (PETSC_LIBRARY_${suffix}) - endmacro (PETSC_FIND_LIBRARY suffix name) - - # Look for petscvec first, if it doesn't exist, we must be using single-library - petsc_find_library (VEC petscvec) - if (PETSC_LIBRARY_VEC) - petsc_find_library (SYS "petscsys;petsc") # libpetscsys is called libpetsc prior to 3.1 (when single-library was introduced) - petsc_find_library (MAT petscmat) - petsc_find_library (DM petscdm) - petsc_find_library (KSP petscksp) - petsc_find_library (SNES petscsnes) - petsc_find_library (TS petscts) - macro (PETSC_JOIN libs deps) - list (APPEND PETSC_LIBRARIES_${libs} ${PETSC_LIBRARIES_${deps}}) - endmacro (PETSC_JOIN libs deps) - petsc_join (VEC SYS) - petsc_join (MAT VEC) - petsc_join (DM MAT) - petsc_join (KSP DM) - petsc_join (SNES KSP) - petsc_join (TS SNES) - petsc_join (ALL TS) - else () - set (PETSC_LIBRARY_VEC "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # There is no libpetscvec - petsc_find_library (SINGLE petsc) - foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) - set (PETSC_LIBRARIES_${pkg} "${PETSC_LIBRARY_SINGLE}") - endforeach () - endif () - if (PETSC_LIBRARY_TS) - message (STATUS "Recognized PETSc install with separate libraries for each package") - else () - message (STATUS "Recognized PETSc install with single library for all packages") - endif () - - include(Check${PETSC_LANGUAGE_BINDINGS}SourceRuns) - macro (PETSC_TEST_RUNS includes libraries runs) - if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "C") - set(_PETSC_ERR_FUNC "CHKERRQ(ierr)") - elseif(${PETSC_LANGUAGE_BINDINGS} STREQUAL "CXX") - set(_PETSC_ERR_FUNC "CHKERRXX(ierr)") - endif() - if (PETSC_VERSION VERSION_GREATER 3.1) - set (_PETSC_TSDestroy "TSDestroy(&ts)") - else () - set (_PETSC_TSDestroy "TSDestroy(ts)") - endif () - - set(_PETSC_TEST_SOURCE " +macro (PETSC_GET_VARIABLE name var) +set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) +execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} show VARIABLE=${name} +OUTPUT_VARIABLE ${var} +RESULT_VARIABLE petsc_return) +endmacro (PETSC_GET_VARIABLE) +petsc_get_variable (PETSC_LIB_DIR petsc_lib_dir) +petsc_get_variable (PETSC_EXTERNAL_LIB_BASIC petsc_libs_external) +petsc_get_variable (PETSC_CCPPFLAGS petsc_cpp_line) +petsc_get_variable (PETSC_INCLUDE petsc_include) +petsc_get_variable (PCC petsc_cc) +petsc_get_variable (PCC_FLAGS petsc_cc_flags) +petsc_get_variable (MPIEXEC petsc_mpiexec) +# We are done with the temporary Makefile, calling PETSC_GET_VARIABLE after this point is invalid! +file (REMOVE ${petsc_config_makefile}) +include (ResolveCompilerPaths) +# Extract include paths and libraries from compile command line +resolve_includes (petsc_includes_all "${petsc_cpp_line}") +#on windows we need to make sure we're linking against the right +#runtime library +if (WIN32) +if (petsc_cc_flags MATCHES "-MT") +set(using_md False) +foreach(flag_var +CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) +if(${flag_var} MATCHES "/MD") +set(using_md True) +endif(${flag_var} MATCHES "/MD") +endforeach(flag_var) +if(${using_md} MATCHES "True") +message(WARNING "PETSc was built with /MT, but /MD is currently set. +See http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F") +endif(${using_md} MATCHES "True") +endif (petsc_cc_flags MATCHES "-MT") +endif (WIN32) +include (CorrectWindowsPaths) +convert_cygwin_path(petsc_lib_dir) +message (STATUS "petsc_lib_dir ${petsc_lib_dir}") +macro (PETSC_FIND_LIBRARY suffix name) +set (PETSC_LIBRARY_${suffix} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # Clear any stale value, if we got here, we need to find it again +if (WIN32) +set (libname lib${name}) #windows expects "libfoo", linux expects "foo" +else (WIN32) +set (libname ${name}) +endif (WIN32) +find_library (PETSC_LIBRARY_${suffix} NAMES ${libname} HINTS ${petsc_lib_dir} NO_DEFAULT_PATH) +set (PETSC_LIBRARIES_${suffix} "${PETSC_LIBRARY_${suffix}}") +mark_as_advanced (PETSC_LIBRARY_${suffix}) +endmacro (PETSC_FIND_LIBRARY suffix name) +# Look for petscvec first, if it doesn't exist, we must be using single-library +petsc_find_library (VEC petscvec) +if (PETSC_LIBRARY_VEC) +petsc_find_library (SYS "petscsys;petsc") # libpetscsys is called libpetsc prior to 3.1 (when single-library was introduced) +petsc_find_library (MAT petscmat) +petsc_find_library (DM petscdm) +petsc_find_library (KSP petscksp) +petsc_find_library (SNES petscsnes) +petsc_find_library (TS petscts) +macro (PETSC_JOIN libs deps) +list (APPEND PETSC_LIBRARIES_${libs} ${PETSC_LIBRARIES_${deps}}) +endmacro (PETSC_JOIN libs deps) +petsc_join (VEC SYS) +petsc_join (MAT VEC) +petsc_join (DM MAT) +petsc_join (KSP DM) +petsc_join (SNES KSP) +petsc_join (TS SNES) +petsc_join (ALL TS) +else () +set (PETSC_LIBRARY_VEC "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) # There is no libpetscvec +petsc_find_library (SINGLE petsc) +foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) +set (PETSC_LIBRARIES_${pkg} "${PETSC_LIBRARY_SINGLE}") +endforeach () +endif () +if (PETSC_LIBRARY_TS) +message (STATUS "Recognized PETSc install with separate libraries for each package") +else () +message (STATUS "Recognized PETSc install with single library for all packages") +endif () +include(Check${PETSC_LANGUAGE_BINDINGS}SourceRuns) +macro (PETSC_TEST_RUNS includes libraries runs) +if(${PETSC_LANGUAGE_BINDINGS} STREQUAL "C") +set(_PETSC_ERR_FUNC "CHKERRQ(ierr)") +elseif(${PETSC_LANGUAGE_BINDINGS} STREQUAL "CXX") +set(_PETSC_ERR_FUNC "CHKERRXX(ierr)") +endif() +if (PETSC_VERSION VERSION_GREATER 3.1) +set (_PETSC_TSDestroy "TSDestroy(&ts)") +else () +set (_PETSC_TSDestroy "TSDestroy(ts)") +endif () +set(_PETSC_TEST_SOURCE " static const char help[] = \"PETSc test program.\"; #include int main(int argc,char *argv[]) { - PetscErrorCode ierr; - TS ts; - - ierr = PetscInitialize(&argc,&argv,0,help);${_PETSC_ERR_FUNC}; - ierr = TSCreate(PETSC_COMM_WORLD,&ts);${_PETSC_ERR_FUNC}; - ierr = TSSetFromOptions(ts);${_PETSC_ERR_FUNC}; - ierr = ${_PETSC_TSDestroy};${_PETSC_ERR_FUNC}; - ierr = PetscFinalize();${_PETSC_ERR_FUNC}; - return 0; +PetscErrorCode ierr; +TS ts; +ierr = PetscInitialize(&argc,&argv,0,help);${_PETSC_ERR_FUNC}; +ierr = TSCreate(PETSC_COMM_WORLD,&ts);${_PETSC_ERR_FUNC}; +ierr = TSSetFromOptions(ts);${_PETSC_ERR_FUNC}; +ierr = ${_PETSC_TSDestroy};${_PETSC_ERR_FUNC}; +ierr = PetscFinalize();${_PETSC_ERR_FUNC}; +return 0; } ") - multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}") - if (${${runs}}) - set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL - "Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE) - endif (${${runs}}) - endmacro (PETSC_TEST_RUNS) - - - find_path (PETSC_INCLUDE_DIR petscts.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH) - find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "bmake/${PETSC_ARCH}" NO_DEFAULT_PATH) - mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF) - set (petsc_includes_minimal ${PETSC_INCLUDE_CONF} ${PETSC_INCLUDE_DIR}) - - petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_minimal) - if (petsc_works_minimal) - message (STATUS "Minimal PETSc includes and libraries work. This probably means we are building with shared libs.") - set (petsc_includes_needed "${petsc_includes_minimal}") - else (petsc_works_minimal) # Minimal includes fail, see if just adding full includes fixes it - petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_allincludes) - if (petsc_works_allincludes) # It does, we just need all the includes ( - message (STATUS "PETSc requires extra include paths, but links correctly with only interface libraries. This is an unexpected configuration (but it seems to work fine).") - set (petsc_includes_needed ${petsc_includes_all}) - else (petsc_works_allincludes) # We are going to need to link the external libs explicitly - resolve_libraries (petsc_libraries_external "${petsc_libs_external}") - foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) - list (APPEND PETSC_LIBRARIES_${pkg} ${petsc_libraries_external}) - endforeach (pkg) - petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_alllibraries) - if (petsc_works_alllibraries) - message (STATUS "PETSc only need minimal includes, but requires explicit linking to all dependencies. This is expected when PETSc is built with static libraries.") - set (petsc_includes_needed ${petsc_includes_minimal}) - else (petsc_works_alllibraries) - # It looks like we really need everything, should have listened to Matt - set (petsc_includes_needed ${petsc_includes_all}) - petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all) - if (petsc_works_all) # We fail anyways - message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.") - else (petsc_works_all) # We fail anyways - message (STATUS "PETSc could not be used, maybe the install is broken.") - endif (petsc_works_all) - endif (petsc_works_alllibraries) - endif (petsc_works_allincludes) - endif (petsc_works_minimal) - - # We do an out-of-source build so __FILE__ will be an absolute path, hence __INSDIR__ is superfluous - if (${PETSC_VERSION} VERSION_LESS 3.1) - set (PETSC_DEFINITIONS "-D__SDIR__=\"\"" CACHE STRING "PETSc definitions" FORCE) - else () - set (PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc definitions" FORCE) - endif () - # Sometimes this can be used to assist FindMPI.cmake - set (PETSC_MPIEXEC ${petsc_mpiexec} CACHE FILEPATH "Executable for running PETSc MPI programs" FORCE) - set (PETSC_INCLUDES ${petsc_includes_needed} CACHE STRING "PETSc include path" FORCE) - set (PETSC_LIBRARIES ${PETSC_LIBRARIES_ALL} CACHE STRING "PETSc libraries" FORCE) - set (PETSC_COMPILER ${petsc_cc} CACHE FILEPATH "PETSc compiler" FORCE) - # Note that we have forced values for all these choices. If you - # change these, you are telling the system to trust you that they - # work. It is likely that you will end up with a broken build. - mark_as_advanced (PETSC_INCLUDES PETSC_LIBRARIES PETSC_COMPILER PETSC_DEFINITIONS PETSC_MPIEXEC PETSC_EXECUTABLE_RUNS) +multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}") +if (${${runs}}) +set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL +"Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE) +endif (${${runs}}) +endmacro (PETSC_TEST_RUNS) +find_path (PETSC_INCLUDE_DIR petscts.h HINTS "${PETSC_DIR}" PATH_SUFFIXES include NO_DEFAULT_PATH) +find_path (PETSC_INCLUDE_CONF petscconf.h HINTS "${PETSC_DIR}" PATH_SUFFIXES "${PETSC_ARCH}/include" "bmake/${PETSC_ARCH}" NO_DEFAULT_PATH) +mark_as_advanced (PETSC_INCLUDE_DIR PETSC_INCLUDE_CONF) +set (petsc_includes_minimal ${PETSC_INCLUDE_CONF} ${PETSC_INCLUDE_DIR}) +petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_minimal) +if (petsc_works_minimal) +message (STATUS "Minimal PETSc includes and libraries work. This probably means we are building with shared libs.") +set (petsc_includes_needed "${petsc_includes_minimal}") +else (petsc_works_minimal) # Minimal includes fail, see if just adding full includes fixes it +petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_allincludes) +if (petsc_works_allincludes) # It does, we just need all the includes ( +message (STATUS "PETSc requires extra include paths, but links correctly with only interface libraries. This is an unexpected configuration (but it seems to work fine).") +set (petsc_includes_needed ${petsc_includes_all}) +else (petsc_works_allincludes) # We are going to need to link the external libs explicitly +resolve_libraries (petsc_libraries_external "${petsc_libs_external}") +foreach (pkg SYS VEC MAT DM KSP SNES TS ALL) +list (APPEND PETSC_LIBRARIES_${pkg} ${petsc_libraries_external}) +endforeach (pkg) +petsc_test_runs ("${petsc_includes_minimal}" "${PETSC_LIBRARIES_TS}" petsc_works_alllibraries) +if (petsc_works_alllibraries) +message (STATUS "PETSc only need minimal includes, but requires explicit linking to all dependencies. This is expected when PETSc is built with static libraries.") +set (petsc_includes_needed ${petsc_includes_minimal}) +else (petsc_works_alllibraries) +# It looks like we really need everything, should have listened to Matt +set (petsc_includes_needed ${petsc_includes_all}) +petsc_test_runs ("${petsc_includes_all}" "${PETSC_LIBRARIES_TS}" petsc_works_all) +if (petsc_works_all) # We fail anyways +message (STATUS "PETSc requires extra include paths and explicit linking to all dependencies. This probably means you have static libraries and something unexpected in PETSc headers.") +else (petsc_works_all) # We fail anyways +message (STATUS "PETSc could not be used, maybe the install is broken.") +endif (petsc_works_all) +endif (petsc_works_alllibraries) +endif (petsc_works_allincludes) +endif (petsc_works_minimal) +# We do an out-of-source build so __FILE__ will be an absolute path, hence __INSDIR__ is superfluous +if (${PETSC_VERSION} VERSION_LESS 3.1) +set (PETSC_DEFINITIONS "-D__SDIR__=\"\"" CACHE STRING "PETSc definitions" FORCE) +else () +set (PETSC_DEFINITIONS "-D__INSDIR__=" CACHE STRING "PETSc definitions" FORCE) +endif () +# Sometimes this can be used to assist FindMPI.cmake +set (PETSC_MPIEXEC ${petsc_mpiexec} CACHE FILEPATH "Executable for running PETSc MPI programs" FORCE) +set (PETSC_INCLUDES ${petsc_includes_needed} CACHE STRING "PETSc include path" FORCE) +set (PETSC_LIBRARIES ${PETSC_LIBRARIES_ALL} CACHE STRING "PETSc libraries" FORCE) +set (PETSC_COMPILER ${petsc_cc} CACHE FILEPATH "PETSc compiler" FORCE) +# Note that we have forced values for all these choices. If you +# change these, you are telling the system to trust you that they +# work. It is likely that you will end up with a broken build. +mark_as_advanced (PETSC_INCLUDES PETSC_LIBRARIES PETSC_COMPILER PETSC_DEFINITIONS PETSC_MPIEXEC PETSC_EXECUTABLE_RUNS) endif () - include (FindPackageHandleStandardArgs) find_package_handle_standard_args (PETSc - "PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH." - PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) +"PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH." +PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) \ No newline at end of file diff --git a/configFiles/petsc_ops_gamg_detailedSummary b/configFiles/petsc_ops_gamg_detailedSummary index 601e08b..ec2ebc3 100644 --- a/configFiles/petsc_ops_gamg_detailedSummary +++ b/configFiles/petsc_ops_gamg_detailedSummary @@ -2,11 +2,13 @@ # This is also a comment line -pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_precondition self -pc_fieldsplit_dm_splits 0 -pc_fieldsplit_0_fields 0,1,2 -pc_fieldsplit_1_fields 3 --fieldsplit_0_pc_type gamg +-fieldsplit_0_pc_type gamg -fieldsplit_0_pc_mg_levels_pc_type jacobi +#-fieldsplit_0_mg_coarse_pc_type svd -fieldsplit_0_mg_coarse_sub_pc_type ? #monitor options #-fieldsplit_0_ksp_converged_reason #-fieldsplit_0_ksp_max_it 100 -fieldsplit_1_ksp_converged_reason -ksp_converged_reason -#-fieldsplit_1_ksp_max_it 3 -ksp_max_it 3 -ksp_rtol 1.0e-8 -ksp_monitor_true_residual --fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual +#-fieldsplit_1_ksp_max_it 3 -ksp_max_it 3 -ksp_rtol 1.0e-8 +#-fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual +-fieldsplit_1_ksp_monitor -ksp_monitor #-log_summary -ksp_view \ No newline at end of file diff --git a/configFiles/petsc_ops_hypre_detailedSummary b/configFiles/petsc_ops_hypre_detailedSummary index 10da9e6..4db5e68 100644 --- a/configFiles/petsc_ops_hypre_detailedSummary +++ b/configFiles/petsc_ops_hypre_detailedSummary @@ -7,5 +7,7 @@ #-fieldsplit_0_ksp_converged_reason #-fieldsplit_0_ksp_max_it 100 -fieldsplit_1_ksp_converged_reason -ksp_converged_reason -#-fieldsplit_1_ksp_max_it 3 -ksp_max_it 3 -ksp_rtol 1.0e-8 -ksp_monitor_true_residual --fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual -log_summary -ksp_view \ No newline at end of file +#-fieldsplit_1_ksp_max_it 3 -ksp_max_it 3 -ksp_rtol 1.0e-8 +#-fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual +-fieldsplit_1_ksp_monitor -ksp_monitor +-log_summary -ksp_view \ No newline at end of file diff --git a/configFiles/petsc_ops_hypre_notDetailedSummary b/configFiles/petsc_ops_hypre_notDetailedSummary index f79b595..6e7fb45 100644 --- a/configFiles/petsc_ops_hypre_notDetailedSummary +++ b/configFiles/petsc_ops_hypre_notDetailedSummary @@ -7,5 +7,7 @@ #-fieldsplit_0_ksp_converged_reason #-fieldsplit_0_ksp_max_it 100 #-fieldsplit_1_ksp_converged_reason -ksp_converged_reason -#-fieldsplit_1_ksp_max_it 3 -ksp_max_it 3 -ksp_rtol 1.0e-8 -ksp_monitor_true_residual -#-fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual -log_summary -ksp_view \ No newline at end of file +#-fieldsplit_1_ksp_max_it 3 -ksp_max_it 3 -ksp_rtol 1.0e-8 +#-fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual +#-fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual +#-log_summary -ksp_view \ No newline at end of file diff --git a/configFiles/petsc_ops_lu b/configFiles/petsc_ops_lu new file mode 100644 index 0000000..766f70a --- /dev/null +++ b/configFiles/petsc_ops_lu @@ -0,0 +1,13 @@ +# Comment line starts with '#' +# This is also a comment line +-pc_type fieldsplit -pc_fieldsplit_type schur -pc_fieldsplit_schur_precondition self +-pc_fieldsplit_dm_splits 0 -pc_fieldsplit_0_fields 0,1,2 -pc_fieldsplit_1_fields 3 +-fieldsplit_0_pc_type lu -fieldsplit_1_ksp_rtol 1.0e-10 +#monitor options +#-fieldsplit_0_ksp_converged_reason +#-fieldsplit_0_ksp_max_it 100 +-fieldsplit_1_ksp_converged_reason -ksp_converged_reason +#-fieldsplit_1_ksp_max_it 3 -ksp_max_it 3 -ksp_rtol 1.0e-8 +#-fieldsplit_1_ksp_monitor_true_residual -ksp_monitor_true_residual +#-fieldsplit_1_ksp_monitor -ksp_monitor +#-log_summary -ksp_view \ No newline at end of file diff --git a/src/PetscAdLemMain.cxx b/src/PetscAdLemMain.cxx index 3507abd..8924f05 100644 --- a/src/PetscAdLemMain.cxx +++ b/src/PetscAdLemMain.cxx @@ -113,6 +113,7 @@ int opsParser(UserOptions &ops) { ierr = PetscOptionsGetString(NULL,"-boundary_condition",optionString,PETSC_MAX_PATH_LEN,&optionFlag);CHKERRQ(ierr); if(!optionFlag) throw "Must provide a valid boundary condition. e.g. dirichlet_at_skull"; ops.boundaryCondition = optionString; + ierr = PetscOptionsGetString(NULL,"--relax_ic_in_csf",optionString,PETSC_MAX_PATH_LEN,&optionFlag);CHKERRQ(ierr); ops.relaxIcInCsf = (bool)optionFlag; diff --git a/src/PetscAdLemTaras3D.cxx b/src/PetscAdLemTaras3D.cxx index 65c00e8..c73cd30 100644 --- a/src/PetscAdLemTaras3D.cxx +++ b/src/PetscAdLemTaras3D.cxx @@ -233,24 +233,24 @@ PetscErrorCode PetscAdLemTaras3D::solveModel(bool operatorChanged) ierr = DMKSPSetComputeOperators(mDa,computeMatrixTaras3d,this);CHKERRQ(ierr); ierr = DMKSPSetComputeRHS(mDa,computeRHSTaras3d,this);CHKERRQ(ierr); } - if(mPressureNullspacePresent) { - ierr = KSPSetNullSpace(mKsp,mNullSpace);CHKERRQ(ierr);//nullSpace for the main system - } ierr = KSPSetFromOptions(mKsp);CHKERRQ(ierr); - ierr = KSPSetUp(mKsp);CHKERRQ(ierr); //register the fieldsplits obtained from options. - - ierr = KSPGetOperators(mKsp,&mA,NULL);CHKERRQ(ierr); - ierr = KSPGetPC(mKsp,&mPc);CHKERRQ(ierr); - - PetscBool isNull; + ierr = KSPSetUp(mKsp);CHKERRQ(ierr); //register the fieldsplits obtained from options. + // ---------- MUST CALL kspsetfromoptions() and kspsetup() before kspgetoperators and matsetnullspace + // otherwise I'm getting a runtime error of mat object type not set (for mA!!) + ierr = KSPGetOperators(mKsp,&mA,NULL);CHKERRQ(ierr); if(mPressureNullspacePresent) { - ierr = MatNullSpaceTest(mNullSpace,mA,&isNull);CHKERRQ(ierr); - if(!isNull) { //FIXME: Must correct this for skull zero boundary condition! - //SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_PLIB,"not a valid system null space \n"); - PetscSynchronizedPrintf(PETSC_COMM_WORLD,"\n WARNING: not a valid system null space\n"); + //ierr = KSPSetNullSpace(mKsp,mNullSpace);CHKERRQ(ierr);//nullSpace for the main system + ierr = MatSetNullSpace(mA,mNullSpace);CHKERRQ(ierr);//nullSpace for the main system, updated for petsc3.6 + PetscBool isNull; + if(mPressureNullspacePresent) { + ierr = MatNullSpaceTest(mNullSpace,mA,&isNull);CHKERRQ(ierr); + if(!isNull) { //FIXME: Must correct this for skull zero boundary condition! + //SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_PLIB,"not a valid system null space \n"); + PetscSynchronizedPrintf(PETSC_COMM_WORLD,"\n WARNING: not a valid system null space\n"); + } } - - } + } + ierr = KSPGetPC(mKsp,&mPc);CHKERRQ(ierr); //Setting up of null spaces and near null spaces for fieldsplits depend upon the kinds of options user have used. PetscBool optionFlag = PETSC_FALSE; @@ -288,11 +288,13 @@ PetscErrorCode PetscAdLemTaras3D::solveModel(bool operatorChanged) ierr = MatNullSpaceDestroy(&rigidBodyModes);CHKERRQ(ierr); } - //If constant pressure nullspace present, set it to SchurComplement ksp. + //If constant pressure nullspace present, set it to SchurComplement matrix. if(mPressureNullspacePresent) { - ierr = KSPSetNullSpace(subKsp[1],mNullSpaceP);CHKERRQ(ierr); + PetscBool isNull; Mat matSc; ierr = KSPGetOperators(subKsp[1],&matSc,NULL);CHKERRQ(ierr); + //ierr = KSPSetNullSpace(subKsp[1],mNullSpaceP);CHKERRQ(ierr); //no longer used in petsc 3.6 + ierr = MatSetNullSpace(matSc,mNullSpaceP);CHKERRQ(ierr); //petsc 3.6 update ierr = MatNullSpaceTest(mNullSpaceP,matSc,&isNull); if(!isNull) {//FIXME: Must correct this for skull zero boundary condition! //SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_PLIB,"not a valid pressure null space \n");