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