1727da7e7SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3a515125bSLeila Ghaffari // 4727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5a515125bSLeila Ghaffari // 6727da7e7SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7a515125bSLeila Ghaffari 8a515125bSLeila Ghaffari /// @file 9a515125bSLeila Ghaffari /// Command line option processing for Navier-Stokes example using PETSc 10a515125bSLeila Ghaffari 11a515125bSLeila Ghaffari #include "../navierstokes.h" 12a515125bSLeila Ghaffari 13a515125bSLeila Ghaffari // Register problems to be available on the command line 14a515125bSLeila Ghaffari PetscErrorCode RegisterProblems_NS(AppCtx app_ctx) { 15a515125bSLeila Ghaffari 16a515125bSLeila Ghaffari 17a515125bSLeila Ghaffari app_ctx->problems = NULL; 18a515125bSLeila Ghaffari PetscErrorCode ierr; 19a515125bSLeila Ghaffari PetscFunctionBeginUser; 20a515125bSLeila Ghaffari 21a515125bSLeila Ghaffari ierr = PetscFunctionListAdd(&app_ctx->problems, "density_current", 22a515125bSLeila Ghaffari NS_DENSITY_CURRENT); CHKERRQ(ierr); 23a515125bSLeila Ghaffari 24a515125bSLeila Ghaffari ierr = PetscFunctionListAdd(&app_ctx->problems, "euler_vortex", 25a515125bSLeila Ghaffari NS_EULER_VORTEX); CHKERRQ(ierr); 26a515125bSLeila Ghaffari 27af8870a9STimothy Aiken ierr = PetscFunctionListAdd(&app_ctx->problems, "shocktube", 28af8870a9STimothy Aiken NS_SHOCKTUBE); CHKERRQ(ierr); 29af8870a9STimothy Aiken 30a515125bSLeila Ghaffari ierr = PetscFunctionListAdd(&app_ctx->problems, "advection", 31a515125bSLeila Ghaffari NS_ADVECTION); CHKERRQ(ierr); 32a515125bSLeila Ghaffari 33a515125bSLeila Ghaffari ierr = PetscFunctionListAdd(&app_ctx->problems, "advection2d", 34a515125bSLeila Ghaffari NS_ADVECTION2D); CHKERRQ(ierr); 35a515125bSLeila Ghaffari 36bb8a0c61SJames Wright ierr = PetscFunctionListAdd(&app_ctx->problems, "blasius", 37bb8a0c61SJames Wright NS_BLASIUS); CHKERRQ(ierr); 38bb8a0c61SJames Wright 39bb8a0c61SJames Wright ierr = PetscFunctionListAdd(&app_ctx->problems, "channel", 40bb8a0c61SJames Wright NS_CHANNEL); CHKERRQ(ierr); 41bb8a0c61SJames Wright 42a515125bSLeila Ghaffari PetscFunctionReturn(0); 43a515125bSLeila Ghaffari } 44a515125bSLeila Ghaffari 45a515125bSLeila Ghaffari // Process general command line options 46002797a3SLeila Ghaffari PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx, 47002797a3SLeila Ghaffari SimpleBC bc) { 48a515125bSLeila Ghaffari 49a515125bSLeila Ghaffari PetscBool ceed_flag = PETSC_FALSE; 50a515125bSLeila Ghaffari PetscBool problem_flag = PETSC_FALSE; 51a515125bSLeila Ghaffari PetscErrorCode ierr; 52a515125bSLeila Ghaffari PetscFunctionBeginUser; 53a515125bSLeila Ghaffari 541485969bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Navier-Stokes in PETSc with libCEED", 551485969bSJeremy L Thompson NULL); 56a515125bSLeila Ghaffari 57a515125bSLeila Ghaffari ierr = PetscOptionsString("-ceed", "CEED resource specifier", 58a515125bSLeila Ghaffari NULL, app_ctx->ceed_resource, app_ctx->ceed_resource, 59a515125bSLeila Ghaffari sizeof(app_ctx->ceed_resource), &ceed_flag); CHKERRQ(ierr); 60a515125bSLeila Ghaffari 61a515125bSLeila Ghaffari app_ctx->test_mode = PETSC_FALSE; 62a515125bSLeila Ghaffari ierr = PetscOptionsBool("-test", "Run in test mode", 63a515125bSLeila Ghaffari NULL, app_ctx->test_mode, &app_ctx->test_mode, NULL); CHKERRQ(ierr); 64a515125bSLeila Ghaffari 65a515125bSLeila Ghaffari app_ctx->test_tol = 1E-11; 66a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-compare_final_state_atol", 67a515125bSLeila Ghaffari "Test absolute tolerance", 68a515125bSLeila Ghaffari NULL, app_ctx->test_tol, &app_ctx->test_tol, NULL); CHKERRQ(ierr); 69a515125bSLeila Ghaffari 70a515125bSLeila Ghaffari ierr = PetscOptionsString("-compare_final_state_filename", "Test filename", 71a515125bSLeila Ghaffari NULL, app_ctx->file_path, app_ctx->file_path, 72a515125bSLeila Ghaffari sizeof(app_ctx->file_path), NULL); CHKERRQ(ierr); 73a515125bSLeila Ghaffari 74a515125bSLeila Ghaffari ierr = PetscOptionsFList("-problem", "Problem to solve", NULL, 75a515125bSLeila Ghaffari app_ctx->problems, 76a515125bSLeila Ghaffari app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name), 77a515125bSLeila Ghaffari &problem_flag); CHKERRQ(ierr); 78a515125bSLeila Ghaffari 79a515125bSLeila Ghaffari app_ctx->viz_refine = 0; 80a515125bSLeila Ghaffari ierr = PetscOptionsInt("-viz_refine", 81a515125bSLeila Ghaffari "Regular refinement levels for visualization", 82a515125bSLeila Ghaffari NULL, app_ctx->viz_refine, &app_ctx->viz_refine, NULL); CHKERRQ(ierr); 83a515125bSLeila Ghaffari 84a515125bSLeila Ghaffari app_ctx->output_freq = 10; 85a515125bSLeila Ghaffari ierr = PetscOptionsInt("-output_freq", 86a515125bSLeila Ghaffari "Frequency of output, in number of steps", 87a515125bSLeila Ghaffari NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL); CHKERRQ(ierr); 88a515125bSLeila Ghaffari 89a515125bSLeila Ghaffari app_ctx->cont_steps = 0; 90a515125bSLeila Ghaffari ierr = PetscOptionsInt("-continue", "Continue from previous solution", 91a515125bSLeila Ghaffari NULL, app_ctx->cont_steps, &app_ctx->cont_steps, NULL); CHKERRQ(ierr); 92a515125bSLeila Ghaffari 93a515125bSLeila Ghaffari app_ctx->degree = 1; 94a515125bSLeila Ghaffari ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements", 95a515125bSLeila Ghaffari NULL, app_ctx->degree, &app_ctx->degree, NULL); CHKERRQ(ierr); 96a515125bSLeila Ghaffari 97a515125bSLeila Ghaffari app_ctx->q_extra = 2; 98a515125bSLeila Ghaffari ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points", 99a515125bSLeila Ghaffari NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); CHKERRQ(ierr); 100a515125bSLeila Ghaffari 101*b107fddaSJed Brown { 102*b107fddaSJed Brown PetscBool option_set; 103*b107fddaSJed Brown char amat_type[256] = ""; 104*b107fddaSJed Brown PetscCall(PetscOptionsFList("-amat_type", 105*b107fddaSJed Brown "Set the type of Amat distinct from Pmat (-dm_mat_type)", 106*b107fddaSJed Brown NULL, MatList, amat_type, amat_type, sizeof(amat_type), &option_set)); 107*b107fddaSJed Brown if (option_set) PetscCall(PetscStrallocpy(amat_type, 108*b107fddaSJed Brown (char **)&app_ctx->amat_type)); 109*b107fddaSJed Brown } 110*b107fddaSJed Brown PetscCall(PetscOptionsBool("-pmat_pbdiagonal", 111*b107fddaSJed Brown "Assemble only point-block diagonal for Pmat", NULL, app_ctx->pmat_pbdiagonal, 112*b107fddaSJed Brown &app_ctx->pmat_pbdiagonal, NULL)); 113*b107fddaSJed Brown 114a515125bSLeila Ghaffari ierr = PetscStrncpy(app_ctx->output_dir, ".", 2); CHKERRQ(ierr); 115a515125bSLeila Ghaffari ierr = PetscOptionsString("-output_dir", "Output directory", 116a515125bSLeila Ghaffari NULL, app_ctx->output_dir, app_ctx->output_dir, 117a515125bSLeila Ghaffari sizeof(app_ctx->output_dir), NULL); CHKERRQ(ierr); 118a515125bSLeila Ghaffari 119a515125bSLeila Ghaffari // Provide default ceed resource if not specified 120a515125bSLeila Ghaffari if (!ceed_flag) { 121a515125bSLeila Ghaffari const char *ceed_resource = "/cpu/self"; 122a515125bSLeila Ghaffari strncpy(app_ctx->ceed_resource, ceed_resource, 10); 123a515125bSLeila Ghaffari } 124a515125bSLeila Ghaffari 125a515125bSLeila Ghaffari // Provide default problem if not specified 126a515125bSLeila Ghaffari if (!problem_flag) { 127a515125bSLeila Ghaffari const char *problem_name = "density_current"; 128a515125bSLeila Ghaffari strncpy(app_ctx->problem_name, problem_name, 16); 129a515125bSLeila Ghaffari } 130a515125bSLeila Ghaffari 131002797a3SLeila Ghaffari // Wall Boundary Conditions 132002797a3SLeila Ghaffari bc->num_wall = 16; 133002797a3SLeila Ghaffari PetscBool flg; 134002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_wall", 135002797a3SLeila Ghaffari "Face IDs to apply wall BC", 136002797a3SLeila Ghaffari NULL, bc->walls, &bc->num_wall, NULL); CHKERRQ(ierr); 137002797a3SLeila Ghaffari bc->num_comps = 5; 138002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-wall_comps", 139002797a3SLeila Ghaffari "An array of constrained component numbers", 140002797a3SLeila Ghaffari NULL, bc->wall_comps, &bc->num_comps, &flg); CHKERRQ(ierr); 141002797a3SLeila Ghaffari // Slip Boundary Conditions 142002797a3SLeila Ghaffari for (PetscInt j=0; j<3; j++) { 143002797a3SLeila Ghaffari bc->num_slip[j] = 16; 144002797a3SLeila Ghaffari PetscBool flg; 145002797a3SLeila Ghaffari const char *flags[3] = {"-bc_slip_x", "-bc_slip_y", "-bc_slip_z"}; 146002797a3SLeila Ghaffari ierr = PetscOptionsIntArray(flags[j], 147002797a3SLeila Ghaffari "Face IDs to apply slip BC", 148002797a3SLeila Ghaffari NULL, bc->slips[j], &bc->num_slip[j], &flg); CHKERRQ(ierr); 149002797a3SLeila Ghaffari if (flg) bc->user_bc = PETSC_TRUE; 150002797a3SLeila Ghaffari } 151002797a3SLeila Ghaffari 152002797a3SLeila Ghaffari // Error if wall and slip BCs are set on the same face 153002797a3SLeila Ghaffari if (bc->user_bc) 154002797a3SLeila Ghaffari for (PetscInt c = 0; c < 3; c++) 155002797a3SLeila Ghaffari for (PetscInt s = 0; s < bc->num_slip[c]; s++) 156002797a3SLeila Ghaffari for (PetscInt w = 0; w < bc->num_wall; w++) 157002797a3SLeila Ghaffari if (bc->slips[c][s] == bc->walls[w]) 158a75026deSJeremy L Thompson SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, 159d940ca4eSJed Brown "Boundary condition already set on face %" PetscInt_FMT "!\n", 160002797a3SLeila Ghaffari bc->walls[w]); 161002797a3SLeila Ghaffari 162002797a3SLeila Ghaffari // Inflow BCs 163002797a3SLeila Ghaffari bc->num_inflow = 16; 164002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_inflow", 165002797a3SLeila Ghaffari "Face IDs to apply inflow BC", 166002797a3SLeila Ghaffari NULL, bc->inflows, &bc->num_inflow, NULL); CHKERRQ(ierr); 167002797a3SLeila Ghaffari // Outflow BCs 168002797a3SLeila Ghaffari bc->num_outflow = 16; 169002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_outflow", 170002797a3SLeila Ghaffari "Face IDs to apply outflow BC", 171002797a3SLeila Ghaffari NULL, bc->outflows, &bc->num_outflow, NULL); CHKERRQ(ierr); 172002797a3SLeila Ghaffari 1731485969bSJeremy L Thompson PetscOptionsEnd(); 174a515125bSLeila Ghaffari 175a515125bSLeila Ghaffari PetscFunctionReturn(0); 176a515125bSLeila Ghaffari } 177