xref: /libCEED/examples/petsc/bpsswarm.c (revision db2becc9f302fe8eb3a32ace50ce3f3a5d42e6c4)
1 // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 //                        libCEED + PETSc Example: CEED BPs
9 //
10 // This example demonstrates a simple usage of libCEED with PETSc to solve the CEED BP benchmark problems, see http://ceed.exascaleproject.org/bps, on
11 // a particle swarm.
12 //
13 // The code uses higher level communication protocols in DMPlex and DMSwarm.
14 //
15 // Build with:
16 //
17 //     make bpsswarm [PETSC_DIR=</path/to/petsc>] [CEED_DIR=</path/to/libceed>]
18 //
19 // Sample runs:
20 //
21 //     bpssphere -problem bp1 -degree 3
22 //     bpssphere -problem bp2 -degree 3
23 //     bpssphere -problem bp3 -degree 3
24 //
25 //TESTARGS(name="BP2") -ceed {ceed_resource} -test -problem bp2 -dm_plex_dim 3 -dm_plex_box_faces 3,3,3 -dm_plex_simplex 0 -swarm uniform -points_per_cell 64
26 //TESTARGS(name="BP3") -ceed {ceed_resource} -test -problem bp3 -dm_plex_dim 3 -dm_plex_box_faces 4,4,4 -dm_plex_simplex 0 -swarm uniform -points_per_cell 64 -tolerance 3e-2
27 //TESTARGS(name="BP5") -ceed {ceed_resource} -test -problem bp5 -dm_plex_dim 3 -dm_plex_box_faces 3,3,3 -dm_plex_simplex 0 -swarm uniform -points_per_cell 64
28 
29 /// @file
30 /// CEED BPs example using PETSc with DMPlex
31 /// See bpsraw.c for a "raw" implementation using a structured grid and bps.c for an implementation using an unstructured grid.
32 static const char help[]              = "Solve CEED BPs on a particle swarm using DMPlex and DMSwarm in PETSc\n";
33 const char        DMSwarmPICField_u[] = "u";
34 
35 #include "bps.h"
36 
37 #include <ceed.h>
38 #include <petscdmplex.h>
39 #include <petscksp.h>
40 #include <stdbool.h>
41 #include <string.h>
42 
43 #include "include/bpsproblemdata.h"
44 #include "include/libceedsetup.h"
45 #include "include/matops.h"
46 #include "include/petscutils.h"
47 #include "include/petscversion.h"
48 #include "include/swarmutils.h"
49 
50 int main(int argc, char **argv) {
51   MPI_Comm             comm;
52   char                 ceed_resource[PETSC_MAX_PATH_LEN] = "/cpu/self", filename[PETSC_MAX_PATH_LEN];
53   double               my_rt_start, my_rt, rt_min, rt_max;
54   PetscScalar          tolerance;
55   PetscMPIInt          comm_size;
56   PetscInt             degree, q_extra, l_size, g_size, dim = 3, num_comp_u = 1, xl_size, num_points = 1728, num_points_per_cell = 64;
57   PetscBool            test_mode, benchmark_mode, read_mesh, write_solution, write_true_solution_swarm;
58   PetscLogStage        solve_stage;
59   Vec                  X, X_loc, rhs;
60   Mat                  mat_O;
61   KSP                  ksp;
62   DM                   dm_mesh, dm_swarm;
63   OperatorApplyContext op_apply_ctx, op_error_ctx;
64   Ceed                 ceed;
65   CeedData             ceed_data;
66   CeedOperator         op_error;
67   BPType               bp_choice;
68   VecType              vec_type;
69   PointSwarmType       point_swarm_type = SWARM_GAUSS;
70   PetscMPIInt          ranks_per_node;
71   char                 hostname[PETSC_MAX_PATH_LEN];
72 
73   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
74   comm = PETSC_COMM_WORLD;
75   PetscCall(MPI_Comm_size(comm, &comm_size));
76 #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
77   {
78     MPI_Comm splitcomm;
79     PetscCall(MPI_Comm_split_type(comm, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &splitcomm));
80     PetscCall(MPI_Comm_size(splitcomm, &ranks_per_node));
81     PetscCall(MPI_Comm_free(&splitcomm));
82   }
83 #else
84   ranks_per_node = -1;  // Unknown
85 #endif
86 
87   // Read command line options
88   PetscOptionsBegin(comm, NULL, "CEED BPs in PETSc", NULL);
89   bp_choice = CEED_BP1;
90   PetscCall(PetscOptionsEnum("-problem", "CEED benchmark problem to solve", NULL, bp_types, (PetscEnum)bp_choice, (PetscEnum *)&bp_choice, NULL));
91   num_comp_u = bp_options[bp_choice].num_comp_u;
92   test_mode  = PETSC_FALSE;
93   PetscCall(PetscOptionsBool("-test", "Testing mode (do not print unless error is large)", NULL, test_mode, &test_mode, NULL));
94   benchmark_mode = PETSC_FALSE;
95   PetscCall(PetscOptionsBool("-benchmark", "Benchmarking mode (prints benchmark statistics)", NULL, benchmark_mode, &benchmark_mode, NULL));
96   write_solution = PETSC_FALSE;
97   PetscCall(PetscOptionsBool("-write_solution", "Write solution for visualization", NULL, write_solution, &write_solution, NULL));
98   write_true_solution_swarm = PETSC_FALSE;
99   PetscCall(PetscOptionsBool("-write_true_solution_swarm", "Write true solution at swarm points for visualization", NULL, write_true_solution_swarm,
100                              &write_true_solution_swarm, NULL));
101   degree = 2;
102   PetscCall(PetscOptionsInt("-degree", "Polynomial degree of tensor product basis", NULL, degree, &degree, NULL));
103   q_extra = bp_options[bp_choice].q_extra;
104   PetscCall(PetscOptionsInt("-q_extra", "Number of extra quadrature points", NULL, q_extra, &q_extra, NULL));
105   PetscCall(PetscOptionsString("-ceed", "CEED resource specifier", NULL, ceed_resource, ceed_resource, sizeof(ceed_resource), NULL));
106   PetscCall(PetscGetHostName(hostname, sizeof hostname));
107   PetscCall(PetscOptionsString("-hostname", "Hostname for output", NULL, hostname, hostname, sizeof(hostname), NULL));
108   read_mesh = PETSC_FALSE;
109   PetscCall(PetscOptionsString("-mesh", "Read mesh from file", NULL, filename, filename, sizeof(filename), &read_mesh));
110   tolerance = 1e-2;
111   PetscCall(PetscOptionsScalar("-tolerance", "Tolerance for L2 error", NULL, tolerance, &tolerance, NULL));
112   PetscCall(PetscOptionsEnum("-swarm", "Swarm points distribution", NULL, point_swarm_types, (PetscEnum)point_swarm_type,
113                              (PetscEnum *)&point_swarm_type, NULL));
114   {
115     PetscBool user_set_num_points_per_cell = PETSC_FALSE;
116     PetscInt  num_cells_total = 1, tmp = dim;
117     PetscInt  num_cells[] = {1, 1, 1};
118 
119     PetscCall(PetscOptionsInt("-points_per_cell", "Total number of swarm points in each cell", NULL, num_points_per_cell, &num_points_per_cell,
120                               &user_set_num_points_per_cell));
121     PetscCall(PetscOptionsInt("-dm_plex_dim", "Background mesh dimension", NULL, dim, &dim, NULL));
122     PetscCall(PetscOptionsIntArray("-dm_plex_box_faces", "Number of cells", NULL, num_cells, &tmp, NULL));
123 
124     PetscCheck(tmp == dim, comm, PETSC_ERR_USER, "Number of values for -dm_plex_box_faces must match dimension");
125 
126     num_cells_total = num_cells[0] * num_cells[1] * num_cells[2];
127     PetscCheck(!user_set_num_points_per_cell || point_swarm_type != SWARM_SINUSOIDAL, comm, PETSC_ERR_USER,
128                "Cannot specify points per cell with sinusoidal points locations");
129     if (!user_set_num_points_per_cell) {
130       PetscCall(PetscOptionsInt("-points", "Total number of swarm points", NULL, num_points, &num_points, NULL));
131       num_points_per_cell = PetscCeilInt(num_points, num_cells_total);
132     }
133     if (point_swarm_type != SWARM_SINUSOIDAL) {
134       PetscInt num_points_per_cell_1d = round(cbrt(num_points_per_cell * 1.0));
135 
136       num_points_per_cell = 1;
137       for (PetscInt i = 0; i < dim; i++) num_points_per_cell *= num_points_per_cell_1d;
138     }
139     num_points = num_points_per_cell * num_cells_total;
140   }
141   {
142     PetscBool flg;
143     PetscInt  p = ranks_per_node;
144     PetscCall(PetscOptionsInt("-p", "Number of MPI ranks per node", NULL, p, &p, &flg));
145     if (flg) ranks_per_node = p;
146   }
147   PetscOptionsEnd();
148 
149   // Setup DM
150   if (read_mesh) {
151     PetscCall(DMPlexCreateFromFile(comm, filename, NULL, PETSC_TRUE, &dm_mesh));
152   } else {
153     PetscCall(DMCreate(comm, &dm_mesh));
154     PetscCall(DMSetType(dm_mesh, DMPLEX));
155     PetscCall(DMSetFromOptions(dm_mesh));
156 
157     // -- Check for tensor product mesh
158     {
159       PetscBool is_simplex;
160 
161       PetscCall(DMPlexIsSimplex(dm_mesh, &is_simplex));
162       PetscCheck(!is_simplex, comm, PETSC_ERR_USER, "Only tensor-product background meshes supported");
163     }
164   }
165   PetscCall(DMGetDimension(dm_mesh, &dim));
166   PetscCall(SetupDMByDegree(dm_mesh, degree, q_extra, num_comp_u, dim, bp_options[bp_choice].enforce_bc));
167 
168   // View mesh
169   PetscCall(DMSetOptionsPrefix(dm_mesh, "final_"));
170   PetscCall(DMViewFromOptions(dm_mesh, NULL, "-dm_view"));
171 
172   // Create particle swarm
173   PetscCall(DMCreate(comm, &dm_swarm));
174   PetscCall(DMSetType(dm_swarm, DMSWARM));
175   PetscCall(DMSetDimension(dm_swarm, dim));
176   PetscCall(DMSwarmSetType(dm_swarm, DMSWARM_PIC));
177   PetscCall(DMSwarmSetCellDM(dm_swarm, dm_mesh));
178 
179   // -- Swarm field
180   PetscCall(DMSwarmRegisterPetscDatatypeField(dm_swarm, DMSwarmPICField_u, num_comp_u, PETSC_SCALAR));
181   PetscCall(DMSwarmFinalizeFieldRegister(dm_swarm));
182   {
183     PetscInt c_start, c_end, num_cells_local;
184     PetscCall(DMPlexGetHeightStratum(dm_mesh, 0, &c_start, &c_end));
185     num_cells_local = c_end - c_start;
186     PetscCall(DMSwarmSetLocalSizes(dm_swarm, num_cells_local * num_points_per_cell, 0));
187   }
188   PetscCall(DMSetFromOptions(dm_swarm));
189 
190   // -- Set swarm point locations
191   PetscCall(DMSwarmInitalizePointLocations(dm_swarm, point_swarm_type, num_points, num_points_per_cell));
192   PetscCall(DMSwarmVectorDefineField(dm_swarm, DMSwarmPICField_u));
193 
194   // -- Final particle swarm
195   PetscCall(PetscObjectSetName((PetscObject)dm_swarm, "Particle Swarm"));
196   PetscCall(DMViewFromOptions(dm_swarm, NULL, "-dm_swarm_view"));
197 
198   // Create vectors
199   PetscCall(DMCreateGlobalVector(dm_mesh, &X));
200   PetscCall(VecGetLocalSize(X, &l_size));
201   PetscCall(VecGetSize(X, &g_size));
202   PetscCall(DMCreateLocalVector(dm_mesh, &X_loc));
203   PetscCall(VecGetSize(X_loc, &xl_size));
204   PetscCall(VecDuplicate(X, &rhs));
205 
206   // Operator
207   PetscCall(PetscMalloc1(1, &op_apply_ctx));
208   PetscCall(PetscMalloc1(1, &op_error_ctx));
209   PetscCall(MatCreateShell(comm, l_size, l_size, g_size, g_size, op_apply_ctx, &mat_O));
210   PetscCall(MatSetDM(mat_O, dm_mesh));
211   PetscCall(MatShellSetOperation(mat_O, MATOP_MULT, (void (*)(void))MatMult_Ceed));
212   PetscCall(MatShellSetOperation(mat_O, MATOP_GET_DIAGONAL, (void (*)(void))MatGetDiag));
213 
214   // Set up libCEED
215   CeedInit(ceed_resource, &ceed);
216   CeedMemType mem_type_backend;
217   CeedGetPreferredMemType(ceed, &mem_type_backend);
218 
219   PetscCall(DMGetVecType(dm_mesh, &vec_type));
220   if (!vec_type) {  // Not yet set by user -dm_vec_type
221     switch (mem_type_backend) {
222       case CEED_MEM_HOST:
223         vec_type = VECSTANDARD;
224         break;
225       case CEED_MEM_DEVICE: {
226         const char *resolved;
227         CeedGetResource(ceed, &resolved);
228         if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA;
229         else if (strstr(resolved, "/gpu/hip/occa")) vec_type = VECSTANDARD;  // https://github.com/CEED/libCEED/issues/678
230         else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP;
231         else vec_type = VECSTANDARD;
232       }
233     }
234     PetscCall(DMSetVecType(dm_mesh, vec_type));
235   }
236 
237   // Print summary
238   if (!test_mode) {
239     PetscInt P = degree + 1, Q = P + q_extra;
240 
241     const char *used_resource;
242     CeedGetResource(ceed, &used_resource);
243 
244     VecType vec_type;
245     PetscCall(VecGetType(X, &vec_type));
246 
247     PetscInt c_start, c_end, num_cells_local;
248     PetscCall(DMPlexGetHeightStratum(dm_mesh, 0, &c_start, &c_end));
249     num_cells_local = c_end - c_start;
250     DMPolytopeType cell_type;
251     PetscCall(DMPlexGetCellType(dm_mesh, c_start, &cell_type));
252     PetscMPIInt comm_size;
253     PetscCall(MPI_Comm_size(comm, &comm_size));
254 
255     PetscInt num_points_local, num_points_global;
256     PetscCall(DMSwarmGetLocalSize(dm_swarm, &num_points_local));
257     PetscCall(DMSwarmGetSize(dm_swarm, &num_points_global));
258 
259     PetscCall(PetscPrintf(comm,
260                           "\n-- CEED Benchmark Problem %" CeedInt_FMT " -- libCEED + PETSc --\n"
261                           "  MPI:\n"
262                           "    Hostname                                : %s\n"
263                           "    Total ranks                             : %d\n"
264                           "    Ranks per compute node                  : %d\n"
265                           "  PETSc:\n"
266                           "    PETSc Vec Type                          : %s\n"
267                           "  libCEED:\n"
268                           "    libCEED Backend                         : %s\n"
269                           "    libCEED Backend MemType                 : %s\n"
270                           "  Mesh:\n"
271                           "    Solution Order (P)                      : %" PetscInt_FMT "\n"
272                           "    Quadrature  Order (Q)                   : %" PetscInt_FMT "\n"
273                           "    Additional quadrature points (q_extra)  : %" PetscInt_FMT "\n"
274                           "    Global nodes                            : %" PetscInt_FMT "\n"
275                           "    Local Elements                          : %" PetscInt_FMT "\n"
276                           "    Owned nodes                             : %" PetscInt_FMT "\n"
277                           "    DoF per node                            : %" PetscInt_FMT "\n"
278                           "  Swarm:\n"
279                           "    Global points                           : %" PetscInt_FMT "\n"
280                           "    Local points                            : %" PetscInt_FMT "\n"
281                           "    Avg points per cell                     : %" PetscInt_FMT "\n"
282                           "    Point distribution                      : %s\n",
283                           bp_choice + 1, hostname, comm_size, ranks_per_node, vec_type, used_resource, CeedMemTypes[mem_type_backend], P, Q, q_extra,
284                           g_size / num_comp_u, num_cells_local, l_size / num_comp_u, num_comp_u, num_points_global, num_points_local,
285                           num_cells_local > 0 ? num_points_local / num_cells_local : 0, point_swarm_types[point_swarm_type]));
286   }
287 
288   // Setup libCEED's objects
289   Vec target;
290 
291   PetscCall(DMCreateLocalVector(dm_swarm, &target));
292   PetscCall(PetscMalloc1(1, &ceed_data));
293   PetscCall(SetupProblemSwarm(dm_swarm, ceed, bp_options[bp_choice], ceed_data, true, rhs, target));
294   PetscCall(SetupErrorOperator(dm_mesh, ceed, bp_options[bp_choice], dim, dim, num_comp_u, &op_error));
295 
296   // Set up apply operator context
297   PetscCall(SetupApplyOperatorCtx(comm, dm_mesh, ceed, ceed_data, X_loc, op_apply_ctx));
298 
299   // Setup solver
300   PetscCall(KSPCreate(comm, &ksp));
301   {
302     PC pc;
303     PetscCall(KSPGetPC(ksp, &pc));
304     if (bp_choice == CEED_BP1 || bp_choice == CEED_BP2) {
305       PetscCall(PCSetType(pc, PCJACOBI));
306       PetscCall(PCJacobiSetType(pc, PC_JACOBI_DIAGONAL));
307     } else {
308       PetscCall(PCSetType(pc, PCNONE));
309     }
310     PetscCall(KSPSetType(ksp, KSPCG));
311     PetscCall(KSPSetNormType(ksp, KSP_NORM_NATURAL));
312     PetscCall(KSPSetTolerances(ksp, 1e-10, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT));
313   }
314   PetscCall(KSPSetFromOptions(ksp));
315   PetscCall(KSPSetOperators(ksp, mat_O, mat_O));
316 
317   // First run, if benchmarking
318   if (benchmark_mode) {
319     PetscCall(KSPSetTolerances(ksp, 1e-10, PETSC_DEFAULT, PETSC_DEFAULT, 1));
320     my_rt_start = MPI_Wtime();
321     PetscCall(KSPSolve(ksp, rhs, X));
322     my_rt = MPI_Wtime() - my_rt_start;
323     PetscCall(MPI_Allreduce(MPI_IN_PLACE, &my_rt, 1, MPI_DOUBLE, MPI_MIN, comm));
324     // Set maxits based on first iteration timing
325     if (my_rt > 0.02) {
326       PetscCall(KSPSetTolerances(ksp, 1e-10, PETSC_DEFAULT, PETSC_DEFAULT, 5));
327     } else {
328       PetscCall(KSPSetTolerances(ksp, 1e-10, PETSC_DEFAULT, PETSC_DEFAULT, 20));
329     }
330   }
331 
332   // Timed solve
333   PetscCall(VecZeroEntries(X));
334   PetscCall(PetscBarrier((PetscObject)ksp));
335 
336   // -- Performance logging
337   PetscCall(PetscLogStageRegister("Solve Stage", &solve_stage));
338   PetscCall(PetscLogStagePush(solve_stage));
339 
340   // -- Solve
341   my_rt_start = MPI_Wtime();
342   PetscCall(KSPSolve(ksp, rhs, X));
343   my_rt = MPI_Wtime() - my_rt_start;
344 
345   // -- Performance logging
346   PetscCall(PetscLogStagePop());
347 
348   // Output results
349   {
350     KSPType            ksp_type;
351     KSPConvergedReason reason;
352     PetscReal          rnorm;
353     PetscInt           its;
354     PetscCall(KSPGetType(ksp, &ksp_type));
355     PetscCall(KSPGetConvergedReason(ksp, &reason));
356     PetscCall(KSPGetIterationNumber(ksp, &its));
357     PetscCall(KSPGetResidualNorm(ksp, &rnorm));
358     if (!test_mode || reason < 0 || rnorm > 1e-8) {
359       PetscCall(PetscPrintf(comm,
360                             "  KSP:\n"
361                             "    KSP Type                                : %s\n"
362                             "    KSP Convergence                         : %s\n"
363                             "    Total KSP Iterations                    : %" PetscInt_FMT "\n"
364                             "    Final rnorm                             : %e\n",
365                             ksp_type, KSPConvergedReasons[reason], its, (double)rnorm));
366     }
367     if (!test_mode) {
368       PetscCall(PetscPrintf(comm, "  Performance:\n"));
369     }
370 
371     // View true solution at particles
372     if (write_true_solution_swarm) {
373       Vec u_swarm, u_swarm_old;
374       PetscCall(DMSwarmSortGetAccess(dm_swarm));
375       PetscCall(DMSwarmCreateLocalVectorFromField(dm_swarm, DMSwarmPICField_u, &u_swarm));
376       PetscCall(VecDuplicate(u_swarm, &u_swarm_old));
377       PetscCall(VecCopy(u_swarm, u_swarm_old));
378       PetscCall(VecCopy(target, u_swarm));
379       PetscCall(DMSwarmDestroyLocalVectorFromField(dm_swarm, DMSwarmPICField_u, &u_swarm));
380       PetscCall(DMSwarmSortRestoreAccess(dm_swarm));
381 
382       PetscCall(DMSwarmViewXDMF(dm_swarm, "swarm.xmf"));
383 
384       PetscCall(DMSwarmSortGetAccess(dm_swarm));
385       PetscCall(DMSwarmCreateLocalVectorFromField(dm_swarm, DMSwarmPICField_u, &u_swarm));
386       PetscCall(VecCopy(u_swarm_old, u_swarm));
387       PetscCall(DMSwarmDestroyLocalVectorFromField(dm_swarm, DMSwarmPICField_u, &u_swarm));
388       PetscCall(DMSwarmSortRestoreAccess(dm_swarm));
389       PetscCall(VecDestroy(&u_swarm_old));
390     }
391 
392     // View solution at mesh points
393     PetscCall(VecViewFromOptions(X, NULL, "-solution_view"));
394 
395     // Compute L2 Error
396     {
397       // Set up error operator context
398       PetscCall(SetupErrorOperatorCtx(comm, dm_mesh, ceed, ceed_data, X_loc, op_error, op_error_ctx));
399       PetscScalar l2_error;
400       PetscCall(ComputeL2Error(X, &l2_error, op_error_ctx));
401 
402       if (!test_mode || l2_error > tolerance) {
403         PetscCall(MPI_Allreduce(&my_rt, &rt_min, 1, MPI_DOUBLE, MPI_MIN, comm));
404         PetscCall(MPI_Allreduce(&my_rt, &rt_max, 1, MPI_DOUBLE, MPI_MAX, comm));
405         PetscCall(PetscPrintf(comm,
406                               "    L2 Error                                : %e\n"
407                               "    CG Solve Time                           : %g (%g) sec\n",
408                               (double)l2_error, rt_max, rt_min));
409       }
410     }
411     if (benchmark_mode && (!test_mode)) {
412       PetscCall(PetscPrintf(comm, "    DoFs/Sec in CG                            : %g (%g) million\n", 1e-6 * g_size * its / rt_max,
413                             1e-6 * g_size * its / rt_min));
414     }
415   }
416 
417   // Output solution
418   if (write_solution) {
419     PetscViewer vtk_viewer_soln;
420 
421     PetscCall(PetscViewerCreate(comm, &vtk_viewer_soln));
422     PetscCall(PetscViewerSetType(vtk_viewer_soln, PETSCVIEWERVTK));
423     PetscCall(PetscViewerFileSetName(vtk_viewer_soln, "solution.vtu"));
424     PetscCall(VecView(X, vtk_viewer_soln));
425     PetscCall(PetscViewerDestroy(&vtk_viewer_soln));
426   }
427 
428   // Cleanup
429   PetscCall(VecDestroy(&X));
430   PetscCall(VecDestroy(&X_loc));
431   PetscCall(VecDestroy(&op_apply_ctx->Y_loc));
432   PetscCall(VecDestroy(&op_error_ctx->Y_loc));
433   PetscCall(MatDestroy(&mat_O));
434   PetscCall(PetscFree(op_apply_ctx));
435   PetscCall(PetscFree(op_error_ctx));
436   PetscCall(CeedDataDestroy(0, ceed_data));
437   PetscCall(DMDestroy(&dm_mesh));
438   PetscCall(DMDestroy(&dm_swarm));
439 
440   PetscCall(VecDestroy(&rhs));
441   PetscCall(VecDestroy(&target));
442   PetscCall(KSPDestroy(&ksp));
443   CeedOperatorDestroy(&op_error);
444   CeedDestroy(&ceed);
445   return PetscFinalize();
446 }
447