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