1 // Copyright (c) 2017-2022, 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 /// Command line option processing for Navier-Stokes example using PETSc 10 11 #include "../navierstokes.h" 12 13 // Register problems to be available on the command line 14 PetscErrorCode RegisterProblems_NS(AppCtx app_ctx) { 15 16 17 app_ctx->problems = NULL; 18 PetscErrorCode ierr; 19 PetscFunctionBeginUser; 20 21 ierr = PetscFunctionListAdd(&app_ctx->problems, "density_current", 22 NS_DENSITY_CURRENT); CHKERRQ(ierr); 23 24 ierr = PetscFunctionListAdd(&app_ctx->problems, "euler_vortex", 25 NS_EULER_VORTEX); CHKERRQ(ierr); 26 27 ierr = PetscFunctionListAdd(&app_ctx->problems, "advection", 28 NS_ADVECTION); CHKERRQ(ierr); 29 30 ierr = PetscFunctionListAdd(&app_ctx->problems, "advection2d", 31 NS_ADVECTION2D); CHKERRQ(ierr); 32 33 PetscFunctionReturn(0); 34 } 35 36 // Process general command line options 37 PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx, 38 SimpleBC bc) { 39 40 PetscBool ceed_flag = PETSC_FALSE; 41 PetscBool problem_flag = PETSC_FALSE; 42 PetscErrorCode ierr; 43 PetscFunctionBeginUser; 44 45 ierr = PetscOptionsBegin(comm, NULL, "Navier-Stokes in PETSc with libCEED", 46 NULL); CHKERRQ(ierr); 47 48 ierr = PetscOptionsString("-ceed", "CEED resource specifier", 49 NULL, app_ctx->ceed_resource, app_ctx->ceed_resource, 50 sizeof(app_ctx->ceed_resource), &ceed_flag); CHKERRQ(ierr); 51 52 app_ctx->test_mode = PETSC_FALSE; 53 ierr = PetscOptionsBool("-test", "Run in test mode", 54 NULL, app_ctx->test_mode, &app_ctx->test_mode, NULL); CHKERRQ(ierr); 55 56 app_ctx->test_tol = 1E-11; 57 ierr = PetscOptionsScalar("-compare_final_state_atol", 58 "Test absolute tolerance", 59 NULL, app_ctx->test_tol, &app_ctx->test_tol, NULL); CHKERRQ(ierr); 60 61 ierr = PetscOptionsString("-compare_final_state_filename", "Test filename", 62 NULL, app_ctx->file_path, app_ctx->file_path, 63 sizeof(app_ctx->file_path), NULL); CHKERRQ(ierr); 64 65 ierr = PetscOptionsFList("-problem", "Problem to solve", NULL, 66 app_ctx->problems, 67 app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name), 68 &problem_flag); CHKERRQ(ierr); 69 70 app_ctx->viz_refine = 0; 71 ierr = PetscOptionsInt("-viz_refine", 72 "Regular refinement levels for visualization", 73 NULL, app_ctx->viz_refine, &app_ctx->viz_refine, NULL); CHKERRQ(ierr); 74 75 app_ctx->output_freq = 10; 76 ierr = PetscOptionsInt("-output_freq", 77 "Frequency of output, in number of steps", 78 NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL); CHKERRQ(ierr); 79 80 app_ctx->cont_steps = 0; 81 ierr = PetscOptionsInt("-continue", "Continue from previous solution", 82 NULL, app_ctx->cont_steps, &app_ctx->cont_steps, NULL); CHKERRQ(ierr); 83 84 app_ctx->degree = 1; 85 ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements", 86 NULL, app_ctx->degree, &app_ctx->degree, NULL); CHKERRQ(ierr); 87 88 app_ctx->q_extra = 2; 89 ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points", 90 NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); CHKERRQ(ierr); 91 92 ierr = PetscStrncpy(app_ctx->output_dir, ".", 2); CHKERRQ(ierr); 93 ierr = PetscOptionsString("-output_dir", "Output directory", 94 NULL, app_ctx->output_dir, app_ctx->output_dir, 95 sizeof(app_ctx->output_dir), NULL); CHKERRQ(ierr); 96 97 // Provide default ceed resource if not specified 98 if (!ceed_flag) { 99 const char *ceed_resource = "/cpu/self"; 100 strncpy(app_ctx->ceed_resource, ceed_resource, 10); 101 } 102 103 // Provide default problem if not specified 104 if (!problem_flag) { 105 const char *problem_name = "density_current"; 106 strncpy(app_ctx->problem_name, problem_name, 16); 107 } 108 109 // Wall Boundary Conditions 110 bc->num_wall = 16; 111 PetscBool flg; 112 ierr = PetscOptionsIntArray("-bc_wall", 113 "Face IDs to apply wall BC", 114 NULL, bc->walls, &bc->num_wall, NULL); CHKERRQ(ierr); 115 bc->num_comps = 5; 116 ierr = PetscOptionsIntArray("-wall_comps", 117 "An array of constrained component numbers", 118 NULL, bc->wall_comps, &bc->num_comps, &flg); CHKERRQ(ierr); 119 // Slip Boundary Conditions 120 for (PetscInt j=0; j<3; j++) { 121 bc->num_slip[j] = 16; 122 PetscBool flg; 123 const char *flags[3] = {"-bc_slip_x", "-bc_slip_y", "-bc_slip_z"}; 124 ierr = PetscOptionsIntArray(flags[j], 125 "Face IDs to apply slip BC", 126 NULL, bc->slips[j], &bc->num_slip[j], &flg); CHKERRQ(ierr); 127 if (flg) bc->user_bc = PETSC_TRUE; 128 } 129 130 // Error if wall and slip BCs are set on the same face 131 if (bc->user_bc) 132 for (PetscInt c = 0; c < 3; c++) 133 for (PetscInt s = 0; s < bc->num_slip[c]; s++) 134 for (PetscInt w = 0; w < bc->num_wall; w++) 135 if (bc->slips[c][s] == bc->walls[w]) 136 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, 137 "Boundary condition already set on face %D!\n", 138 bc->walls[w]); 139 140 // Inflow BCs 141 bc->num_inflow = 16; 142 ierr = PetscOptionsIntArray("-bc_inflow", 143 "Face IDs to apply inflow BC", 144 NULL, bc->inflows, &bc->num_inflow, NULL); CHKERRQ(ierr); 145 // Outflow BCs 146 bc->num_outflow = 16; 147 ierr = PetscOptionsIntArray("-bc_outflow", 148 "Face IDs to apply outflow BC", 149 NULL, bc->outflows, &bc->num_outflow, NULL); CHKERRQ(ierr); 150 151 ierr = PetscOptionsEnd(); CHKERRQ(ierr); 152 153 PetscFunctionReturn(0); 154 } 155