xref: /libCEED/examples/fluids/qfunctions/stg_shur14.h (revision e8b03feea03d6d78c8ccc26338cef4a425955b6d)
1ba6664aeSJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2ba6664aeSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3ba6664aeSJames Wright //
4ba6664aeSJames Wright // SPDX-License-Identifier: BSD-2-Clause
5ba6664aeSJames Wright //
6ba6664aeSJames Wright // This file is part of CEED:  http://github.com/ceed
7ba6664aeSJames Wright 
8ba6664aeSJames Wright /// @file
9ba6664aeSJames Wright /// Implementation of the Synthetic Turbulence Generation (STG) algorithm
10ba6664aeSJames Wright /// presented in Shur et al. 2014
11ba6664aeSJames Wright //
12ba6664aeSJames Wright /// SetupSTG_Rand reads in the input files and fills in STGShur14Context. Then
13ba6664aeSJames Wright /// STGShur14_CalcQF is run over quadrature points. Before the program exits,
14ba6664aeSJames Wright /// TearDownSTG is run to free the memory of the allocated arrays.
15ba6664aeSJames Wright 
16ba6664aeSJames Wright #ifndef stg_shur14_h
17ba6664aeSJames Wright #define stg_shur14_h
18ba6664aeSJames Wright 
19ba6664aeSJames Wright #include <math.h>
20ba6664aeSJames Wright #include <ceed.h>
21ba6664aeSJames Wright #include <stdlib.h>
22ba6664aeSJames Wright #include "stg_shur14_type.h"
23ba6664aeSJames Wright 
24ba6664aeSJames Wright #ifndef M_PI
25ba6664aeSJames Wright #define M_PI    3.14159265358979323846
26ba6664aeSJames Wright #endif
27ba6664aeSJames Wright 
28ba6664aeSJames Wright #define STG_NMODES_MAX 1024
29ba6664aeSJames Wright 
30ba6664aeSJames Wright CEED_QFUNCTION_HELPER CeedScalar Max(CeedScalar a, CeedScalar b) { return a < b ? b : a; }
31ba6664aeSJames Wright CEED_QFUNCTION_HELPER CeedScalar Min(CeedScalar a, CeedScalar b) { return a < b ? a : b; }
32ba6664aeSJames Wright 
33ba6664aeSJames Wright /*
34ba6664aeSJames Wright  * @brief Interpolate quantities from input profile to given location
35ba6664aeSJames Wright  *
36ba6664aeSJames Wright  * Assumed that prof_dw[i+1] > prof_dw[i] and prof_dw[0] = 0
37ba6664aeSJames Wright  * If dw > prof_dw[-1], then the interpolation takes the values at prof_dw[-1]
38ba6664aeSJames Wright  *
39ba6664aeSJames Wright  * @param[in]  dw      Distance to the nearest wall
40ba6664aeSJames Wright  * @param[out] ubar    Mean velocity at dw
41ba6664aeSJames Wright  * @param[out] cij     Cholesky decomposition at dw
42ba6664aeSJames Wright  * @param[out] eps     Turbulent dissipation at dw
43ba6664aeSJames Wright  * @param[out] lt      Turbulent length scale at dw
44ba6664aeSJames Wright  * @param[in]  stg_ctx STGShur14Context for the problem
45ba6664aeSJames Wright  */
46ba6664aeSJames Wright CEED_QFUNCTION_HELPER void InterpolateProfile(const CeedScalar dw,
47ba6664aeSJames Wright     CeedScalar ubar[3], CeedScalar cij[6], CeedScalar *eps, CeedScalar *lt,
48ba6664aeSJames Wright     const STGShur14Context stg_ctx) {
49ba6664aeSJames Wright 
50ba6664aeSJames Wright   const CeedInt    nprofs    = stg_ctx->nprofs;
51ba6664aeSJames Wright   const CeedScalar *prof_dw  = &stg_ctx->data[stg_ctx->offsets.prof_dw];
52ba6664aeSJames Wright   const CeedScalar *prof_eps = &stg_ctx->data[stg_ctx->offsets.eps];
53ba6664aeSJames Wright   const CeedScalar *prof_lt  = &stg_ctx->data[stg_ctx->offsets.lt];
54ba6664aeSJames Wright   const CeedScalar *prof_ubar = &stg_ctx->data[stg_ctx->offsets.ubar];
55ba6664aeSJames Wright   const CeedScalar *prof_cij  = &stg_ctx->data[stg_ctx->offsets.cij];
56ba6664aeSJames Wright   CeedInt idx=-1;
57ba6664aeSJames Wright 
58ba6664aeSJames Wright   for(CeedInt i=0; i<nprofs; i++) {
59ba6664aeSJames Wright     if (dw < prof_dw[i]) {
60ba6664aeSJames Wright       idx = i;
61ba6664aeSJames Wright       break;
62ba6664aeSJames Wright     }
63ba6664aeSJames Wright   }
64ba6664aeSJames Wright 
65ba6664aeSJames Wright   if (idx > 0) { // y within the bounds of prof_dw
66ba6664aeSJames Wright     CeedScalar coeff = (dw - prof_dw[idx-1]) / (prof_dw[idx] - prof_dw[idx-1]);
67ba6664aeSJames Wright 
68ba6664aeSJames Wright     //*INDENT-OFF*
69ba6664aeSJames Wright     ubar[0] = prof_ubar[0*nprofs+idx-1] + coeff*( prof_ubar[0*nprofs+idx] - prof_ubar[0*nprofs+idx-1] );
70ba6664aeSJames Wright     ubar[1] = prof_ubar[1*nprofs+idx-1] + coeff*( prof_ubar[1*nprofs+idx] - prof_ubar[1*nprofs+idx-1] );
71ba6664aeSJames Wright     ubar[2] = prof_ubar[2*nprofs+idx-1] + coeff*( prof_ubar[2*nprofs+idx] - prof_ubar[2*nprofs+idx-1] );
72ba6664aeSJames Wright     cij[0]  = prof_cij[0*nprofs+idx-1]  + coeff*( prof_cij[0*nprofs+idx]  - prof_cij[0*nprofs+idx-1] );
73ba6664aeSJames Wright     cij[1]  = prof_cij[1*nprofs+idx-1]  + coeff*( prof_cij[1*nprofs+idx]  - prof_cij[1*nprofs+idx-1] );
74ba6664aeSJames Wright     cij[2]  = prof_cij[2*nprofs+idx-1]  + coeff*( prof_cij[2*nprofs+idx]  - prof_cij[2*nprofs+idx-1] );
75ba6664aeSJames Wright     cij[3]  = prof_cij[3*nprofs+idx-1]  + coeff*( prof_cij[3*nprofs+idx]  - prof_cij[3*nprofs+idx-1] );
76ba6664aeSJames Wright     cij[4]  = prof_cij[4*nprofs+idx-1]  + coeff*( prof_cij[4*nprofs+idx]  - prof_cij[4*nprofs+idx-1] );
77ba6664aeSJames Wright     cij[5]  = prof_cij[5*nprofs+idx-1]  + coeff*( prof_cij[5*nprofs+idx]  - prof_cij[5*nprofs+idx-1] );
78ba6664aeSJames Wright     *eps    = prof_eps[idx-1]           + coeff*( prof_eps[idx]           - prof_eps[idx-1] );
79ba6664aeSJames Wright     *lt     = prof_lt[idx-1]            + coeff*( prof_lt[idx]            - prof_lt[idx-1] );
80ba6664aeSJames Wright     //*INDENT-ON*
81ba6664aeSJames Wright   } else { // y outside bounds of prof_dw
82ba6664aeSJames Wright     ubar[0] = prof_ubar[1*nprofs-1];
83ba6664aeSJames Wright     ubar[1] = prof_ubar[2*nprofs-1];
84ba6664aeSJames Wright     ubar[2] = prof_ubar[3*nprofs-1];
85ba6664aeSJames Wright     cij[0]  = prof_cij[1*nprofs-1];
86ba6664aeSJames Wright     cij[1]  = prof_cij[2*nprofs-1];
87ba6664aeSJames Wright     cij[2]  = prof_cij[3*nprofs-1];
88ba6664aeSJames Wright     cij[3]  = prof_cij[4*nprofs-1];
89ba6664aeSJames Wright     cij[4]  = prof_cij[5*nprofs-1];
90ba6664aeSJames Wright     cij[5]  = prof_cij[6*nprofs-1];
91ba6664aeSJames Wright     *eps    = prof_eps[nprofs-1];
92ba6664aeSJames Wright     *lt     = prof_lt[nprofs-1];
93ba6664aeSJames Wright   }
94ba6664aeSJames Wright }
95ba6664aeSJames Wright 
96ba6664aeSJames Wright /*
97ba6664aeSJames Wright  * @brief Calculate spectrum coefficients for STG
98ba6664aeSJames Wright  *
99ba6664aeSJames Wright  * Calculates q_n at a given distance to the wall
100ba6664aeSJames Wright  *
101ba6664aeSJames Wright  * @param[in]  dw      Distance to the nearest wall
102ba6664aeSJames Wright  * @param[in]  eps     Turbulent dissipation w/rt dw
103ba6664aeSJames Wright  * @param[in]  lt      Turbulent length scale w/rt dw
104ba6664aeSJames Wright  * @param[in]  h       Element lengths in coordinate directions
105ba6664aeSJames Wright  * @param[in]  nu      Dynamic Viscosity;
106ba6664aeSJames Wright  * @param[in]  stg_ctx STGShur14Context for the problem
107ba6664aeSJames Wright  * @param[out] qn      Spectrum coefficients, [nmodes]
108ba6664aeSJames Wright  */
109ba6664aeSJames Wright void CEED_QFUNCTION_HELPER(CalcSpectrum)(const CeedScalar dw,
110ba6664aeSJames Wright     const CeedScalar eps, const CeedScalar lt, const CeedScalar h[3],
111ba6664aeSJames Wright     const CeedScalar nu, CeedScalar qn[], const STGShur14Context stg_ctx) {
112ba6664aeSJames Wright 
113ba6664aeSJames Wright   const CeedInt    nmodes = stg_ctx->nmodes;
114ba6664aeSJames Wright   const CeedScalar *kappa = &stg_ctx->data[stg_ctx->offsets.kappa];
115ba6664aeSJames Wright 
116ba6664aeSJames Wright   const CeedScalar hmax = Max( Max(h[0], h[1]), h[2]);
117ba6664aeSJames Wright   const CeedScalar ke   = 2*M_PI/Min(2*dw, 3*lt);
118ba6664aeSJames Wright   const CeedScalar keta = 2*M_PI*pow(pow(nu,3.0)/eps, -0.25);
119ba6664aeSJames Wright   const CeedScalar kcut =
120ba6664aeSJames Wright     M_PI/ Min( Max(Max(h[1], h[2]), 0.3*hmax) + 0.1*dw, hmax );
121ba6664aeSJames Wright   CeedScalar fcut, feta, Ektot=0.0;
122ba6664aeSJames Wright 
123ba6664aeSJames Wright   for(CeedInt n=0; n<nmodes; n++) {
124ba6664aeSJames Wright     feta   = exp(-Square(12*kappa[n]/keta));
125ba6664aeSJames Wright     fcut   = exp( -pow(4*Max(kappa[n] - 0.9*kcut, 0)/kcut, 3.) );
126ba6664aeSJames Wright     qn[n]  = pow(kappa[n]/ke, 4.)
127ba6664aeSJames Wright              * pow(1 + 2.4*Square(kappa[n]/ke),-17./6)*feta*fcut;
128ba6664aeSJames Wright     qn[n] *= n==0 ? kappa[0] : kappa[n] - kappa[n-1];
129ba6664aeSJames Wright     Ektot += qn[n];
130ba6664aeSJames Wright   }
131ba6664aeSJames Wright 
132961c9c98SJames Wright   if (Ektot == 0) return;
133ba6664aeSJames Wright   for(CeedInt n=0; n<nmodes; n++) qn[n] /= Ektot;
134ba6664aeSJames Wright }
135ba6664aeSJames Wright 
136ba6664aeSJames Wright /******************************************************
137ba6664aeSJames Wright  * @brief Calculate u(x,t) for STG inflow condition
138ba6664aeSJames Wright  *
139ba6664aeSJames Wright  * @param[in]  X       Location to evaluate u(X,t)
140ba6664aeSJames Wright  * @param[in]  t       Time to evaluate u(X,t)
141ba6664aeSJames Wright  * @param[in]  ubar    Mean velocity at X
142ba6664aeSJames Wright  * @param[in]  cij     Cholesky decomposition at X
143ba6664aeSJames Wright  * @param[in]  qn      Wavemode amplitudes at X, [nmodes]
144ba6664aeSJames Wright  * @param[out] u       Velocity at X and t
145ba6664aeSJames Wright  * @param[in]  stg_ctx STGShur14Context for the problem
146ba6664aeSJames Wright  */
147ba6664aeSJames Wright void CEED_QFUNCTION_HELPER(STGShur14_Calc)(const CeedScalar X[3],
148ba6664aeSJames Wright     const CeedScalar t, const CeedScalar ubar[3], const CeedScalar cij[6],
149ba6664aeSJames Wright     const CeedScalar qn[], CeedScalar u[3],
150ba6664aeSJames Wright     const STGShur14Context stg_ctx) {
151ba6664aeSJames Wright 
152ba6664aeSJames Wright   //*INDENT-OFF*
153ba6664aeSJames Wright   const CeedInt    nmodes = stg_ctx->nmodes;
154ba6664aeSJames Wright   const CeedScalar *kappa = &stg_ctx->data[stg_ctx->offsets.kappa];
155ba6664aeSJames Wright   const CeedScalar *phi   = &stg_ctx->data[stg_ctx->offsets.phi];
156ba6664aeSJames Wright   const CeedScalar *sigma = &stg_ctx->data[stg_ctx->offsets.sigma];
157ba6664aeSJames Wright   const CeedScalar *d     = &stg_ctx->data[stg_ctx->offsets.d];
158ba6664aeSJames Wright   //*INDENT-ON*
159ba6664aeSJames Wright   CeedScalar xdotd, vp[3] = {0.};
160ba6664aeSJames Wright   CeedScalar xhat[] = {0., X[1], X[2]};
161ba6664aeSJames Wright 
162ba6664aeSJames Wright   CeedPragmaSIMD
163ba6664aeSJames Wright   for(CeedInt n=0; n<nmodes; n++) {
164ba6664aeSJames Wright     xhat[0] = (X[0] - stg_ctx->u0*t)*Max(2*kappa[0]/kappa[n], 0.1);
165ba6664aeSJames Wright     xdotd = 0.;
166ba6664aeSJames Wright     for(CeedInt i=0; i<3; i++) xdotd += d[i*nmodes+n]*xhat[i];
167ba6664aeSJames Wright     const CeedScalar cos_kxdp = cos(kappa[n]*xdotd + phi[n]);
168961c9c98SJames Wright     vp[0] += sqrt(qn[n])*sigma[0*nmodes+n] * cos_kxdp;
169961c9c98SJames Wright     vp[1] += sqrt(qn[n])*sigma[1*nmodes+n] * cos_kxdp;
170961c9c98SJames Wright     vp[2] += sqrt(qn[n])*sigma[2*nmodes+n] * cos_kxdp;
171ba6664aeSJames Wright   }
172961c9c98SJames Wright   for(CeedInt i=0; i<3; i++) vp[i] *= 2*sqrt(1.5);
173ba6664aeSJames Wright 
174ba6664aeSJames Wright   u[0] = ubar[0] + cij[0]*vp[0];
175ba6664aeSJames Wright   u[1] = ubar[1] + cij[3]*vp[0] + cij[1]*vp[1];
176ba6664aeSJames Wright   u[2] = ubar[2] + cij[4]*vp[0] + cij[5]*vp[1] + cij[2]*vp[2];
177ba6664aeSJames Wright }
178ba6664aeSJames Wright 
179ba6664aeSJames Wright /********************************************************************
180ba6664aeSJames Wright  * @brief QFunction to calculate the inflow boundary condition
181ba6664aeSJames Wright  *
182ba6664aeSJames Wright  * This will loop through quadrature points, calculate the wavemode amplitudes
183ba6664aeSJames Wright  * at each location, then calculate the actual velocity.
184ba6664aeSJames Wright  */
185ba6664aeSJames Wright CEED_QFUNCTION(STGShur14_Inflow)(void *ctx, CeedInt Q,
186ba6664aeSJames Wright                                  const CeedScalar *const *in,
187ba6664aeSJames Wright                                  CeedScalar *const *out) {
188ba6664aeSJames Wright 
189ba6664aeSJames Wright   //*INDENT-OFF*
190ba6664aeSJames Wright   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA]) in[0],
191*e8b03feeSJames Wright                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA]) in[2],
192*e8b03feeSJames Wright                    (*X)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA]) in[3];
193ba6664aeSJames Wright 
194ba6664aeSJames Wright    CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA]) out[0];
195ba6664aeSJames Wright 
196ba6664aeSJames Wright   //*INDENT-ON*
197ba6664aeSJames Wright 
198ba6664aeSJames Wright   const STGShur14Context stg_ctx = (STGShur14Context) ctx;
199ba6664aeSJames Wright   CeedScalar qn[STG_NMODES_MAX], u[3], ubar[3], cij[6], eps, lt;
200ba6664aeSJames Wright   const bool is_implicit  = stg_ctx->is_implicit;
201ba6664aeSJames Wright   const bool mean_only    = stg_ctx->mean_only;
202ba6664aeSJames Wright   const bool prescribe_T  = stg_ctx->prescribe_T;
203ba6664aeSJames Wright   const CeedScalar dx     = stg_ctx->dx;
204ba6664aeSJames Wright   const CeedScalar mu     = stg_ctx->newtonian_ctx.mu;
205ba6664aeSJames Wright   const CeedScalar time   = stg_ctx->time;
206ba6664aeSJames Wright   const CeedScalar theta0 = stg_ctx->theta0;
207ba6664aeSJames Wright   const CeedScalar P0     = stg_ctx->P0;
208ba6664aeSJames Wright   const CeedScalar cv     = stg_ctx->newtonian_ctx.cv;
209ba6664aeSJames Wright   const CeedScalar cp     = stg_ctx->newtonian_ctx.cp;
210ba6664aeSJames Wright   const CeedScalar Rd     = cp - cv;
211ba6664aeSJames Wright   const CeedScalar gamma  = cp/cv;
212ba6664aeSJames Wright 
213ba6664aeSJames Wright   CeedPragmaSIMD
214ba6664aeSJames Wright   for(CeedInt i=0; i<Q; i++) {
215ba6664aeSJames Wright     const CeedScalar rho = prescribe_T ? q[0][i] : P0 / (Rd * theta0);
216ba6664aeSJames Wright     const CeedScalar x[] = { X[0][i], X[1][i], X[2][i] };
217ba6664aeSJames Wright     const CeedScalar dXdx[2][3] = {
218ba6664aeSJames Wright       {q_data_sur[4][i], q_data_sur[5][i], q_data_sur[6][i]},
219ba6664aeSJames Wright       {q_data_sur[7][i], q_data_sur[8][i], q_data_sur[9][i]}
220ba6664aeSJames Wright     };
221ba6664aeSJames Wright 
222ba6664aeSJames Wright     CeedScalar h[3];
223ba6664aeSJames Wright     for (CeedInt j=0; j<3; j++)
224ba6664aeSJames Wright       h[j] = 2/sqrt(dXdx[0][j]*dXdx[0][j] + dXdx[1][j]*dXdx[1][j]);
225ba6664aeSJames Wright     h[0] = dx;
226ba6664aeSJames Wright 
227ba6664aeSJames Wright     InterpolateProfile(X[1][i], ubar, cij, &eps, &lt, stg_ctx);
228ba6664aeSJames Wright     if (!mean_only) {
229ba6664aeSJames Wright       CalcSpectrum(X[1][i], eps, lt, h, mu/rho, qn, stg_ctx);
230ba6664aeSJames Wright       STGShur14_Calc(x, time, ubar, cij, qn, u, stg_ctx);
231ba6664aeSJames Wright     } else {
232ba6664aeSJames Wright       for (CeedInt j=0; j<3; j++) u[j] = ubar[j];
233ba6664aeSJames Wright     }
234ba6664aeSJames Wright 
235ba6664aeSJames Wright     const CeedScalar E_kinetic = .5 * rho * (u[0]*u[0] +
236ba6664aeSJames Wright                                  u[1]*u[1] +
237ba6664aeSJames Wright                                  u[2]*u[2]);
238ba6664aeSJames Wright     CeedScalar E_internal, P;
239ba6664aeSJames Wright     if (prescribe_T) {
240ba6664aeSJames Wright       // Temperature is being set weakly (theta0) and for constant cv this sets E_internal
241ba6664aeSJames Wright       E_internal = rho * cv * theta0;
242ba6664aeSJames Wright       // Find pressure using
243ba6664aeSJames Wright       P = rho * Rd * theta0; // interior rho with exterior T
244ba6664aeSJames Wright     } else {
245ba6664aeSJames Wright       E_internal = q[4][i] - E_kinetic; // uses prescribed rho and u, E from solution
246ba6664aeSJames Wright       P = E_internal * (gamma - 1.);
247ba6664aeSJames Wright     }
248ba6664aeSJames Wright 
249ba6664aeSJames Wright     const CeedScalar wdetJb  = (is_implicit ? -1. : 1.) * q_data_sur[0][i];
250ba6664aeSJames Wright     // ---- Normal vect
251ba6664aeSJames Wright     const CeedScalar norm[3] = {q_data_sur[1][i],
252ba6664aeSJames Wright                                 q_data_sur[2][i],
253ba6664aeSJames Wright                                 q_data_sur[3][i]
254ba6664aeSJames Wright                                };
255ba6664aeSJames Wright 
256ba6664aeSJames Wright     const CeedScalar E = E_internal + E_kinetic;
257ba6664aeSJames Wright 
258ba6664aeSJames Wright     // Velocity normal to the boundary
259ba6664aeSJames Wright     const CeedScalar u_normal = norm[0]*u[0] +
260ba6664aeSJames Wright                                 norm[1]*u[1] +
261ba6664aeSJames Wright                                 norm[2]*u[2];
262ba6664aeSJames Wright     // The Physics
263ba6664aeSJames Wright     // Zero v so all future terms can safely sum into it
264ba6664aeSJames Wright     for (CeedInt j=0; j<5; j++) v[j][i] = 0.;
265ba6664aeSJames Wright 
266ba6664aeSJames Wright     // The Physics
267ba6664aeSJames Wright     // -- Density
268ba6664aeSJames Wright     v[0][i] -= wdetJb * rho * u_normal;
269ba6664aeSJames Wright 
270ba6664aeSJames Wright     // -- Momentum
271ba6664aeSJames Wright     for (CeedInt j=0; j<3; j++)
272ba6664aeSJames Wright       v[j+1][i] -= wdetJb *(rho * u_normal * u[j] +
273ba6664aeSJames Wright                             norm[j] * P);
274ba6664aeSJames Wright 
275ba6664aeSJames Wright     // -- Total Energy Density
276ba6664aeSJames Wright     v[4][i] -= wdetJb * u_normal * (E + P);
277ba6664aeSJames Wright   }
278ba6664aeSJames Wright   return 0;
279ba6664aeSJames Wright }
280ba6664aeSJames Wright 
2814e139266SJames Wright /* Compute boundary integral for strong STG enforcement
2824e139266SJames Wright  *
2834e139266SJames Wright  * This assumes that density is set strongly and temperature is allowed to
2844e139266SJames Wright  * float
2854e139266SJames Wright  */
2864e139266SJames Wright CEED_QFUNCTION(STGShur14_Inflow_Strong)(void *ctx, CeedInt Q,
2874e139266SJames Wright                                         const CeedScalar *const *in,
2884e139266SJames Wright                                         CeedScalar *const *out) {
2894e139266SJames Wright 
2904e139266SJames Wright   //*INDENT-OFF*
2914e139266SJames Wright   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA]) in[0],
292*e8b03feeSJames Wright                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA]) in[2];
2934e139266SJames Wright 
2944e139266SJames Wright   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA]) out[0];
2954e139266SJames Wright 
2964e139266SJames Wright   //*INDENT-ON*
2974e139266SJames Wright 
2984e139266SJames Wright   const STGShur14Context stg_ctx = (STGShur14Context) ctx;
2994e139266SJames Wright   const bool is_implicit  = stg_ctx->is_implicit;
3004e139266SJames Wright   const CeedScalar cv     = stg_ctx->newtonian_ctx.cv;
3014e139266SJames Wright   const CeedScalar cp     = stg_ctx->newtonian_ctx.cp;
3024e139266SJames Wright   const CeedScalar gamma  = cp/cv;
3034e139266SJames Wright 
3044e139266SJames Wright   CeedPragmaSIMD
3054e139266SJames Wright   for(CeedInt i=0; i<Q; i++) {
3064e139266SJames Wright     const CeedScalar rho        = q[0][i];
3074e139266SJames Wright     const CeedScalar u[]        = {q[1][i]/rho, q[2][i]/rho, q[3][i]/rho};
3084e139266SJames Wright     const CeedScalar E_kinetic  = .5 * rho * (u[0]*u[0] + u[1]*u[1] + u[2]*u[2]);
3094e139266SJames Wright     const CeedScalar E_internal = q[4][i] - E_kinetic;
3104e139266SJames Wright     const CeedScalar P          = E_internal * (gamma - 1.);
3114e139266SJames Wright 
3124e139266SJames Wright     const CeedScalar wdetJb  = (is_implicit ? -1. : 1.) * q_data_sur[0][i];
3134e139266SJames Wright     // ---- Normal vect
3144e139266SJames Wright     const CeedScalar norm[3] = {q_data_sur[1][i],
3154e139266SJames Wright                                 q_data_sur[2][i],
3164e139266SJames Wright                                 q_data_sur[3][i]
3174e139266SJames Wright                                };
3184e139266SJames Wright 
3194e139266SJames Wright     const CeedScalar E = E_internal + E_kinetic;
3204e139266SJames Wright 
3214e139266SJames Wright     // Velocity normal to the boundary
3224e139266SJames Wright     const CeedScalar u_normal = norm[0]*u[0] +
3234e139266SJames Wright                                 norm[1]*u[1] +
3244e139266SJames Wright                                 norm[2]*u[2];
3254e139266SJames Wright     // The Physics
3264e139266SJames Wright     // Zero v so all future terms can safely sum into it
3274e139266SJames Wright     for (CeedInt j=0; j<5; j++) v[j][i] = 0.;
3284e139266SJames Wright 
3294e139266SJames Wright     // The Physics
3304e139266SJames Wright     // -- Density
3314e139266SJames Wright     v[0][i] -= wdetJb * rho * u_normal;
3324e139266SJames Wright 
3334e139266SJames Wright     // -- Momentum
3344e139266SJames Wright     for (CeedInt j=0; j<3; j++)
3354e139266SJames Wright       v[j+1][i] -= wdetJb *(rho * u_normal * u[j] +
3364e139266SJames Wright                             norm[j] * P);
3374e139266SJames Wright 
3384e139266SJames Wright     // -- Total Energy Density
3394e139266SJames Wright     v[4][i] -= wdetJb * u_normal * (E + P);
3404e139266SJames Wright   }
3414e139266SJames Wright   return 0;
3424e139266SJames Wright }
343ba6664aeSJames Wright 
344ba6664aeSJames Wright #endif // stg_shur14_h
345