xref: /libCEED/examples/solids/include/structs.h (revision 80a9ef0545a39c00cdcaab1ca26f8053604f3120)
1 #ifndef structs_h
2 #define structs_h
3 
4 #include <ceed.h>
5 #include <petsc.h>
6 #include "../problems/cl-problems.h"
7 
8 // -----------------------------------------------------------------------------
9 // Command Line Options
10 // -----------------------------------------------------------------------------
11 // Forcing function options
12 typedef enum {
13   FORCE_NONE = 0, FORCE_CONST = 1, FORCE_MMS = 2
14 } forcingType;
15 static const char *const forcing_types[] = {"none",
16                                             "constant",
17                                             "mms",
18                                             "forcingType","FORCE_",0
19                                            };
20 static const char *const forcing_types_for_disp[] = {"None",
21                                                      "Constant",
22                                                      "Manufactured solution"
23                                                     };
24 
25 // Multigrid options
26 typedef enum {
27   MULTIGRID_LOGARITHMIC = 0, MULTIGRID_UNIFORM = 1, MULTIGRID_NONE = 2
28 } multigridType;
29 static const char *const multigrid_types [] = {"logarithmic",
30                                                "uniform",
31                                                "none",
32                                                "multigridType","MULTIGRID",0
33                                               };
34 static const char *const multigrid_types_for_disp[] = {"P-multigrid, logarithmic coarsening",
35                                                        "P-multigrind, uniform coarsening",
36                                                        "No multigrid"
37                                                       };
38 
39 // -----------------------------------------------------------------------------
40 // Application data structs
41 // -----------------------------------------------------------------------------
42 // Units
43 typedef struct Units_ *Units;
44 struct Units_ {
45   // Fundamental units
46   PetscScalar meter;
47   PetscScalar kilogram;
48   PetscScalar second;
49   // Derived unit
50   PetscScalar Pascal;
51 };
52 
53 // Application context from user command line options
54 typedef struct AppCtx_ *AppCtx;
55 struct AppCtx_ {
56   const char    *name, *name_for_disp;                 // problem name
57   char          ceed_resource[PETSC_MAX_PATH_LEN];     // libCEED backend
58   char          mesh_file[PETSC_MAX_PATH_LEN];         // exodusII mesh file
59   char          output_dir[PETSC_MAX_PATH_LEN];
60   PetscBool     test_mode;
61   PetscBool     view_soln;
62   PetscBool     view_final_soln;
63   PetscViewer   energy_viewer;
64   problemType   problem_choice;
65   forcingType   forcing_choice;
66   multigridType multigrid_choice;
67   PetscInt      degree;
68   PetscInt      q_extra;
69   PetscInt      num_levels;
70   PetscInt      *level_degrees;
71   PetscInt      num_increments;                        // Number of steps
72   PetscInt      bc_clamp_count;
73   PetscInt      bc_clamp_faces[16];
74   // [translation; 3] [rotation axis; 3] [rotation magnitude c_0, c_1]
75   // The rotations are (c_0 + c_1 s) \pi, where s = x · axis
76   PetscScalar   bc_clamp_max[16][8];
77   PetscInt      bc_traction_count;
78   PetscInt      bc_traction_faces[16];
79   PetscScalar   bc_traction_vector[16][3];
80   PetscScalar   forcing_vector[3];
81   PetscReal     test_tol;
82   PetscReal     expect_final_strain;
83 };
84 
85 // Problem specific data
86 // *INDENT-OFF*
87 typedef struct {
88   CeedInt           geo_data_size;
89   CeedQFunctionUser setup_geo, apply, jacob, energy, diagnostic;
90   const char        *setup_geo_loc, *apply_loc, *jacob_loc, *energy_loc,
91                     *diagnostic_loc;
92   CeedQuadMode      quad_mode;
93 } problemData;
94 // *INDENT-ON*
95 
96 // Forcing function data
97 typedef struct {
98   CeedQFunctionUser setup_forcing;
99   const char        *setup_forcing_loc;
100 } forcingData;
101 
102 extern forcingData forcing_options[3];
103 
104 // Data for PETSc Matshell
105 typedef struct UserMult_ *UserMult;
106 struct UserMult_ {
107   MPI_Comm        comm;
108   DM              dm;
109   Vec             X_loc, Y_loc, neumann_bcs;
110   CeedVector      x_ceed, y_ceed;
111   CeedOperator    op;
112   CeedQFunction   qf;
113   Ceed            ceed;
114   PetscScalar     load_increment;
115   CeedQFunctionContext ctx_phys, ctx_phys_smoother;
116 };
117 
118 // Data for Jacobian setup routine
119 typedef struct FormJacobCtx_ *FormJacobCtx;
120 struct FormJacobCtx_ {
121   UserMult     *jacob_ctx;
122   PetscInt     num_levels;
123   SNES         snes_coarse;
124   Mat          *jacob_mat, jacob_mat_coarse;
125   Vec          u_coarse;
126 };
127 
128 // Data for PETSc Prolongation/Restriction Matshell
129 typedef struct UserMultProlongRestr_ *UserMultProlongRestr;
130 struct UserMultProlongRestr_ {
131   MPI_Comm     comm;
132   DM           dm_c, dm_f;
133   Vec          loc_vec_c, loc_vec_f;
134   CeedVector   ceed_vec_c, ceed_vec_f;
135   CeedOperator op_prolong, op_restrict;
136   Ceed         ceed;
137 };
138 
139 #define SOLIDS_MAX_NUMBER_FIELDS 16
140 
141 // libCEED data struct for level
142 typedef struct CeedData_ *CeedData;
143 struct CeedData_ {
144   Ceed                ceed;
145   CeedBasis           basis_x, basis_u, basis_c_to_f, basis_energy,
146                       basis_diagnostic;
147   CeedElemRestriction elem_restr_x, elem_restr_u, elem_restr_geo_data_i,
148                       elem_restr_energy, elem_restr_diagnostic,
149                       elem_restr_geo_data_diagnostic_i,
150                       elem_restr_stored_fields_i[SOLIDS_MAX_NUMBER_FIELDS];
151   CeedQFunction       qf_residual, qf_jacobian, qf_energy, qf_diagnostic;
152   CeedOperator        op_residual, op_jacobian, op_restrict, op_prolong,
153                       op_energy,
154                       op_diagnostic;
155   CeedVector          geo_data, geo_data_diagnostic, x_ceed, y_ceed,
156                       true_soln, stored_fields[SOLIDS_MAX_NUMBER_FIELDS];
157 };
158 
159 typedef struct {
160   CeedQFunctionUser setup_geo, residual, jacobian, energy,
161                     diagnostic, true_soln;
162   const char *setup_geo_loc, *residual_loc, *jacobian_loc, *energy_loc,
163         *diagnostic_loc, *true_soln_loc;
164   CeedQuadMode quadrature_mode;
165   CeedInt geo_data_size, number_fields_stored;
166   CeedInt *field_sizes;
167   const char *const *field_names;
168 } ProblemData;
169 
170 #endif // structs_h
171