1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 /// @file 9 /// Utility functions for setting up EULER_VORTEX 10 11 #include "../navierstokes.h" 12 #include "../qfunctions/setupgeo.h" 13 #include "../qfunctions/eulervortex.h" 14 15 PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, DM dm, void *setup_ctx, 16 void *ctx) { 17 EulerTestType euler_test; 18 SetupContext setup_context = *(SetupContext *)setup_ctx; 19 User user = *(User *)ctx; 20 StabilizationType stab; 21 MPI_Comm comm = PETSC_COMM_WORLD; 22 PetscBool implicit; 23 PetscBool has_curr_time = PETSC_TRUE; 24 PetscBool has_neumann = PETSC_TRUE; 25 PetscInt ierr; 26 PetscFunctionBeginUser; 27 28 ierr = PetscCalloc1(1, &user->phys->euler_ctx); CHKERRQ(ierr); 29 30 // ------------------------------------------------------ 31 // SET UP DENSITY_CURRENT 32 // ------------------------------------------------------ 33 problem->dim = 3; 34 problem->q_data_size_vol = 10; 35 problem->q_data_size_sur = 4; 36 problem->setup_vol = Setup; 37 problem->setup_vol_loc = Setup_loc; 38 problem->setup_sur = SetupBoundary; 39 problem->setup_sur_loc = SetupBoundary_loc; 40 problem->ics = ICsEuler; 41 problem->ics_loc = ICsEuler_loc; 42 problem->apply_vol_rhs = Euler; 43 problem->apply_vol_rhs_loc = Euler_loc; 44 problem->apply_vol_ifunction = IFunction_Euler; 45 problem->apply_vol_ifunction_loc = IFunction_Euler_loc; 46 problem->apply_inflow = TravelingVortex_Inflow; 47 problem->apply_inflow_loc = TravelingVortex_Inflow_loc; 48 problem->apply_outflow = Euler_Outflow; 49 problem->apply_outflow_loc = Euler_Outflow_loc; 50 problem->bc = Exact_Euler; 51 problem->setup_ctx = SetupContext_EULER_VORTEX; 52 problem->non_zero_time = PETSC_TRUE; 53 problem->print_info = PRINT_EULER_VORTEX; 54 55 // ------------------------------------------------------ 56 // Create the libCEED context 57 // ------------------------------------------------------ 58 CeedScalar vortex_strength = 5.; // - 59 CeedScalar c_tau = 0.5; // - 60 // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010 61 PetscReal center[3], // m 62 mean_velocity[3] = {1., 1., 0}; // m/s 63 PetscReal domain_min[3], domain_max[3], domain_size[3]; 64 ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr); 65 for (int i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 66 67 // ------------------------------------------------------ 68 // Create the PETSc context 69 // ------------------------------------------------------ 70 PetscScalar meter = 1e-2; // 1 meter in scaled length units 71 PetscScalar second = 1e-2; // 1 second in scaled time units 72 73 // ------------------------------------------------------ 74 // Command line Options 75 // ------------------------------------------------------ 76 PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", NULL); 77 // -- Physics 78 ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex", 79 NULL, vortex_strength, &vortex_strength, NULL); 80 CHKERRQ(ierr); 81 PetscInt n = problem->dim; 82 PetscBool user_velocity; 83 ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector", 84 NULL, mean_velocity, &n, &user_velocity); 85 CHKERRQ(ierr); 86 for (int i=0; i<3; i++) center[i] = .5*domain_size[i]; 87 n = problem->dim; 88 ierr = PetscOptionsRealArray("-center", "Location of vortex center", 89 NULL, center, &n, NULL); CHKERRQ(ierr); 90 ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", 91 NULL, implicit=PETSC_FALSE, &implicit, NULL); 92 CHKERRQ(ierr); 93 ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL, 94 EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX), 95 (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr); 96 ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL, 97 StabilizationTypes, (PetscEnum)(stab = STAB_NONE), 98 (PetscEnum *)&stab, NULL); CHKERRQ(ierr); 99 ierr = PetscOptionsScalar("-c_tau", "Stabilization constant", 100 NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr); 101 // -- Units 102 ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 103 NULL, meter, &meter, NULL); CHKERRQ(ierr); 104 meter = fabs(meter); 105 ierr = PetscOptionsScalar("-units_second","1 second in scaled time units", 106 NULL, second, &second, NULL); CHKERRQ(ierr); 107 second = fabs(second); 108 109 // -- Warnings 110 if (stab == STAB_SUPG && !implicit) { 111 ierr = PetscPrintf(comm, 112 "Warning! Use -stab supg only with -implicit\n"); 113 CHKERRQ(ierr); 114 } 115 if (user_velocity && (euler_test == EULER_TEST_1 116 || euler_test == EULER_TEST_3)) { 117 ierr = PetscPrintf(comm, 118 "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n"); 119 CHKERRQ(ierr); 120 } 121 122 PetscOptionsEnd(); 123 124 // ------------------------------------------------------ 125 // Set up the PETSc context 126 // ------------------------------------------------------ 127 user->units->meter = meter; 128 user->units->second = second; 129 130 // ------------------------------------------------------ 131 // Set up the libCEED context 132 // ------------------------------------------------------ 133 // -- Scale variables to desired units 134 for (int i=0; i<3; i++) { 135 center[i] *= meter; 136 domain_size[i] *= meter; 137 mean_velocity[i] *= (meter/second); 138 } 139 problem->dm_scale = meter; 140 141 // -- Setup Context 142 setup_context->lx = domain_size[0]; 143 setup_context->ly = domain_size[1]; 144 setup_context->lz = domain_size[2]; 145 setup_context->center[0] = center[0]; 146 setup_context->center[1] = center[1]; 147 setup_context->center[2] = center[2]; 148 setup_context->time = 0; 149 150 // -- QFunction Context 151 user->phys->stab = stab; 152 user->phys->euler_test = euler_test; 153 user->phys->implicit = implicit; 154 user->phys->has_curr_time = has_curr_time; 155 user->phys->has_neumann = has_neumann; 156 user->phys->euler_ctx->curr_time = 0.; 157 user->phys->euler_ctx->implicit = implicit; 158 user->phys->euler_ctx->euler_test = euler_test; 159 user->phys->euler_ctx->center[0] = center[0]; 160 user->phys->euler_ctx->center[1] = center[1]; 161 user->phys->euler_ctx->center[2] = center[2]; 162 user->phys->euler_ctx->vortex_strength = vortex_strength; 163 user->phys->euler_ctx->c_tau = c_tau; 164 user->phys->euler_ctx->mean_velocity[0] = mean_velocity[0]; 165 user->phys->euler_ctx->mean_velocity[1] = mean_velocity[1]; 166 user->phys->euler_ctx->mean_velocity[2] = mean_velocity[2]; 167 user->phys->euler_ctx->stabilization = stab; 168 169 PetscFunctionReturn(0); 170 } 171 172 PetscErrorCode SetupContext_EULER_VORTEX(Ceed ceed, CeedData ceed_data, 173 AppCtx app_ctx, SetupContext setup_ctx, Physics phys) { 174 PetscFunctionBeginUser; 175 CeedQFunctionContextCreate(ceed, &ceed_data->setup_context); 176 CeedQFunctionContextSetData(ceed_data->setup_context, CEED_MEM_HOST, 177 CEED_USE_POINTER, 178 sizeof(*setup_ctx), setup_ctx); 179 CeedQFunctionContextCreate(ceed, &ceed_data->euler_context); 180 CeedQFunctionContextSetData(ceed_data->euler_context, CEED_MEM_HOST, 181 CEED_USE_POINTER, 182 sizeof(*phys->euler_ctx), phys->euler_ctx); 183 CeedQFunctionContextRegisterDouble(ceed_data->euler_context, "solution time", 184 offsetof(struct EulerContext_, curr_time), 1, "Phyiscal time of the solution"); 185 186 if (ceed_data->qf_ics) 187 CeedQFunctionSetContext(ceed_data->qf_ics, ceed_data->euler_context); 188 if (ceed_data->qf_rhs_vol) 189 CeedQFunctionSetContext(ceed_data->qf_rhs_vol, ceed_data->euler_context); 190 if (ceed_data->qf_ifunction_vol) 191 CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, ceed_data->euler_context); 192 if (ceed_data->qf_apply_inflow) 193 CeedQFunctionSetContext(ceed_data->qf_apply_inflow, ceed_data->euler_context); 194 if (ceed_data->qf_apply_outflow) 195 CeedQFunctionSetContext(ceed_data->qf_apply_outflow, ceed_data->euler_context); 196 PetscFunctionReturn(0); 197 } 198 199 PetscErrorCode PRINT_EULER_VORTEX(Physics phys, SetupContext setup_ctx, 200 AppCtx app_ctx) { 201 MPI_Comm comm = PETSC_COMM_WORLD; 202 PetscErrorCode ierr; 203 PetscFunctionBeginUser; 204 205 ierr = PetscPrintf(comm, 206 " Problem:\n" 207 " Problem Name : %s\n" 208 " Test Case : %s\n" 209 " Background Velocity : %f,%f,%f\n" 210 " Stabilization : %s\n", 211 app_ctx->problem_name, EulerTestTypes[phys->euler_test], 212 phys->euler_ctx->mean_velocity[0], 213 phys->euler_ctx->mean_velocity[1], 214 phys->euler_ctx->mean_velocity[2], 215 StabilizationTypes[phys->stab]); CHKERRQ(ierr); 216 217 PetscFunctionReturn(0); 218 } 219