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