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 /// Utility functions for setting up SHOCKTUBE 19 20 #include "../qfunctions/shocktube.h" 21 22 #include "../navierstokes.h" 23 #include "../qfunctions/setupgeo.h" 24 25 PetscErrorCode NS_SHOCKTUBE(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { 26 SetupContextShock setup_context; 27 User user = *(User *)ctx; 28 MPI_Comm comm = PETSC_COMM_WORLD; 29 PetscBool implicit; 30 PetscBool yzb; 31 PetscInt stab; 32 PetscBool has_curr_time = PETSC_FALSE; 33 ShockTubeContext shocktube_ctx; 34 CeedQFunctionContext shocktube_context; 35 36 PetscFunctionBeginUser; 37 PetscCall(PetscCalloc1(1, &setup_context)); 38 PetscCall(PetscCalloc1(1, &shocktube_ctx)); 39 40 // ------------------------------------------------------ 41 // SET UP SHOCKTUBE 42 // ------------------------------------------------------ 43 problem->dim = 3; 44 problem->q_data_size_vol = 10; 45 problem->q_data_size_sur = 4; 46 problem->setup_vol.qfunction = Setup; 47 problem->setup_vol.qfunction_loc = Setup_loc; 48 problem->setup_sur.qfunction = SetupBoundary; 49 problem->setup_sur.qfunction_loc = SetupBoundary_loc; 50 problem->ics.qfunction = ICsShockTube; 51 problem->ics.qfunction_loc = ICsShockTube_loc; 52 problem->apply_vol_rhs.qfunction = EulerShockTube; 53 problem->apply_vol_rhs.qfunction_loc = EulerShockTube_loc; 54 problem->apply_vol_ifunction.qfunction = NULL; 55 problem->apply_vol_ifunction.qfunction_loc = NULL; 56 problem->bc = Exact_ShockTube; 57 problem->bc_ctx = setup_context; 58 problem->non_zero_time = PETSC_FALSE; 59 problem->print_info = PRINT_SHOCKTUBE; 60 61 // ------------------------------------------------------ 62 // Create the libCEED context 63 // ------------------------------------------------------ 64 // Driver section initial conditions 65 CeedScalar P_high = 1.0; // Pa 66 CeedScalar rho_high = 1.0; // kg/m^3 67 // Driven section initial conditions 68 CeedScalar P_low = 0.1; // Pa 69 CeedScalar rho_low = 0.125; // kg/m^3 70 // Stabilization parameter 71 CeedScalar c_tau = 0.5; // -, based on Hughes et al (2010) 72 // Tuning parameters for the YZB shock capturing 73 CeedScalar Cyzb = 0.1; // -, used in approximation of (Na),x 74 CeedScalar Byzb = 2.0; // -, 1 for smooth shocks 75 // 2 for sharp shocks 76 PetscReal domain_min[3], domain_max[3], domain_size[3]; 77 PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 78 for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 79 80 // ------------------------------------------------------ 81 // Create the PETSc context 82 // ------------------------------------------------------ 83 PetscScalar meter = 1e-2; // 1 meter in scaled length units 84 PetscScalar second = 1e-2; // 1 second in scaled time units 85 86 // ------------------------------------------------------ 87 // Command line Options 88 // ------------------------------------------------------ 89 PetscOptionsBegin(comm, NULL, "Options for SHOCKTUBE problem", NULL); 90 91 // -- Numerical formulation options 92 PetscCall(PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", NULL, implicit = PETSC_FALSE, &implicit, NULL)); 93 PetscCall(PetscOptionsEnum("-stab", "Stabilization method", NULL, StabilizationTypes, (PetscEnum)(stab = STAB_NONE), (PetscEnum *)&stab, NULL)); 94 PetscCall(PetscOptionsScalar("-c_tau", "Stabilization constant", NULL, c_tau, &c_tau, NULL)); 95 PetscCall(PetscOptionsBool("-yzb", "Use YZB discontinuity capturing", NULL, yzb = PETSC_FALSE, &yzb, NULL)); 96 97 // -- Units 98 PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, meter, &meter, NULL)); 99 meter = fabs(meter); 100 PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, second, &second, NULL)); 101 second = fabs(second); 102 103 // -- Warnings 104 if (stab == STAB_SUPG) { 105 PetscCall(PetscPrintf(comm, "Warning! -stab supg not implemented for the shocktube problem. \n")); 106 } 107 if (yzb && implicit) { 108 PetscCall(PetscPrintf(comm, "Warning! -yzb only implemented for explicit timestepping. \n")); 109 } 110 111 PetscOptionsEnd(); 112 113 // ------------------------------------------------------ 114 // Set up the PETSc context 115 // ------------------------------------------------------ 116 user->units->meter = meter; 117 user->units->second = second; 118 119 // ------------------------------------------------------ 120 // Set up the libCEED context 121 // ------------------------------------------------------ 122 // -- Scale variables to desired units 123 for (PetscInt i = 0; i < 3; i++) { 124 domain_size[i] *= meter; 125 domain_min[i] *= meter; 126 } 127 problem->dm_scale = meter; 128 CeedScalar mid_point = 0.5 * (domain_size[0] + domain_min[0]); 129 130 // -- Setup Context 131 setup_context->mid_point = mid_point; 132 setup_context->time = 0.0; 133 setup_context->P_high = P_high; 134 setup_context->rho_high = rho_high; 135 setup_context->P_low = P_low; 136 setup_context->rho_low = rho_low; 137 138 // -- QFunction Context 139 user->phys->implicit = implicit; 140 user->phys->has_curr_time = has_curr_time; 141 shocktube_ctx->implicit = implicit; 142 shocktube_ctx->stabilization = stab; 143 shocktube_ctx->yzb = yzb; 144 shocktube_ctx->Cyzb = Cyzb; 145 shocktube_ctx->Byzb = Byzb; 146 shocktube_ctx->c_tau = c_tau; 147 148 CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context); 149 CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context); 150 CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc); 151 152 CeedQFunctionContextCreate(user->ceed, &shocktube_context); 153 CeedQFunctionContextSetData(shocktube_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*shocktube_ctx), shocktube_ctx); 154 CeedQFunctionContextSetDataDestroy(shocktube_context, CEED_MEM_HOST, FreeContextPetsc); 155 problem->apply_vol_rhs.qfunction_context = shocktube_context; 156 PetscFunctionReturn(0); 157 } 158 159 PetscErrorCode PRINT_SHOCKTUBE(ProblemData *problem, AppCtx app_ctx) { 160 MPI_Comm comm = PETSC_COMM_WORLD; 161 PetscFunctionBeginUser; 162 163 PetscCall(PetscPrintf(comm, 164 " Problem:\n" 165 " Problem Name : %s\n", 166 app_ctx->problem_name)); 167 168 PetscFunctionReturn(0); 169 } 170