/****************************************************************************** * * AMDiS - Adaptive multidimensional simulations * * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved. * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis * * Authors: * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * * This file is part of AMDiS * * See also license.opensource.txt in the distribution. * ******************************************************************************/ /** \file PetscWrapper.h */ #ifndef AMDIS_PETSCWRAPPER_H #define AMDIS_PETSCWRAPPER_H #include #include namespace AMDiS { // functions for PETSc API changes namespace petsc { inline PetscErrorCode options_view(PetscViewer viewer) { #if (PETSC_VERSION_MINOR >= 7) return PetscOptionsView(PETSC_NULL, viewer); #else return PetscOptionsView(viewer); #endif } inline PetscErrorCode options_insert_string(const char in_str[]) { #if (PETSC_VERSION_MINOR >= 7) return PetscOptionsInsertString(PETSC_NULL, in_str); #else return PetscOptionsInsertString(in_str); #endif } inline PetscErrorCode ksp_set_operators(KSP ksp, Mat Amat,Mat Pmat) { #if (PETSC_VERSION_MINOR >= 5) return KSPSetOperators(ksp, Amat, Pmat); #else return KSPSetOperators(ksp, Amat, Pmat, SAME_NONZERO_PATTERN); #endif } inline PetscErrorCode ksp_get_operators(KSP ksp, Mat *Amat,Mat *Pmat) { #if (PETSC_VERSION_MINOR >= 5) return KSPGetOperators(ksp, Amat, Pmat); #else return KSPGetOperators(ksp, Amat, Pmat, SAME_NONZERO_PATTERN); #endif } template inline PetscErrorCode ksp_monitor_set(KSP ksp, Monitor monitor) { #if (PETSC_VERSION_MINOR >= 7) PetscViewerAndFormat *vf; PetscErrorCode ierr; ierr = PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_DEFAULT,&vf);CHKERRQ(ierr); ierr = KSPMonitorSet(ksp,(PetscErrorCode (*)(KSP,PetscInt,PetscReal,void*))monitor,vf,(PetscErrorCode (*)(void**))PetscViewerAndFormatDestroy);CHKERRQ(ierr); return ierr; #else return KSPMonitorSet(ksp, monitor, PETSC_NULL, PETSC_NULL); #endif } inline PetscErrorCode mat_create_vecs(Mat mat,Vec *right,Vec *left) { #if (PETSC_VERSION_MINOR >= 6) return MatCreateVecs(mat, right, left); #else return MatGetVecs(mat, right, left); #endif } inline PetscErrorCode mat_nullspace_remove(MatNullSpace sp,Vec vec) { #if (PETSC_VERSION_MINOR >= 5) return MatNullSpaceRemove(sp, vec); #else return MatNullSpaceRemove(sp, vec, PETSC_NULL); #endif } } // end namespace petsc } // end namespace AMDiS #endif