xref: /libCEED/examples/petsc/include/structs.h (revision d275d636ccaa61e594421fac80252590e7a77ccf)
1 // Copyright (c) 2017-2025, 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 /// @file
9 /// Data structures for PETSc examples
10 #pragma once
11 
12 #include <ceed.h>
13 #include <petsc.h>
14 
15 // -----------------------------------------------------------------------------
16 // PETSc Operator Structs
17 // -----------------------------------------------------------------------------
18 
19 // Data for PETSc Matshell
20 typedef struct OperatorApplyContext_ *OperatorApplyContext;
21 struct OperatorApplyContext_ {
22   MPI_Comm     comm;
23   DM           dm;
24   Vec          X_loc, Y_loc, diag;
25   CeedVector   x_ceed, y_ceed;
26   CeedOperator op;
27   Ceed         ceed;
28 };
29 
30 // Data for PETSc Prolong/Restrict Matshells
31 typedef struct ProlongRestrContext_ *ProlongRestrContext;
32 struct ProlongRestrContext_ {
33   MPI_Comm     comm;
34   DM           dmc, dmf;
35   Vec          loc_vec_c, loc_vec_f, mult_vec;
36   CeedVector   ceed_vec_c, ceed_vec_f;
37   CeedOperator op_prolong, op_restrict;
38   Ceed         ceed;
39 };
40 
41 // -----------------------------------------------------------------------------
42 // libCEED Data Structs
43 // -----------------------------------------------------------------------------
44 
45 // libCEED data struct for level
46 typedef struct CeedData_ *CeedData;
47 struct CeedData_ {
48   Ceed                ceed;
49   CeedBasis           basis_x, basis_u;
50   CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_u_i, elem_restr_qd_i;
51   CeedQFunction       qf_apply;
52   CeedOperator        op_apply, op_restrict, op_prolong;
53   CeedVector          q_data, x_ceed, y_ceed;
54   CeedInt             q_data_size;
55 };
56 
57 // BP specific data
58 typedef struct {
59   CeedInt           num_comp_x, num_comp_u, topo_dim, q_data_size, q_extra;
60   CeedQFunctionUser setup_geo, setup_rhs, apply, error;
61   const char       *setup_geo_loc, *setup_rhs_loc, *apply_loc, *error_loc;
62   CeedEvalMode      in_mode, out_mode;
63   CeedQuadMode      q_mode;
64   PetscBool         enforce_bc;
65 } BPData;
66 
67 // BP options
68 typedef enum { CEED_BP1 = 0, CEED_BP2 = 1, CEED_BP3 = 2, CEED_BP4 = 3, CEED_BP5 = 4, CEED_BP6 = 5 } BPType;
69 
70 // -----------------------------------------------------------------------------
71 // Parameter structure for running problems
72 // -----------------------------------------------------------------------------
73 typedef struct RunParams_ *RunParams;
74 struct RunParams_ {
75   MPI_Comm      comm;
76   PetscBool     test_mode, read_mesh, user_l_nodes, write_solution, simplex;
77   char         *filename, *hostname;
78   PetscInt      local_nodes, degree, q_extra, dim, num_comp_u, *mesh_elem;
79   PetscInt      ksp_max_it_clip[2];
80   PetscMPIInt   ranks_per_node;
81   BPType        bp_choice;
82   PetscLogStage solve_stage;
83 };
84