13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 377841947SLeila Ghaffari // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 577841947SLeila Ghaffari // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 777841947SLeila Ghaffari 877841947SLeila Ghaffari /// @file 977841947SLeila Ghaffari /// Command line option processing for Navier-Stokes example using PETSc 1077841947SLeila Ghaffari 1177841947SLeila Ghaffari #include "../navierstokes.h" 1277841947SLeila Ghaffari 1377841947SLeila Ghaffari // Register problems to be available on the command line 1477841947SLeila Ghaffari PetscErrorCode RegisterProblems_NS(AppCtx app_ctx) { 1577841947SLeila Ghaffari 1677841947SLeila Ghaffari 1777841947SLeila Ghaffari app_ctx->problems = NULL; 1877841947SLeila Ghaffari PetscFunctionBeginUser; 1977841947SLeila Ghaffari 20cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "density_current", 21cea0a271SJames Wright NS_DENSITY_CURRENT)); 2277841947SLeila Ghaffari 23cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "euler_vortex", 24cea0a271SJames Wright NS_EULER_VORTEX)); 2577841947SLeila Ghaffari 26cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "shocktube", 27cea0a271SJames Wright NS_SHOCKTUBE)); 28019b7682STimothy Aiken 29cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "advection", 30cea0a271SJames Wright NS_ADVECTION)); 3177841947SLeila Ghaffari 32cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "advection2d", 33cea0a271SJames Wright NS_ADVECTION2D)); 3477841947SLeila Ghaffari 35cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "blasius", 36cea0a271SJames Wright NS_BLASIUS)); 3788626eedSJames Wright 38cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "channel", 39cea0a271SJames Wright NS_CHANNEL)); 40cea0a271SJames Wright 41cea0a271SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "newtonian_wave", 42cea0a271SJames Wright NS_NEWTONIAN_WAVE)); 4388626eedSJames Wright 4477841947SLeila Ghaffari PetscFunctionReturn(0); 4577841947SLeila Ghaffari } 4677841947SLeila Ghaffari 4777841947SLeila Ghaffari // Process general command line options 482fe7aee7SLeila Ghaffari PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx, 492fe7aee7SLeila Ghaffari SimpleBC bc) { 5077841947SLeila Ghaffari 5177841947SLeila Ghaffari PetscBool ceed_flag = PETSC_FALSE; 5277841947SLeila Ghaffari PetscBool problem_flag = PETSC_FALSE; 53*69293791SJames Wright PetscBool option_set = PETSC_FALSE; 5477841947SLeila Ghaffari PetscErrorCode ierr; 5577841947SLeila Ghaffari PetscFunctionBeginUser; 5677841947SLeila Ghaffari 5767490bc6SJeremy L Thompson PetscOptionsBegin(comm, NULL, "Navier-Stokes in PETSc with libCEED", 5867490bc6SJeremy L Thompson NULL); 5977841947SLeila Ghaffari 6077841947SLeila Ghaffari ierr = PetscOptionsString("-ceed", "CEED resource specifier", 6177841947SLeila Ghaffari NULL, app_ctx->ceed_resource, app_ctx->ceed_resource, 6277841947SLeila Ghaffari sizeof(app_ctx->ceed_resource), &ceed_flag); CHKERRQ(ierr); 6377841947SLeila Ghaffari 6477841947SLeila Ghaffari app_ctx->test_mode = PETSC_FALSE; 6577841947SLeila Ghaffari ierr = PetscOptionsBool("-test", "Run in test mode", 6677841947SLeila Ghaffari NULL, app_ctx->test_mode, &app_ctx->test_mode, NULL); CHKERRQ(ierr); 6777841947SLeila Ghaffari 6877841947SLeila Ghaffari app_ctx->test_tol = 1E-11; 6977841947SLeila Ghaffari ierr = PetscOptionsScalar("-compare_final_state_atol", 7077841947SLeila Ghaffari "Test absolute tolerance", 7177841947SLeila Ghaffari NULL, app_ctx->test_tol, &app_ctx->test_tol, NULL); CHKERRQ(ierr); 7277841947SLeila Ghaffari 7377841947SLeila Ghaffari ierr = PetscOptionsString("-compare_final_state_filename", "Test filename", 7477841947SLeila Ghaffari NULL, app_ctx->file_path, app_ctx->file_path, 7577841947SLeila Ghaffari sizeof(app_ctx->file_path), NULL); CHKERRQ(ierr); 7677841947SLeila Ghaffari 7777841947SLeila Ghaffari ierr = PetscOptionsFList("-problem", "Problem to solve", NULL, 7877841947SLeila Ghaffari app_ctx->problems, 7977841947SLeila Ghaffari app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name), 8077841947SLeila Ghaffari &problem_flag); CHKERRQ(ierr); 8177841947SLeila Ghaffari 8277841947SLeila Ghaffari app_ctx->viz_refine = 0; 8377841947SLeila Ghaffari ierr = PetscOptionsInt("-viz_refine", 8477841947SLeila Ghaffari "Regular refinement levels for visualization", 8577841947SLeila Ghaffari NULL, app_ctx->viz_refine, &app_ctx->viz_refine, NULL); CHKERRQ(ierr); 8677841947SLeila Ghaffari 8777841947SLeila Ghaffari app_ctx->output_freq = 10; 8877841947SLeila Ghaffari ierr = PetscOptionsInt("-output_freq", 8977841947SLeila Ghaffari "Frequency of output, in number of steps", 9077841947SLeila Ghaffari NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL); CHKERRQ(ierr); 9177841947SLeila Ghaffari 92*69293791SJames Wright PetscCall(PetscOptionsBool("-output_add_stepnum2bin", 93*69293791SJames Wright "Add step number to the binary outputs", 94*69293791SJames Wright NULL, app_ctx->add_stepnum2bin, &app_ctx->add_stepnum2bin, NULL)); 95*69293791SJames Wright 96*69293791SJames Wright PetscCall(PetscStrncpy(app_ctx->output_dir, ".", 2)); 97*69293791SJames Wright PetscCall(PetscOptionsString("-output_dir", "Output directory", 98*69293791SJames Wright NULL, app_ctx->output_dir, app_ctx->output_dir, 99*69293791SJames Wright sizeof(app_ctx->output_dir), NULL)); 100*69293791SJames Wright 10177841947SLeila Ghaffari app_ctx->cont_steps = 0; 10277841947SLeila Ghaffari ierr = PetscOptionsInt("-continue", "Continue from previous solution", 10377841947SLeila Ghaffari NULL, app_ctx->cont_steps, &app_ctx->cont_steps, NULL); CHKERRQ(ierr); 10477841947SLeila Ghaffari 105*69293791SJames Wright PetscCall(PetscStrcpy(app_ctx->cont_file, "[output_dir]/ns-solution.bin")); 106*69293791SJames Wright PetscCall(PetscOptionsString("-continue_filename", 107*69293791SJames Wright "Filename to get initial condition from", 108*69293791SJames Wright NULL, app_ctx->cont_file, app_ctx->cont_file, 109*69293791SJames Wright sizeof(app_ctx->cont_file), &option_set)); 110*69293791SJames Wright if(!option_set) PetscCall(PetscSNPrintf(app_ctx->cont_file, 111*69293791SJames Wright sizeof app_ctx->cont_file, "%s/ns-solution.bin", 112*69293791SJames Wright app_ctx->output_dir)); 113*69293791SJames Wright 114*69293791SJames Wright PetscCall(PetscStrcpy(app_ctx->cont_time_file, "[output_dir]/ns-time.bin")); 115*69293791SJames Wright PetscCall(PetscOptionsString("-continue_time_filename", 116*69293791SJames Wright "Filename to get initial condition time from", 117*69293791SJames Wright NULL, app_ctx->cont_time_file, app_ctx->cont_time_file, 118*69293791SJames Wright sizeof(app_ctx->cont_time_file), &option_set)); 119*69293791SJames Wright if(!option_set) PetscCall(PetscSNPrintf(app_ctx->cont_time_file, 120*69293791SJames Wright sizeof app_ctx->cont_time_file, "%s/ns-time.bin", 121*69293791SJames Wright app_ctx->output_dir)); 122*69293791SJames Wright 12377841947SLeila Ghaffari app_ctx->degree = 1; 12477841947SLeila Ghaffari ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements", 12577841947SLeila Ghaffari NULL, app_ctx->degree, &app_ctx->degree, NULL); CHKERRQ(ierr); 12677841947SLeila Ghaffari 12777841947SLeila Ghaffari app_ctx->q_extra = 2; 12877841947SLeila Ghaffari ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points", 12977841947SLeila Ghaffari NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); CHKERRQ(ierr); 13077841947SLeila Ghaffari 131544be873SJed Brown { 132544be873SJed Brown PetscBool option_set; 133544be873SJed Brown char amat_type[256] = ""; 134544be873SJed Brown PetscCall(PetscOptionsFList("-amat_type", 135544be873SJed Brown "Set the type of Amat distinct from Pmat (-dm_mat_type)", 136544be873SJed Brown NULL, MatList, amat_type, amat_type, sizeof(amat_type), &option_set)); 137544be873SJed Brown if (option_set) PetscCall(PetscStrallocpy(amat_type, 138544be873SJed Brown (char **)&app_ctx->amat_type)); 139544be873SJed Brown } 140544be873SJed Brown PetscCall(PetscOptionsBool("-pmat_pbdiagonal", 141544be873SJed Brown "Assemble only point-block diagonal for Pmat", NULL, app_ctx->pmat_pbdiagonal, 142544be873SJed Brown &app_ctx->pmat_pbdiagonal, NULL)); 143544be873SJed Brown 14477841947SLeila Ghaffari // Provide default ceed resource if not specified 14577841947SLeila Ghaffari if (!ceed_flag) { 14677841947SLeila Ghaffari const char *ceed_resource = "/cpu/self"; 14777841947SLeila Ghaffari strncpy(app_ctx->ceed_resource, ceed_resource, 10); 14877841947SLeila Ghaffari } 14977841947SLeila Ghaffari 15077841947SLeila Ghaffari // Provide default problem if not specified 15177841947SLeila Ghaffari if (!problem_flag) { 15277841947SLeila Ghaffari const char *problem_name = "density_current"; 15377841947SLeila Ghaffari strncpy(app_ctx->problem_name, problem_name, 16); 15477841947SLeila Ghaffari } 15577841947SLeila Ghaffari 1562fe7aee7SLeila Ghaffari // Wall Boundary Conditions 1572fe7aee7SLeila Ghaffari bc->num_wall = 16; 1582fe7aee7SLeila Ghaffari PetscBool flg; 1592fe7aee7SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_wall", 1602fe7aee7SLeila Ghaffari "Face IDs to apply wall BC", 1612fe7aee7SLeila Ghaffari NULL, bc->walls, &bc->num_wall, NULL); CHKERRQ(ierr); 1622fe7aee7SLeila Ghaffari bc->num_comps = 5; 1632fe7aee7SLeila Ghaffari ierr = PetscOptionsIntArray("-wall_comps", 1642fe7aee7SLeila Ghaffari "An array of constrained component numbers", 1652fe7aee7SLeila Ghaffari NULL, bc->wall_comps, &bc->num_comps, &flg); CHKERRQ(ierr); 1662fe7aee7SLeila Ghaffari // Slip Boundary Conditions 1672fe7aee7SLeila Ghaffari for (PetscInt j=0; j<3; j++) { 1682fe7aee7SLeila Ghaffari bc->num_slip[j] = 16; 1692fe7aee7SLeila Ghaffari PetscBool flg; 1702fe7aee7SLeila Ghaffari const char *flags[3] = {"-bc_slip_x", "-bc_slip_y", "-bc_slip_z"}; 1712fe7aee7SLeila Ghaffari ierr = PetscOptionsIntArray(flags[j], 1722fe7aee7SLeila Ghaffari "Face IDs to apply slip BC", 1732fe7aee7SLeila Ghaffari NULL, bc->slips[j], &bc->num_slip[j], &flg); CHKERRQ(ierr); 1742fe7aee7SLeila Ghaffari if (flg) bc->user_bc = PETSC_TRUE; 1752fe7aee7SLeila Ghaffari } 1762fe7aee7SLeila Ghaffari 1772fe7aee7SLeila Ghaffari // Error if wall and slip BCs are set on the same face 1782fe7aee7SLeila Ghaffari if (bc->user_bc) 1792fe7aee7SLeila Ghaffari for (PetscInt c = 0; c < 3; c++) 1802fe7aee7SLeila Ghaffari for (PetscInt s = 0; s < bc->num_slip[c]; s++) 1812fe7aee7SLeila Ghaffari for (PetscInt w = 0; w < bc->num_wall; w++) 1822fe7aee7SLeila Ghaffari if (bc->slips[c][s] == bc->walls[w]) 1837578c821SJeremy L Thompson SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, 18408140895SJed Brown "Boundary condition already set on face %" PetscInt_FMT "!\n", 1852fe7aee7SLeila Ghaffari bc->walls[w]); 1862fe7aee7SLeila Ghaffari 1872fe7aee7SLeila Ghaffari // Inflow BCs 1882fe7aee7SLeila Ghaffari bc->num_inflow = 16; 1892fe7aee7SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_inflow", 1902fe7aee7SLeila Ghaffari "Face IDs to apply inflow BC", 1912fe7aee7SLeila Ghaffari NULL, bc->inflows, &bc->num_inflow, NULL); CHKERRQ(ierr); 1922fe7aee7SLeila Ghaffari // Outflow BCs 1932fe7aee7SLeila Ghaffari bc->num_outflow = 16; 1942fe7aee7SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_outflow", 1952fe7aee7SLeila Ghaffari "Face IDs to apply outflow BC", 1962fe7aee7SLeila Ghaffari NULL, bc->outflows, &bc->num_outflow, NULL); CHKERRQ(ierr); 197f4ca79c2SJames Wright // Freestream BCs 198f4ca79c2SJames Wright bc->num_freestream = 16; 199f4ca79c2SJames Wright ierr = PetscOptionsIntArray("-bc_freestream", 200f4ca79c2SJames Wright "Face IDs to apply freestream BC", 201f4ca79c2SJames Wright NULL, bc->freestreams, &bc->num_freestream, NULL); CHKERRQ(ierr); 2022fe7aee7SLeila Ghaffari 20367490bc6SJeremy L Thompson PetscOptionsEnd(); 20477841947SLeila Ghaffari 20577841947SLeila Ghaffari PetscFunctionReturn(0); 20677841947SLeila Ghaffari } 207