Line data Source code
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 57 939370 : WrappedPetsc<Vec>::destroy() 58 : { 59 939370 : LibmeshPetscCallA(PETSC_COMM_SELF, VecDestroy(&obj)); 60 939370 : } 61 : 62 : template <> 63 : void 64 47523 : WrappedPetsc<KSP>::destroy() 65 : { 66 47523 : LibmeshPetscCallA(PETSC_COMM_SELF, KSPDestroy(&obj)); 67 47523 : } 68 : 69 : template <> 70 : void 71 208642 : WrappedPetsc<IS>::destroy() 72 : { 73 208642 : LibmeshPetscCallA(PETSC_COMM_SELF, ISDestroy(&obj)); 74 208642 : } 75 : 76 : template <> 77 : void 78 855632 : WrappedPetsc<Mat>::destroy() 79 : { 80 855632 : LibmeshPetscCallA(PETSC_COMM_SELF, MatDestroy(&obj)); 81 855632 : } 82 : 83 : template <> 84 : void 85 656606 : WrappedPetsc<VecScatter>::destroy() 86 : { 87 656606 : LibmeshPetscCallA(PETSC_COMM_SELF, VecScatterDestroy(&obj)); 88 656606 : } 89 : 90 : template <> 91 : void 92 210 : WrappedPetsc<PetscViewer>::destroy() 93 : { 94 210 : LibmeshPetscCallA(PETSC_COMM_SELF, PetscViewerDestroy(&obj)); 95 210 : } 96 : 97 : template <> 98 : void 99 0 : WrappedPetsc<MatNullSpace>::destroy() 100 : { 101 0 : LibmeshPetscCallA(PETSC_COMM_SELF, MatNullSpaceDestroy(&obj)); 102 0 : } 103 : 104 : template <> 105 : void 106 29960 : WrappedPetsc<DM>::destroy() 107 : { 108 29960 : LibmeshPetscCallA(PETSC_COMM_SELF, DMDestroy(&obj)); 109 29960 : } 110 : 111 : template <> 112 : void 113 0 : WrappedPetsc<MatPartitioning>::destroy() 114 : { 115 0 : LibmeshPetscCallA(PETSC_COMM_SELF, MatPartitioningDestroy(&obj)); 116 0 : } 117 : 118 : template <> 119 : void 120 31290 : WrappedPetsc<SNES>::destroy() 121 : { 122 31290 : LibmeshPetscCallA(PETSC_COMM_SELF, SNESDestroy(&obj)); 123 31290 : } 124 : 125 : template <> 126 : void 127 0 : WrappedPetsc<PC>::destroy() 128 : { 129 0 : LibmeshPetscCallA(PETSC_COMM_SELF, PCDestroy(&obj)); 130 0 : } 131 : 132 : template <> 133 : void 134 560 : WrappedPetsc<PetscSection>::destroy() 135 : { 136 560 : LibmeshPetscCallA(PETSC_COMM_SELF, PetscSectionDestroy(&obj)); 137 560 : } 138 : } 139 : 140 : #endif // LIBMESH_HAVE_PETSC