xref: /honee/qfunctions/stg_shur14.h (revision 0a8dc919752e430e44133d22a954b6dfe4bd42c8)
1493642f1SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2493642f1SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3493642f1SJames Wright //
4493642f1SJames Wright // SPDX-License-Identifier: BSD-2-Clause
5493642f1SJames Wright //
6493642f1SJames Wright // This file is part of CEED:  http://github.com/ceed
7493642f1SJames Wright 
8493642f1SJames Wright /// @file
9493642f1SJames Wright /// Implementation of the Synthetic Turbulence Generation (STG) algorithm
10493642f1SJames Wright /// presented in Shur et al. 2014
11493642f1SJames Wright //
12493642f1SJames Wright /// SetupSTG_Rand reads in the input files and fills in STGShur14Context. Then
13493642f1SJames Wright /// STGShur14_CalcQF is run over quadrature points. Before the program exits,
14493642f1SJames Wright /// TearDownSTG is run to free the memory of the allocated arrays.
15493642f1SJames Wright 
16493642f1SJames Wright #ifndef stg_shur14_h
17493642f1SJames Wright #define stg_shur14_h
18493642f1SJames Wright 
19493642f1SJames Wright #include <math.h>
20493642f1SJames Wright #include <ceed.h>
21493642f1SJames Wright #include <stdlib.h>
22493642f1SJames Wright #include "stg_shur14_type.h"
23493642f1SJames Wright 
24493642f1SJames Wright #ifndef M_PI
25493642f1SJames Wright #define M_PI    3.14159265358979323846
26493642f1SJames Wright #endif
27493642f1SJames Wright 
28493642f1SJames Wright #define STG_NMODES_MAX 1024
29493642f1SJames Wright 
30493642f1SJames Wright CEED_QFUNCTION_HELPER CeedScalar Max(CeedScalar a, CeedScalar b) { return a < b ? b : a; }
31493642f1SJames Wright CEED_QFUNCTION_HELPER CeedScalar Min(CeedScalar a, CeedScalar b) { return a < b ? a : b; }
32493642f1SJames Wright 
33493642f1SJames Wright /*
34493642f1SJames Wright  * @brief Interpolate quantities from input profile to given location
35493642f1SJames Wright  *
36493642f1SJames Wright  * Assumed that prof_dw[i+1] > prof_dw[i] and prof_dw[0] = 0
37493642f1SJames Wright  * If dw > prof_dw[-1], then the interpolation takes the values at prof_dw[-1]
38493642f1SJames Wright  *
39493642f1SJames Wright  * @param[in]  dw      Distance to the nearest wall
40493642f1SJames Wright  * @param[out] ubar    Mean velocity at dw
41493642f1SJames Wright  * @param[out] cij     Cholesky decomposition at dw
42493642f1SJames Wright  * @param[out] eps     Turbulent dissipation at dw
43493642f1SJames Wright  * @param[out] lt      Turbulent length scale at dw
44493642f1SJames Wright  * @param[in]  stg_ctx STGShur14Context for the problem
45493642f1SJames Wright  */
46493642f1SJames Wright CEED_QFUNCTION_HELPER void InterpolateProfile(const CeedScalar dw,
47493642f1SJames Wright     CeedScalar ubar[3], CeedScalar cij[6], CeedScalar *eps, CeedScalar *lt,
48493642f1SJames Wright     const STGShur14Context stg_ctx) {
49493642f1SJames Wright 
50493642f1SJames Wright   const CeedInt    nprofs    = stg_ctx->nprofs;
51493642f1SJames Wright   const CeedScalar *prof_dw  = &stg_ctx->data[stg_ctx->offsets.prof_dw];
52493642f1SJames Wright   const CeedScalar *prof_eps = &stg_ctx->data[stg_ctx->offsets.eps];
53493642f1SJames Wright   const CeedScalar *prof_lt  = &stg_ctx->data[stg_ctx->offsets.lt];
54493642f1SJames Wright   const CeedScalar *prof_ubar = &stg_ctx->data[stg_ctx->offsets.ubar];
55493642f1SJames Wright   const CeedScalar *prof_cij  = &stg_ctx->data[stg_ctx->offsets.cij];
56493642f1SJames Wright   CeedInt idx=-1;
57493642f1SJames Wright 
58493642f1SJames Wright   for(CeedInt i=0; i<nprofs; i++) {
59493642f1SJames Wright     if (dw < prof_dw[i]) {
60493642f1SJames Wright       idx = i;
61493642f1SJames Wright       break;
62493642f1SJames Wright     }
63493642f1SJames Wright   }
64493642f1SJames Wright 
65493642f1SJames Wright   if (idx > 0) { // y within the bounds of prof_dw
66493642f1SJames Wright     CeedScalar coeff = (dw - prof_dw[idx-1]) / (prof_dw[idx] - prof_dw[idx-1]);
67493642f1SJames Wright 
68493642f1SJames Wright     //*INDENT-OFF*
69493642f1SJames Wright     ubar[0] = prof_ubar[0*nprofs+idx-1] + coeff*( prof_ubar[0*nprofs+idx] - prof_ubar[0*nprofs+idx-1] );
70493642f1SJames Wright     ubar[1] = prof_ubar[1*nprofs+idx-1] + coeff*( prof_ubar[1*nprofs+idx] - prof_ubar[1*nprofs+idx-1] );
71493642f1SJames Wright     ubar[2] = prof_ubar[2*nprofs+idx-1] + coeff*( prof_ubar[2*nprofs+idx] - prof_ubar[2*nprofs+idx-1] );
72493642f1SJames Wright     cij[0]  = prof_cij[0*nprofs+idx-1]  + coeff*( prof_cij[0*nprofs+idx]  - prof_cij[0*nprofs+idx-1] );
73493642f1SJames Wright     cij[1]  = prof_cij[1*nprofs+idx-1]  + coeff*( prof_cij[1*nprofs+idx]  - prof_cij[1*nprofs+idx-1] );
74493642f1SJames Wright     cij[2]  = prof_cij[2*nprofs+idx-1]  + coeff*( prof_cij[2*nprofs+idx]  - prof_cij[2*nprofs+idx-1] );
75493642f1SJames Wright     cij[3]  = prof_cij[3*nprofs+idx-1]  + coeff*( prof_cij[3*nprofs+idx]  - prof_cij[3*nprofs+idx-1] );
76493642f1SJames Wright     cij[4]  = prof_cij[4*nprofs+idx-1]  + coeff*( prof_cij[4*nprofs+idx]  - prof_cij[4*nprofs+idx-1] );
77493642f1SJames Wright     cij[5]  = prof_cij[5*nprofs+idx-1]  + coeff*( prof_cij[5*nprofs+idx]  - prof_cij[5*nprofs+idx-1] );
78493642f1SJames Wright     *eps    = prof_eps[idx-1]           + coeff*( prof_eps[idx]           - prof_eps[idx-1] );
79493642f1SJames Wright     *lt     = prof_lt[idx-1]            + coeff*( prof_lt[idx]            - prof_lt[idx-1] );
80493642f1SJames Wright     //*INDENT-ON*
81493642f1SJames Wright   } else { // y outside bounds of prof_dw
82493642f1SJames Wright     ubar[0] = prof_ubar[1*nprofs-1];
83493642f1SJames Wright     ubar[1] = prof_ubar[2*nprofs-1];
84493642f1SJames Wright     ubar[2] = prof_ubar[3*nprofs-1];
85493642f1SJames Wright     cij[0]  = prof_cij[1*nprofs-1];
86493642f1SJames Wright     cij[1]  = prof_cij[2*nprofs-1];
87493642f1SJames Wright     cij[2]  = prof_cij[3*nprofs-1];
88493642f1SJames Wright     cij[3]  = prof_cij[4*nprofs-1];
89493642f1SJames Wright     cij[4]  = prof_cij[5*nprofs-1];
90493642f1SJames Wright     cij[5]  = prof_cij[6*nprofs-1];
91493642f1SJames Wright     *eps    = prof_eps[nprofs-1];
92493642f1SJames Wright     *lt     = prof_lt[nprofs-1];
93493642f1SJames Wright   }
94493642f1SJames Wright }
95493642f1SJames Wright 
96493642f1SJames Wright /*
97493642f1SJames Wright  * @brief Calculate spectrum coefficients for STG
98493642f1SJames Wright  *
99493642f1SJames Wright  * Calculates q_n at a given distance to the wall
100493642f1SJames Wright  *
101493642f1SJames Wright  * @param[in]  dw      Distance to the nearest wall
102493642f1SJames Wright  * @param[in]  eps     Turbulent dissipation w/rt dw
103493642f1SJames Wright  * @param[in]  lt      Turbulent length scale w/rt dw
104493642f1SJames Wright  * @param[in]  h       Element lengths in coordinate directions
105493642f1SJames Wright  * @param[in]  nu      Dynamic Viscosity;
106493642f1SJames Wright  * @param[in]  stg_ctx STGShur14Context for the problem
107493642f1SJames Wright  * @param[out] qn      Spectrum coefficients, [nmodes]
108493642f1SJames Wright  */
109493642f1SJames Wright void CEED_QFUNCTION_HELPER(CalcSpectrum)(const CeedScalar dw,
110493642f1SJames Wright     const CeedScalar eps, const CeedScalar lt, const CeedScalar h[3],
111493642f1SJames Wright     const CeedScalar nu, CeedScalar qn[], const STGShur14Context stg_ctx) {
112493642f1SJames Wright 
113493642f1SJames Wright   const CeedInt    nmodes = stg_ctx->nmodes;
114493642f1SJames Wright   const CeedScalar *kappa = &stg_ctx->data[stg_ctx->offsets.kappa];
115493642f1SJames Wright 
116493642f1SJames Wright   const CeedScalar hmax = Max( Max(h[0], h[1]), h[2]);
117493642f1SJames Wright   const CeedScalar ke   = 2*M_PI/Min(2*dw, 3*lt);
118493642f1SJames Wright   const CeedScalar keta = 2*M_PI*pow(pow(nu,3.0)/eps, -0.25);
119493642f1SJames Wright   const CeedScalar kcut =
120493642f1SJames Wright     M_PI/ Min( Max(Max(h[1], h[2]), 0.3*hmax) + 0.1*dw, hmax );
121493642f1SJames Wright   CeedScalar fcut, feta, Ektot=0.0;
122493642f1SJames Wright 
123493642f1SJames Wright   for(CeedInt n=0; n<nmodes; n++) {
124493642f1SJames Wright     feta   = exp(-Square(12*kappa[n]/keta));
125493642f1SJames Wright     fcut   = exp( -pow(4*Max(kappa[n] - 0.9*kcut, 0)/kcut, 3.) );
126493642f1SJames Wright     qn[n]  = pow(kappa[n]/ke, 4.)
127493642f1SJames Wright              * pow(1 + 2.4*Square(kappa[n]/ke),-17./6)*feta*fcut;
128493642f1SJames Wright     qn[n] *= n==0 ? kappa[0] : kappa[n] - kappa[n-1];
129493642f1SJames Wright     Ektot += qn[n];
130493642f1SJames Wright   }
131493642f1SJames Wright 
132*0a8dc919SJames Wright   if (Ektot == 0) return;
133493642f1SJames Wright   for(CeedInt n=0; n<nmodes; n++) qn[n] /= Ektot;
134493642f1SJames Wright }
135493642f1SJames Wright 
136493642f1SJames Wright /******************************************************
137493642f1SJames Wright  * @brief Calculate u(x,t) for STG inflow condition
138493642f1SJames Wright  *
139493642f1SJames Wright  * @param[in]  X       Location to evaluate u(X,t)
140493642f1SJames Wright  * @param[in]  t       Time to evaluate u(X,t)
141493642f1SJames Wright  * @param[in]  ubar    Mean velocity at X
142493642f1SJames Wright  * @param[in]  cij     Cholesky decomposition at X
143493642f1SJames Wright  * @param[in]  qn      Wavemode amplitudes at X, [nmodes]
144493642f1SJames Wright  * @param[out] u       Velocity at X and t
145493642f1SJames Wright  * @param[in]  stg_ctx STGShur14Context for the problem
146493642f1SJames Wright  */
147493642f1SJames Wright void CEED_QFUNCTION_HELPER(STGShur14_Calc)(const CeedScalar X[3],
148493642f1SJames Wright     const CeedScalar t, const CeedScalar ubar[3], const CeedScalar cij[6],
149493642f1SJames Wright     const CeedScalar qn[], CeedScalar u[3],
150493642f1SJames Wright     const STGShur14Context stg_ctx) {
151493642f1SJames Wright 
152493642f1SJames Wright   //*INDENT-OFF*
153493642f1SJames Wright   const CeedInt    nmodes = stg_ctx->nmodes;
154493642f1SJames Wright   const CeedScalar *kappa = &stg_ctx->data[stg_ctx->offsets.kappa];
155493642f1SJames Wright   const CeedScalar *phi   = &stg_ctx->data[stg_ctx->offsets.phi];
156493642f1SJames Wright   const CeedScalar *sigma = &stg_ctx->data[stg_ctx->offsets.sigma];
157493642f1SJames Wright   const CeedScalar *d     = &stg_ctx->data[stg_ctx->offsets.d];
158493642f1SJames Wright   //*INDENT-ON*
159493642f1SJames Wright   CeedScalar xdotd, vp[3] = {0.};
160493642f1SJames Wright   CeedScalar xhat[] = {0., X[1], X[2]};
161493642f1SJames Wright 
162493642f1SJames Wright   CeedPragmaSIMD
163493642f1SJames Wright   for(CeedInt n=0; n<nmodes; n++) {
164493642f1SJames Wright     xhat[0] = (X[0] - stg_ctx->u0*t)*Max(2*kappa[0]/kappa[n], 0.1);
165493642f1SJames Wright     xdotd = 0.;
166493642f1SJames Wright     for(CeedInt i=0; i<3; i++) xdotd += d[i*nmodes+n]*xhat[i];
167493642f1SJames Wright     const CeedScalar cos_kxdp = cos(kappa[n]*xdotd + phi[n]);
168*0a8dc919SJames Wright     vp[0] += sqrt(qn[n])*sigma[0*nmodes+n] * cos_kxdp;
169*0a8dc919SJames Wright     vp[1] += sqrt(qn[n])*sigma[1*nmodes+n] * cos_kxdp;
170*0a8dc919SJames Wright     vp[2] += sqrt(qn[n])*sigma[2*nmodes+n] * cos_kxdp;
171493642f1SJames Wright   }
172*0a8dc919SJames Wright   for(CeedInt i=0; i<3; i++) vp[i] *= 2*sqrt(1.5);
173493642f1SJames Wright 
174493642f1SJames Wright   u[0] = ubar[0] + cij[0]*vp[0];
175493642f1SJames Wright   u[1] = ubar[1] + cij[3]*vp[0] + cij[1]*vp[1];
176493642f1SJames Wright   u[2] = ubar[2] + cij[4]*vp[0] + cij[5]*vp[1] + cij[2]*vp[2];
177493642f1SJames Wright }
178493642f1SJames Wright 
179493642f1SJames Wright /********************************************************************
180493642f1SJames Wright  * @brief QFunction to calculate the inflow boundary condition
181493642f1SJames Wright  *
182493642f1SJames Wright  * This will loop through quadrature points, calculate the wavemode amplitudes
183493642f1SJames Wright  * at each location, then calculate the actual velocity.
184493642f1SJames Wright  */
185493642f1SJames Wright CEED_QFUNCTION(STGShur14_Inflow)(void *ctx, CeedInt Q,
186493642f1SJames Wright                                  const CeedScalar *const *in,
187493642f1SJames Wright                                  CeedScalar *const *out) {
188493642f1SJames Wright 
189493642f1SJames Wright   //*INDENT-OFF*
190493642f1SJames Wright   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA]) in[0],
191493642f1SJames Wright                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA]) in[1],
192493642f1SJames Wright                    (*X)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA]) in[2];
193493642f1SJames Wright 
194493642f1SJames Wright    CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA]) out[0];
195493642f1SJames Wright 
196493642f1SJames Wright   //*INDENT-ON*
197493642f1SJames Wright 
198493642f1SJames Wright   const STGShur14Context stg_ctx = (STGShur14Context) ctx;
199493642f1SJames Wright   CeedScalar qn[STG_NMODES_MAX], u[3], ubar[3], cij[6], eps, lt;
200493642f1SJames Wright   const bool is_implicit  = stg_ctx->is_implicit;
201493642f1SJames Wright   const bool mean_only    = stg_ctx->mean_only;
202493642f1SJames Wright   const bool prescribe_T  = stg_ctx->prescribe_T;
203493642f1SJames Wright   const CeedScalar dx     = stg_ctx->dx;
204493642f1SJames Wright   const CeedScalar mu     = stg_ctx->newtonian_ctx.mu;
205493642f1SJames Wright   const CeedScalar time   = stg_ctx->time;
206493642f1SJames Wright   const CeedScalar theta0 = stg_ctx->theta0;
207493642f1SJames Wright   const CeedScalar P0     = stg_ctx->P0;
208493642f1SJames Wright   const CeedScalar cv     = stg_ctx->newtonian_ctx.cv;
209493642f1SJames Wright   const CeedScalar cp     = stg_ctx->newtonian_ctx.cp;
210493642f1SJames Wright   const CeedScalar Rd     = cp - cv;
211493642f1SJames Wright   const CeedScalar gamma  = cp/cv;
212493642f1SJames Wright 
213493642f1SJames Wright   CeedPragmaSIMD
214493642f1SJames Wright   for(CeedInt i=0; i<Q; i++) {
215493642f1SJames Wright     const CeedScalar rho = prescribe_T ? q[0][i] : P0 / (Rd * theta0);
216493642f1SJames Wright     const CeedScalar x[] = { X[0][i], X[1][i], X[2][i] };
217493642f1SJames Wright     const CeedScalar dXdx[2][3] = {
218493642f1SJames Wright       {q_data_sur[4][i], q_data_sur[5][i], q_data_sur[6][i]},
219493642f1SJames Wright       {q_data_sur[7][i], q_data_sur[8][i], q_data_sur[9][i]}
220493642f1SJames Wright     };
221493642f1SJames Wright 
222493642f1SJames Wright     CeedScalar h[3];
223493642f1SJames Wright     for (CeedInt j=0; j<3; j++)
224493642f1SJames Wright       h[j] = 2/sqrt(dXdx[0][j]*dXdx[0][j] + dXdx[1][j]*dXdx[1][j]);
225493642f1SJames Wright     h[0] = dx;
226493642f1SJames Wright 
227493642f1SJames Wright     InterpolateProfile(X[1][i], ubar, cij, &eps, &lt, stg_ctx);
228493642f1SJames Wright     if (!mean_only) {
229493642f1SJames Wright       CalcSpectrum(X[1][i], eps, lt, h, mu/rho, qn, stg_ctx);
230493642f1SJames Wright       STGShur14_Calc(x, time, ubar, cij, qn, u, stg_ctx);
231493642f1SJames Wright     } else {
232493642f1SJames Wright       for (CeedInt j=0; j<3; j++) u[j] = ubar[j];
233493642f1SJames Wright     }
234493642f1SJames Wright 
235493642f1SJames Wright     const CeedScalar E_kinetic = .5 * rho * (u[0]*u[0] +
236493642f1SJames Wright                                  u[1]*u[1] +
237493642f1SJames Wright                                  u[2]*u[2]);
238493642f1SJames Wright     CeedScalar E_internal, P;
239493642f1SJames Wright     if (prescribe_T) {
240493642f1SJames Wright       // Temperature is being set weakly (theta0) and for constant cv this sets E_internal
241493642f1SJames Wright       E_internal = rho * cv * theta0;
242493642f1SJames Wright       // Find pressure using
243493642f1SJames Wright       P = rho * Rd * theta0; // interior rho with exterior T
244493642f1SJames Wright     } else {
245493642f1SJames Wright       E_internal = q[4][i] - E_kinetic; // uses prescribed rho and u, E from solution
246493642f1SJames Wright       P = E_internal * (gamma - 1.);
247493642f1SJames Wright     }
248493642f1SJames Wright 
249493642f1SJames Wright     const CeedScalar wdetJb  = (is_implicit ? -1. : 1.) * q_data_sur[0][i];
250493642f1SJames Wright     // ---- Normal vect
251493642f1SJames Wright     const CeedScalar norm[3] = {q_data_sur[1][i],
252493642f1SJames Wright                                 q_data_sur[2][i],
253493642f1SJames Wright                                 q_data_sur[3][i]
254493642f1SJames Wright                                };
255493642f1SJames Wright 
256493642f1SJames Wright     const CeedScalar E = E_internal + E_kinetic;
257493642f1SJames Wright 
258493642f1SJames Wright     // Velocity normal to the boundary
259493642f1SJames Wright     const CeedScalar u_normal = norm[0]*u[0] +
260493642f1SJames Wright                                 norm[1]*u[1] +
261493642f1SJames Wright                                 norm[2]*u[2];
262493642f1SJames Wright     // The Physics
263493642f1SJames Wright     // Zero v so all future terms can safely sum into it
264493642f1SJames Wright     for (CeedInt j=0; j<5; j++) v[j][i] = 0.;
265493642f1SJames Wright 
266493642f1SJames Wright     // The Physics
267493642f1SJames Wright     // -- Density
268493642f1SJames Wright     v[0][i] -= wdetJb * rho * u_normal;
269493642f1SJames Wright 
270493642f1SJames Wright     // -- Momentum
271493642f1SJames Wright     for (CeedInt j=0; j<3; j++)
272493642f1SJames Wright       v[j+1][i] -= wdetJb *(rho * u_normal * u[j] +
273493642f1SJames Wright                             norm[j] * P);
274493642f1SJames Wright 
275493642f1SJames Wright     // -- Total Energy Density
276493642f1SJames Wright     v[4][i] -= wdetJb * u_normal * (E + P);
277493642f1SJames Wright   }
278493642f1SJames Wright   return 0;
279493642f1SJames Wright }
280493642f1SJames Wright 
281e6098bcdSJames Wright /* Compute boundary integral for strong STG enforcement
282e6098bcdSJames Wright  *
283e6098bcdSJames Wright  * This assumes that density is set strongly and temperature is allowed to
284e6098bcdSJames Wright  * float
285e6098bcdSJames Wright  */
286e6098bcdSJames Wright CEED_QFUNCTION(STGShur14_Inflow_Strong)(void *ctx, CeedInt Q,
287e6098bcdSJames Wright                                         const CeedScalar *const *in,
288e6098bcdSJames Wright                                         CeedScalar *const *out) {
289e6098bcdSJames Wright 
290e6098bcdSJames Wright   //*INDENT-OFF*
291e6098bcdSJames Wright   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA]) in[0],
292e6098bcdSJames Wright                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA]) in[1];
293e6098bcdSJames Wright 
294e6098bcdSJames Wright   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA]) out[0];
295e6098bcdSJames Wright 
296e6098bcdSJames Wright   //*INDENT-ON*
297e6098bcdSJames Wright 
298e6098bcdSJames Wright   const STGShur14Context stg_ctx = (STGShur14Context) ctx;
299e6098bcdSJames Wright   const bool is_implicit  = stg_ctx->is_implicit;
300e6098bcdSJames Wright   const CeedScalar cv     = stg_ctx->newtonian_ctx.cv;
301e6098bcdSJames Wright   const CeedScalar cp     = stg_ctx->newtonian_ctx.cp;
302e6098bcdSJames Wright   const CeedScalar gamma  = cp/cv;
303e6098bcdSJames Wright 
304e6098bcdSJames Wright   CeedPragmaSIMD
305e6098bcdSJames Wright   for(CeedInt i=0; i<Q; i++) {
306e6098bcdSJames Wright     const CeedScalar rho        = q[0][i];
307e6098bcdSJames Wright     const CeedScalar u[]        = {q[1][i]/rho, q[2][i]/rho, q[3][i]/rho};
308e6098bcdSJames Wright     const CeedScalar E_kinetic  = .5 * rho * (u[0]*u[0] + u[1]*u[1] + u[2]*u[2]);
309e6098bcdSJames Wright     const CeedScalar E_internal = q[4][i] - E_kinetic;
310e6098bcdSJames Wright     const CeedScalar P          = E_internal * (gamma - 1.);
311e6098bcdSJames Wright 
312e6098bcdSJames Wright     const CeedScalar wdetJb  = (is_implicit ? -1. : 1.) * q_data_sur[0][i];
313e6098bcdSJames Wright     // ---- Normal vect
314e6098bcdSJames Wright     const CeedScalar norm[3] = {q_data_sur[1][i],
315e6098bcdSJames Wright                                 q_data_sur[2][i],
316e6098bcdSJames Wright                                 q_data_sur[3][i]
317e6098bcdSJames Wright                                };
318e6098bcdSJames Wright 
319e6098bcdSJames Wright     const CeedScalar E = E_internal + E_kinetic;
320e6098bcdSJames Wright 
321e6098bcdSJames Wright     // Velocity normal to the boundary
322e6098bcdSJames Wright     const CeedScalar u_normal = norm[0]*u[0] +
323e6098bcdSJames Wright                                 norm[1]*u[1] +
324e6098bcdSJames Wright                                 norm[2]*u[2];
325e6098bcdSJames Wright     // The Physics
326e6098bcdSJames Wright     // Zero v so all future terms can safely sum into it
327e6098bcdSJames Wright     for (CeedInt j=0; j<5; j++) v[j][i] = 0.;
328e6098bcdSJames Wright 
329e6098bcdSJames Wright     // The Physics
330e6098bcdSJames Wright     // -- Density
331e6098bcdSJames Wright     v[0][i] -= wdetJb * rho * u_normal;
332e6098bcdSJames Wright 
333e6098bcdSJames Wright     // -- Momentum
334e6098bcdSJames Wright     for (CeedInt j=0; j<3; j++)
335e6098bcdSJames Wright       v[j+1][i] -= wdetJb *(rho * u_normal * u[j] +
336e6098bcdSJames Wright                             norm[j] * P);
337e6098bcdSJames Wright 
338e6098bcdSJames Wright     // -- Total Energy Density
339e6098bcdSJames Wright     v[4][i] -= wdetJb * u_normal * (E + P);
340e6098bcdSJames Wright   }
341e6098bcdSJames Wright   return 0;
342e6098bcdSJames Wright }
343493642f1SJames Wright 
344493642f1SJames Wright #endif // stg_shur14_h
345