1ea61e9acSJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2ea61e9acSJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3019b7682STimothy Aiken // 4ea61e9acSJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5019b7682STimothy Aiken // 6ea61e9acSJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7019b7682STimothy Aiken 8019b7682STimothy Aiken /// @file 9019b7682STimothy Aiken /// Utility functions for setting up SHOCKTUBE 10019b7682STimothy Aiken 11019b7682STimothy Aiken #include "../qfunctions/shocktube.h" 12019b7682STimothy Aiken 1349aac155SJeremy L Thompson #include <ceed.h> 1449aac155SJeremy L Thompson #include <petscdm.h> 1549aac155SJeremy L Thompson 162b730f8bSJeremy L Thompson #include "../navierstokes.h" 172b730f8bSJeremy L Thompson #include "../qfunctions/setupgeo.h" 186ef2784eSLeila Ghaffari 1946de7363SJames Wright PetscErrorCode NS_SHOCKTUBE(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { 2097baf651SJames Wright SetupContextShock setup_context; 21019b7682STimothy Aiken User user = *(User *)ctx; 22*a424bcd0SJames Wright MPI_Comm comm = user->comm; 23*a424bcd0SJames Wright Ceed ceed = user->ceed; 24019b7682STimothy Aiken PetscBool implicit; 25019b7682STimothy Aiken PetscBool yzb; 26019b7682STimothy Aiken PetscInt stab; 27019b7682STimothy Aiken PetscBool has_curr_time = PETSC_FALSE; 28841e4c73SJed Brown ShockTubeContext shocktube_ctx; 29841e4c73SJed Brown CeedQFunctionContext shocktube_context; 30019b7682STimothy Aiken 31841e4c73SJed Brown PetscFunctionBeginUser; 322b730f8bSJeremy L Thompson PetscCall(PetscCalloc1(1, &setup_context)); 332b730f8bSJeremy L Thompson PetscCall(PetscCalloc1(1, &shocktube_ctx)); 34019b7682STimothy Aiken 35019b7682STimothy Aiken // ------------------------------------------------------ 36019b7682STimothy Aiken // SET UP SHOCKTUBE 37019b7682STimothy Aiken // ------------------------------------------------------ 38019b7682STimothy Aiken problem->dim = 3; 39019b7682STimothy Aiken problem->q_data_size_vol = 10; 40019b7682STimothy Aiken problem->q_data_size_sur = 4; 4191e5af17SJed Brown problem->setup_vol.qfunction = Setup; 4291e5af17SJed Brown problem->setup_vol.qfunction_loc = Setup_loc; 4391e5af17SJed Brown problem->setup_sur.qfunction = SetupBoundary; 4491e5af17SJed Brown problem->setup_sur.qfunction_loc = SetupBoundary_loc; 4591e5af17SJed Brown problem->ics.qfunction = ICsShockTube; 4691e5af17SJed Brown problem->ics.qfunction_loc = ICsShockTube_loc; 4791e5af17SJed Brown problem->apply_vol_rhs.qfunction = EulerShockTube; 4891e5af17SJed Brown problem->apply_vol_rhs.qfunction_loc = EulerShockTube_loc; 4991e5af17SJed Brown problem->apply_vol_ifunction.qfunction = NULL; 5091e5af17SJed Brown problem->apply_vol_ifunction.qfunction_loc = NULL; 51019b7682STimothy Aiken problem->non_zero_time = PETSC_FALSE; 52019b7682STimothy Aiken problem->print_info = PRINT_SHOCKTUBE; 53019b7682STimothy Aiken 54019b7682STimothy Aiken // ------------------------------------------------------ 55019b7682STimothy Aiken // Create the libCEED context 56019b7682STimothy Aiken // ------------------------------------------------------ 57019b7682STimothy Aiken // Driver section initial conditions 58019b7682STimothy Aiken CeedScalar P_high = 1.0; // Pa 59019b7682STimothy Aiken CeedScalar rho_high = 1.0; // kg/m^3 60019b7682STimothy Aiken // Driven section initial conditions 61019b7682STimothy Aiken CeedScalar P_low = 0.1; // Pa 62019b7682STimothy Aiken CeedScalar rho_low = 0.125; // kg/m^3 63019b7682STimothy Aiken // Stabilization parameter 64019b7682STimothy Aiken CeedScalar c_tau = 0.5; // -, based on Hughes et al (2010) 65019b7682STimothy Aiken // Tuning parameters for the YZB shock capturing 66019b7682STimothy Aiken CeedScalar Cyzb = 0.1; // -, used in approximation of (Na),x 67019b7682STimothy Aiken CeedScalar Byzb = 2.0; // -, 1 for smooth shocks 68019b7682STimothy Aiken // 2 for sharp shocks 69019b7682STimothy Aiken PetscReal domain_min[3], domain_max[3], domain_size[3]; 702b730f8bSJeremy L Thompson PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 71ba6664aeSJames Wright for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 72019b7682STimothy Aiken 73019b7682STimothy Aiken // ------------------------------------------------------ 74019b7682STimothy Aiken // Create the PETSc context 75019b7682STimothy Aiken // ------------------------------------------------------ 76019b7682STimothy Aiken PetscScalar meter = 1e-2; // 1 meter in scaled length units 77019b7682STimothy Aiken PetscScalar second = 1e-2; // 1 second in scaled time units 78019b7682STimothy Aiken 79019b7682STimothy Aiken // ------------------------------------------------------ 80019b7682STimothy Aiken // Command line Options 81019b7682STimothy Aiken // ------------------------------------------------------ 82019b7682STimothy Aiken PetscOptionsBegin(comm, NULL, "Options for SHOCKTUBE problem", NULL); 83019b7682STimothy Aiken 84019b7682STimothy Aiken // -- Numerical formulation options 852b730f8bSJeremy L Thompson PetscCall(PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", NULL, implicit = PETSC_FALSE, &implicit, NULL)); 862b730f8bSJeremy L Thompson PetscCall(PetscOptionsEnum("-stab", "Stabilization method", NULL, StabilizationTypes, (PetscEnum)(stab = STAB_NONE), (PetscEnum *)&stab, NULL)); 872b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-c_tau", "Stabilization constant", NULL, c_tau, &c_tau, NULL)); 882b730f8bSJeremy L Thompson PetscCall(PetscOptionsBool("-yzb", "Use YZB discontinuity capturing", NULL, yzb = PETSC_FALSE, &yzb, NULL)); 89019b7682STimothy Aiken 90019b7682STimothy Aiken // -- Units 912b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, meter, &meter, NULL)); 92019b7682STimothy Aiken meter = fabs(meter); 932b730f8bSJeremy L Thompson PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, second, &second, NULL)); 94019b7682STimothy Aiken second = fabs(second); 95019b7682STimothy Aiken 96019b7682STimothy Aiken // -- Warnings 97019b7682STimothy Aiken if (stab == STAB_SUPG) { 982b730f8bSJeremy L Thompson PetscCall(PetscPrintf(comm, "Warning! -stab supg not implemented for the shocktube problem. \n")); 99019b7682STimothy Aiken } 100019b7682STimothy Aiken if (yzb && implicit) { 1012b730f8bSJeremy L Thompson PetscCall(PetscPrintf(comm, "Warning! -yzb only implemented for explicit timestepping. \n")); 102019b7682STimothy Aiken } 103019b7682STimothy Aiken 104019b7682STimothy Aiken PetscOptionsEnd(); 105019b7682STimothy Aiken 106019b7682STimothy Aiken // ------------------------------------------------------ 107019b7682STimothy Aiken // Set up the PETSc context 108019b7682STimothy Aiken // ------------------------------------------------------ 109019b7682STimothy Aiken user->units->meter = meter; 110019b7682STimothy Aiken user->units->second = second; 111019b7682STimothy Aiken 112019b7682STimothy Aiken // ------------------------------------------------------ 113019b7682STimothy Aiken // Set up the libCEED context 114019b7682STimothy Aiken // ------------------------------------------------------ 115019b7682STimothy Aiken // -- Scale variables to desired units 116ba6664aeSJames Wright for (PetscInt i = 0; i < 3; i++) { 117019b7682STimothy Aiken domain_size[i] *= meter; 118019b7682STimothy Aiken domain_min[i] *= meter; 119019b7682STimothy Aiken } 120019b7682STimothy Aiken problem->dm_scale = meter; 121019b7682STimothy Aiken CeedScalar mid_point = 0.5 * (domain_size[0] + domain_min[0]); 122019b7682STimothy Aiken 123019b7682STimothy Aiken // -- Setup Context 124019b7682STimothy Aiken setup_context->mid_point = mid_point; 125019b7682STimothy Aiken setup_context->time = 0.0; 126019b7682STimothy Aiken setup_context->P_high = P_high; 127019b7682STimothy Aiken setup_context->rho_high = rho_high; 128019b7682STimothy Aiken setup_context->P_low = P_low; 129019b7682STimothy Aiken setup_context->rho_low = rho_low; 130019b7682STimothy Aiken 131019b7682STimothy Aiken // -- QFunction Context 132019b7682STimothy Aiken user->phys->implicit = implicit; 133019b7682STimothy Aiken user->phys->has_curr_time = has_curr_time; 134841e4c73SJed Brown shocktube_ctx->implicit = implicit; 135841e4c73SJed Brown shocktube_ctx->stabilization = stab; 136841e4c73SJed Brown shocktube_ctx->yzb = yzb; 137841e4c73SJed Brown shocktube_ctx->Cyzb = Cyzb; 138841e4c73SJed Brown shocktube_ctx->Byzb = Byzb; 139841e4c73SJed Brown shocktube_ctx->c_tau = c_tau; 140019b7682STimothy Aiken 141*a424bcd0SJames Wright PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context)); 142*a424bcd0SJames Wright PetscCallCeed(ceed, 143*a424bcd0SJames Wright CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context)); 144*a424bcd0SJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc)); 145019b7682STimothy Aiken 146*a424bcd0SJames Wright PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &shocktube_context)); 147*a424bcd0SJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetData(shocktube_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*shocktube_ctx), shocktube_ctx)); 148*a424bcd0SJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(shocktube_context, CEED_MEM_HOST, FreeContextPetsc)); 149841e4c73SJed Brown problem->apply_vol_rhs.qfunction_context = shocktube_context; 150ee4ca9cbSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 151019b7682STimothy Aiken } 152019b7682STimothy Aiken 153367c849eSJames Wright PetscErrorCode PRINT_SHOCKTUBE(User user, ProblemData *problem, AppCtx app_ctx) { 154367c849eSJames Wright MPI_Comm comm = user->comm; 155019b7682STimothy Aiken PetscFunctionBeginUser; 156019b7682STimothy Aiken 1572b730f8bSJeremy L Thompson PetscCall(PetscPrintf(comm, 158019b7682STimothy Aiken " Problem:\n" 159019b7682STimothy Aiken " Problem Name : %s\n", 1602b730f8bSJeremy L Thompson app_ctx->problem_name)); 161019b7682STimothy Aiken 162ee4ca9cbSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 163019b7682STimothy Aiken } 164