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 EULER_VORTEX 19 20 #include "../navierstokes.h" 21 #include "../qfunctions/setupgeo.h" 22 #include "../qfunctions/eulervortex.h" 23 24 PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, void *setup_ctx, 25 void *ctx) { 26 EulerTestType euler_test; 27 SetupContext setup_context = *(SetupContext *)setup_ctx; 28 User user = *(User *)ctx; 29 StabilizationType stab; 30 MPI_Comm comm = PETSC_COMM_WORLD; 31 PetscBool implicit; 32 PetscBool has_curr_time = PETSC_TRUE; 33 PetscBool has_neumann = PETSC_TRUE; 34 PetscInt ierr; 35 PetscFunctionBeginUser; 36 37 ierr = PetscCalloc1(1, &user->phys->euler_ctx); CHKERRQ(ierr); 38 39 // ------------------------------------------------------ 40 // SET UP DENSITY_CURRENT 41 // ------------------------------------------------------ 42 problem->dim = 3; 43 problem->q_data_size_vol = 10; 44 problem->q_data_size_sur = 4; 45 problem->setup_vol = Setup; 46 problem->setup_vol_loc = Setup_loc; 47 problem->setup_sur = SetupBoundary; 48 problem->setup_sur_loc = SetupBoundary_loc; 49 problem->ics = ICsEuler; 50 problem->ics_loc = ICsEuler_loc; 51 problem->apply_vol_rhs = Euler; 52 problem->apply_vol_rhs_loc = Euler_loc; 53 problem->apply_vol_ifunction = IFunction_Euler; 54 problem->apply_vol_ifunction_loc = IFunction_Euler_loc; 55 problem->apply_sur = Euler_Sur; 56 problem->apply_sur_loc = Euler_Sur_loc; 57 problem->bc = Exact_Euler; 58 problem->setup_ctx = SetupContext_EULER_VORTEX; 59 problem->bc_func = BC_EULER_VORTEX; 60 problem->non_zero_time = PETSC_TRUE; 61 problem->print_info = PRINT_EULER_VORTEX; 62 63 // ------------------------------------------------------ 64 // Create the libCEED context 65 // ------------------------------------------------------ 66 CeedScalar vortex_strength = 5.; // - 67 CeedScalar c_tau = 0.25; // - 68 // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010 69 PetscScalar lx = 1000.; // m 70 PetscScalar ly = 1000.; // m 71 PetscScalar lz = 1.; // m 72 PetscReal center[3], mean_velocity[3] = {1., 1., 0}; 73 74 // ------------------------------------------------------ 75 // Create the PETSc context 76 // ------------------------------------------------------ 77 PetscScalar meter = 1e-2; // 1 meter in scaled length units 78 PetscScalar second = 1e-2; // 1 second in scaled time units 79 80 // ------------------------------------------------------ 81 // Command line Options 82 // ------------------------------------------------------ 83 ierr = PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", 84 NULL); CHKERRQ(ierr); 85 // -- Physics 86 ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex", 87 NULL, vortex_strength, &vortex_strength, NULL); 88 CHKERRQ(ierr); 89 PetscInt n = problem->dim; 90 PetscBool user_velocity; 91 ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector", 92 NULL, mean_velocity, &n, &user_velocity); 93 CHKERRQ(ierr); 94 ierr = PetscOptionsScalar("-lx", "Length scale in x direction", 95 NULL, lx, &lx, NULL); CHKERRQ(ierr); 96 ierr = PetscOptionsScalar("-ly", "Length scale in y direction", 97 NULL, ly, &ly, NULL); CHKERRQ(ierr); 98 ierr = PetscOptionsScalar("-lz", "Length scale in z direction", 99 NULL, lz, &lz, NULL); CHKERRQ(ierr); 100 n = problem->dim; 101 center[0] = 0.5 * lx; 102 center[1] = 0.5 * ly; 103 center[2] = 0.5 * lz; 104 ierr = PetscOptionsRealArray("-center", "Location of vortex center", 105 NULL, center, &n, NULL); CHKERRQ(ierr); 106 ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", 107 NULL, implicit=PETSC_FALSE, &implicit, NULL); 108 CHKERRQ(ierr); 109 ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL, 110 EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX), 111 (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr); 112 ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL, 113 StabilizationTypes, (PetscEnum)(stab = STAB_NONE), 114 (PetscEnum *)&stab, NULL); CHKERRQ(ierr); 115 ierr = PetscOptionsScalar("-c_tau", "Stabilization constant", 116 NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr); 117 // -- Units 118 ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 119 NULL, meter, &meter, NULL); CHKERRQ(ierr); 120 meter = fabs(meter); 121 ierr = PetscOptionsScalar("-units_second","1 second in scaled time units", 122 NULL, second, &second, NULL); CHKERRQ(ierr); 123 second = fabs(second); 124 125 // -- Warnings 126 if (stab == STAB_SUPG && !implicit) { 127 ierr = PetscPrintf(comm, 128 "Warning! Use -stab supg only with -implicit\n"); 129 CHKERRQ(ierr); 130 } 131 if (user_velocity && (euler_test == EULER_TEST_1 132 || euler_test == EULER_TEST_3)) { 133 ierr = PetscPrintf(comm, 134 "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n"); 135 CHKERRQ(ierr); 136 } 137 138 ierr = PetscOptionsEnd(); CHKERRQ(ierr); 139 140 // ------------------------------------------------------ 141 // Set up the PETSc context 142 // ------------------------------------------------------ 143 user->units->meter = meter; 144 user->units->second = second; 145 146 // ------------------------------------------------------ 147 // Set up the libCEED context 148 // ------------------------------------------------------ 149 // -- Scale variables to desired units 150 lx = fabs(lx) * meter; 151 ly = fabs(ly) * meter; 152 lz = fabs(lz) * meter; 153 for (int i=0; i<3; i++) center[i] *= meter; 154 155 // -- Setup Context 156 setup_context->lx = lx; 157 setup_context->ly = ly; 158 setup_context->lz = lz; 159 setup_context->center[0] = center[0]; 160 setup_context->center[1] = center[1]; 161 setup_context->center[2] = center[2]; 162 setup_context->time = 0; 163 164 // -- QFunction Context 165 user->phys->stab = stab; 166 user->phys->euler_test = euler_test; 167 user->phys->implicit = implicit; 168 user->phys->has_curr_time = has_curr_time; 169 user->phys->has_neumann = has_neumann; 170 user->phys->euler_ctx->curr_time = 0.; 171 user->phys->euler_ctx->implicit = implicit; 172 user->phys->euler_ctx->euler_test = euler_test; 173 user->phys->euler_ctx->center[0] = center[0]; 174 user->phys->euler_ctx->center[1] = center[1]; 175 user->phys->euler_ctx->center[2] = center[2]; 176 user->phys->euler_ctx->vortex_strength = vortex_strength; 177 user->phys->euler_ctx->c_tau = c_tau; 178 user->phys->euler_ctx->mean_velocity[0] = mean_velocity[0]; 179 user->phys->euler_ctx->mean_velocity[1] = mean_velocity[1]; 180 user->phys->euler_ctx->mean_velocity[2] = mean_velocity[2]; 181 user->phys->euler_ctx->stabilization = stab; 182 183 PetscFunctionReturn(0); 184 } 185 186 PetscErrorCode SetupContext_EULER_VORTEX(Ceed ceed, CeedData ceed_data, 187 AppCtx app_ctx, SetupContext setup_ctx, Physics phys) { 188 PetscFunctionBeginUser; 189 190 CeedQFunctionContextCreate(ceed, &ceed_data->setup_context); 191 CeedQFunctionContextSetData(ceed_data->setup_context, CEED_MEM_HOST, 192 CEED_USE_POINTER, 193 sizeof(*setup_ctx), setup_ctx); 194 CeedQFunctionContextCreate(ceed, &ceed_data->euler_context); 195 CeedQFunctionContextSetData(ceed_data->euler_context, CEED_MEM_HOST, 196 CEED_USE_POINTER, 197 sizeof(*phys->euler_ctx), phys->euler_ctx); 198 if (ceed_data->qf_ics) 199 CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->euler_context); 200 if (ceed_data->qf_apply_sur) 201 CeedQFunctionSetContext(ceed_data->qf_apply_sur, ceed_data->euler_context); 202 if (ceed_data->qf_rhs_vol) 203 CeedQFunctionSetContext(ceed_data->qf_rhs_vol, ceed_data->euler_context); 204 if (ceed_data->qf_ifunction_vol) 205 CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, ceed_data->euler_context); 206 207 PetscFunctionReturn(0); 208 } 209 210 PetscErrorCode BC_EULER_VORTEX(DM dm, SimpleBC bc, Physics phys, 211 void *setup_ctx) { 212 PetscErrorCode ierr; 213 PetscFunctionBeginUser; 214 215 // Define boundary conditions 216 bc->num_slip[2] = 2; bc->slips[2][0] = 1; bc->slips[2][1] = 2; 217 218 // Set boundary conditions 219 DMLabel label; 220 ierr = DMGetLabel(dm, "Face Sets", &label); CHKERRQ(ierr); 221 PetscInt comps[1] = {3}; 222 ierr = DMAddBoundary(dm, DM_BC_ESSENTIAL, "slipz", label, "Face Sets", 223 bc->num_slip[2], bc->slips[2], 0, 1, comps, 224 (void(*)(void))NULL, NULL, setup_ctx, NULL); 225 CHKERRQ(ierr); 226 227 PetscFunctionReturn(0); 228 } 229 230 PetscErrorCode PRINT_EULER_VORTEX(Physics phys, SetupContext setup_ctx, 231 AppCtx app_ctx) { 232 MPI_Comm comm = PETSC_COMM_WORLD; 233 PetscErrorCode ierr; 234 PetscFunctionBeginUser; 235 236 ierr = PetscPrintf(comm, 237 " Problem:\n" 238 " Problem Name : %s\n" 239 " Test Case : %s\n" 240 " Background Velocity : %f,%f,%f\n" 241 " Stabilization : %s\n", 242 app_ctx->problem_name, EulerTestTypes[phys->euler_test], 243 phys->euler_ctx->mean_velocity[0], 244 phys->euler_ctx->mean_velocity[1], 245 phys->euler_ctx->mean_velocity[2], 246 StabilizationTypes[phys->stab]); CHKERRQ(ierr); 247 248 PetscFunctionReturn(0); 249 } 250