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 PetscFunctionBeginUser; 19a515125bSLeila Ghaffari 20335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "density_current", 21335cfff3SJames Wright NS_DENSITY_CURRENT)); 22a515125bSLeila Ghaffari 23335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "euler_vortex", 24335cfff3SJames Wright NS_EULER_VORTEX)); 25a515125bSLeila Ghaffari 26335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "shocktube", 27335cfff3SJames Wright NS_SHOCKTUBE)); 28af8870a9STimothy Aiken 29335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "advection", 30335cfff3SJames Wright NS_ADVECTION)); 31a515125bSLeila Ghaffari 32335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "advection2d", 33335cfff3SJames Wright NS_ADVECTION2D)); 34a515125bSLeila Ghaffari 35335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "blasius", 36335cfff3SJames Wright NS_BLASIUS)); 37bb8a0c61SJames Wright 38335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "channel", 39335cfff3SJames Wright NS_CHANNEL)); 40335cfff3SJames Wright 41335cfff3SJames Wright PetscCall(PetscFunctionListAdd(&app_ctx->problems, "newtonian_wave", 42335cfff3SJames Wright NS_NEWTONIAN_WAVE)); 43bb8a0c61SJames Wright 44a515125bSLeila Ghaffari PetscFunctionReturn(0); 45a515125bSLeila Ghaffari } 46a515125bSLeila Ghaffari 47a515125bSLeila Ghaffari // Process general command line options 48002797a3SLeila Ghaffari PetscErrorCode ProcessCommandLineOptions(MPI_Comm comm, AppCtx app_ctx, 49002797a3SLeila Ghaffari SimpleBC bc) { 50a515125bSLeila Ghaffari 51a515125bSLeila Ghaffari PetscBool ceed_flag = PETSC_FALSE; 52a515125bSLeila Ghaffari PetscBool problem_flag = PETSC_FALSE; 53*91a36801SJames Wright PetscBool option_set = PETSC_FALSE; 54a515125bSLeila Ghaffari PetscErrorCode ierr; 55a515125bSLeila Ghaffari PetscFunctionBeginUser; 56a515125bSLeila Ghaffari 571485969bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Navier-Stokes in PETSc with libCEED", 581485969bSJeremy L Thompson NULL); 59a515125bSLeila Ghaffari 60a515125bSLeila Ghaffari ierr = PetscOptionsString("-ceed", "CEED resource specifier", 61a515125bSLeila Ghaffari NULL, app_ctx->ceed_resource, app_ctx->ceed_resource, 62a515125bSLeila Ghaffari sizeof(app_ctx->ceed_resource), &ceed_flag); CHKERRQ(ierr); 63a515125bSLeila Ghaffari 64a515125bSLeila Ghaffari app_ctx->test_mode = PETSC_FALSE; 65a515125bSLeila Ghaffari ierr = PetscOptionsBool("-test", "Run in test mode", 66a515125bSLeila Ghaffari NULL, app_ctx->test_mode, &app_ctx->test_mode, NULL); CHKERRQ(ierr); 67a515125bSLeila Ghaffari 68a515125bSLeila Ghaffari app_ctx->test_tol = 1E-11; 69a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-compare_final_state_atol", 70a515125bSLeila Ghaffari "Test absolute tolerance", 71a515125bSLeila Ghaffari NULL, app_ctx->test_tol, &app_ctx->test_tol, NULL); CHKERRQ(ierr); 72a515125bSLeila Ghaffari 73a515125bSLeila Ghaffari ierr = PetscOptionsString("-compare_final_state_filename", "Test filename", 74a515125bSLeila Ghaffari NULL, app_ctx->file_path, app_ctx->file_path, 75a515125bSLeila Ghaffari sizeof(app_ctx->file_path), NULL); CHKERRQ(ierr); 76a515125bSLeila Ghaffari 77a515125bSLeila Ghaffari ierr = PetscOptionsFList("-problem", "Problem to solve", NULL, 78a515125bSLeila Ghaffari app_ctx->problems, 79a515125bSLeila Ghaffari app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name), 80a515125bSLeila Ghaffari &problem_flag); CHKERRQ(ierr); 81a515125bSLeila Ghaffari 82a515125bSLeila Ghaffari app_ctx->viz_refine = 0; 83a515125bSLeila Ghaffari ierr = PetscOptionsInt("-viz_refine", 84a515125bSLeila Ghaffari "Regular refinement levels for visualization", 85a515125bSLeila Ghaffari NULL, app_ctx->viz_refine, &app_ctx->viz_refine, NULL); CHKERRQ(ierr); 86a515125bSLeila Ghaffari 87a515125bSLeila Ghaffari app_ctx->output_freq = 10; 88a515125bSLeila Ghaffari ierr = PetscOptionsInt("-output_freq", 89a515125bSLeila Ghaffari "Frequency of output, in number of steps", 90a515125bSLeila Ghaffari NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL); CHKERRQ(ierr); 91a515125bSLeila Ghaffari 92*91a36801SJames Wright PetscCall(PetscOptionsBool("-output_add_stepnum2bin", 93*91a36801SJames Wright "Add step number to the binary outputs", 94*91a36801SJames Wright NULL, app_ctx->add_stepnum2bin, &app_ctx->add_stepnum2bin, NULL)); 95*91a36801SJames Wright 96*91a36801SJames Wright PetscCall(PetscStrncpy(app_ctx->output_dir, ".", 2)); 97*91a36801SJames Wright PetscCall(PetscOptionsString("-output_dir", "Output directory", 98*91a36801SJames Wright NULL, app_ctx->output_dir, app_ctx->output_dir, 99*91a36801SJames Wright sizeof(app_ctx->output_dir), NULL)); 100*91a36801SJames Wright 101a515125bSLeila Ghaffari app_ctx->cont_steps = 0; 102a515125bSLeila Ghaffari ierr = PetscOptionsInt("-continue", "Continue from previous solution", 103a515125bSLeila Ghaffari NULL, app_ctx->cont_steps, &app_ctx->cont_steps, NULL); CHKERRQ(ierr); 104a515125bSLeila Ghaffari 105*91a36801SJames Wright PetscCall(PetscStrcpy(app_ctx->cont_file, "[output_dir]/ns-solution.bin")); 106*91a36801SJames Wright PetscCall(PetscOptionsString("-continue_filename", 107*91a36801SJames Wright "Filename to get initial condition from", 108*91a36801SJames Wright NULL, app_ctx->cont_file, app_ctx->cont_file, 109*91a36801SJames Wright sizeof(app_ctx->cont_file), &option_set)); 110*91a36801SJames Wright if(!option_set) PetscCall(PetscSNPrintf(app_ctx->cont_file, 111*91a36801SJames Wright sizeof app_ctx->cont_file, "%s/ns-solution.bin", 112*91a36801SJames Wright app_ctx->output_dir)); 113*91a36801SJames Wright 114*91a36801SJames Wright PetscCall(PetscStrcpy(app_ctx->cont_time_file, "[output_dir]/ns-time.bin")); 115*91a36801SJames Wright PetscCall(PetscOptionsString("-continue_time_filename", 116*91a36801SJames Wright "Filename to get initial condition time from", 117*91a36801SJames Wright NULL, app_ctx->cont_time_file, app_ctx->cont_time_file, 118*91a36801SJames Wright sizeof(app_ctx->cont_time_file), &option_set)); 119*91a36801SJames Wright if(!option_set) PetscCall(PetscSNPrintf(app_ctx->cont_time_file, 120*91a36801SJames Wright sizeof app_ctx->cont_time_file, "%s/ns-time.bin", 121*91a36801SJames Wright app_ctx->output_dir)); 122*91a36801SJames Wright 123a515125bSLeila Ghaffari app_ctx->degree = 1; 124a515125bSLeila Ghaffari ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements", 125a515125bSLeila Ghaffari NULL, app_ctx->degree, &app_ctx->degree, NULL); CHKERRQ(ierr); 126a515125bSLeila Ghaffari 127a515125bSLeila Ghaffari app_ctx->q_extra = 2; 128a515125bSLeila Ghaffari ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points", 129a515125bSLeila Ghaffari NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); CHKERRQ(ierr); 130a515125bSLeila Ghaffari 131b107fddaSJed Brown { 132b107fddaSJed Brown PetscBool option_set; 133b107fddaSJed Brown char amat_type[256] = ""; 134b107fddaSJed Brown PetscCall(PetscOptionsFList("-amat_type", 135b107fddaSJed Brown "Set the type of Amat distinct from Pmat (-dm_mat_type)", 136b107fddaSJed Brown NULL, MatList, amat_type, amat_type, sizeof(amat_type), &option_set)); 137b107fddaSJed Brown if (option_set) PetscCall(PetscStrallocpy(amat_type, 138b107fddaSJed Brown (char **)&app_ctx->amat_type)); 139b107fddaSJed Brown } 140b107fddaSJed Brown PetscCall(PetscOptionsBool("-pmat_pbdiagonal", 141b107fddaSJed Brown "Assemble only point-block diagonal for Pmat", NULL, app_ctx->pmat_pbdiagonal, 142b107fddaSJed Brown &app_ctx->pmat_pbdiagonal, NULL)); 143b107fddaSJed Brown 144a515125bSLeila Ghaffari // Provide default ceed resource if not specified 145a515125bSLeila Ghaffari if (!ceed_flag) { 146a515125bSLeila Ghaffari const char *ceed_resource = "/cpu/self"; 147a515125bSLeila Ghaffari strncpy(app_ctx->ceed_resource, ceed_resource, 10); 148a515125bSLeila Ghaffari } 149a515125bSLeila Ghaffari 150a515125bSLeila Ghaffari // Provide default problem if not specified 151a515125bSLeila Ghaffari if (!problem_flag) { 152a515125bSLeila Ghaffari const char *problem_name = "density_current"; 153a515125bSLeila Ghaffari strncpy(app_ctx->problem_name, problem_name, 16); 154a515125bSLeila Ghaffari } 155a515125bSLeila Ghaffari 156002797a3SLeila Ghaffari // Wall Boundary Conditions 157002797a3SLeila Ghaffari bc->num_wall = 16; 158002797a3SLeila Ghaffari PetscBool flg; 159002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_wall", 160002797a3SLeila Ghaffari "Face IDs to apply wall BC", 161002797a3SLeila Ghaffari NULL, bc->walls, &bc->num_wall, NULL); CHKERRQ(ierr); 162002797a3SLeila Ghaffari bc->num_comps = 5; 163002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-wall_comps", 164002797a3SLeila Ghaffari "An array of constrained component numbers", 165002797a3SLeila Ghaffari NULL, bc->wall_comps, &bc->num_comps, &flg); CHKERRQ(ierr); 166002797a3SLeila Ghaffari // Slip Boundary Conditions 167002797a3SLeila Ghaffari for (PetscInt j=0; j<3; j++) { 168002797a3SLeila Ghaffari bc->num_slip[j] = 16; 169002797a3SLeila Ghaffari PetscBool flg; 170002797a3SLeila Ghaffari const char *flags[3] = {"-bc_slip_x", "-bc_slip_y", "-bc_slip_z"}; 171002797a3SLeila Ghaffari ierr = PetscOptionsIntArray(flags[j], 172002797a3SLeila Ghaffari "Face IDs to apply slip BC", 173002797a3SLeila Ghaffari NULL, bc->slips[j], &bc->num_slip[j], &flg); CHKERRQ(ierr); 174002797a3SLeila Ghaffari if (flg) bc->user_bc = PETSC_TRUE; 175002797a3SLeila Ghaffari } 176002797a3SLeila Ghaffari 177002797a3SLeila Ghaffari // Error if wall and slip BCs are set on the same face 178002797a3SLeila Ghaffari if (bc->user_bc) 179002797a3SLeila Ghaffari for (PetscInt c = 0; c < 3; c++) 180002797a3SLeila Ghaffari for (PetscInt s = 0; s < bc->num_slip[c]; s++) 181002797a3SLeila Ghaffari for (PetscInt w = 0; w < bc->num_wall; w++) 182002797a3SLeila Ghaffari if (bc->slips[c][s] == bc->walls[w]) 183a75026deSJeremy L Thompson SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, 184d940ca4eSJed Brown "Boundary condition already set on face %" PetscInt_FMT "!\n", 185002797a3SLeila Ghaffari bc->walls[w]); 186002797a3SLeila Ghaffari 187002797a3SLeila Ghaffari // Inflow BCs 188002797a3SLeila Ghaffari bc->num_inflow = 16; 189002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_inflow", 190002797a3SLeila Ghaffari "Face IDs to apply inflow BC", 191002797a3SLeila Ghaffari NULL, bc->inflows, &bc->num_inflow, NULL); CHKERRQ(ierr); 192002797a3SLeila Ghaffari // Outflow BCs 193002797a3SLeila Ghaffari bc->num_outflow = 16; 194002797a3SLeila Ghaffari ierr = PetscOptionsIntArray("-bc_outflow", 195002797a3SLeila Ghaffari "Face IDs to apply outflow BC", 196002797a3SLeila Ghaffari NULL, bc->outflows, &bc->num_outflow, NULL); CHKERRQ(ierr); 197df55ba5fSJames Wright // Freestream BCs 198df55ba5fSJames Wright bc->num_freestream = 16; 199df55ba5fSJames Wright ierr = PetscOptionsIntArray("-bc_freestream", 200df55ba5fSJames Wright "Face IDs to apply freestream BC", 201df55ba5fSJames Wright NULL, bc->freestreams, &bc->num_freestream, NULL); CHKERRQ(ierr); 202002797a3SLeila Ghaffari 2031485969bSJeremy L Thompson PetscOptionsEnd(); 204a515125bSLeila Ghaffari 205a515125bSLeila Ghaffari PetscFunctionReturn(0); 206a515125bSLeila Ghaffari } 207