1*ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2*ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3a515125bSLeila Ghaffari 4a515125bSLeila Ghaffari /// @file 5a515125bSLeila Ghaffari /// Utility functions for setting up EULER_VORTEX 6a515125bSLeila Ghaffari 7a515125bSLeila Ghaffari #include "../qfunctions/eulervortex.h" 8a515125bSLeila Ghaffari 9e419654dSJeremy L Thompson #include <ceed.h> 10e419654dSJeremy L Thompson #include <petscdm.h> 11e419654dSJeremy L Thompson 12149fb536SJames Wright #include <navierstokes.h> 136dd99bedSLeila Ghaffari 14991aef52SJames Wright PetscErrorCode NS_EULER_VORTEX(ProblemData problem, DM dm, void *ctx, SimpleBC bc) { 15a515125bSLeila Ghaffari EulerTestType euler_test; 16a515125bSLeila Ghaffari User user = *(User *)ctx; 17139613f2SLeila Ghaffari StabilizationType stab; 18b4c37c5cSJames Wright MPI_Comm comm = user->comm; 19b4c37c5cSJames Wright Ceed ceed = user->ceed; 20a515125bSLeila Ghaffari PetscBool implicit; 2115a3537eSJed Brown EulerContext euler_ctx; 2215a3537eSJed Brown CeedQFunctionContext euler_context; 23a515125bSLeila Ghaffari 2415a3537eSJed Brown PetscFunctionBeginUser; 252b916ea7SJeremy L Thompson PetscCall(PetscCalloc1(1, &euler_ctx)); 26a515125bSLeila Ghaffari 27a515125bSLeila Ghaffari // ------------------------------------------------------ 28a515125bSLeila Ghaffari // SET UP DENSITY_CURRENT 29a515125bSLeila Ghaffari // ------------------------------------------------------ 30a515125bSLeila Ghaffari problem->dim = 3; 319785fe93SJed Brown problem->ics.qfunction = ICsEuler; 329785fe93SJed Brown problem->ics.qfunction_loc = ICsEuler_loc; 339785fe93SJed Brown problem->apply_vol_rhs.qfunction = Euler; 349785fe93SJed Brown problem->apply_vol_rhs.qfunction_loc = Euler_loc; 359785fe93SJed Brown problem->apply_vol_ifunction.qfunction = IFunction_Euler; 369785fe93SJed Brown problem->apply_vol_ifunction.qfunction_loc = IFunction_Euler_loc; 379785fe93SJed Brown problem->apply_inflow.qfunction = TravelingVortex_Inflow; 389785fe93SJed Brown problem->apply_inflow.qfunction_loc = TravelingVortex_Inflow_loc; 399785fe93SJed Brown problem->apply_outflow.qfunction = Euler_Outflow; 409785fe93SJed Brown problem->apply_outflow.qfunction_loc = Euler_Outflow_loc; 4158ce1233SJames Wright problem->compute_exact_solution_error = PETSC_TRUE; 42a515125bSLeila Ghaffari problem->print_info = PRINT_EULER_VORTEX; 43a515125bSLeila Ghaffari 44a515125bSLeila Ghaffari // ------------------------------------------------------ 45a515125bSLeila Ghaffari // Create the libCEED context 46a515125bSLeila Ghaffari // ------------------------------------------------------ 47a515125bSLeila Ghaffari CeedScalar vortex_strength = 5.; // - 48f821ee77SLeila Ghaffari CeedScalar c_tau = 0.5; // - 49d8a22b9eSJed Brown // c_tau = 0.5 is reported as "optimal" in Hughes et al 2010 503b451b28SLeila Ghaffari PetscReal center[3], // m 513b451b28SLeila Ghaffari mean_velocity[3] = {1., 1., 0}; // m/s 5205a512bdSLeila Ghaffari PetscReal domain_min[3], domain_max[3], domain_size[3]; 532b916ea7SJeremy L Thompson PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 54493642f1SJames Wright for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 55a515125bSLeila Ghaffari 56a515125bSLeila Ghaffari // ------------------------------------------------------ 57a515125bSLeila Ghaffari // Create the PETSc context 58a515125bSLeila Ghaffari // ------------------------------------------------------ 59a515125bSLeila Ghaffari PetscScalar meter = 1e-2; // 1 meter in scaled length units 60a515125bSLeila Ghaffari PetscScalar second = 1e-2; // 1 second in scaled time units 61a515125bSLeila Ghaffari 62a515125bSLeila Ghaffari // ------------------------------------------------------ 63a515125bSLeila Ghaffari // Command line Options 64a515125bSLeila Ghaffari // ------------------------------------------------------ 651485969bSJeremy L Thompson PetscOptionsBegin(comm, NULL, "Options for EULER_VORTEX problem", NULL); 66a515125bSLeila Ghaffari // -- Physics 672b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-vortex_strength", "Strength of Vortex", NULL, vortex_strength, &vortex_strength, NULL)); 68a515125bSLeila Ghaffari PetscInt n = problem->dim; 69a515125bSLeila Ghaffari PetscBool user_velocity; 702b916ea7SJeremy L Thompson PetscCall(PetscOptionsRealArray("-mean_velocity", "Background velocity vector", NULL, mean_velocity, &n, &user_velocity)); 71493642f1SJames Wright for (PetscInt i = 0; i < 3; i++) center[i] = .5 * domain_size[i]; 72a515125bSLeila Ghaffari n = problem->dim; 732b916ea7SJeremy L Thompson PetscCall(PetscOptionsRealArray("-center", "Location of vortex center", NULL, center, &n, NULL)); 742b916ea7SJeremy L Thompson PetscCall(PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", NULL, implicit = PETSC_FALSE, &implicit, NULL)); 752b916ea7SJeremy L Thompson PetscCall(PetscOptionsEnum("-euler_test", "Euler test option", NULL, EulerTestTypes, (PetscEnum)(euler_test = EULER_TEST_ISENTROPIC_VORTEX), 762b916ea7SJeremy L Thompson (PetscEnum *)&euler_test, NULL)); 772b916ea7SJeremy L Thompson PetscCall(PetscOptionsEnum("-stab", "Stabilization method", NULL, StabilizationTypes, (PetscEnum)(stab = STAB_NONE), (PetscEnum *)&stab, NULL)); 782b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-c_tau", "Stabilization constant", NULL, c_tau, &c_tau, NULL)); 79a515125bSLeila Ghaffari // -- Units 802b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, meter, &meter, NULL)); 81a515125bSLeila Ghaffari meter = fabs(meter); 822b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, second, &second, NULL)); 83a515125bSLeila Ghaffari second = fabs(second); 84a515125bSLeila Ghaffari 85a515125bSLeila Ghaffari // -- Warnings 86139613f2SLeila Ghaffari if (stab == STAB_SUPG && !implicit) { 872b916ea7SJeremy L Thompson PetscCall(PetscPrintf(comm, "Warning! Use -stab supg only with -implicit\n")); 88139613f2SLeila Ghaffari } 892b916ea7SJeremy L Thompson if (user_velocity && (euler_test == EULER_TEST_1 || euler_test == EULER_TEST_3)) { 902b916ea7SJeremy L Thompson PetscCall(PetscPrintf(comm, "Warning! Background velocity vector for -euler_test t1 and -euler_test t3 is (0,0,0)\n")); 91a515125bSLeila Ghaffari } 92a515125bSLeila Ghaffari 931485969bSJeremy L Thompson PetscOptionsEnd(); 94a515125bSLeila Ghaffari 95a515125bSLeila Ghaffari // ------------------------------------------------------ 96a515125bSLeila Ghaffari // Set up the PETSc context 97a515125bSLeila Ghaffari // ------------------------------------------------------ 98a515125bSLeila Ghaffari user->units->meter = meter; 99a515125bSLeila Ghaffari user->units->second = second; 100a515125bSLeila Ghaffari 101a515125bSLeila Ghaffari // ------------------------------------------------------ 102a515125bSLeila Ghaffari // Set up the libCEED context 103a515125bSLeila Ghaffari // ------------------------------------------------------ 104a515125bSLeila Ghaffari // -- Scale variables to desired units 105493642f1SJames Wright for (PetscInt i = 0; i < 3; i++) { 1063b451b28SLeila Ghaffari center[i] *= meter; 10705a512bdSLeila Ghaffari domain_size[i] *= meter; 10805a512bdSLeila Ghaffari mean_velocity[i] *= (meter / second); 1093b451b28SLeila Ghaffari } 11005a512bdSLeila Ghaffari problem->dm_scale = meter; 111a515125bSLeila Ghaffari 112a515125bSLeila Ghaffari // -- QFunction Context 113a515125bSLeila Ghaffari user->phys->implicit = implicit; 11415a3537eSJed Brown euler_ctx->curr_time = 0.; 11515a3537eSJed Brown euler_ctx->implicit = implicit; 11615a3537eSJed Brown euler_ctx->euler_test = euler_test; 11715a3537eSJed Brown euler_ctx->center[0] = center[0]; 11815a3537eSJed Brown euler_ctx->center[1] = center[1]; 11915a3537eSJed Brown euler_ctx->center[2] = center[2]; 12015a3537eSJed Brown euler_ctx->vortex_strength = vortex_strength; 12115a3537eSJed Brown euler_ctx->c_tau = c_tau; 12215a3537eSJed Brown euler_ctx->mean_velocity[0] = mean_velocity[0]; 12315a3537eSJed Brown euler_ctx->mean_velocity[1] = mean_velocity[1]; 12415a3537eSJed Brown euler_ctx->mean_velocity[2] = mean_velocity[2]; 12515a3537eSJed Brown euler_ctx->stabilization = stab; 126a515125bSLeila Ghaffari 127b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &euler_context)); 128b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetData(euler_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*euler_ctx), euler_ctx)); 129b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(euler_context, CEED_MEM_HOST, FreeContextPetsc)); 130b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(euler_context, "solution time", offsetof(struct EulerContext_, curr_time), 1, 131b4c37c5cSJames Wright "Physical time of the solution")); 132b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->ics.qfunction_context)); 133b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_rhs.qfunction_context)); 134b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_ifunction.qfunction_context)); 135b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_inflow.qfunction_context)); 136b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_outflow.qfunction_context)); 13719e95c73SJames Wright PetscCallCeed(ceed, CeedQFunctionContextDestroy(&euler_context)); 138d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 139a515125bSLeila Ghaffari } 140a515125bSLeila Ghaffari 141991aef52SJames Wright PetscErrorCode PRINT_EULER_VORTEX(User user, ProblemData problem, AppCtx app_ctx) { 1422d49c0afSJames Wright MPI_Comm comm = user->comm; 143b4c37c5cSJames Wright Ceed ceed = user->ceed; 14415a3537eSJed Brown EulerContext euler_ctx; 145a515125bSLeila Ghaffari 14615a3537eSJed Brown PetscFunctionBeginUser; 147b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &euler_ctx)); 1482b916ea7SJeremy L Thompson PetscCall(PetscPrintf(comm, 149a515125bSLeila Ghaffari " Problem:\n" 150a515125bSLeila Ghaffari " Problem Name : %s\n" 151a515125bSLeila Ghaffari " Test Case : %s\n" 152139613f2SLeila Ghaffari " Background Velocity : %f,%f,%f\n" 153139613f2SLeila Ghaffari " Stabilization : %s\n", 1542b916ea7SJeremy L Thompson app_ctx->problem_name, EulerTestTypes[euler_ctx->euler_test], euler_ctx->mean_velocity[0], euler_ctx->mean_velocity[1], 1552b916ea7SJeremy L Thompson euler_ctx->mean_velocity[2], StabilizationTypes[euler_ctx->stabilization])); 156a515125bSLeila Ghaffari 157b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &euler_ctx)); 158d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 159a515125bSLeila Ghaffari } 160