1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3 4 /// @file 5 /// Utility functions for setting up Gaussian Wave problem 6 7 #include "../qfunctions/gaussianwave.h" 8 9 #include <ceed.h> 10 #include <petscdm.h> 11 12 #include <navierstokes.h> 13 #include "../qfunctions/bc_freestream_type.h" 14 15 PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData problem, DM dm, void *ctx) { 16 Honee honee = *(Honee *)ctx; 17 MPI_Comm comm = honee->comm; 18 Ceed ceed = honee->ceed; 19 GaussianWaveContext gausswave_ctx; 20 NewtonianIdealGasContext newtonian_ig_ctx; 21 CeedQFunctionContext gausswave_qfctx; 22 23 PetscFunctionBeginUser; 24 PetscCall(NS_NEWTONIAN_IG(problem, dm, ctx)); 25 26 // -- Option Defaults 27 CeedScalar epicenter[3] = {0.}; // m 28 CeedScalar width = 0.002; // m 29 CeedScalar amplitude = 0.1; // - 30 31 PetscOptionsBegin(comm, NULL, "Options for GAUSSIAN_WAVE problem", NULL); 32 PetscInt narray = 3; 33 PetscCall(PetscOptionsScalarArray("-epicenter", "Coordinates of center of wave", NULL, epicenter, &narray, NULL)); 34 PetscCheck(narray == 3, comm, PETSC_ERR_ARG_SIZ, "-epicenter should recieve array of size 3, instead recieved size %" PetscInt_FMT ".", narray); 35 PetscCall(PetscOptionsScalar("-width", "Width parameter for perturbation size", NULL, width, &width, NULL)); 36 PetscCall(PetscOptionsScalar("-amplitude", "Amplitude of the perturbation", NULL, amplitude, &litude, NULL)); 37 PetscOptionsEnd(); 38 39 width *= honee->units->meter; 40 for (int i = 0; i < 3; i++) epicenter[i] *= honee->units->meter; 41 42 // -- Set gausswave_ctx struct values 43 PetscCall(PetscNew(&gausswave_ctx)); 44 PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfctx, CEED_MEM_HOST, &newtonian_ig_ctx)); 45 for (PetscCount b = 0; b < problem->num_bc_defs; b++) { 46 BCDefinition bc_def = problem->bc_defs[b]; 47 HoneeBCStruct honee_bc; 48 const char *name; 49 50 PetscCall(BCDefinitionGetInfo(bc_def, &name, NULL, NULL)); 51 if (!strcmp(name, "freestream")) { 52 FreestreamContext freestream_ctx; 53 PetscCall(BCDefinitionGetContext(bc_def, &honee_bc)); 54 PetscCallCeed(ceed, CeedQFunctionContextGetData(honee_bc->qfctx, CEED_MEM_HOST, &freestream_ctx)); 55 gausswave_ctx->S_infty = freestream_ctx->S_infty; 56 PetscCallCeed(ceed, CeedQFunctionContextRestoreData(honee_bc->qfctx, &freestream_ctx)); 57 break; 58 } 59 } 60 61 gausswave_ctx->amplitude = amplitude; 62 gausswave_ctx->width = width; 63 gausswave_ctx->newt_ctx = *newtonian_ig_ctx; 64 PetscCall(PetscArraycpy(gausswave_ctx->epicenter, epicenter, 3)); 65 66 PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfctx, &newtonian_ig_ctx)); 67 68 PetscCallCeed(ceed, CeedQFunctionContextCreate(honee->ceed, &gausswave_qfctx)); 69 PetscCallCeed(ceed, CeedQFunctionContextSetData(gausswave_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*gausswave_ctx), gausswave_ctx)); 70 PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(gausswave_qfctx, CEED_MEM_HOST, FreeContextPetsc)); 71 PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->ics.qfctx)); 72 73 switch (honee->phys->state_var) { 74 case STATEVAR_CONSERVATIVE: 75 problem->ics = (HoneeQFSpec){.qf_func_ptr = IC_GaussianWave_Conserv, .qf_loc = IC_GaussianWave_Conserv_loc}; 76 break; 77 case STATEVAR_PRIMITIVE: 78 problem->ics = (HoneeQFSpec){.qf_func_ptr = IC_GaussianWave_Prim, .qf_loc = IC_GaussianWave_Prim_loc}; 79 break; 80 case STATEVAR_ENTROPY: 81 problem->ics = (HoneeQFSpec){.qf_func_ptr = IC_GaussianWave_Entropy, .qf_loc = IC_GaussianWave_Entropy_loc}; 82 break; 83 } 84 problem->ics.qfctx = gausswave_qfctx; 85 PetscFunctionReturn(PETSC_SUCCESS); 86 } 87