xref: /libCEED/examples/fluids/src/cloptions.c (revision 88b783a108a0e7f73f6a4b1c66ee7b6d1a268995)
1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3 // reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 /// @file
18 /// Command line option processing for Navier-Stokes example using PETSc
19 
20 #include "../navierstokes.h"
21 
22 // Register problems to be available on the command line
23 PetscErrorCode RegisterProblems_NS(AppCtx app_ctx) {
24 
25 
26   app_ctx->problems = NULL;
27   PetscErrorCode   ierr;
28   PetscFunctionBeginUser;
29 
30   ierr = PetscFunctionListAdd(&app_ctx->problems, "density_current",
31                               NS_DENSITY_CURRENT); CHKERRQ(ierr);
32 
33   ierr = PetscFunctionListAdd(&app_ctx->problems, "euler_vortex",
34                               NS_EULER_VORTEX); CHKERRQ(ierr);
35 
36   ierr = PetscFunctionListAdd(&app_ctx->problems, "advection",
37                               NS_ADVECTION); CHKERRQ(ierr);
38 
39   ierr = PetscFunctionListAdd(&app_ctx->problems, "advection2d",
40                               NS_ADVECTION2D); 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   ierr = PetscOptionsBegin(comm, NULL, "Navier-Stokes in PETSc with libCEED",
55                            NULL); CHKERRQ(ierr);
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   ierr = PetscStrncpy(app_ctx->output_dir, ".", 2); CHKERRQ(ierr);
102   ierr = PetscOptionsString("-output_dir", "Output directory",
103                             NULL, app_ctx->output_dir, app_ctx->output_dir,
104                             sizeof(app_ctx->output_dir), NULL); CHKERRQ(ierr);
105 
106   // Provide default ceed resource if not specified
107   if (!ceed_flag) {
108     const char *ceed_resource = "/cpu/self";
109     strncpy(app_ctx->ceed_resource, ceed_resource, 10);
110   }
111 
112   // Provide default problem if not specified
113   if (!problem_flag) {
114     const char *problem_name = "density_current";
115     strncpy(app_ctx->problem_name, problem_name, 16);
116   }
117 
118   // Wall Boundary Conditions
119   bc->num_wall = 16;
120   PetscBool flg;
121   ierr = PetscOptionsIntArray("-bc_wall",
122                               "Face IDs to apply wall BC",
123                               NULL, bc->walls, &bc->num_wall, NULL); CHKERRQ(ierr);
124   bc->num_comps = 5;
125   ierr = PetscOptionsIntArray("-wall_comps",
126                               "An array of constrained component numbers",
127                               NULL, bc->wall_comps, &bc->num_comps, &flg); CHKERRQ(ierr);
128   // Slip Boundary Conditions
129   for (PetscInt j=0; j<3; j++) {
130     bc->num_slip[j] = 16;
131     PetscBool flg;
132     const char *flags[3] = {"-bc_slip_x", "-bc_slip_y", "-bc_slip_z"};
133     ierr = PetscOptionsIntArray(flags[j],
134                                 "Face IDs to apply slip BC",
135                                 NULL, bc->slips[j], &bc->num_slip[j], &flg); CHKERRQ(ierr);
136     if (flg) bc->user_bc = PETSC_TRUE;
137   }
138 
139   // Error if wall and slip BCs are set on the same face
140   if (bc->user_bc)
141     for (PetscInt c = 0; c < 3; c++)
142       for (PetscInt s = 0; s < bc->num_slip[c]; s++)
143         for (PetscInt w = 0; w < bc->num_wall; w++)
144           if (bc->slips[c][s] == bc->walls[w])
145             SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
146                     "Boundary condition already set on face %D!\n",
147                     bc->walls[w]);
148 
149   // Inflow BCs
150   bc->num_inflow = 16;
151   ierr = PetscOptionsIntArray("-bc_inflow",
152                               "Face IDs to apply inflow BC",
153                               NULL, bc->inflows, &bc->num_inflow, NULL); CHKERRQ(ierr);
154   // Outflow BCs
155   bc->num_outflow = 16;
156   ierr = PetscOptionsIntArray("-bc_outflow",
157                               "Face IDs to apply outflow BC",
158                               NULL, bc->outflows, &bc->num_outflow, NULL); CHKERRQ(ierr);
159 
160   ierr = PetscOptionsEnd(); CHKERRQ(ierr);
161 
162   PetscFunctionReturn(0);
163 }
164