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