petsc_macro.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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 // Wrapped to avoid triggering our more paranoid warnings
63 #include <petsc.h>
65 
66 #if PETSC_RELEASE_LESS_THAN(3,1,1)
67 typedef PetscTruth PetscBool;
68 #endif
69 
70 #if PETSC_RELEASE_LESS_THAN(3,1,1)
71 # define LibMeshVecDestroy(x) VecDestroy(*(x))
72 # define LibMeshVecScatterDestroy(x) VecScatterDestroy(*(x))
73 # define LibMeshMatDestroy(x) MatDestroy(*(x))
74 # define LibMeshISDestroy(x) ISDestroy(*(x))
75 # define LibMeshKSPDestroy(x) KSPDestroy(*(x))
76 # define LibMeshSNESDestroy(x) SNESDestroy(*(x))
77 # define LibMeshPetscViewerDestroy(x) PetscViewerDestroy(*(x))
78 # define LibMeshPCDestroy(x) PCDestroy(*(x))
79 #else
80 # define LibMeshVecDestroy(x) VecDestroy(x)
81 # define LibMeshVecScatterDestroy(x) VecScatterDestroy(x)
82 # define LibMeshMatDestroy(x) MatDestroy(x)
83 # define LibMeshISDestroy(x) ISDestroy(x)
84 # define LibMeshKSPDestroy(x) KSPDestroy(x)
85 # define LibMeshSNESDestroy(x) SNESDestroy(x)
86 # define LibMeshPetscViewerDestroy(x) PetscViewerDestroy(x)
87 # define LibMeshPCDestroy(x) PCDestroy(x)
88 #endif
89 
90 // Once PETSc-3.11.0 is released, "&& PETSC_VERSION_RELEASE" should be removed
91 #if PETSC_VERSION_LESS_THAN(3,11,0) && PETSC_VERSION_RELEASE
92 # define LibMeshVecScatterCreate(xin,ix,yin,iy,newctx) VecScatterCreate(xin,ix,yin,iy,newctx)
93 #else
94 # define LibMeshVecScatterCreate(xin,ix,yin,iy,newctx) VecScatterCreateWithData(xin,ix,yin,iy,newctx)
95 #endif
96 
97 #if PETSC_RELEASE_LESS_THAN(3,1,1)
99 # define ISCreateLibMesh(comm,n,idx,mode,is) \
100  ((mode) == PETSC_USE_POINTER \
101  ? ISCreateGeneralWithArray((comm),(n),(idx),(is)) \
102  : ((mode) == PETSC_OWN_POINTER \
103  ? ISCreateGeneralNC((comm),(n),(idx),(is)) \
104  : ISCreateGeneral((comm),(n),(idx),(is))))
105 #else
106 # define ISCreateLibMesh(comm,n,idx,mode,is) ISCreateGeneral((comm),(n),(idx),(mode),(is))
107 #endif
108 
109 // As of release 3.8.0, MatGetSubMatrix was renamed to MatCreateSubMatrix.
110 #if PETSC_RELEASE_LESS_THAN(3,8,0)
111 # define LibMeshCreateSubMatrix MatGetSubMatrix
112 #else
113 # define LibMeshCreateSubMatrix MatCreateSubMatrix
114 #endif
115 
116 #else // LIBMESH_HAVE_PETSC
117 
118 #define PETSC_VERSION_LESS_THAN(major,minor,subminor) 1
119 #define PETSC_RELEASE_LESS_THAN(major,minor,subminor) 1
120 
121 #endif // LIBMESH_HAVE_PETSC
122 
123 #endif // LIBMESH_PETSC_MACRO_H
PetscTruth PetscBool
Definition: petsc_macro.h:67
PetscCopyMode
Definition: petsc_macro.h:98