xref: /libCEED/examples/fluids/src/cloptions.c (revision fe39081bde35575d343c5f0379375a7ca839aa36)
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 
48   PetscBool ceed_flag = PETSC_FALSE;
49   PetscBool problem_flag = PETSC_FALSE;
50   PetscErrorCode ierr;
51   PetscFunctionBeginUser;
52 
53   ierr = PetscOptionsBegin(comm, NULL, "Navier-Stokes in PETSc with libCEED",
54                            NULL); CHKERRQ(ierr);
55 
56   ierr = PetscOptionsString("-ceed", "CEED resource specifier",
57                             NULL, app_ctx->ceed_resource, app_ctx->ceed_resource,
58                             sizeof(app_ctx->ceed_resource), &ceed_flag); CHKERRQ(ierr);
59 
60   app_ctx->test_mode = PETSC_FALSE;
61   ierr = PetscOptionsBool("-test", "Run in test mode",
62                           NULL, app_ctx->test_mode, &app_ctx->test_mode, NULL); CHKERRQ(ierr);
63 
64   app_ctx->test_tol = 1E-11;
65   ierr = PetscOptionsScalar("-compare_final_state_atol",
66                             "Test absolute tolerance",
67                             NULL, app_ctx->test_tol, &app_ctx->test_tol, NULL); CHKERRQ(ierr);
68 
69   ierr = PetscOptionsString("-compare_final_state_filename", "Test filename",
70                             NULL, app_ctx->file_path, app_ctx->file_path,
71                             sizeof(app_ctx->file_path), NULL); CHKERRQ(ierr);
72 
73   ierr = PetscOptionsFList("-problem", "Problem to solve", NULL,
74                            app_ctx->problems,
75                            app_ctx->problem_name, app_ctx->problem_name, sizeof(app_ctx->problem_name),
76                            &problem_flag); CHKERRQ(ierr);
77 
78   app_ctx->viz_refine = 0;
79   ierr = PetscOptionsInt("-viz_refine",
80                          "Regular refinement levels for visualization",
81                          NULL, app_ctx->viz_refine, &app_ctx->viz_refine, NULL); CHKERRQ(ierr);
82 
83   app_ctx->output_freq = 10;
84   ierr = PetscOptionsInt("-output_freq",
85                          "Frequency of output, in number of steps",
86                          NULL, app_ctx->output_freq, &app_ctx->output_freq, NULL); CHKERRQ(ierr);
87 
88   app_ctx->cont_steps = 0;
89   ierr = PetscOptionsInt("-continue", "Continue from previous solution",
90                          NULL, app_ctx->cont_steps, &app_ctx->cont_steps, NULL); CHKERRQ(ierr);
91 
92   app_ctx->degree = 1;
93   ierr = PetscOptionsInt("-degree", "Polynomial degree of finite elements",
94                          NULL, app_ctx->degree, &app_ctx->degree, NULL); CHKERRQ(ierr);
95 
96   app_ctx->q_extra = 2;
97   ierr = PetscOptionsInt("-q_extra", "Number of extra quadrature points",
98                          NULL, app_ctx->q_extra, &app_ctx->q_extra, NULL); CHKERRQ(ierr);
99 
100   ierr = PetscStrncpy(app_ctx->output_dir, ".", 2); CHKERRQ(ierr);
101   ierr = PetscOptionsString("-output_dir", "Output directory",
102                             NULL, app_ctx->output_dir, app_ctx->output_dir,
103                             sizeof(app_ctx->output_dir), NULL); CHKERRQ(ierr);
104 
105   // Provide default ceed resource if not specified
106   if (!ceed_flag) {
107     const char *ceed_resource = "/cpu/self";
108     strncpy(app_ctx->ceed_resource, ceed_resource, 10);
109   }
110 
111   // Provide default problem if not specified
112   if (!problem_flag) {
113     const char *problem_name = "density_current";
114     strncpy(app_ctx->problem_name, problem_name, 16);
115   }
116 
117   ierr = PetscOptionsEnd(); CHKERRQ(ierr);
118 
119   PetscFunctionReturn(0);
120 }
121