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, DM dm, 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_inflow = TravelingVortex_Inflow; 56 problem->apply_inflow_loc = TravelingVortex_Inflow_loc; 57 problem->apply_outflow = Euler_Outflow; 58 problem->apply_outflow_loc = Euler_Outflow_loc; 59 problem->bc = Exact_Euler; 60 problem->setup_ctx = SetupContext_EULER_VORTEX; 61 problem->non_zero_time = PETSC_TRUE; 62 problem->print_info = PRINT_EULER_VORTEX; 63 64 // ------------------------------------------------------ 65 // Create the libCEED context 66 // ------------------------------------------------------ 67 CeedScalar vortex_strength = 5.; // - 68 CeedScalar c_tau = 0.5; // - 69 // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010 70 PetscReal center[3], // m 71 mean_velocity[3] = {1., 1., 0}; // m/s 72 PetscReal domain_min[3], domain_max[3], domain_size[3]; 73 ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr); 74 for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 75 76 // ------------------------------------------------------ 77 // Create the PETSc context 78 // ------------------------------------------------------ 79 PetscScalar meter = 1e-2; // 1 meter in scaled length units 80 PetscScalar second = 1e-2; // 1 second in scaled time units 81 82 // ------------------------------------------------------ 83 // Command line Options 84 // ------------------------------------------------------ 85 ierr = PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", 86 NULL); CHKERRQ(ierr); 87 // -- Physics 88 ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex", 89 NULL, vortex_strength, &vortex_strength, NULL); 90 CHKERRQ(ierr); 91 PetscInt n = problem->dim; 92 PetscBool user_velocity; 93 ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector", 94 NULL, mean_velocity, &n, &user_velocity); 95 CHKERRQ(ierr); 96 for (int i=0; i<3; i++) center[i] = .5*domain_size[i]; 97 n = problem->dim; 98 ierr = PetscOptionsRealArray("-center", "Location of vortex center", 99 NULL, center, &n, NULL); CHKERRQ(ierr); 100 ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", 101 NULL, implicit=PETSC_FALSE, &implicit, NULL); 102 CHKERRQ(ierr); 103 ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL, 104 EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX), 105 (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr); 106 ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL, 107 StabilizationTypes, (PetscEnum)(stab = STAB_NONE), 108 (PetscEnum *)&stab, NULL); CHKERRQ(ierr); 109 ierr = PetscOptionsScalar("-c_tau", "Stabilization constant", 110 NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr); 111 // -- Units 112 ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 113 NULL, meter, &meter, NULL); CHKERRQ(ierr); 114 meter = fabs(meter); 115 ierr = PetscOptionsScalar("-units_second","1 second in scaled time units", 116 NULL, second, &second, NULL); CHKERRQ(ierr); 117 second = fabs(second); 118 119 // -- Warnings 120 if (stab == STAB_SUPG && !implicit) { 121 ierr = PetscPrintf(comm, 122 "Warning! Use -stab supg only with -implicit\n"); 123 CHKERRQ(ierr); 124 } 125 if (user_velocity && (euler_test == EULER_TEST_1 126 || euler_test == EULER_TEST_3)) { 127 ierr = PetscPrintf(comm, 128 "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n"); 129 CHKERRQ(ierr); 130 } 131 132 ierr = PetscOptionsEnd(); CHKERRQ(ierr); 133 134 // ------------------------------------------------------ 135 // Set up the PETSc context 136 // ------------------------------------------------------ 137 user->units->meter = meter; 138 user->units->second = second; 139 140 // ------------------------------------------------------ 141 // Set up the libCEED context 142 // ------------------------------------------------------ 143 // -- Scale variables to desired units 144 for (int i=0; i<3; i++) { 145 center[i] *= meter; 146 domain_size[i] *= meter; 147 mean_velocity[i] *= (meter/second); 148 } 149 problem->dm_scale = meter; 150 151 // -- Setup Context 152 setup_context->lx = domain_size[0]; 153 setup_context->ly = domain_size[1]; 154 setup_context->lz = domain_size[2]; 155 setup_context->center[0] = center[0]; 156 setup_context->center[1] = center[1]; 157 setup_context->center[2] = center[2]; 158 setup_context->time = 0; 159 160 // -- QFunction Context 161 user->phys->stab = stab; 162 user->phys->euler_test = euler_test; 163 user->phys->implicit = implicit; 164 user->phys->has_curr_time = has_curr_time; 165 user->phys->has_neumann = has_neumann; 166 user->phys->euler_ctx->curr_time = 0.; 167 user->phys->euler_ctx->implicit = implicit; 168 user->phys->euler_ctx->euler_test = euler_test; 169 user->phys->euler_ctx->center[0] = center[0]; 170 user->phys->euler_ctx->center[1] = center[1]; 171 user->phys->euler_ctx->center[2] = center[2]; 172 user->phys->euler_ctx->vortex_strength = vortex_strength; 173 user->phys->euler_ctx->c_tau = c_tau; 174 user->phys->euler_ctx->mean_velocity[0] = mean_velocity[0]; 175 user->phys->euler_ctx->mean_velocity[1] = mean_velocity[1]; 176 user->phys->euler_ctx->mean_velocity[2] = mean_velocity[2]; 177 user->phys->euler_ctx->stabilization = stab; 178 179 PetscFunctionReturn(0); 180 } 181 182 PetscErrorCode SetupContext_EULER_VORTEX(Ceed ceed, CeedData ceed_data, 183 AppCtx app_ctx, SetupContext setup_ctx, Physics phys) { 184 PetscFunctionBeginUser; 185 CeedQFunctionContextCreate(ceed, &ceed_data->setup_context); 186 CeedQFunctionContextSetData(ceed_data->setup_context, CEED_MEM_HOST, 187 CEED_USE_POINTER, 188 sizeof(*setup_ctx), setup_ctx); 189 CeedQFunctionContextCreate(ceed, &ceed_data->euler_context); 190 CeedQFunctionContextSetData(ceed_data->euler_context, CEED_MEM_HOST, 191 CEED_USE_POINTER, 192 sizeof(*phys->euler_ctx), phys->euler_ctx); 193 if (ceed_data->qf_ics) 194 CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->euler_context); 195 if (ceed_data->qf_rhs_vol) 196 CeedQFunctionSetContext(ceed_data->qf_rhs_vol, ceed_data->euler_context); 197 if (ceed_data->qf_ifunction_vol) 198 CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, ceed_data->euler_context); 199 if (ceed_data->qf_apply_inflow) 200 CeedQFunctionSetContext(ceed_data->qf_apply_inflow, ceed_data->euler_context); 201 if (ceed_data->qf_apply_outflow) 202 CeedQFunctionSetContext(ceed_data->qf_apply_outflow, ceed_data->euler_context); 203 PetscFunctionReturn(0); 204 } 205 206 PetscErrorCode PRINT_EULER_VORTEX(Physics phys, SetupContext setup_ctx, 207 AppCtx app_ctx) { 208 MPI_Comm comm = PETSC_COMM_WORLD; 209 PetscErrorCode ierr; 210 PetscFunctionBeginUser; 211 212 ierr = PetscPrintf(comm, 213 " Problem:\n" 214 " Problem Name : %s\n" 215 " Test Case : %s\n" 216 " Background Velocity : %f,%f,%f\n" 217 " Stabilization : %s\n", 218 app_ctx->problem_name, EulerTestTypes[phys->euler_test], 219 phys->euler_ctx->mean_velocity[0], 220 phys->euler_ctx->mean_velocity[1], 221 phys->euler_ctx->mean_velocity[2], 222 StabilizationTypes[phys->stab]); CHKERRQ(ierr); 223 224 PetscFunctionReturn(0); 225 } 226