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) { 16a515125bSLeila Ghaffari EulerTestType euler_test; 17a515125bSLeila Ghaffari User user = *(User *)ctx; 18139613f2SLeila Ghaffari StabilizationType stab; 19a515125bSLeila Ghaffari MPI_Comm comm = PETSC_COMM_WORLD; 20a515125bSLeila Ghaffari PetscBool implicit; 21a515125bSLeila Ghaffari PetscBool has_curr_time = PETSC_TRUE; 22a515125bSLeila Ghaffari PetscBool has_neumann = PETSC_TRUE; 23a515125bSLeila Ghaffari PetscInt ierr; 2415a3537eSJed Brown EulerContext euler_ctx; 2515a3537eSJed Brown CeedQFunctionContext euler_context; 26a515125bSLeila Ghaffari 2715a3537eSJed Brown PetscFunctionBeginUser; 2815a3537eSJed Brown ierr = PetscCalloc1(1, &euler_ctx); CHKERRQ(ierr); 29a515125bSLeila Ghaffari 30a515125bSLeila Ghaffari // ------------------------------------------------------ 31a515125bSLeila Ghaffari // SET UP DENSITY_CURRENT 32a515125bSLeila Ghaffari // ------------------------------------------------------ 33a515125bSLeila Ghaffari problem->dim = 3; 34a515125bSLeila Ghaffari problem->q_data_size_vol = 10; 35*493642f1SJames Wright problem->q_data_size_sur = 10; 369785fe93SJed Brown problem->setup_vol.qfunction = Setup; 379785fe93SJed Brown problem->setup_vol.qfunction_loc = Setup_loc; 389785fe93SJed Brown problem->setup_sur.qfunction = SetupBoundary; 399785fe93SJed Brown problem->setup_sur.qfunction_loc = SetupBoundary_loc; 409785fe93SJed Brown problem->ics.qfunction = ICsEuler; 419785fe93SJed Brown problem->ics.qfunction_loc = ICsEuler_loc; 429785fe93SJed Brown problem->apply_vol_rhs.qfunction = Euler; 439785fe93SJed Brown problem->apply_vol_rhs.qfunction_loc = Euler_loc; 449785fe93SJed Brown problem->apply_vol_ifunction.qfunction = IFunction_Euler; 459785fe93SJed Brown problem->apply_vol_ifunction.qfunction_loc = IFunction_Euler_loc; 469785fe93SJed Brown problem->apply_inflow.qfunction = TravelingVortex_Inflow; 479785fe93SJed Brown problem->apply_inflow.qfunction_loc = TravelingVortex_Inflow_loc; 489785fe93SJed Brown problem->apply_outflow.qfunction = Euler_Outflow; 499785fe93SJed Brown problem->apply_outflow.qfunction_loc = Euler_Outflow_loc; 50a515125bSLeila Ghaffari problem->bc = Exact_Euler; 51b7f03f12SJed Brown problem->bc_ctx = euler_ctx; 52a515125bSLeila Ghaffari problem->non_zero_time = PETSC_TRUE; 53a515125bSLeila Ghaffari problem->print_info = PRINT_EULER_VORTEX; 54a515125bSLeila Ghaffari 55a515125bSLeila Ghaffari // ------------------------------------------------------ 56a515125bSLeila Ghaffari // Create the libCEED context 57a515125bSLeila Ghaffari // ------------------------------------------------------ 58a515125bSLeila Ghaffari CeedScalar vortex_strength = 5.; // - 59f821ee77SLeila Ghaffari CeedScalar c_tau = 0.5; // - 60d8a22b9eSJed Brown // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010 613b451b28SLeila Ghaffari PetscReal center[3], // m 623b451b28SLeila Ghaffari mean_velocity[3] = {1., 1., 0}; // m/s 6305a512bdSLeila Ghaffari PetscReal domain_min[3], domain_max[3], domain_size[3]; 6405a512bdSLeila Ghaffari ierr = DMGetBoundingBox(dm, domain_min, domain_max); CHKERRQ(ierr); 65*493642f1SJames Wright for (PetscInt i=0; i<3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 66a515125bSLeila Ghaffari 67a515125bSLeila Ghaffari // ------------------------------------------------------ 68a515125bSLeila Ghaffari // Create the PETSc context 69a515125bSLeila Ghaffari // ------------------------------------------------------ 70a515125bSLeila Ghaffari PetscScalar meter = 1e-2; // 1 meter in scaled length units 71a515125bSLeila Ghaffari PetscScalar second = 1e-2; // 1 second in scaled time units 72a515125bSLeila Ghaffari 73a515125bSLeila Ghaffari // ------------------------------------------------------ 74a515125bSLeila Ghaffari // Command line Options 75a515125bSLeila Ghaffari // ------------------------------------------------------ 761485969bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", NULL); 77a515125bSLeila Ghaffari // -- Physics 78a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-vortex_strength", "Strength of Vortex", 79a515125bSLeila Ghaffari NULL, vortex_strength, &vortex_strength, NULL); 80a515125bSLeila Ghaffari CHKERRQ(ierr); 81a515125bSLeila Ghaffari PetscInt n = problem->dim; 82a515125bSLeila Ghaffari PetscBool user_velocity; 83a515125bSLeila Ghaffari ierr = PetscOptionsRealArray("-mean_velocity", "Background velocity vector", 84a515125bSLeila Ghaffari NULL, mean_velocity, &n, &user_velocity); 85a515125bSLeila Ghaffari CHKERRQ(ierr); 86*493642f1SJames Wright for (PetscInt i=0; i<3; i++) center[i] = .5*domain_size[i]; 87a515125bSLeila Ghaffari n = problem->dim; 88a515125bSLeila Ghaffari ierr = PetscOptionsRealArray("-center", "Location of vortex center", 89a515125bSLeila Ghaffari NULL, center, &n, NULL); CHKERRQ(ierr); 90a515125bSLeila Ghaffari ierr = PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", 91a515125bSLeila Ghaffari NULL, implicit=PETSC_FALSE, &implicit, NULL); 92a515125bSLeila Ghaffari CHKERRQ(ierr); 93a515125bSLeila Ghaffari ierr = PetscOptionsEnum("-euler_test", "Euler test option", NULL, 94575f8106SLeila Ghaffari EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX), 95a515125bSLeila Ghaffari (PetscEnum *)&euler_test, NULL); CHKERRQ(ierr); 96139613f2SLeila Ghaffari ierr = PetscOptionsEnum("-stab", "Stabilization method", NULL, 97139613f2SLeila Ghaffari StabilizationTypes, (PetscEnum)(stab = STAB_NONE), 98139613f2SLeila Ghaffari (PetscEnum *)&stab, NULL); CHKERRQ(ierr); 99d8a22b9eSJed Brown ierr = PetscOptionsScalar("-c_tau", "Stabilization constant", 100d8a22b9eSJed Brown NULL, c_tau, &c_tau, NULL); CHKERRQ(ierr); 101a515125bSLeila Ghaffari // -- Units 102a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-units_meter", "1 meter in scaled length units", 103a515125bSLeila Ghaffari NULL, meter, &meter, NULL); CHKERRQ(ierr); 104a515125bSLeila Ghaffari meter = fabs(meter); 105a515125bSLeila Ghaffari ierr = PetscOptionsScalar("-units_second","1 second in scaled time units", 106a515125bSLeila Ghaffari NULL, second, &second, NULL); CHKERRQ(ierr); 107a515125bSLeila Ghaffari second = fabs(second); 108a515125bSLeila Ghaffari 109a515125bSLeila Ghaffari // -- Warnings 110139613f2SLeila Ghaffari if (stab == STAB_SUPG && !implicit) { 111139613f2SLeila Ghaffari ierr = PetscPrintf(comm, 112139613f2SLeila Ghaffari "Warning! Use -stab supg only with -implicit\n"); 113139613f2SLeila Ghaffari CHKERRQ(ierr); 114139613f2SLeila Ghaffari } 115a515125bSLeila Ghaffari if (user_velocity && (euler_test == EULER_TEST_1 116a515125bSLeila Ghaffari || euler_test == EULER_TEST_3)) { 117a515125bSLeila Ghaffari ierr = PetscPrintf(comm, 118a515125bSLeila Ghaffari "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n"); 119a515125bSLeila Ghaffari CHKERRQ(ierr); 120a515125bSLeila Ghaffari } 121a515125bSLeila Ghaffari 1221485969bSJeremy L Thompson PetscOptionsEnd(); 123a515125bSLeila Ghaffari 124a515125bSLeila Ghaffari // ------------------------------------------------------ 125a515125bSLeila Ghaffari // Set up the PETSc context 126a515125bSLeila Ghaffari // ------------------------------------------------------ 127a515125bSLeila Ghaffari user->units->meter = meter; 128a515125bSLeila Ghaffari user->units->second = second; 129a515125bSLeila Ghaffari 130a515125bSLeila Ghaffari // ------------------------------------------------------ 131a515125bSLeila Ghaffari // Set up the libCEED context 132a515125bSLeila Ghaffari // ------------------------------------------------------ 133a515125bSLeila Ghaffari // -- Scale variables to desired units 134*493642f1SJames Wright for (PetscInt i=0; i<3; i++) { 1353b451b28SLeila Ghaffari center[i] *= meter; 13605a512bdSLeila Ghaffari domain_size[i] *= meter; 13705a512bdSLeila Ghaffari mean_velocity[i] *= (meter/second); 1383b451b28SLeila Ghaffari } 13905a512bdSLeila Ghaffari problem->dm_scale = meter; 140a515125bSLeila Ghaffari 141a515125bSLeila Ghaffari // -- QFunction Context 142139613f2SLeila Ghaffari user->phys->stab = stab; 143a515125bSLeila Ghaffari user->phys->euler_test = euler_test; 144a515125bSLeila Ghaffari user->phys->implicit = implicit; 145a515125bSLeila Ghaffari user->phys->has_curr_time = has_curr_time; 146a515125bSLeila Ghaffari user->phys->has_neumann = has_neumann; 14715a3537eSJed Brown euler_ctx->curr_time = 0.; 14815a3537eSJed Brown euler_ctx->implicit = implicit; 14915a3537eSJed Brown euler_ctx->euler_test = euler_test; 15015a3537eSJed Brown euler_ctx->center[0] = center[0]; 15115a3537eSJed Brown euler_ctx->center[1] = center[1]; 15215a3537eSJed Brown euler_ctx->center[2] = center[2]; 15315a3537eSJed Brown euler_ctx->vortex_strength = vortex_strength; 15415a3537eSJed Brown euler_ctx->c_tau = c_tau; 15515a3537eSJed Brown euler_ctx->mean_velocity[0] = mean_velocity[0]; 15615a3537eSJed Brown euler_ctx->mean_velocity[1] = mean_velocity[1]; 15715a3537eSJed Brown euler_ctx->mean_velocity[2] = mean_velocity[2]; 15815a3537eSJed Brown euler_ctx->stabilization = stab; 159a515125bSLeila Ghaffari 16015a3537eSJed Brown CeedQFunctionContextCreate(user->ceed, &euler_context); 16115a3537eSJed Brown CeedQFunctionContextSetData(euler_context, CEED_MEM_HOST, CEED_USE_POINTER, 16215a3537eSJed Brown sizeof(*euler_ctx), euler_ctx); 16315a3537eSJed Brown CeedQFunctionContextSetDataDestroy(euler_context, CEED_MEM_HOST, 16415a3537eSJed Brown FreeContextPetsc); 16515a3537eSJed Brown CeedQFunctionContextRegisterDouble(euler_context, "solution time", 16692ada588SJames Wright offsetof(struct EulerContext_, curr_time), 1, "Phyiscal time of the solution"); 167b7f03f12SJed Brown CeedQFunctionContextReferenceCopy(euler_context, 168b7f03f12SJed Brown &problem->ics.qfunction_context); 16915a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17015a3537eSJed Brown &problem->apply_vol_rhs.qfunction_context); 17115a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17215a3537eSJed Brown &problem->apply_vol_ifunction.qfunction_context); 17315a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17415a3537eSJed Brown &problem->apply_inflow.qfunction_context); 17515a3537eSJed Brown CeedQFunctionContextReferenceCopy(euler_context, 17615a3537eSJed Brown &problem->apply_outflow.qfunction_context); 177a515125bSLeila Ghaffari PetscFunctionReturn(0); 178a515125bSLeila Ghaffari } 179a515125bSLeila Ghaffari 18040ccd21cSJed Brown PetscErrorCode PRINT_EULER_VORTEX(ProblemData *problem, 181a515125bSLeila Ghaffari AppCtx app_ctx) { 182a515125bSLeila Ghaffari MPI_Comm comm = PETSC_COMM_WORLD; 183a515125bSLeila Ghaffari PetscErrorCode ierr; 18415a3537eSJed Brown EulerContext euler_ctx; 185a515125bSLeila Ghaffari 18615a3537eSJed Brown PetscFunctionBeginUser; 18715a3537eSJed Brown CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, 18815a3537eSJed Brown &euler_ctx); 189a515125bSLeila Ghaffari ierr = PetscPrintf(comm, 190a515125bSLeila Ghaffari " Problem:\n" 191a515125bSLeila Ghaffari " Problem Name : %s\n" 192a515125bSLeila Ghaffari " Test Case : %s\n" 193139613f2SLeila Ghaffari " Background Velocity : %f,%f,%f\n" 194139613f2SLeila Ghaffari " Stabilization : %s\n", 19515a3537eSJed Brown app_ctx->problem_name, EulerTestTypes[euler_ctx->euler_test], 19615a3537eSJed Brown euler_ctx->mean_velocity[0], 19715a3537eSJed Brown euler_ctx->mean_velocity[1], 19815a3537eSJed Brown euler_ctx->mean_velocity[2], 19915a3537eSJed Brown StabilizationTypes[euler_ctx->stabilization]); CHKERRQ(ierr); 200a515125bSLeila Ghaffari 20115a3537eSJed Brown CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &euler_ctx); 202a515125bSLeila Ghaffari PetscFunctionReturn(0); 203a515125bSLeila Ghaffari } 204