1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3 // reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 // libCEED + PETSc Example: Navier-Stokes 18 // 19 // This example demonstrates a simple usage of libCEED with PETSc to solve a 20 // Navier-Stokes problem. 21 // 22 // The code is intentionally "raw", using only low-level communication 23 // primitives. 24 // 25 // Build with: 26 // 27 // make [PETSC_DIR=</path/to/petsc>] [CEED_DIR=</path/to/libceed>] navierstokes 28 // 29 // Sample runs: 30 // 31 // ./navierstokes -ceed /cpu/self -problem density_current -degree 1 32 // ./navierstokes -ceed /gpu/cuda -problem advection -degree 1 33 // 34 //TESTARGS(name="dc_explicit") -ceed {ceed_resource} -test -degree 3 -dm_plex_box_faces 1,1,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -center 62.5,62.5,187.5 -rc 100. -thetaC -35. -ts_dt 1e-3 -compare_final_state_atol 1E-11 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-dc-explicit.bin 35 //TESTARGS(name="dc_implicit_stab_none") -ceed {ceed_resource} -test -degree 3 -dm_plex_box_faces 1,1,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -center 62.5,62.5,187.5 -rc 100. -thetaC -35. -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-dc-implicit-stab-none.bin 36 //TESTARGS(name="adv_rotation_explicit_strong") -ceed {ceed_resource} -test -problem advection -strong_form 1 -degree 3 -dm_plex_box_faces 2,2,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -rc 100. -ts_dt 1e-3 -compare_final_state_atol 1E-11 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-adv-rotation-explicit-strong.bin 37 //TESTARGS(name="adv_rotation_implicit_sharp_cylinder") -ceed {ceed_resource} -test -problem advection -bubble_type cylinder -bubble_continuity back_sharp -degree 3 -dm_plex_box_faces 1,1,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -rc 100. -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-adv-rotation-implicit-sharp-cylinder.bin 38 //TESTARGS(name="adv_rotation_implicit_stab_supg") -ceed {ceed_resource} -test -problem advection -CtauS .3 -stab supg -degree 3 -dm_plex_box_faces 1,1,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -rc 100. -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-adv-rotation-implicit-stab-supg.bin 39 //TESTARGS(name="adv_translation_implicit_stab_su") -ceed {ceed_resource} -test -problem advection -CtauS .3 -stab su -degree 3 -dm_plex_box_faces 1,1,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -rc 100. -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -wind_type translation -wind_translation .53,-1.33,-2.65 -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-adv-translation-implicit-stab-su.bin 40 //TESTARGS(name="adv2d_rotation_explicit_strong") -ceed {ceed_resource} -test -problem advection2d -strong_form 1 -degree 3 -dm_plex_box_faces 2,2 -units_kilogram 1e-9 -lx 125 -ly 125 -rc 100. -ts_dt 1e-3 -compare_final_state_atol 1E-11 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-adv2d-rotation-explicit-strong.bin 41 //TESTARGS(name="adv2d_rotation_implicit_stab_supg") -ceed {ceed_resource} -test -problem advection2d -CtauS .3 -stab supg -degree 3 -dm_plex_box_faces 1,1,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -rc 100. -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-adv2d-rotation-implicit-stab-supg.bin 42 //TESTARGS(name="adv2d_translation_implicit_stab_su") -ceed {ceed_resource} -test -problem advection2d -CtauS .3 -stab su -degree 3 -dm_plex_box_faces 1,1,2 -units_kilogram 1e-9 -lx 125 -ly 125 -lz 250 -rc 100. -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -wind_type translation -wind_translation .53,-1.33,0 -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-adv2d-translation-implicit-stab-su.bin 43 //TESTARGS(name="euler_implicit_test_none") -ceed {ceed_resource} -test -problem euler_vortex -degree 3 -dm_plex_box_faces 1,1,2 -units_meter 1e-4 -lx 125 -ly 125 -lz 1 -mean_velocity 1.4,-2.,0 -vortex_strength 2 -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-implicit-test-none.bin 44 //TESTARGS(name="euler_explicit_test_none") -ceed {ceed_resource} -test -problem euler_vortex -degree 3 -dm_plex_box_faces 2,2,1 -units_meter 1e-4 -lx 125 -ly 125 -lz 1 -mean_velocity 1.4,-2.,0 -vortex_strength 2 -ts_dt 1e-7 -ts_rk_type 5bs -ts_rtol 1e-10 -ts_atol 1e-10 -compare_final_state_atol 1E-7 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-explicit-test-none.bin 45 //TESTARGS(name="euler_implicit_test_t1") -ceed {ceed_resource} -test -problem euler_vortex -euler_test t1 -degree 3 -dm_plex_box_faces 1,1,2 -units_meter 1e-4 -lx 125 -ly 125 -lz 1 -vortex_strength 2 -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-implicit-test-t1.bin 46 //TESTARGS(name="euler_implicit_test_t2") -ceed {ceed_resource} -test -problem euler_vortex -euler_test t2 -degree 3 -dm_plex_box_faces 1,1,2 -units_meter 1e-4 -lx 125 -ly 125 -lz 1 -mean_velocity 1.4,-2.,0 -vortex_strength 2 -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-implicit-test-t2.bin 47 //TESTARGS(name="euler_implicit_test_t3") -ceed {ceed_resource} -test -problem euler_vortex -euler_test t3 -degree 3 -dm_plex_box_faces 1,1,2 -units_meter 1e-4 -lx 125 -ly 125 -lz 1 -vortex_strength 2 -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-implicit-test-t3.bin 48 //TESTARGS(name="euler_implicit_test_t4") -ceed {ceed_resource} -test -problem euler_vortex -euler_test t4 -degree 3 -dm_plex_box_faces 1,1,2 -units_meter 1e-4 -lx 125 -ly 125 -lz 1 -mean_velocity 1.4,-2.,0 -vortex_strength 2 -ksp_atol 1e-4 -ksp_rtol 1e-3 -ksp_type bcgs -snes_atol 1e-3 -snes_lag_jacobian 100 -snes_lag_jacobian_persists -snes_mf_operator -ts_dt 1e-3 -implicit -ts_type alpha -compare_final_state_atol 5E-4 -compare_final_state_filename examples/fluids/tests-output/fluids-navierstokes-euler-implicit-test-t4.bin 49 50 /// @file 51 /// Navier-Stokes example using PETSc 52 53 const char help[] = "Solve Navier-Stokes using PETSc and libCEED\n"; 54 55 #include "navierstokes.h" 56 57 int main(int argc, char **argv) { 58 // --------------------------------------------------------------------------- 59 // Initialize PETSc 60 // --------------------------------------------------------------------------- 61 PetscInt ierr; 62 ierr = PetscInitialize(&argc, &argv, NULL, help); 63 if (ierr) return ierr; 64 65 // --------------------------------------------------------------------------- 66 // Create structs 67 // --------------------------------------------------------------------------- 68 AppCtx app_ctx; 69 ierr = PetscCalloc1(1, &app_ctx); CHKERRQ(ierr); 70 71 ProblemData *problem = NULL; 72 ierr = PetscCalloc1(1, &problem); CHKERRQ(ierr); 73 74 User user; 75 ierr = PetscCalloc1(1, &user); CHKERRQ(ierr); 76 77 CeedData ceed_data; 78 ierr = PetscCalloc1(1, &ceed_data); CHKERRQ(ierr); 79 80 SimpleBC bc; 81 ierr = PetscCalloc1(1, &bc); CHKERRQ(ierr); 82 83 SetupContext setup_ctx; 84 ierr = PetscCalloc1(1, &setup_ctx); CHKERRQ(ierr); 85 86 Physics phys_ctx; 87 ierr = PetscCalloc1(1, &phys_ctx); CHKERRQ(ierr); 88 89 Units units; 90 ierr = PetscCalloc1(1, &units); CHKERRQ(ierr); 91 92 user->app_ctx = app_ctx; 93 user->units = units; 94 user->phys = phys_ctx; 95 96 // --------------------------------------------------------------------------- 97 // Process command line options 98 // --------------------------------------------------------------------------- 99 // -- Register problems to be available on the command line 100 ierr = RegisterProblems_NS(app_ctx); CHKERRQ(ierr); 101 102 // -- Process general command line options 103 MPI_Comm comm = PETSC_COMM_WORLD; 104 user->comm = comm; 105 ierr = ProcessCommandLineOptions(comm, app_ctx); CHKERRQ(ierr); 106 107 // --------------------------------------------------------------------------- 108 // Choose the problem from the list of registered problems 109 // --------------------------------------------------------------------------- 110 { 111 PetscErrorCode (*p)(ProblemData *, void *, void *); 112 ierr = PetscFunctionListFind(app_ctx->problems, app_ctx->problem_name, &p); 113 CHKERRQ(ierr); 114 if (!p) SETERRQ1(PETSC_COMM_SELF, 1, "Problem '%s' not found", 115 app_ctx->problem_name); 116 ierr = (*p)(problem, &setup_ctx, &user); CHKERRQ(ierr); 117 } 118 119 // --------------------------------------------------------------------------- 120 // Initialize libCEED 121 // --------------------------------------------------------------------------- 122 // -- Initialize backend 123 Ceed ceed; 124 CeedInit(app_ctx->ceed_resource, &ceed); 125 user->ceed = ceed; 126 127 // -- Check preferred MemType 128 CeedMemType mem_type_backend; 129 CeedGetPreferredMemType(ceed, &mem_type_backend); 130 131 // --------------------------------------------------------------------------- 132 // Set up global mesh 133 // --------------------------------------------------------------------------- 134 // -- Create distribute DM 135 DM dm; 136 ierr = CreateDistributedDM(comm, problem, setup_ctx, &dm); CHKERRQ(ierr); 137 VecType vec_type = NULL; 138 switch (mem_type_backend) { 139 case CEED_MEM_HOST: vec_type = VECSTANDARD; break; 140 case CEED_MEM_DEVICE: { 141 const char *resolved; 142 CeedGetResource(ceed, &resolved); 143 if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA; 144 else if (strstr(resolved, "/gpu/hip")) vec_type = VECHIP; 145 else vec_type = VECSTANDARD; 146 } 147 } 148 ierr = DMSetVecType(dm, vec_type); CHKERRQ(ierr); 149 ierr = DMSetFromOptions(dm); CHKERRQ(ierr); 150 user->dm = dm; 151 152 // -- Set up DM 153 ierr = SetUpDM(dm, problem, app_ctx->degree, bc, phys_ctx, setup_ctx); 154 CHKERRQ(ierr); 155 156 // -- Refine DM for high-order viz 157 if (app_ctx->viz_refine) { 158 ierr = VizRefineDM(dm, user, problem, bc, phys_ctx, setup_ctx); 159 CHKERRQ(ierr); 160 } 161 162 // --------------------------------------------------------------------------- 163 // Set up libCEED 164 // --------------------------------------------------------------------------- 165 // -- Set up libCEED objects 166 ierr = SetupLibceed(ceed, ceed_data, dm, user, app_ctx, problem, bc); 167 CHKERRQ(ierr); 168 169 // -- Set up context for QFunctions 170 ierr = problem->setup_ctx(ceed, ceed_data, app_ctx, setup_ctx, phys_ctx); 171 CHKERRQ(ierr); 172 173 // --------------------------------------------------------------------------- 174 // Set up ICs 175 // --------------------------------------------------------------------------- 176 // -- Set up global state vector Q 177 Vec Q; 178 ierr = DMCreateGlobalVector(dm, &Q); CHKERRQ(ierr); 179 ierr = VecZeroEntries(Q); CHKERRQ(ierr); 180 181 // -- Set up local state vector Q_loc 182 Vec Q_loc; 183 ierr = DMGetLocalVector(dm, &Q_loc); CHKERRQ(ierr); 184 185 // -- Fix multiplicity for ICs 186 ierr = ICs_FixMultiplicity(dm, ceed_data, Q_loc, Q, 0.0); CHKERRQ(ierr); 187 188 // --------------------------------------------------------------------------- 189 // Set up lumped mass matrix 190 // --------------------------------------------------------------------------- 191 // -- Set up global mass vector 192 ierr = VecDuplicate(Q, &user->M); CHKERRQ(ierr); 193 194 // -- Compute lumped mass matrix 195 ierr = ComputeLumpedMassMatrix(ceed, dm, ceed_data, user->M); CHKERRQ(ierr); 196 197 // --------------------------------------------------------------------------- 198 // Record boundary values from initial condition 199 // --------------------------------------------------------------------------- 200 // -- This overrides DMPlexInsertBoundaryValues(). 201 // We use this for the main simulation DM because the reference 202 // DMPlexInsertBoundaryValues() is very slow. If we disable this, we should 203 // still get the same results due to the problem->bc function, but with 204 // potentially much slower execution. 205 if (1) {ierr = SetBCsFromICs_NS(dm, Q, Q_loc); CHKERRQ(ierr);} 206 207 // --------------------------------------------------------------------------- 208 // Create output directory 209 // --------------------------------------------------------------------------- 210 PetscMPIInt rank; 211 MPI_Comm_rank(comm, &rank); 212 if (!rank) {ierr = PetscMkdir(app_ctx->output_dir); CHKERRQ(ierr);} 213 214 // --------------------------------------------------------------------------- 215 // Gather initial Q values in case of continuation of simulation 216 // --------------------------------------------------------------------------- 217 // -- Set up initial values from binary file 218 if (app_ctx->cont_steps) { 219 ierr = SetupICsFromBinary(comm, app_ctx, Q); CHKERRQ(ierr); 220 } 221 222 // --------------------------------------------------------------------------- 223 // Print problem summary 224 // --------------------------------------------------------------------------- 225 if (!app_ctx->test_mode) { 226 227 // Header and rank 228 char host_name[PETSC_MAX_PATH_LEN]; 229 int comm_size; 230 ierr = PetscGetHostName(host_name, sizeof host_name); CHKERRQ(ierr); 231 ierr = MPI_Comm_size(comm, &comm_size); CHKERRQ(ierr); 232 ierr = PetscPrintf(comm, 233 "\n-- Navier-Stokes solver - libCEED + PETSc --\n" 234 " MPI:\n" 235 " Host Name : %s\n" 236 " Total ranks : %d\n", 237 host_name, comm_size); CHKERRQ(ierr); 238 239 // Problem specific info 240 ierr = problem->print_info(phys_ctx, setup_ctx, app_ctx); CHKERRQ(ierr); 241 242 // libCEED 243 const char *used_resource; 244 CeedGetResource(ceed, &used_resource); 245 ierr = PetscPrintf(comm, 246 " libCEED:\n" 247 " libCEED Backend : %s\n" 248 " libCEED Backend MemType : %s\n", 249 used_resource, CeedMemTypes[mem_type_backend]); CHKERRQ(ierr); 250 // PETSc 251 char box_faces_str[PETSC_MAX_PATH_LEN] = "NONE"; 252 ierr = PetscOptionsGetString(NULL, NULL, "-dm_plex_box_faces", box_faces_str, 253 sizeof(box_faces_str), NULL); CHKERRQ(ierr); 254 ierr = PetscPrintf(comm, 255 " PETSc:\n" 256 " Box Faces : %s\n" 257 " Time Stepping Scheme : %s\n", 258 box_faces_str, phys_ctx->implicit ? "implicit" : "explicit"); CHKERRQ(ierr); 259 // Mesh 260 const PetscInt num_comp_q = 5; 261 CeedInt glob_dofs, owned_dofs; 262 PetscInt glob_nodes, owned_nodes; 263 const CeedInt num_P = app_ctx->degree + 1, 264 num_Q = num_P + app_ctx->q_extra; 265 // -- Get global size 266 ierr = VecGetSize(Q, &glob_dofs); CHKERRQ(ierr); 267 ierr = VecGetLocalSize(Q, &owned_dofs); CHKERRQ(ierr); 268 glob_nodes = glob_dofs/num_comp_q; 269 // -- Get local size 270 ierr = VecGetSize(Q_loc, &owned_nodes); CHKERRQ(ierr); 271 owned_nodes /= num_comp_q; 272 ierr = PetscPrintf(comm, 273 " Mesh:\n" 274 " Number of 1D Basis Nodes (P) : %d\n" 275 " Number of 1D Quadrature Points (Q) : %d\n" 276 " Global DoFs : %D\n" 277 " Owned DoFs : %D\n" 278 " DoFs per node : %D\n" 279 " Global nodes : %D\n" 280 " Owned nodes : %D\n", 281 num_P, num_Q, glob_dofs, owned_dofs, num_comp_q, 282 glob_nodes, owned_nodes); CHKERRQ(ierr); 283 } 284 // -- Restore Q_loc 285 ierr = DMRestoreLocalVector(dm, &Q_loc); CHKERRQ(ierr); 286 287 // --------------------------------------------------------------------------- 288 // TS: Create, setup, and solve 289 // --------------------------------------------------------------------------- 290 TS ts; 291 PetscScalar final_time; 292 ierr = TSSolve_NS(dm, user, app_ctx, phys_ctx, &Q, &final_time, &ts); 293 CHKERRQ(ierr); 294 295 // --------------------------------------------------------------------------- 296 // Post-processing 297 // --------------------------------------------------------------------------- 298 ierr = PostProcess_NS(ts, ceed_data, dm, problem, app_ctx, Q, final_time); 299 CHKERRQ(ierr); 300 301 // --------------------------------------------------------------------------- 302 // Destroy libCEED objects 303 // --------------------------------------------------------------------------- 304 // -- Vectors 305 CeedVectorDestroy(&ceed_data->x_coord); 306 CeedVectorDestroy(&ceed_data->q_data); 307 CeedVectorDestroy(&user->q_ceed); 308 CeedVectorDestroy(&user->q_dot_ceed); 309 CeedVectorDestroy(&user->g_ceed); 310 311 // -- Contexts 312 CeedQFunctionContextDestroy(&ceed_data->setup_context); 313 CeedQFunctionContextDestroy(&ceed_data->dc_context); 314 CeedQFunctionContextDestroy(&ceed_data->advection_context); 315 CeedQFunctionContextDestroy(&ceed_data->euler_context); 316 317 // -- QFunctions 318 CeedQFunctionDestroy(&ceed_data->qf_setup_vol); 319 CeedQFunctionDestroy(&ceed_data->qf_ics); 320 CeedQFunctionDestroy(&ceed_data->qf_rhs_vol); 321 CeedQFunctionDestroy(&ceed_data->qf_ifunction_vol); 322 CeedQFunctionDestroy(&ceed_data->qf_setup_sur); 323 CeedQFunctionDestroy(&ceed_data->qf_apply_sur); 324 325 // -- Bases 326 CeedBasisDestroy(&ceed_data->basis_q); 327 CeedBasisDestroy(&ceed_data->basis_x); 328 CeedBasisDestroy(&ceed_data->basis_xc); 329 CeedBasisDestroy(&ceed_data->basis_q_sur); 330 CeedBasisDestroy(&ceed_data->basis_x_sur); 331 CeedBasisDestroy(&ceed_data->basis_xc_sur); 332 333 // -- Restrictions 334 CeedElemRestrictionDestroy(&ceed_data->elem_restr_q); 335 CeedElemRestrictionDestroy(&ceed_data->elem_restr_x); 336 CeedElemRestrictionDestroy(&ceed_data->elem_restr_qd_i); 337 338 // -- Operators 339 CeedOperatorDestroy(&ceed_data->op_setup_vol); 340 CeedOperatorDestroy(&ceed_data->op_ics); 341 CeedOperatorDestroy(&user->op_rhs_vol); 342 CeedOperatorDestroy(&user->op_ifunction_vol); 343 CeedOperatorDestroy(&user->op_rhs); 344 CeedOperatorDestroy(&user->op_ifunction); 345 346 // -- Ceed 347 CeedDestroy(&ceed); 348 349 // --------------------------------------------------------------------------- 350 // Clean up PETSc 351 // --------------------------------------------------------------------------- 352 // -- Vectors 353 ierr = VecDestroy(&Q); CHKERRQ(ierr); 354 ierr = VecDestroy(&user->M); CHKERRQ(ierr); 355 356 // -- Matrices 357 ierr = MatDestroy(&user->interp_viz); CHKERRQ(ierr); 358 359 // -- DM 360 ierr = DMDestroy(&dm); CHKERRQ(ierr); 361 ierr = DMDestroy(&user->dm_viz); CHKERRQ(ierr); 362 363 // -- TS 364 ierr = TSDestroy(&ts); CHKERRQ(ierr); 365 366 // -- Function list 367 ierr = PetscFunctionListDestroy(&app_ctx->problems); CHKERRQ(ierr); 368 369 // -- Structs 370 ierr = PetscFree(units); CHKERRQ(ierr); 371 ierr = PetscFree(user); CHKERRQ(ierr); 372 ierr = PetscFree(problem); CHKERRQ(ierr); 373 ierr = PetscFree(bc); CHKERRQ(ierr); 374 ierr = PetscFree(setup_ctx); CHKERRQ(ierr); 375 ierr = PetscFree(phys_ctx->dc_ctx); CHKERRQ(ierr); 376 ierr = PetscFree(phys_ctx->euler_ctx); CHKERRQ(ierr); 377 ierr = PetscFree(phys_ctx->advection_ctx); CHKERRQ(ierr); 378 ierr = PetscFree(phys_ctx); CHKERRQ(ierr); 379 ierr = PetscFree(app_ctx); CHKERRQ(ierr); 380 ierr = PetscFree(ceed_data); CHKERRQ(ierr); 381 382 return PetscFinalize(); 383 } 384