xref: /honee/qfunctions/gaussianwave.h (revision a32db64d340db16914d4892be21e91c50f2a7cbd)
1 // Copyright (c) 2017-2024, 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 /// Thermodynamic wave propogation for testing freestream/non-reflecting boundary conditions. Proposed in Mengaldo et. al. 2014
10 #include <ceed.h>
11 #include <math.h>
12 
13 #include "newtonian_state.h"
14 #include "utils.h"
15 
16 typedef struct GaussianWaveContext_ *GaussianWaveContext;
17 struct GaussianWaveContext_ {
18   CeedScalar                       epicenter[3];  // Location of the perturbation
19   CeedScalar                       width;         // Controls width of the perturbation
20   CeedScalar                       amplitude;     // Amplitude of the perturbation
21   State                            S_infty;       // Flow state at infinity
22   struct NewtonianIdealGasContext_ newt_ctx;
23 };
24 
25 CEED_QFUNCTION_HELPER int IC_GaussianWave(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, StateVariable state_var) {
26   const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
27 
28   CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
29 
30   const GaussianWaveContext      context  = (GaussianWaveContext)ctx;
31   const NewtonianIdealGasContext newt_ctx = &context->newt_ctx;
32 
33   const CeedScalar amplitude = context->amplitude;
34   const CeedScalar width     = context->width;
35   const State      S_infty   = context->S_infty;
36   const CeedScalar xc        = context->epicenter[0];
37   const CeedScalar yc        = context->epicenter[1];
38 
39   const CeedScalar gamma = HeatCapacityRatio(newt_ctx);
40 
41   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
42     CeedScalar       U[5] = {0.}, qi[5] = {0.};
43     const CeedScalar x[3]      = {X[0][i], X[1][i], X[2][i]};
44     const CeedScalar x0        = x[0] - xc;
45     const CeedScalar y0        = x[1] - yc;
46     const CeedScalar e_kinetic = 0.5 * S_infty.U.density * Dot3(S_infty.Y.velocity, S_infty.Y.velocity);
47 
48     const CeedScalar perturbation = 1 + amplitude * exp(-(Square(x0) + Square(y0)) / (2 * Square(width)));
49 
50     U[0] = S_infty.U.density * perturbation;
51     U[1] = S_infty.Y.velocity[0] * U[0];
52     U[2] = S_infty.Y.velocity[1] * U[0];
53     U[3] = S_infty.Y.velocity[2] * U[0];
54     U[4] = S_infty.Y.pressure / (gamma - 1) * perturbation + e_kinetic;
55 
56     State initCond = StateFromU(newt_ctx, U);
57     StateToQ(newt_ctx, initCond, qi, state_var);
58 
59     for (CeedInt j = 0; j < 5; j++) q0[j][i] = qi[j];
60   }
61 
62   return 0;
63 }
64 
65 CEED_QFUNCTION(IC_GaussianWave_Conserv)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
66   return IC_GaussianWave(ctx, Q, in, out, STATEVAR_CONSERVATIVE);
67 }
68 
69 CEED_QFUNCTION(IC_GaussianWave_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
70   return IC_GaussianWave(ctx, Q, in, out, STATEVAR_PRIMITIVE);
71 }
72 
73 CEED_QFUNCTION(IC_GaussianWave_Entropy)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
74   return IC_GaussianWave(ctx, Q, in, out, STATEVAR_ENTROPY);
75 }
76