xref: /honee/problems/shocktube.c (revision 15a3537e9964f372164f639b6e497665c63d4d0c)
1af8870a9STimothy Aiken // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2af8870a9STimothy Aiken // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3af8870a9STimothy Aiken // reserved. See files LICENSE and NOTICE for details.
4af8870a9STimothy Aiken //
5af8870a9STimothy Aiken // This file is part of CEED, a collection of benchmarks, miniapps, software
6af8870a9STimothy Aiken // libraries and APIs for efficient high-order finite element and spectral
7af8870a9STimothy Aiken // element discretizations for exascale applications. For more information and
8af8870a9STimothy Aiken // source code availability see http://github.com/ceed.
9af8870a9STimothy Aiken //
10af8870a9STimothy Aiken // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11af8870a9STimothy Aiken // a collaborative effort of two U.S. Department of Energy organizations (Office
12af8870a9STimothy Aiken // of Science and the National Nuclear Security Administration) responsible for
13af8870a9STimothy Aiken // the planning and preparation of a capable exascale ecosystem, including
14af8870a9STimothy Aiken // software, applications, hardware, advanced system engineering and early
15af8870a9STimothy Aiken // testbed platforms, in support of the nation's exascale computing imperative.
16af8870a9STimothy Aiken 
17af8870a9STimothy Aiken /// @file
18af8870a9STimothy Aiken /// Utility functions for setting up SHOCKTUBE
19af8870a9STimothy Aiken 
20af8870a9STimothy Aiken #include "../navierstokes.h"
21af8870a9STimothy Aiken #include "../qfunctions/setupgeo.h"
22af8870a9STimothy Aiken #include "../qfunctions/shocktube.h"
23af8870a9STimothy Aiken 
24af8870a9STimothy Aiken PetscErrorCode NS_SHOCKTUBE(ProblemData *problem, DM dm, void *setup_ctx,
25af8870a9STimothy Aiken                             void *ctx) {
26af8870a9STimothy Aiken   SetupContext      setup_context = *(SetupContext *)setup_ctx;
27af8870a9STimothy Aiken   User              user = *(User *)ctx;
28af8870a9STimothy Aiken   MPI_Comm          comm = PETSC_COMM_WORLD;
29af8870a9STimothy Aiken   PetscBool         implicit;
30af8870a9STimothy Aiken   PetscBool         yzb;
31af8870a9STimothy Aiken   PetscInt          stab;
32af8870a9STimothy Aiken   PetscBool         has_curr_time = PETSC_FALSE;
33af8870a9STimothy Aiken   PetscInt          ierr;
34*15a3537eSJed Brown   ShockTubeContext  shocktube_ctx;
35*15a3537eSJed Brown   CeedQFunctionContext shocktube_context;
36af8870a9STimothy Aiken 
37*15a3537eSJed Brown 
38*15a3537eSJed Brown   PetscFunctionBeginUser;
39*15a3537eSJed Brown   ierr = PetscCalloc1(1, &shocktube_ctx); CHKERRQ(ierr);
40af8870a9STimothy Aiken 
41af8870a9STimothy Aiken   // ------------------------------------------------------
42af8870a9STimothy Aiken   //               SET UP SHOCKTUBE
43af8870a9STimothy Aiken   // ------------------------------------------------------
44af8870a9STimothy Aiken   problem->dim                               = 3;
45af8870a9STimothy Aiken   problem->q_data_size_vol                   = 10;
46af8870a9STimothy Aiken   problem->q_data_size_sur                   = 4;
479785fe93SJed Brown   problem->setup_vol.qfunction               = Setup;
489785fe93SJed Brown   problem->setup_vol.qfunction_loc           = Setup_loc;
499785fe93SJed Brown   problem->setup_sur.qfunction               = SetupBoundary;
509785fe93SJed Brown   problem->setup_sur.qfunction_loc           = SetupBoundary_loc;
519785fe93SJed Brown   problem->ics.qfunction                     = ICsShockTube;
529785fe93SJed Brown   problem->ics.qfunction_loc                 = ICsShockTube_loc;
539785fe93SJed Brown   problem->apply_vol_rhs.qfunction           = EulerShockTube;
549785fe93SJed Brown   problem->apply_vol_rhs.qfunction_loc       = EulerShockTube_loc;
559785fe93SJed Brown   problem->apply_vol_ifunction.qfunction     = NULL;
569785fe93SJed Brown   problem->apply_vol_ifunction.qfunction_loc = NULL;
57af8870a9STimothy Aiken   problem->bc                                = Exact_ShockTube;
58af8870a9STimothy Aiken   problem->non_zero_time                     = PETSC_FALSE;
59af8870a9STimothy Aiken   problem->print_info                        = PRINT_SHOCKTUBE;
60af8870a9STimothy Aiken 
61af8870a9STimothy Aiken   // ------------------------------------------------------
62af8870a9STimothy Aiken   //             Create the libCEED context
63af8870a9STimothy Aiken   // ------------------------------------------------------
64af8870a9STimothy Aiken   // Driver section initial conditions
65af8870a9STimothy Aiken   CeedScalar P_high          = 1.0;     // Pa
66af8870a9STimothy Aiken   CeedScalar rho_high        = 1.0;     // kg/m^3
67af8870a9STimothy Aiken   // Driven section initial conditions
68af8870a9STimothy Aiken   CeedScalar P_low           = 0.1;     // Pa
69af8870a9STimothy Aiken   CeedScalar rho_low         = 0.125;   // kg/m^3
70af8870a9STimothy Aiken   // Stabilization parameter
71af8870a9STimothy Aiken   CeedScalar c_tau           = 0.5;     // -, based on Hughes et al (2010)
72af8870a9STimothy Aiken   // Tuning parameters for the YZB shock capturing
73af8870a9STimothy Aiken   CeedScalar Cyzb            = 0.1;     // -, used in approximation of (Na),x
74af8870a9STimothy Aiken   CeedScalar Byzb            = 2.0;     // -, 1 for smooth shocks
75af8870a9STimothy Aiken   //                                          2 for sharp shocks
76af8870a9STimothy Aiken   PetscReal domain_min[3], domain_max[3], domain_size[3];
77af8870a9STimothy Aiken   ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr);
78af8870a9STimothy Aiken   for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i];
79af8870a9STimothy Aiken 
80af8870a9STimothy Aiken   // ------------------------------------------------------
81af8870a9STimothy Aiken   //             Create the PETSc context
82af8870a9STimothy Aiken   // ------------------------------------------------------
83af8870a9STimothy Aiken   PetscScalar meter    = 1e-2; // 1 meter in scaled length units
84af8870a9STimothy Aiken   PetscScalar second   = 1e-2; // 1 second in scaled time units
85af8870a9STimothy Aiken 
86af8870a9STimothy Aiken   // ------------------------------------------------------
87af8870a9STimothy Aiken   //              Command line Options
88af8870a9STimothy Aiken   // ------------------------------------------------------
89af8870a9STimothy Aiken   PetscOptionsBegin(comm, NULL, "Options for SHOCKTUBE problem", NULL);
90af8870a9STimothy Aiken 
91af8870a9STimothy Aiken   // -- Numerical formulation options
92af8870a9STimothy Aiken   ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation",
93af8870a9STimothy Aiken                           NULL, implicit=PETSC_FALSE, &implicit, NULL); CHKERRQ(ierr);
94af8870a9STimothy Aiken   ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL,
95af8870a9STimothy Aiken                           StabilizationTypes, (PetscEnum)(stab = STAB_NONE),
96af8870a9STimothy Aiken                           (PetscEnum *)&stab, NULL); CHKERRQ(ierr);
97af8870a9STimothy Aiken   ierr = PetscOptionsScalar("-c_tau", "Stabilization constant",
98af8870a9STimothy Aiken                             NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr);
99af8870a9STimothy Aiken   ierr = PetscOptionsBool("-yzb", "Use YZB discontinuity capturing",
100af8870a9STimothy Aiken                           NULL, yzb=PETSC_FALSE, &yzb, NULL); CHKERRQ(ierr);
101af8870a9STimothy Aiken 
102af8870a9STimothy Aiken   // -- Units
103af8870a9STimothy Aiken   ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units",
104af8870a9STimothy Aiken                             NULL, meter, &meter, NULL); CHKERRQ(ierr);
105af8870a9STimothy Aiken   meter = fabs(meter);
106af8870a9STimothy Aiken   ierr = PetscOptionsScalar("-units_second","1 second in scaled time units",
107af8870a9STimothy Aiken                             NULL, second, &second, NULL); CHKERRQ(ierr);
108af8870a9STimothy Aiken   second = fabs(second);
109af8870a9STimothy Aiken 
110af8870a9STimothy Aiken   // -- Warnings
111af8870a9STimothy Aiken   if (stab == STAB_SUPG) {
112af8870a9STimothy Aiken     ierr = PetscPrintf(comm,
113af8870a9STimothy Aiken                        "Warning! -stab supg not implemented for the shocktube problem. \n");
114af8870a9STimothy Aiken     CHKERRQ(ierr);
115af8870a9STimothy Aiken   }
116af8870a9STimothy Aiken   if (yzb && implicit) {
117af8870a9STimothy Aiken     ierr = PetscPrintf(comm,
118af8870a9STimothy Aiken                        "Warning! -yzb only implemented for explicit timestepping. \n");
119af8870a9STimothy Aiken     CHKERRQ(ierr);
120af8870a9STimothy Aiken   }
121af8870a9STimothy Aiken 
122af8870a9STimothy Aiken 
123af8870a9STimothy Aiken   PetscOptionsEnd();
124af8870a9STimothy Aiken 
125af8870a9STimothy Aiken   // ------------------------------------------------------
126af8870a9STimothy Aiken   //           Set up the PETSc context
127af8870a9STimothy Aiken   // ------------------------------------------------------
128af8870a9STimothy Aiken   user->units->meter  = meter;
129af8870a9STimothy Aiken   user->units->second = second;
130af8870a9STimothy Aiken 
131af8870a9STimothy Aiken   // ------------------------------------------------------
132af8870a9STimothy Aiken   //           Set up the libCEED context
133af8870a9STimothy Aiken   // ------------------------------------------------------
134af8870a9STimothy Aiken   // -- Scale variables to desired units
135af8870a9STimothy Aiken   for (int i=0; i<3; i++) {
136af8870a9STimothy Aiken     domain_size[i] *= meter;
137af8870a9STimothy Aiken     domain_min[i] *= meter;
138af8870a9STimothy Aiken   }
139af8870a9STimothy Aiken   problem->dm_scale = meter;
140af8870a9STimothy Aiken   CeedScalar mid_point = 0.5*(domain_size[0]+domain_min[0]);
141af8870a9STimothy Aiken 
142af8870a9STimothy Aiken   // -- Setup Context
143af8870a9STimothy Aiken   setup_context->lx        = domain_size[0];
144af8870a9STimothy Aiken   setup_context->ly        = domain_size[1];
145af8870a9STimothy Aiken   setup_context->lz        = domain_size[2];
146af8870a9STimothy Aiken   setup_context->mid_point = mid_point;
147af8870a9STimothy Aiken   setup_context->time      = 0.0;
148af8870a9STimothy Aiken   setup_context->P_high    = P_high;
149af8870a9STimothy Aiken   setup_context->rho_high  = rho_high;
150af8870a9STimothy Aiken   setup_context->P_low     = P_low;
151af8870a9STimothy Aiken   setup_context->rho_low   = rho_low;
152af8870a9STimothy Aiken 
153af8870a9STimothy Aiken   // -- QFunction Context
154af8870a9STimothy Aiken   user->phys->implicit                      = implicit;
155af8870a9STimothy Aiken   user->phys->has_curr_time                 = has_curr_time;
156*15a3537eSJed Brown   shocktube_ctx->implicit       = implicit;
157*15a3537eSJed Brown   shocktube_ctx->stabilization  = stab;
158*15a3537eSJed Brown   shocktube_ctx->yzb            = yzb;
159*15a3537eSJed Brown   shocktube_ctx->Cyzb           = Cyzb;
160*15a3537eSJed Brown   shocktube_ctx->Byzb           = Byzb;
161*15a3537eSJed Brown   shocktube_ctx->c_tau          = c_tau;
162af8870a9STimothy Aiken 
163*15a3537eSJed Brown   CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context);
164*15a3537eSJed Brown   CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST,
165*15a3537eSJed Brown                               CEED_USE_POINTER, sizeof(*setup_context), setup_context);
166af8870a9STimothy Aiken 
167*15a3537eSJed Brown   CeedQFunctionContextCreate(user->ceed, &shocktube_context);
168*15a3537eSJed Brown   CeedQFunctionContextSetData(shocktube_context, CEED_MEM_HOST,
169af8870a9STimothy Aiken                               CEED_USE_POINTER,
170*15a3537eSJed Brown                               sizeof(*shocktube_ctx), shocktube_ctx);
171*15a3537eSJed Brown   CeedQFunctionContextSetDataDestroy(shocktube_context, CEED_MEM_HOST,
172*15a3537eSJed Brown                                      FreeContextPetsc);
173*15a3537eSJed Brown   problem->apply_vol_rhs.qfunction_context = shocktube_context;
174af8870a9STimothy Aiken   PetscFunctionReturn(0);
175af8870a9STimothy Aiken }
176af8870a9STimothy Aiken 
177*15a3537eSJed Brown PetscErrorCode PRINT_SHOCKTUBE(ProblemData *problem, SetupContext setup_ctx,
178af8870a9STimothy Aiken                                AppCtx app_ctx) {
179af8870a9STimothy Aiken   MPI_Comm       comm = PETSC_COMM_WORLD;
180af8870a9STimothy Aiken   PetscErrorCode ierr;
181af8870a9STimothy Aiken   PetscFunctionBeginUser;
182af8870a9STimothy Aiken 
183af8870a9STimothy Aiken   ierr = PetscPrintf(comm,
184af8870a9STimothy Aiken                      "  Problem:\n"
185af8870a9STimothy Aiken                      "    Problem Name                       : %s\n",
186af8870a9STimothy Aiken                      app_ctx->problem_name); CHKERRQ(ierr);
187af8870a9STimothy Aiken 
188af8870a9STimothy Aiken   PetscFunctionReturn(0);
189af8870a9STimothy Aiken }
190