libMesh
wrapped_petsc.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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 #include "libmesh/libmesh_config.h"
19 
20 #ifdef LIBMESH_HAVE_PETSC
21 
22 // libMesh includes
23 #include "libmesh/wrapped_petsc.h"
24 #include "libmesh/petsc_macro.h"
25 #include "libmesh/petsc_solver_exception.h"
26 
27 // PETSc includes
28 #ifdef I
29 #define LIBMESH_SAW_I
30 #endif
31 
32 #include <petscksp.h>
33 #include <petscvec.h>
34 #include <petscis.h>
35 #include <petscmat.h>
36 #include <petscviewer.h>
37 #include <petscpc.h>
38 #include <petscsnes.h>
39 #include <petscdm.h>
40 #include <petscsf.h>
41 // PetscSection got its own header file in 3.12, prior to that it was
42 // defined in petscis.h
43 #if !PETSC_VERSION_LESS_THAN(3, 12, 0)
44 #include <petscsection.h>
45 #endif
46 
47 #ifndef LIBMESH_SAW_I
48 #undef I // Avoid complex.h contamination
49 #endif
50 
51 namespace libMesh
52 {
53 // Specializations of the destroy() method for different PETSc classes
54 // This could also be macro-ized, but maybe it's not necessary?
55 template <>
56 void
58 {
59  LibmeshPetscCallA(PETSC_COMM_SELF, VecDestroy(&obj));
60 }
61 
62 template <>
63 void
65 {
66  LibmeshPetscCallA(PETSC_COMM_SELF, KSPDestroy(&obj));
67 }
68 
69 template <>
70 void
72 {
73  LibmeshPetscCallA(PETSC_COMM_SELF, ISDestroy(&obj));
74 }
75 
76 template <>
77 void
79 {
80  LibmeshPetscCallA(PETSC_COMM_SELF, MatDestroy(&obj));
81 }
82 
83 template <>
84 void
86 {
87  LibmeshPetscCallA(PETSC_COMM_SELF, VecScatterDestroy(&obj));
88 }
89 
90 template <>
91 void
93 {
94  LibmeshPetscCallA(PETSC_COMM_SELF, PetscViewerDestroy(&obj));
95 }
96 
97 template <>
98 void
100 {
101  LibmeshPetscCallA(PETSC_COMM_SELF, MatNullSpaceDestroy(&obj));
102 }
103 
104 template <>
105 void
107 {
108  LibmeshPetscCallA(PETSC_COMM_SELF, DMDestroy(&obj));
109 }
110 
111 template <>
112 void
114 {
115  LibmeshPetscCallA(PETSC_COMM_SELF, MatPartitioningDestroy(&obj));
116 }
117 
118 template <>
119 void
121 {
122  LibmeshPetscCallA(PETSC_COMM_SELF, SNESDestroy(&obj));
123 }
124 
125 template <>
126 void
128 {
129  LibmeshPetscCallA(PETSC_COMM_SELF, PCDestroy(&obj));
130 }
131 
132 template <>
133 void
135 {
136  LibmeshPetscCallA(PETSC_COMM_SELF, PetscSectionDestroy(&obj));
137 }
138 }
139 
140 #endif // LIBMESH_HAVE_PETSC
The libMesh namespace provides an interface to certain functionality in the library.
void destroy(triangulateio &t, IO_Type)
Frees any memory which has been dynamically allocated by Triangle.
void destroy()
Must be specialized to call the appropriate XXXDestroy() routine in order for a WrappedPetsc<T> objec...