Skip to content

Commit b964294

Browse files
committed
Satsify different CI configs
1 parent 17092ad commit b964294

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

examples/miscellaneous/miscellaneous_ex17/miscellaneous_ex17.C

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
#include "libmesh/fe.h"
3030

3131
// Define Gauss quadrature rules.
32-
#include "libmesh/petsc_solver_exception.h"
33-
#include "libmesh/petsc_vector.h"
3432
#include "libmesh/quadrature_gauss.h"
3533

3634
// Define useful datatypes for finite element
3735
// matrix and vector components.
38-
#include "libmesh/petsc_matrix.h"
3936
#include "libmesh/numeric_vector.h"
37+
#include "libmesh/sparse_matrix.h"
4038
#include "libmesh/dense_matrix.h"
4139
#include "libmesh/dense_vector.h"
4240
#include "libmesh/elem.h"
@@ -45,7 +43,13 @@
4543
// Define the DofMap, which handles degree of freedom
4644
// indexing.
4745
#include "libmesh/dof_map.h"
46+
47+
#ifdef LIBMESH_HAVE_PETSC
48+
// include PETSc headers
49+
#include "libmesh/petsc_matrix.h"
50+
#include "libmesh/petsc_vector.h"
4851
#include "petscksp.h"
52+
#endif
4953

5054
#include <iostream>
5155

@@ -65,9 +69,6 @@ int main (int argc, char ** argv)
6569
// Initialize libraries, like in example 2.
6670
LibMeshInit init (argc, argv);
6771

68-
// This example requires a linear solver package.
69-
libmesh_example_requires(libMesh::default_solver_package() == PETSC_SOLVERS, "--enable-petsc");
70-
7172
// Brief message to the user regarding the program name
7273
// and command line arguments.
7374
libMesh::out << "Running " << argv[0];
@@ -113,8 +114,12 @@ int main (int argc, char ** argv)
113114
system.attach_assemble_function(assemble_poisson);
114115

115116
// Add the preconditioner matrix
116-
auto & pre_sparse_matrix = system.add_matrix("preconditioner");
117-
pre_sparse_matrix.use_hash_table(true);
117+
system.add_matrix("preconditioner");
118+
#ifdef LIBMESH_HAVE_PETSC
119+
#if PETSC_RELEASE_GREATER_EQUALS(3, 19, 0)
120+
system.get_matrix("preconditioner").use_hash_table(true);
121+
#endif
122+
#endif
118123

119124
// Initialize the data structures for the equation system.
120125
equation_systems.init();
@@ -127,7 +132,7 @@ int main (int argc, char ** argv)
127132

128133
#ifdef LIBMESH_HAVE_PETSC
129134
auto & sys_matrix = cast_ref<PetscMatrix<Number> &>(system.get_system_matrix());
130-
auto & pre_matrix = cast_ref<PetscMatrix<Number> &>(pre_sparse_matrix);
135+
auto & pre_matrix = cast_ref<PetscMatrix<Number> &>(system.get_matrix("preconditioner"));
131136
LibmeshPetscCall2(system.comm(), PetscOptionsSetValue(NULL, "-ksp_monitor", NULL));
132137

133138
auto solve = [&sys_matrix, &pre_matrix, &system]() {
@@ -147,6 +152,9 @@ int main (int argc, char ** argv)
147152

148153
// solve
149154
solve();
155+
156+
// MatResetHash added in PETSc version 3.23
157+
#if !PETSC_VERSION_LESS_THAN(3, 23, 0)
150158
// reset the memory
151159
// sys_matrix.reset_memory(); # See https://gitlab.com/petsc/petsc/-/merge_requests/8063
152160
pre_matrix.reset_memory();
@@ -160,6 +168,7 @@ int main (int argc, char ** argv)
160168
system.assemble();
161169
// resolve
162170
solve();
171+
#endif
163172
#endif
164173

165174
// All done.

0 commit comments

Comments
 (0)