1727da7e7SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3a515125bSLeila Ghaffari // 4727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5a515125bSLeila Ghaffari // 6727da7e7SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7a515125bSLeila Ghaffari 8a515125bSLeila Ghaffari /// @file 9a515125bSLeila Ghaffari /// Utility functions for setting up EULER_VORTEX 10a515125bSLeila Ghaffari 11a515125bSLeila Ghaffari #include "../navierstokes.h" 12a515125bSLeila Ghaffari #include "../qfunctions/setupgeo.h" 13a515125bSLeila Ghaffari #include "../qfunctions/eulervortex.h" 14a515125bSLeila Ghaffari 15b7f03f12SJed Brown PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, DM dm, void *ctx) { 16*6dd99bedSLeila Ghaffari 17a515125bSLeila Ghaffari EulerTestType euler_test; 18a515125bSLeila Ghaffari User user = *(User *)ctx; 19139613f2SLeila Ghaffari StabilizationType stab; 20a515125bSLeila Ghaffari MPI_Comm comm = PETSC_COMM_WORLD; 21a515125bSLeila Ghaffari PetscBool implicit; 22a515125bSLeila Ghaffari PetscBool has_curr_time = PETSC_TRUE; 23a515125bSLeila Ghaffari PetscBool has_neumann = PETSC_TRUE; 24a515125bSLeila Ghaffari PetscInt ierr; 2515a3537eSJed Brown EulerContext euler_ctx; 2615a3537eSJed Brown CeedQFunctionContext euler_context; 27a515125bSLeila Ghaffari 2815a3537eSJed Brown PetscFunctionBeginUser; 2915a3537eSJed Brown ierr = PetscCalloc1(1, &euler_ctx); CHKERRQ(ierr); 30a515125bSLeila Ghaffari 31a515125bSLeila Ghaffari // ------------------------------------------------------ 32a515125bSLeila Ghaffari // SET UP DENSITY_CURRENT 33a515125bSLeila Ghaffari // ------------------------------------------------------ 34a515125bSLeila Ghaffari problem->dim = 3; 35a515125bSLeila Ghaffari problem->q_data_size_vol = 10; 36493642f1SJames Wright problem->q_data_size_sur = 10; 379785fe93SJed Brown problem->setup_vol.qfunction = Setup; 389785fe93SJed Brown problem->setup_vol.qfunction_loc = Setup_loc; 399785fe93SJed Brown problem->setup_sur.qfunction = SetupBoundary; 409785fe93SJed Brown problem->setup_sur.qfunction_loc = SetupBoundary_loc; 419785fe93SJed Brown problem->ics.qfunction = ICsEuler; 429785fe93SJed Brown problem->ics.qfunction_loc = ICsEuler_loc; 439785fe93SJed Brown problem->apply_vol_rhs.qfunction = Euler; 449785fe93SJed Brown problem->apply_vol_rhs.qfunction_loc = Euler_loc; 459785fe93SJed Brown problem->apply_vol_ifunction.qfunction = IFunction_Euler; 469785fe93SJed Brown problem->apply_vol_ifunction.qfunction_loc = IFunction_Euler_loc; 479785fe93SJed Brown problem->apply_inflow.qfunction = TravelingVortex_Inflow; 489785fe93SJed Brown problem->apply_inflow.qfunction_loc = TravelingVortex_Inflow_loc; 499785fe93SJed Brown problem->apply_outflow.qfunction = Euler_Outflow; 509785fe93SJed Brown problem->apply_outflow.qfunction_loc = Euler_Outflow_loc; 51a515125bSLeila Ghaffari problem->bc = Exact_Euler; 52b7f03f12SJed Brown problem->bc_ctx = euler_ctx; 53a515125bSLeila Ghaffari problem->non_zero_time = PETSC_TRUE; 54a515125bSLeila Ghaffari problem->print_info = PRINT_EULER_VORTEX; 55a515125bSLeila Ghaffari 56a515125bSLeila Ghaffari // ------------------------------------------------------ 57a515125bSLeila Ghaffari // Create the libCEED context 58a515125bSLeila Ghaffari // ------------------------------------------------------ 59a515125bSLeila Ghaffari CeedScalar vortex_strength = 5.; // - 60f821ee77SLeila Ghaffari CeedScalar c_tau = 0.5; // - 61d8a22b9eSJed Brown // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010 623b451b28SLeila Ghaffari PetscReal center[3], // m 633b451b28SLeila Ghaffari mean_velocity[3] = {1., 1., 0}; // m/s 6405a512bdSLeila Ghaffari PetscReal domain_min[3], domain_max[3], domain_size[3]; 6505a512bdSLeila Ghaffari ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr); 66493642f1SJames Wright for (PetscInt i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 67a515125bSLeila Ghaffari 68a515125bSLeila Ghaffari // ------------------------------------------------------ 69a515125bSLeila Ghaffari // Create the PETSc context 70a515125bSLeila Ghaffari // ------------------------------------------------------ 71a515125bSLeila Ghaffari PetscScalar meter = 1e-2; // 1 meter in scaled length units 72a515125bSLeila Ghaffari PetscScalar second = 1e-2; // 1 second in scaled time units 73a515125bSLeila Ghaffari 74a515125bSLeila Ghaffari // ------------------------------------------------------ 75a515125bSLeila Ghaffari // Command line Options 76a515125bSLeila Ghaffari // ------------------------------------------------------ 771485969bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", NULL); 78a515125bSLeila Ghaffari // -- Physics 79a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex", 80a515125bSLeila Ghaffari NULL, vortex_strength, &vortex_strength, NULL); 81a515125bSLeila Ghaffari CHKERRQ(ierr); 82a515125bSLeila Ghaffari PetscInt n = problem->dim; 83a515125bSLeila Ghaffari PetscBool user_velocity; 84a515125bSLeila Ghaffari ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector", 85a515125bSLeila Ghaffari NULL, mean_velocity, &n, &user_velocity); 86a515125bSLeila Ghaffari CHKERRQ(ierr); 87493642f1SJames Wright for (PetscInt i=0; i<3; i++) center[i] = .5*domain_size[i]; 88a515125bSLeila Ghaffari n = problem->dim; 89a515125bSLeila Ghaffari ierr = PetscOptionsRealArray("-center", "Location of vortex center", 90a515125bSLeila Ghaffari NULL, center, &n, NULL); CHKERRQ(ierr); 91a515125bSLeila Ghaffari ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", 92a515125bSLeila Ghaffari NULL, implicit=PETSC_FALSE, &implicit, NULL); 93a515125bSLeila Ghaffari CHKERRQ(ierr); 94a515125bSLeila Ghaffari ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL, 95575f8106SLeila Ghaffari EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX), 96a515125bSLeila Ghaffari (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr); 97139613f2SLeila Ghaffari ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL, 98139613f2SLeila Ghaffari StabilizationTypes, (PetscEnum)(stab = STAB_NONE), 99139613f2SLeila Ghaffari (PetscEnum *)&stab, NULL); CHKERRQ(ierr); 100d8a22b9eSJed Brown ierr = PetscOptionsScalar("-c_tau", "Stabilization constant", 101d8a22b9eSJed Brown NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr); 102a515125bSLeila Ghaffari // -- Units 103a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 104a515125bSLeila Ghaffari NULL, meter, &meter, NULL); CHKERRQ(ierr); 105a515125bSLeila Ghaffari meter = fabs(meter); 106a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-units_second","1 second in scaled time units", 107a515125bSLeila Ghaffari NULL, second, &second, NULL); CHKERRQ(ierr); 108a515125bSLeila Ghaffari second = fabs(second); 109a515125bSLeila Ghaffari 110a515125bSLeila Ghaffari // -- Warnings 111139613f2SLeila Ghaffari if (stab == STAB_SUPG && !implicit) { 112139613f2SLeila Ghaffari ierr = PetscPrintf(comm, 113139613f2SLeila Ghaffari "Warning! Use -stab supg only with -implicit\n"); 114139613f2SLeila Ghaffari CHKERRQ(ierr); 115139613f2SLeila Ghaffari } 116a515125bSLeila Ghaffari if (user_velocity && (euler_test == EULER_TEST_1 117a515125bSLeila Ghaffari || euler_test == EULER_TEST_3)) { 118a515125bSLeila Ghaffari ierr = PetscPrintf(comm, 119a515125bSLeila Ghaffari "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n"); 120a515125bSLeila Ghaffari CHKERRQ(ierr); 121a515125bSLeila Ghaffari } 122a515125bSLeila Ghaffari 1231485969bSJeremy L Thompson PetscOptionsEnd(); 124a515125bSLeila Ghaffari 125a515125bSLeila Ghaffari // ------------------------------------------------------ 126a515125bSLeila Ghaffari // Set up the PETSc context 127a515125bSLeila Ghaffari // ------------------------------------------------------ 128a515125bSLeila Ghaffari user->units->meter = meter; 129a515125bSLeila Ghaffari user->units->second = second; 130a515125bSLeila Ghaffari 131a515125bSLeila Ghaffari // ------------------------------------------------------ 132a515125bSLeila Ghaffari // Set up the libCEED context 133a515125bSLeila Ghaffari // ------------------------------------------------------ 134a515125bSLeila Ghaffari // -- Scale variables to desired units 135493642f1SJames Wright for (PetscInt i=0; i<3; i++) { 1363b451b28SLeila Ghaffari center[i] *= meter; 13705a512bdSLeila Ghaffari domain_size[i] *= meter; 13805a512bdSLeila Ghaffari mean_velocity[i] *= (meter/second); 1393b451b28SLeila Ghaffari } 14005a512bdSLeila Ghaffari problem->dm_scale = meter; 141a515125bSLeila Ghaffari 142a515125bSLeila Ghaffari // -- QFunction Context 143139613f2SLeila Ghaffari user->phys->stab = stab; 144a515125bSLeila Ghaffari user->phys->euler_test = euler_test; 145a515125bSLeila Ghaffari user->phys->implicit = implicit; 146a515125bSLeila Ghaffari user->phys->has_curr_time = has_curr_time; 147a515125bSLeila Ghaffari user->phys->has_neumann = has_neumann; 14815a3537eSJed Brown euler_ctx->curr_time = 0.; 14915a3537eSJed Brown euler_ctx->implicit = implicit; 15015a3537eSJed Brown euler_ctx->euler_test = euler_test; 15115a3537eSJed Brown euler_ctx->center[0] = center[0]; 15215a3537eSJed Brown euler_ctx->center[1] = center[1]; 15315a3537eSJed Brown euler_ctx->center[2] = center[2]; 15415a3537eSJed Brown euler_ctx->vortex_strength = vortex_strength; 15515a3537eSJed Brown euler_ctx->c_tau = c_tau; 15615a3537eSJed Brown euler_ctx->mean_velocity[0] = mean_velocity[0]; 15715a3537eSJed Brown euler_ctx->mean_velocity[1] = mean_velocity[1]; 15815a3537eSJed Brown euler_ctx->mean_velocity[2] = mean_velocity[2]; 15915a3537eSJed Brown euler_ctx->stabilization = stab; 160a515125bSLeila Ghaffari 16115a3537eSJed Brown CeedQFunctionContextCreate(user->ceed, &euler_context); 16215a3537eSJed Brown CeedQFunctionContextSetData(euler_context, CEED_MEM_HOST, CEED_USE_POINTER, 16315a3537eSJed Brown sizeof(*euler_ctx), euler_ctx); 16415a3537eSJed Brown CeedQFunctionContextSetDataDestroy(euler_context, CEED_MEM_HOST, 16515a3537eSJed Brown FreeContextPetsc); 16615a3537eSJed Brown CeedQFunctionContextRegisterDouble(euler_context, "solution time", 16792ada588SJames Wright offsetof(struct EulerContext_, curr_time), 1, "Phyiscal time of the solution"); 168b7f03f12SJed Brown CeedQFunctionContextReferenceCopy(euler_context, 169b7f03f12SJed Brown &problem->ics.qfunction_context); 17015a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17115a3537eSJed Brown &problem->apply_vol_rhs.qfunction_context); 17215a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17315a3537eSJed Brown &problem->apply_vol_ifunction.qfunction_context); 17415a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17515a3537eSJed Brown &problem->apply_inflow.qfunction_context); 17615a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17715a3537eSJed Brown &problem->apply_outflow.qfunction_context); 178a515125bSLeila Ghaffari PetscFunctionReturn(0); 179a515125bSLeila Ghaffari } 180a515125bSLeila Ghaffari 18140ccd21cSJed Brown PetscErrorCode PRINT_EULER_VORTEX(ProblemData *problem, 182a515125bSLeila Ghaffari AppCtx app_ctx) { 183a515125bSLeila Ghaffari MPI_Comm comm = PETSC_COMM_WORLD; 184a515125bSLeila Ghaffari PetscErrorCode ierr; 18515a3537eSJed Brown EulerContext euler_ctx; 186a515125bSLeila Ghaffari 18715a3537eSJed Brown PetscFunctionBeginUser; 18815a3537eSJed Brown CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, 18915a3537eSJed Brown &euler_ctx); 190a515125bSLeila Ghaffari ierr = PetscPrintf(comm, 191a515125bSLeila Ghaffari " Problem:\n" 192a515125bSLeila Ghaffari " Problem Name : %s\n" 193a515125bSLeila Ghaffari " Test Case : %s\n" 194139613f2SLeila Ghaffari " Background Velocity : %f,%f,%f\n" 195139613f2SLeila Ghaffari " Stabilization : %s\n", 19615a3537eSJed Brown app_ctx->problem_name, EulerTestTypes[euler_ctx->euler_test], 19715a3537eSJed Brown euler_ctx->mean_velocity[0], 19815a3537eSJed Brown euler_ctx->mean_velocity[1], 19915a3537eSJed Brown euler_ctx->mean_velocity[2], 20015a3537eSJed Brown StabilizationTypes[euler_ctx->stabilization]); CHKERRQ(ierr); 201a515125bSLeila Ghaffari 20215a3537eSJed Brown CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &euler_ctx); 203a515125bSLeila Ghaffari PetscFunctionReturn(0); 204a515125bSLeila Ghaffari } 205