xref: /honee/src/cloptions.c (revision 335cfff331e29f59cd0bfaaf04552a80d603e0f0)
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 
20*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "density_current",
21*335cfff3SJames Wright                                  NS_DENSITY_CURRENT));
22a515125bSLeila Ghaffari 
23*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "euler_vortex",
24*335cfff3SJames Wright                                  NS_EULER_VORTEX));
25a515125bSLeila Ghaffari 
26*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "shocktube",
27*335cfff3SJames Wright                                  NS_SHOCKTUBE));
28af8870a9STimothy Aiken 
29*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "advection",
30*335cfff3SJames Wright                                  NS_ADVECTION));
31a515125bSLeila Ghaffari 
32*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "advection2d",
33*335cfff3SJames Wright                                  NS_ADVECTION2D));
34a515125bSLeila Ghaffari 
35*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "blasius",
36*335cfff3SJames Wright                                  NS_BLASIUS));
37bb8a0c61SJames Wright 
38*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "channel",
39*335cfff3SJames Wright                                  NS_CHANNEL));
40*335cfff3SJames Wright 
41*335cfff3SJames Wright   PetscCall(PetscFunctionListAdd(&app_ctx->problems, "newtonian_wave",
42*335cfff3SJames 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;
53a515125bSLeila Ghaffari   PetscErrorCode ierr;
54a515125bSLeila Ghaffari   PetscFunctionBeginUser;
55a515125bSLeila Ghaffari 
561485969bSJeremy L Thompson   PetscOptionsBegin(comm, NULL, "Navier-Stokes in PETSc with libCEED",
571485969bSJeremy L Thompson                     NULL);
58a515125bSLeila Ghaffari 
59a515125bSLeila Ghaffari   ierr = PetscOptionsString("-ceed", "CEED resource specifier",
60a515125bSLeila Ghaffari                             NULL, app_ctx->ceed_resource, app_ctx->ceed_resource,
61a515125bSLeila Ghaffari                             sizeof(app_ctx->ceed_resource), &ceed_flag); CHKERRQ(ierr);
62a515125bSLeila Ghaffari 
63a515125bSLeila Ghaffari   app_ctx->test_mode = PETSC_FALSE;
64a515125bSLeila Ghaffari   ierr = PetscOptionsBool("-test", "Run in test mode",
65a515125bSLeila Ghaffari                           NULL, app_ctx->test_mode, &app_ctx->test_mode, NULL); CHKERRQ(ierr);
66a515125bSLeila Ghaffari 
67a515125bSLeila Ghaffari   app_ctx->test_tol = 1E-11;
68a515125bSLeila Ghaffari   ierr = PetscOptionsScalar("-compare_final_state_atol",
69a515125bSLeila Ghaffari                             "Test absolute tolerance",
70a515125bSLeila Ghaffari                             NULL, app_ctx->test_tol, &app_ctx->test_tol, NULL); CHKERRQ(ierr);
71a515125bSLeila Ghaffari 
72a515125bSLeila Ghaffari   ierr = PetscOptionsString("-compare_final_state_filename", "Test filename",
73a515125bSLeila Ghaffari                             NULL, app_ctx->file_path, app_ctx->file_path,
74a515125bSLeila Ghaffari                             sizeof(app_ctx->file_path), NULL); CHKERRQ(ierr);
75a515125bSLeila Ghaffari 
76a515125bSLeila Ghaffari   ierr = PetscOptionsFList("-problem", "Problem to solve", NULL,
77a515125bSLeila Ghaffari                            app_ctx->problems,
78a515125bSLeila Ghaffari                            app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name),
79a515125bSLeila Ghaffari                            &problem_flag); CHKERRQ(ierr);
80a515125bSLeila Ghaffari 
81a515125bSLeila Ghaffari   app_ctx->viz_refine = 0;
82a515125bSLeila Ghaffari   ierr = PetscOptionsInt("-viz_refine",
83a515125bSLeila Ghaffari                          "Regular refinement levels for visualization",
84a515125bSLeila Ghaffari                          NULL, app_ctx->viz_refine, &app_ctx->viz_refine, NULL); CHKERRQ(ierr);
85a515125bSLeila Ghaffari 
86a515125bSLeila Ghaffari   app_ctx->output_freq = 10;
87a515125bSLeila Ghaffari   ierr = PetscOptionsInt("-output_freq",
88a515125bSLeila Ghaffari                          "Frequency of output, in number of steps",
89a515125bSLeila Ghaffari                          NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL); CHKERRQ(ierr);
90a515125bSLeila Ghaffari 
91a515125bSLeila Ghaffari   app_ctx->cont_steps = 0;
92a515125bSLeila Ghaffari   ierr = PetscOptionsInt("-continue", "Continue from previous solution",
93a515125bSLeila Ghaffari                          NULL, app_ctx->cont_steps, &app_ctx->cont_steps, NULL); CHKERRQ(ierr);
94a515125bSLeila Ghaffari 
95a515125bSLeila Ghaffari   app_ctx->degree = 1;
96a515125bSLeila Ghaffari   ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements",
97a515125bSLeila Ghaffari                          NULL, app_ctx->degree, &app_ctx->degree, NULL); CHKERRQ(ierr);
98a515125bSLeila Ghaffari 
99a515125bSLeila Ghaffari   app_ctx->q_extra = 2;
100a515125bSLeila Ghaffari   ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points",
101a515125bSLeila Ghaffari                          NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); CHKERRQ(ierr);
102a515125bSLeila Ghaffari 
103b107fddaSJed Brown   {
104b107fddaSJed Brown     PetscBool option_set;
105b107fddaSJed Brown     char amat_type[256] = "";
106b107fddaSJed Brown     PetscCall(PetscOptionsFList("-amat_type",
107b107fddaSJed Brown                                 "Set the type of Amat distinct from Pmat (-dm_mat_type)",
108b107fddaSJed Brown                                 NULL, MatList, amat_type, amat_type, sizeof(amat_type), &option_set));
109b107fddaSJed Brown     if (option_set) PetscCall(PetscStrallocpy(amat_type,
110b107fddaSJed Brown                                 (char **)&app_ctx->amat_type));
111b107fddaSJed Brown   }
112b107fddaSJed Brown   PetscCall(PetscOptionsBool("-pmat_pbdiagonal",
113b107fddaSJed Brown                              "Assemble only point-block diagonal for Pmat", NULL, app_ctx->pmat_pbdiagonal,
114b107fddaSJed Brown                              &app_ctx->pmat_pbdiagonal, NULL));
115b107fddaSJed Brown 
116a515125bSLeila Ghaffari   ierr = PetscStrncpy(app_ctx->output_dir, ".", 2); CHKERRQ(ierr);
117a515125bSLeila Ghaffari   ierr = PetscOptionsString("-output_dir", "Output directory",
118a515125bSLeila Ghaffari                             NULL, app_ctx->output_dir, app_ctx->output_dir,
119a515125bSLeila Ghaffari                             sizeof(app_ctx->output_dir), NULL); CHKERRQ(ierr);
120a515125bSLeila Ghaffari 
121a515125bSLeila Ghaffari   // Provide default ceed resource if not specified
122a515125bSLeila Ghaffari   if (!ceed_flag) {
123a515125bSLeila Ghaffari     const char *ceed_resource = "/cpu/self";
124a515125bSLeila Ghaffari     strncpy(app_ctx->ceed_resource, ceed_resource, 10);
125a515125bSLeila Ghaffari   }
126a515125bSLeila Ghaffari 
127a515125bSLeila Ghaffari   // Provide default problem if not specified
128a515125bSLeila Ghaffari   if (!problem_flag) {
129a515125bSLeila Ghaffari     const char *problem_name = "density_current";
130a515125bSLeila Ghaffari     strncpy(app_ctx->problem_name, problem_name, 16);
131a515125bSLeila Ghaffari   }
132a515125bSLeila Ghaffari 
133002797a3SLeila Ghaffari   // Wall Boundary Conditions
134002797a3SLeila Ghaffari   bc->num_wall = 16;
135002797a3SLeila Ghaffari   PetscBool flg;
136002797a3SLeila Ghaffari   ierr = PetscOptionsIntArray("-bc_wall",
137002797a3SLeila Ghaffari                               "Face IDs to apply wall BC",
138002797a3SLeila Ghaffari                               NULL, bc->walls, &bc->num_wall, NULL); CHKERRQ(ierr);
139002797a3SLeila Ghaffari   bc->num_comps = 5;
140002797a3SLeila Ghaffari   ierr = PetscOptionsIntArray("-wall_comps",
141002797a3SLeila Ghaffari                               "An array of constrained component numbers",
142002797a3SLeila Ghaffari                               NULL, bc->wall_comps, &bc->num_comps, &flg); CHKERRQ(ierr);
143002797a3SLeila Ghaffari   // Slip Boundary Conditions
144002797a3SLeila Ghaffari   for (PetscInt j=0; j<3; j++) {
145002797a3SLeila Ghaffari     bc->num_slip[j] = 16;
146002797a3SLeila Ghaffari     PetscBool flg;
147002797a3SLeila Ghaffari     const char *flags[3] = {"-bc_slip_x", "-bc_slip_y", "-bc_slip_z"};
148002797a3SLeila Ghaffari     ierr = PetscOptionsIntArray(flags[j],
149002797a3SLeila Ghaffari                                 "Face IDs to apply slip BC",
150002797a3SLeila Ghaffari                                 NULL, bc->slips[j], &bc->num_slip[j], &flg); CHKERRQ(ierr);
151002797a3SLeila Ghaffari     if (flg) bc->user_bc = PETSC_TRUE;
152002797a3SLeila Ghaffari   }
153002797a3SLeila Ghaffari 
154002797a3SLeila Ghaffari   // Error if wall and slip BCs are set on the same face
155002797a3SLeila Ghaffari   if (bc->user_bc)
156002797a3SLeila Ghaffari     for (PetscInt c = 0; c < 3; c++)
157002797a3SLeila Ghaffari       for (PetscInt s = 0; s < bc->num_slip[c]; s++)
158002797a3SLeila Ghaffari         for (PetscInt w = 0; w < bc->num_wall; w++)
159002797a3SLeila Ghaffari           if (bc->slips[c][s] == bc->walls[w])
160a75026deSJeremy L Thompson             SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
161d940ca4eSJed Brown                     "Boundary condition already set on face %" PetscInt_FMT "!\n",
162002797a3SLeila Ghaffari                     bc->walls[w]);
163002797a3SLeila Ghaffari 
164002797a3SLeila Ghaffari   // Inflow BCs
165002797a3SLeila Ghaffari   bc->num_inflow = 16;
166002797a3SLeila Ghaffari   ierr = PetscOptionsIntArray("-bc_inflow",
167002797a3SLeila Ghaffari                               "Face IDs to apply inflow BC",
168002797a3SLeila Ghaffari                               NULL, bc->inflows, &bc->num_inflow, NULL); CHKERRQ(ierr);
169002797a3SLeila Ghaffari   // Outflow BCs
170002797a3SLeila Ghaffari   bc->num_outflow = 16;
171002797a3SLeila Ghaffari   ierr = PetscOptionsIntArray("-bc_outflow",
172002797a3SLeila Ghaffari                               "Face IDs to apply outflow BC",
173002797a3SLeila Ghaffari                               NULL, bc->outflows, &bc->num_outflow, NULL); CHKERRQ(ierr);
174df55ba5fSJames Wright   // Freestream BCs
175df55ba5fSJames Wright   bc->num_freestream = 16;
176df55ba5fSJames Wright   ierr = PetscOptionsIntArray("-bc_freestream",
177df55ba5fSJames Wright                               "Face IDs to apply freestream BC",
178df55ba5fSJames Wright                               NULL, bc->freestreams, &bc->num_freestream, NULL); CHKERRQ(ierr);
179002797a3SLeila Ghaffari 
1801485969bSJeremy L Thompson   PetscOptionsEnd();
181a515125bSLeila Ghaffari 
182a515125bSLeila Ghaffari   PetscFunctionReturn(0);
183a515125bSLeila Ghaffari }
184