libMesh
petsc_macro.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #ifndef LIBMESH_PETSC_MACRO_H
19 #define LIBMESH_PETSC_MACRO_H
20 
21 // Local includes
22 #include "libmesh/libmesh_config.h"
23 
24 #ifdef LIBMESH_HAVE_PETSC
25 
26 // A convenient macro for comparing PETSc versions. Returns 1 if the
27 // current PETSc version is < major.minor.subminor and zero otherwise.
28 //
29 // This macro does not require petscversion.h to be included for it to work correctly.
30 // It instead relies on the PETSc version numbers detected during configure. Note that if
31 // LIBMESH_HAVE_PETSC is not defined, none of the LIBMESH_DETECTED_PETSC_VERSION_* variables will
32 // be defined either.
33 #define PETSC_VERSION_LESS_THAN(major,minor,subminor) \
34  ((LIBMESH_DETECTED_PETSC_VERSION_MAJOR < (major) || \
35  (LIBMESH_DETECTED_PETSC_VERSION_MAJOR == (major) && (LIBMESH_DETECTED_PETSC_VERSION_MINOR < (minor) || \
36  (LIBMESH_DETECTED_PETSC_VERSION_MINOR == (minor) && \
37  LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR < (subminor))))) ? 1 : 0)
38 
39 // The PETSC_VERSION_RELEASE constant was introduced just prior to 2.3.0 (ca. Apr 22 2005),
40 // so fall back to using PETSC_VERSION_LESS_THAN in case it doesn't exist.
41 #ifdef LIBMESH_DETECTED_PETSC_VERSION_RELEASE
42 
43 #define PETSC_RELEASE_LESS_THAN(major,minor,subminor) \
44  (PETSC_VERSION_LESS_THAN(major,minor,subminor) && LIBMESH_DETECTED_PETSC_VERSION_RELEASE)
45 
46 #else
47 
48 #define PETSC_RELEASE_LESS_THAN(major,minor,subminor) \
49  (PETSC_VERSION_LESS_THAN(major,minor,subminor))
50 
51 #endif
52 
53 // We used to have workarounds for missing extern "C" in old PETSc
54 // versions. We no longer support PETSc versions so old, but we do
55 // still support libMesh applications old enough to have used these
56 // macros.
57 #define EXTERN_C_FOR_PETSC_BEGIN
58 #define EXTERN_C_FOR_PETSC_END
59 
60 // Petsc include files
61 #include <petsc.h>
62 
63 #if PETSC_RELEASE_LESS_THAN(3,1,1)
64 typedef PetscTruth PetscBool;
65 #endif
66 
67 #if PETSC_RELEASE_LESS_THAN(3,1,1)
68 # define LibMeshVecDestroy(x) VecDestroy(*(x))
69 # define LibMeshVecScatterDestroy(x) VecScatterDestroy(*(x))
70 # define LibMeshMatDestroy(x) MatDestroy(*(x))
71 # define LibMeshISDestroy(x) ISDestroy(*(x))
72 # define LibMeshKSPDestroy(x) KSPDestroy(*(x))
73 # define LibMeshSNESDestroy(x) SNESDestroy(*(x))
74 # define LibMeshPetscViewerDestroy(x) PetscViewerDestroy(*(x))
75 # define LibMeshPCDestroy(x) PCDestroy(*(x))
76 #else
77 # define LibMeshVecDestroy(x) VecDestroy(x)
78 # define LibMeshVecScatterDestroy(x) VecScatterDestroy(x)
79 # define LibMeshMatDestroy(x) MatDestroy(x)
80 # define LibMeshISDestroy(x) ISDestroy(x)
81 # define LibMeshKSPDestroy(x) KSPDestroy(x)
82 # define LibMeshSNESDestroy(x) SNESDestroy(x)
83 # define LibMeshPetscViewerDestroy(x) PetscViewerDestroy(x)
84 # define LibMeshPCDestroy(x) PCDestroy(x)
85 #endif
86 
87 #if PETSC_RELEASE_LESS_THAN(3,1,1)
89 # define ISCreateLibMesh(comm,n,idx,mode,is) \
90  ((mode) == PETSC_USE_POINTER \
91  ? ISCreateGeneralWithArray((comm),(n),(idx),(is)) \
92  : ((mode) == PETSC_OWN_POINTER \
93  ? ISCreateGeneralNC((comm),(n),(idx),(is)) \
94  : ISCreateGeneral((comm),(n),(idx),(is))))
95 #else
96 # define ISCreateLibMesh(comm,n,idx,mode,is) ISCreateGeneral((comm),(n),(idx),(mode),(is))
97 #endif
98 
99 // As of release 3.8.0, MatGetSubMatrix was renamed to MatCreateSubMatrix.
100 #if PETSC_RELEASE_LESS_THAN(3,8,0)
101 # define LibMeshCreateSubMatrix MatGetSubMatrix
102 #else
103 # define LibMeshCreateSubMatrix MatCreateSubMatrix
104 #endif
105 
106 #else // LIBMESH_HAVE_PETSC
107 
108 #define PETSC_VERSION_LESS_THAN(major,minor,subminor) 1
109 #define PETSC_RELEASE_LESS_THAN(major,minor,subminor) 1
110 
111 #endif // LIBMESH_HAVE_PETSC
112 
113 #endif // LIBMESH_PETSC_MACRO_H
PetscTruth PetscBool
Definition: petsc_macro.h:64
PetscCopyMode
Definition: petsc_macro.h:88