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 "../qfunctions/eulervortex.h" 12 13 #include <ceed.h> 14 #include <petscdm.h> 15 16 #include "../navierstokes.h" 17 #include "../qfunctions/setupgeo.h" 18 19 PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { 20 EulerTestType euler_test; 21 User user = *(User *)ctx; 22 StabilizationType stab; 23 MPI_Comm comm = PETSC_COMM_WORLD; 24 PetscBool implicit; 25 PetscBool has_curr_time = PETSC_TRUE; 26 PetscBool has_neumann = PETSC_TRUE; 27 EulerContext euler_ctx; 28 CeedQFunctionContext euler_context; 29 30 PetscFunctionBeginUser; 31 PetscCall(PetscCalloc1(1, &euler_ctx)); 32 33 // ------------------------------------------------------ 34 // SET UP DENSITY_CURRENT 35 // ------------------------------------------------------ 36 problem->dim = 3; 37 problem->q_data_size_vol = 10; 38 problem->q_data_size_sur = 10; 39 problem->setup_vol.qfunction = Setup; 40 problem->setup_vol.qfunction_loc = Setup_loc; 41 problem->setup_sur.qfunction = SetupBoundary; 42 problem->setup_sur.qfunction_loc = SetupBoundary_loc; 43 problem->ics.qfunction = ICsEuler; 44 problem->ics.qfunction_loc = ICsEuler_loc; 45 problem->apply_vol_rhs.qfunction = Euler; 46 problem->apply_vol_rhs.qfunction_loc = Euler_loc; 47 problem->apply_vol_ifunction.qfunction = IFunction_Euler; 48 problem->apply_vol_ifunction.qfunction_loc = IFunction_Euler_loc; 49 problem->apply_inflow.qfunction = TravelingVortex_Inflow; 50 problem->apply_inflow.qfunction_loc = TravelingVortex_Inflow_loc; 51 problem->apply_outflow.qfunction = Euler_Outflow; 52 problem->apply_outflow.qfunction_loc = Euler_Outflow_loc; 53 problem->non_zero_time = PETSC_TRUE; 54 problem->print_info = PRINT_EULER_VORTEX; 55 56 // ------------------------------------------------------ 57 // Create the libCEED context 58 // ------------------------------------------------------ 59 CeedScalar vortex_strength = 5.; // - 60 CeedScalar c_tau = 0.5; // - 61 // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010 62 PetscReal center[3], // m 63 mean_velocity[3] = {1., 1., 0}; // m/s 64 PetscReal domain_min[3], domain_max[3], domain_size[3]; 65 PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 66 for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 67 68 // ------------------------------------------------------ 69 // Create the PETSc context 70 // ------------------------------------------------------ 71 PetscScalar meter = 1e-2; // 1 meter in scaled length units 72 PetscScalar second = 1e-2; // 1 second in scaled time units 73 74 // ------------------------------------------------------ 75 // Command line Options 76 // ------------------------------------------------------ 77 PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", NULL); 78 // -- Physics 79 PetscCall(PetscOptionsScalar("-vortex_strength", "Strength of Vortex", NULL, vortex_strength, &vortex_strength, NULL)); 80 PetscInt n = problem->dim; 81 PetscBool user_velocity; 82 PetscCall(PetscOptionsRealArray("-mean_velocity", "Background velocity vector", NULL, mean_velocity, &n, &user_velocity)); 83 for (PetscInt i = 0; i < 3; i++) center[i] = .5 * domain_size[i]; 84 n = problem->dim; 85 PetscCall(PetscOptionsRealArray("-center", "Location of vortex center", NULL, center, &n, NULL)); 86 PetscCall(PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", NULL, implicit = PETSC_FALSE, &implicit, NULL)); 87 PetscCall(PetscOptionsEnum("-euler_test", "Euler test option", NULL, EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX), 88 (PetscEnum *)&euler_test, NULL)); 89 PetscCall(PetscOptionsEnum("-stab", "Stabilization method", NULL, StabilizationTypes, (PetscEnum)(stab = STAB_NONE), (PetscEnum *)&stab, NULL)); 90 PetscCall(PetscOptionsScalar("-c_tau", "Stabilization constant", NULL, c_tau, &c_tau, NULL)); 91 // -- Units 92 PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, meter, &meter, NULL)); 93 meter = fabs(meter); 94 PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, second, &second, NULL)); 95 second = fabs(second); 96 97 // -- Warnings 98 if (stab == STAB_SUPG && !implicit) { 99 PetscCall(PetscPrintf(comm, "Warning! Use -stab supg only with -implicit\n")); 100 } 101 if (user_velocity && (euler_test == EULER_TEST_1 || euler_test == EULER_TEST_3)) { 102 PetscCall(PetscPrintf(comm, "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n")); 103 } 104 105 PetscOptionsEnd(); 106 107 // ------------------------------------------------------ 108 // Set up the PETSc context 109 // ------------------------------------------------------ 110 user->units->meter = meter; 111 user->units->second = second; 112 113 // ------------------------------------------------------ 114 // Set up the libCEED context 115 // ------------------------------------------------------ 116 // -- Scale variables to desired units 117 for (PetscInt i = 0; i < 3; i++) { 118 center[i] *= meter; 119 domain_size[i] *= meter; 120 mean_velocity[i] *= (meter / second); 121 } 122 problem->dm_scale = meter; 123 124 // -- QFunction Context 125 user->phys->stab = stab; 126 user->phys->euler_test = euler_test; 127 user->phys->implicit = implicit; 128 user->phys->has_curr_time = has_curr_time; 129 user->phys->has_neumann = has_neumann; 130 euler_ctx->curr_time = 0.; 131 euler_ctx->implicit = implicit; 132 euler_ctx->euler_test = euler_test; 133 euler_ctx->center[0] = center[0]; 134 euler_ctx->center[1] = center[1]; 135 euler_ctx->center[2] = center[2]; 136 euler_ctx->vortex_strength = vortex_strength; 137 euler_ctx->c_tau = c_tau; 138 euler_ctx->mean_velocity[0] = mean_velocity[0]; 139 euler_ctx->mean_velocity[1] = mean_velocity[1]; 140 euler_ctx->mean_velocity[2] = mean_velocity[2]; 141 euler_ctx->stabilization = stab; 142 143 CeedQFunctionContextCreate(user->ceed, &euler_context); 144 CeedQFunctionContextSetData(euler_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*euler_ctx), euler_ctx); 145 CeedQFunctionContextSetDataDestroy(euler_context, CEED_MEM_HOST, FreeContextPetsc); 146 CeedQFunctionContextRegisterDouble(euler_context, "solution time", offsetof(struct EulerContext_, curr_time), 1, "Physical time of the solution"); 147 CeedQFunctionContextReferenceCopy(euler_context, &problem->ics.qfunction_context); 148 CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_rhs.qfunction_context); 149 CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_ifunction.qfunction_context); 150 CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_inflow.qfunction_context); 151 CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_outflow.qfunction_context); 152 PetscFunctionReturn(PETSC_SUCCESS); 153 } 154 155 PetscErrorCode PRINT_EULER_VORTEX(ProblemData *problem, AppCtx app_ctx) { 156 MPI_Comm comm = PETSC_COMM_WORLD; 157 EulerContext euler_ctx; 158 159 PetscFunctionBeginUser; 160 CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &euler_ctx); 161 PetscCall(PetscPrintf(comm, 162 " Problem:\n" 163 " Problem Name : %s\n" 164 " Test Case : %s\n" 165 " Background Velocity : %f,%f,%f\n" 166 " Stabilization : %s\n", 167 app_ctx->problem_name, EulerTestTypes[euler_ctx->euler_test], euler_ctx->mean_velocity[0], euler_ctx->mean_velocity[1], 168 euler_ctx->mean_velocity[2], StabilizationTypes[euler_ctx->stabilization])); 169 170 CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &euler_ctx); 171 PetscFunctionReturn(PETSC_SUCCESS); 172 } 173