xref: /honee/qfunctions/stg_shur14.h (revision 9ef62cdd671e63b39574697057ecee188cdbe8df)
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 //
1204e40bb6SJeremy L Thompson /// SetupSTG_Rand reads in the input files and fills in STGShur14Context.
1304e40bb6SJeremy L Thompson /// Then STGShur14_CalcQF is run over quadrature points.
1404e40bb6SJeremy L Thompson /// Before the program exits, 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 <ceed.h>
20d0cce58aSJeremy L Thompson #include <math.h>
21493642f1SJames Wright #include <stdlib.h>
222b916ea7SJeremy L Thompson 
233d65b166SJames Wright #include "newtonian_state.h"
24493642f1SJames Wright #include "stg_shur14_type.h"
25704b8bbeSJames Wright #include "utils.h"
26493642f1SJames Wright 
27493642f1SJames Wright #define STG_NMODES_MAX 1024
28493642f1SJames Wright 
29493642f1SJames Wright /*
30493642f1SJames Wright  * @brief Interpolate quantities from input profile to given location
31493642f1SJames Wright  *
32c77f3192SJames Wright  * Assumed that prof_wd[i+1] > prof_wd[i] and prof_wd[0] = 0
33c77f3192SJames Wright  * If wall_dist > prof_wd[-1], then the interpolation takes the values at prof_wd[-1]
34493642f1SJames Wright  *
35c77f3192SJames Wright  * @param[in]  wall_dist Distance to the nearest wall
36c77f3192SJames Wright  * @param[out] ubar      Mean velocity at wall_dist
37c77f3192SJames Wright  * @param[out] cij       Cholesky decomposition at wall_dist
38c77f3192SJames Wright  * @param[out] eps       Turbulent dissipation at wall_dist
39c77f3192SJames Wright  * @param[out] lt        Turbulent length scale at wall_dist
40493642f1SJames Wright  * @param[in]  stg_ctx   STGShur14Context for the problem
41493642f1SJames Wright  */
422b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void InterpolateProfile(const CeedScalar wall_dist, CeedScalar ubar[3], CeedScalar cij[6], CeedScalar *eps, CeedScalar *lt,
43493642f1SJames Wright                                               const STGShur14Context stg_ctx) {
44493642f1SJames Wright   const CeedInt     nprofs    = stg_ctx->nprofs;
45c77f3192SJames Wright   const CeedScalar *prof_wd   = &stg_ctx->data[stg_ctx->offsets.wall_dist];
46493642f1SJames Wright   const CeedScalar *prof_eps  = &stg_ctx->data[stg_ctx->offsets.eps];
47493642f1SJames Wright   const CeedScalar *prof_lt   = &stg_ctx->data[stg_ctx->offsets.lt];
48493642f1SJames Wright   const CeedScalar *prof_ubar = &stg_ctx->data[stg_ctx->offsets.ubar];
49493642f1SJames Wright   const CeedScalar *prof_cij  = &stg_ctx->data[stg_ctx->offsets.cij];
50493642f1SJames Wright   CeedInt           idx       = -1;
51493642f1SJames Wright 
52493642f1SJames Wright   for (CeedInt i = 0; i < nprofs; i++) {
53c77f3192SJames Wright     if (wall_dist < prof_wd[i]) {
54493642f1SJames Wright       idx = i;
55493642f1SJames Wright       break;
56493642f1SJames Wright     }
57493642f1SJames Wright   }
58493642f1SJames Wright 
59c77f3192SJames Wright   if (idx > 0) {  // y within the bounds of prof_wd
60c77f3192SJames Wright     CeedScalar coeff = (wall_dist - prof_wd[idx - 1]) / (prof_wd[idx] - prof_wd[idx - 1]);
61c77f3192SJames Wright 
62493642f1SJames Wright     ubar[0] = prof_ubar[0 * nprofs + idx - 1] + coeff * (prof_ubar[0 * nprofs + idx] - prof_ubar[0 * nprofs + idx - 1]);
63493642f1SJames Wright     ubar[1] = prof_ubar[1 * nprofs + idx - 1] + coeff * (prof_ubar[1 * nprofs + idx] - prof_ubar[1 * nprofs + idx - 1]);
64493642f1SJames Wright     ubar[2] = prof_ubar[2 * nprofs + idx - 1] + coeff * (prof_ubar[2 * nprofs + idx] - prof_ubar[2 * nprofs + idx - 1]);
65493642f1SJames Wright     cij[0]  = prof_cij[0 * nprofs + idx - 1] + coeff * (prof_cij[0 * nprofs + idx] - prof_cij[0 * nprofs + idx - 1]);
66493642f1SJames Wright     cij[1]  = prof_cij[1 * nprofs + idx - 1] + coeff * (prof_cij[1 * nprofs + idx] - prof_cij[1 * nprofs + idx - 1]);
67493642f1SJames Wright     cij[2]  = prof_cij[2 * nprofs + idx - 1] + coeff * (prof_cij[2 * nprofs + idx] - prof_cij[2 * nprofs + idx - 1]);
68493642f1SJames Wright     cij[3]  = prof_cij[3 * nprofs + idx - 1] + coeff * (prof_cij[3 * nprofs + idx] - prof_cij[3 * nprofs + idx - 1]);
69493642f1SJames Wright     cij[4]  = prof_cij[4 * nprofs + idx - 1] + coeff * (prof_cij[4 * nprofs + idx] - prof_cij[4 * nprofs + idx - 1]);
70493642f1SJames Wright     cij[5]  = prof_cij[5 * nprofs + idx - 1] + coeff * (prof_cij[5 * nprofs + idx] - prof_cij[5 * nprofs + idx - 1]);
71493642f1SJames Wright     *eps    = prof_eps[idx - 1] + coeff * (prof_eps[idx] - prof_eps[idx - 1]);
72493642f1SJames Wright     *lt     = prof_lt[idx - 1] + coeff * (prof_lt[idx] - prof_lt[idx - 1]);
73c77f3192SJames Wright   } else {  // y outside bounds of prof_wd
74493642f1SJames Wright     ubar[0] = prof_ubar[1 * nprofs - 1];
75493642f1SJames Wright     ubar[1] = prof_ubar[2 * nprofs - 1];
76493642f1SJames Wright     ubar[2] = prof_ubar[3 * nprofs - 1];
77493642f1SJames Wright     cij[0]  = prof_cij[1 * nprofs - 1];
78493642f1SJames Wright     cij[1]  = prof_cij[2 * nprofs - 1];
79493642f1SJames Wright     cij[2]  = prof_cij[3 * nprofs - 1];
80493642f1SJames Wright     cij[3]  = prof_cij[4 * nprofs - 1];
81493642f1SJames Wright     cij[4]  = prof_cij[5 * nprofs - 1];
82493642f1SJames Wright     cij[5]  = prof_cij[6 * nprofs - 1];
83493642f1SJames Wright     *eps    = prof_eps[nprofs - 1];
84493642f1SJames Wright     *lt     = prof_lt[nprofs - 1];
85493642f1SJames Wright   }
86493642f1SJames Wright }
87493642f1SJames Wright 
88493642f1SJames Wright /*
8971cd6200SJames Wright  * @brief Calculate spectrum coefficient, qn
9071cd6200SJames Wright  *
9171cd6200SJames Wright  * Calculates q_n at a given distance to the wall
9271cd6200SJames Wright  *
9371cd6200SJames Wright  * @param[in]  kappa     nth wavenumber
9471cd6200SJames Wright  * @param[in]  dkappa    Difference between wavenumbers
9571cd6200SJames Wright  * @param[in]  keta      Dissipation wavenumber
9671cd6200SJames Wright  * @param[in]  kcut      Mesh-induced cutoff wavenumber
9771cd6200SJames Wright  * @param[in]  ke        Energy-containing wavenumber
98*9ef62cddSJames Wright  * @param[in]  Ektot_inv Inverse of total turbulent kinetic energy of spectrum
9971cd6200SJames Wright  * @returns    qn        Spectrum coefficient
10071cd6200SJames Wright  */
1012b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar Calc_qn(const CeedScalar kappa, const CeedScalar dkappa, const CeedScalar keta, const CeedScalar kcut,
10270b0cb14SJames Wright                                          const CeedScalar ke, const CeedScalar Ektot_inv) {
1032b916ea7SJeremy L Thompson   const CeedScalar feta_x_fcut = exp(-Square(12 * kappa / keta) - Cube(4 * Max(kappa - 0.9 * kcut, 0) / kcut));
1042b916ea7SJeremy L Thompson   return pow(kappa / ke, 4.) * pow(1 + 2.4 * Square(kappa / ke), -17. / 6) * feta_x_fcut * dkappa * Ektot_inv;
10571cd6200SJames Wright }
10671cd6200SJames Wright 
10771cd6200SJames Wright // Calculate hmax, ke, keta, and kcut
1082b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void SpectrumConstants(const CeedScalar wall_dist, const CeedScalar eps, const CeedScalar lt, const CeedScalar h[3],
1092b916ea7SJeremy L Thompson                                              const CeedScalar nu, CeedScalar *hmax, CeedScalar *ke, CeedScalar *keta, CeedScalar *kcut) {
11071cd6200SJames Wright   *hmax = Max(Max(h[0], h[1]), h[2]);
111c77f3192SJames Wright   *ke   = wall_dist == 0 ? 1e16 : 2 * M_PI / Min(2 * wall_dist, 3 * lt);
11271cd6200SJames Wright   *keta = 2 * M_PI * pow(Cube(nu) / eps, -0.25);
113c77f3192SJames Wright   *kcut = M_PI / Min(Max(Max(h[1], h[2]), 0.3 * (*hmax)) + 0.1 * wall_dist, *hmax);
11471cd6200SJames Wright }
11571cd6200SJames Wright 
11671cd6200SJames Wright /*
117493642f1SJames Wright  * @brief Calculate spectrum coefficients for STG
118493642f1SJames Wright  *
119493642f1SJames Wright  * Calculates q_n at a given distance to the wall
120493642f1SJames Wright  *
121c77f3192SJames Wright  * @param[in]  wall_dist Distance to the nearest wall
122c77f3192SJames Wright  * @param[in]  eps       Turbulent dissipation w/rt wall_dist
123c77f3192SJames Wright  * @param[in]  lt        Turbulent length scale w/rt wall_dist
124493642f1SJames Wright  * @param[in]  h         Element lengths in coordinate directions
125493642f1SJames Wright  * @param[in]  nu        Dynamic Viscosity;
126493642f1SJames Wright  * @param[in]  stg_ctx   STGShur14Context for the problem
127493642f1SJames Wright  * @param[out] qn        Spectrum coefficients, [nmodes]
128493642f1SJames Wright  */
1292b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void CalcSpectrum(const CeedScalar wall_dist, const CeedScalar eps, const CeedScalar lt, const CeedScalar h[3],
130493642f1SJames Wright                                         const CeedScalar nu, CeedScalar qn[], const STGShur14Context stg_ctx) {
131493642f1SJames Wright   const CeedInt     nmodes = stg_ctx->nmodes;
132493642f1SJames Wright   const CeedScalar *kappa  = &stg_ctx->data[stg_ctx->offsets.kappa];
13371cd6200SJames Wright   CeedScalar        hmax, ke, keta, kcut, Ektot = 0.0;
1342b916ea7SJeremy L Thompson 
135c77f3192SJames Wright   SpectrumConstants(wall_dist, eps, lt, h, nu, &hmax, &ke, &keta, &kcut);
136493642f1SJames Wright 
137493642f1SJames Wright   for (CeedInt n = 0; n < nmodes; n++) {
13871cd6200SJames Wright     const CeedScalar dkappa = n == 0 ? kappa[0] : kappa[n] - kappa[n - 1];
13971cd6200SJames Wright     qn[n]                   = Calc_qn(kappa[n], dkappa, keta, kcut, ke, 1.0);
140493642f1SJames Wright     Ektot += qn[n];
141493642f1SJames Wright   }
142493642f1SJames Wright 
1430a8dc919SJames Wright   if (Ektot == 0) return;
144493642f1SJames Wright   for (CeedInt n = 0; n < nmodes; n++) qn[n] /= Ektot;
145493642f1SJames Wright }
146493642f1SJames Wright 
147493642f1SJames Wright /******************************************************
148493642f1SJames Wright  * @brief Calculate u(x,t) for STG inflow condition
149493642f1SJames Wright  *
150493642f1SJames Wright  * @param[in]  X       Location to evaluate u(X,t)
151493642f1SJames Wright  * @param[in]  t       Time to evaluate u(X,t)
152493642f1SJames Wright  * @param[in]  ubar    Mean velocity at X
153493642f1SJames Wright  * @param[in]  cij     Cholesky decomposition at X
154493642f1SJames Wright  * @param[in]  qn      Wavemode amplitudes at X, [nmodes]
155493642f1SJames Wright  * @param[out] u       Velocity at X and t
156493642f1SJames Wright  * @param[in]  stg_ctx STGShur14Context for the problem
157493642f1SJames Wright  */
1582b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void STGShur14_Calc(const CeedScalar X[3], const CeedScalar t, const CeedScalar ubar[3], const CeedScalar cij[6],
1592b916ea7SJeremy L Thompson                                           const CeedScalar qn[], CeedScalar u[3], const STGShur14Context stg_ctx) {
160493642f1SJames Wright   const CeedInt     nmodes = stg_ctx->nmodes;
161493642f1SJames Wright   const CeedScalar *kappa  = &stg_ctx->data[stg_ctx->offsets.kappa];
162493642f1SJames Wright   const CeedScalar *phi    = &stg_ctx->data[stg_ctx->offsets.phi];
163493642f1SJames Wright   const CeedScalar *sigma  = &stg_ctx->data[stg_ctx->offsets.sigma];
164493642f1SJames Wright   const CeedScalar *d      = &stg_ctx->data[stg_ctx->offsets.d];
165493642f1SJames Wright   CeedScalar        xdotd, vp[3] = {0.};
166493642f1SJames Wright   CeedScalar        xhat[] = {0., X[1], X[2]};
167493642f1SJames Wright 
1682b916ea7SJeremy L Thompson   CeedPragmaSIMD for (CeedInt n = 0; n < nmodes; n++) {
169493642f1SJames Wright     xhat[0] = (X[0] - stg_ctx->u0 * t) * Max(2 * kappa[0] / kappa[n], 0.1);
170493642f1SJames Wright     xdotd   = 0.;
171493642f1SJames Wright     for (CeedInt i = 0; i < 3; i++) xdotd += d[i * nmodes + n] * xhat[i];
172493642f1SJames Wright     const CeedScalar cos_kxdp = cos(kappa[n] * xdotd + phi[n]);
1730a8dc919SJames Wright     vp[0] += sqrt(qn[n]) * sigma[0 * nmodes + n] * cos_kxdp;
1740a8dc919SJames Wright     vp[1] += sqrt(qn[n]) * sigma[1 * nmodes + n] * cos_kxdp;
1750a8dc919SJames Wright     vp[2] += sqrt(qn[n]) * sigma[2 * nmodes + n] * cos_kxdp;
176493642f1SJames Wright   }
1770a8dc919SJames Wright   for (CeedInt i = 0; i < 3; i++) vp[i] *= 2 * sqrt(1.5);
178493642f1SJames Wright 
179493642f1SJames Wright   u[0] = ubar[0] + cij[0] * vp[0];
180493642f1SJames Wright   u[1] = ubar[1] + cij[3] * vp[0] + cij[1] * vp[1];
181493642f1SJames Wright   u[2] = ubar[2] + cij[4] * vp[0] + cij[5] * vp[1] + cij[2] * vp[2];
182493642f1SJames Wright }
183493642f1SJames Wright 
1848eea80fcSJames Wright /******************************************************
1858eea80fcSJames Wright  * @brief Calculate u(x,t) for STG inflow condition
1868eea80fcSJames Wright  *
1878eea80fcSJames Wright  * @param[in]  X         Location to evaluate u(X,t)
1888eea80fcSJames Wright  * @param[in]  t         Time to evaluate u(X,t)
1898eea80fcSJames Wright  * @param[in]  ubar      Mean velocity at X
1908eea80fcSJames Wright  * @param[in]  cij       Cholesky decomposition at X
191c77f3192SJames Wright  * @param[in]  Ektot     Total spectrum energy at this location
192c77f3192SJames Wright  * @param[in]  h         Element size in 3 directions
193c77f3192SJames Wright  * @param[in]  wall_dist Distance to closest wall
194c77f3192SJames Wright  * @param[in]  eps       Turbulent dissipation
195c77f3192SJames Wright  * @param[in]  lt        Turbulent length scale
1968eea80fcSJames Wright  * @param[out] u         Velocity at X and t
1978eea80fcSJames Wright  * @param[in]  stg_ctx   STGShur14Context for the problem
1988eea80fcSJames Wright  */
1992b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void STGShur14_Calc_PrecompEktot(const CeedScalar X[3], const CeedScalar t, const CeedScalar ubar[3], const CeedScalar cij[6],
200c77f3192SJames Wright                                                        const CeedScalar Ektot, const CeedScalar h[3], const CeedScalar wall_dist,
2018eea80fcSJames Wright                                                        const CeedScalar eps, const CeedScalar lt, const CeedScalar nu, CeedScalar u[3],
2028eea80fcSJames Wright                                                        const STGShur14Context stg_ctx) {
2038eea80fcSJames Wright   const CeedInt     nmodes = stg_ctx->nmodes;
2048eea80fcSJames Wright   const CeedScalar *kappa  = &stg_ctx->data[stg_ctx->offsets.kappa];
2058eea80fcSJames Wright   const CeedScalar *phi    = &stg_ctx->data[stg_ctx->offsets.phi];
2068eea80fcSJames Wright   const CeedScalar *sigma  = &stg_ctx->data[stg_ctx->offsets.sigma];
2078eea80fcSJames Wright   const CeedScalar *d      = &stg_ctx->data[stg_ctx->offsets.d];
2088eea80fcSJames Wright   CeedScalar        hmax, ke, keta, kcut;
209c77f3192SJames Wright   SpectrumConstants(wall_dist, eps, lt, h, nu, &hmax, &ke, &keta, &kcut);
2108eea80fcSJames Wright   CeedScalar xdotd, vp[3] = {0.};
2118eea80fcSJames Wright   CeedScalar xhat[] = {0., X[1], X[2]};
2128eea80fcSJames Wright 
2132b916ea7SJeremy L Thompson   CeedPragmaSIMD for (CeedInt n = 0; n < nmodes; n++) {
2148eea80fcSJames Wright     xhat[0] = (X[0] - stg_ctx->u0 * t) * Max(2 * kappa[0] / kappa[n], 0.1);
2158eea80fcSJames Wright     xdotd   = 0.;
2168eea80fcSJames Wright     for (CeedInt i = 0; i < 3; i++) xdotd += d[i * nmodes + n] * xhat[i];
2178eea80fcSJames Wright     const CeedScalar cos_kxdp = cos(kappa[n] * xdotd + phi[n]);
2188eea80fcSJames Wright     const CeedScalar dkappa   = n == 0 ? kappa[0] : kappa[n] - kappa[n - 1];
2198eea80fcSJames Wright     const CeedScalar qn       = Calc_qn(kappa[n], dkappa, keta, kcut, ke, Ektot);
2208eea80fcSJames Wright     vp[0] += sqrt(qn) * sigma[0 * nmodes + n] * cos_kxdp;
2218eea80fcSJames Wright     vp[1] += sqrt(qn) * sigma[1 * nmodes + n] * cos_kxdp;
2228eea80fcSJames Wright     vp[2] += sqrt(qn) * sigma[2 * nmodes + n] * cos_kxdp;
2238eea80fcSJames Wright   }
2248eea80fcSJames Wright   for (CeedInt i = 0; i < 3; i++) vp[i] *= 2 * sqrt(1.5);
2258eea80fcSJames Wright 
2268eea80fcSJames Wright   u[0] = ubar[0] + cij[0] * vp[0];
2278eea80fcSJames Wright   u[1] = ubar[1] + cij[3] * vp[0] + cij[1] * vp[1];
2288eea80fcSJames Wright   u[2] = ubar[2] + cij[4] * vp[0] + cij[5] * vp[1] + cij[2] * vp[2];
2298eea80fcSJames Wright }
2308eea80fcSJames Wright 
23170b0cb14SJames Wright // Create preprocessed input for the stg calculation
23270b0cb14SJames Wright //
23370b0cb14SJames Wright // stg_data[0] = 1 / Ektot (inverse of total spectrum energy)
2342b916ea7SJeremy L Thompson CEED_QFUNCTION(Preprocess_STGShur14)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
2353d65b166SJames Wright   const CeedScalar(*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
2363d65b166SJames Wright   const CeedScalar(*x)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[1];
2378eea80fcSJames Wright 
2388eea80fcSJames Wright   CeedScalar(*stg_data) = (CeedScalar(*))out[0];
2398eea80fcSJames Wright 
2408eea80fcSJames Wright   CeedScalar             ubar[3], cij[6], eps, lt;
2418eea80fcSJames Wright   const STGShur14Context stg_ctx = (STGShur14Context)ctx;
2428eea80fcSJames Wright   const CeedScalar       dx      = stg_ctx->dx;
2438eea80fcSJames Wright   const CeedScalar       mu      = stg_ctx->newtonian_ctx.mu;
2448eea80fcSJames Wright   const CeedScalar       theta0  = stg_ctx->theta0;
2458eea80fcSJames Wright   const CeedScalar       P0      = stg_ctx->P0;
2463d65b166SJames Wright   const CeedScalar       Rd      = GasConstant(&stg_ctx->newtonian_ctx);
2478eea80fcSJames Wright   const CeedScalar       rho     = P0 / (Rd * theta0);
2488eea80fcSJames Wright   const CeedScalar       nu      = mu / rho;
2498eea80fcSJames Wright 
2508eea80fcSJames Wright   const CeedInt     nmodes = stg_ctx->nmodes;
2518eea80fcSJames Wright   const CeedScalar *kappa  = &stg_ctx->data[stg_ctx->offsets.kappa];
2529eeef72bSJames Wright   CeedScalar        hmax, ke, keta, kcut;
2538eea80fcSJames Wright 
2542b916ea7SJeremy L Thompson   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
255c77f3192SJames Wright     const CeedScalar wall_dist  = x[1][i];
2568eea80fcSJames Wright     const CeedScalar dXdx[2][3] = {
2578eea80fcSJames Wright         {q_data_sur[4][i], q_data_sur[5][i], q_data_sur[6][i]},
2588eea80fcSJames Wright         {q_data_sur[7][i], q_data_sur[8][i], q_data_sur[9][i]}
2598eea80fcSJames Wright     };
2608eea80fcSJames Wright 
2618eea80fcSJames Wright     CeedScalar h[3];
2628eea80fcSJames Wright     h[0] = dx;
2632b916ea7SJeremy L Thompson     for (CeedInt j = 1; j < 3; j++) h[j] = 2 / sqrt(dXdx[0][j] * dXdx[0][j] + dXdx[1][j] * dXdx[1][j]);
2648eea80fcSJames Wright 
265c77f3192SJames Wright     InterpolateProfile(wall_dist, ubar, cij, &eps, &lt, stg_ctx);
266c77f3192SJames Wright     SpectrumConstants(wall_dist, eps, lt, h, nu, &hmax, &ke, &keta, &kcut);
2678eea80fcSJames Wright 
2688eea80fcSJames Wright     // Calculate total TKE per spectrum
2692f638ed2SJames Wright     CeedScalar Ek_tot = 0;
2702b916ea7SJeremy L Thompson     CeedPragmaSIMD for (CeedInt n = 0; n < nmodes; n++) {
2718eea80fcSJames Wright       const CeedScalar dkappa = n == 0 ? kappa[0] : kappa[n] - kappa[n - 1];
2722f638ed2SJames Wright       Ek_tot += Calc_qn(kappa[n], dkappa, keta, kcut, ke, 1.0);
2738eea80fcSJames Wright     }
2742f638ed2SJames Wright     // avoid underflowed and poorly defined spectrum coefficients
2752f638ed2SJames Wright     stg_data[i] = Ek_tot != 0 ? 1 / Ek_tot : 0;
2768eea80fcSJames Wright   }
2778eea80fcSJames Wright   return 0;
2788eea80fcSJames Wright }
2798eea80fcSJames Wright 
28043bff553SJames Wright // Extrude the STGInflow profile through out the domain for an initial condition
2812b916ea7SJeremy L Thompson CEED_QFUNCTION(ICsSTG)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
28243bff553SJames Wright   // Inputs
2833d65b166SJames Wright   const CeedScalar(*x)[CEED_Q_VLA]    = (const CeedScalar(*)[CEED_Q_VLA])in[0];
2844f0244d1SJeremy L Thompson   const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1];
2853d65b166SJames Wright 
28643bff553SJames Wright   // Outputs
28743bff553SJames Wright   CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
28843bff553SJames Wright 
28943bff553SJames Wright   const STGShur14Context stg_ctx = (STGShur14Context)ctx;
290d4e0f297SJames Wright   CeedScalar             qn[STG_NMODES_MAX], u[3], ubar[3], cij[6], eps, lt;
291d4e0f297SJames Wright   const CeedScalar       dx     = stg_ctx->dx;
292d4e0f297SJames Wright   const CeedScalar       time   = stg_ctx->time;
29343bff553SJames Wright   const CeedScalar       theta0 = stg_ctx->theta0;
29443bff553SJames Wright   const CeedScalar       P0     = stg_ctx->P0;
29543bff553SJames Wright   const CeedScalar       cv     = stg_ctx->newtonian_ctx.cv;
2963d65b166SJames Wright   const CeedScalar       rho    = P0 / (GasConstant(&stg_ctx->newtonian_ctx) * theta0);
2973d65b166SJames Wright   const CeedScalar       nu     = stg_ctx->newtonian_ctx.mu / rho;
29843bff553SJames Wright 
2992b916ea7SJeremy L Thompson   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
300d4e0f297SJames Wright     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
3014f0244d1SJeremy L Thompson     CeedScalar       dXdx[3][3];
3024f0244d1SJeremy L Thompson     {
3034f0244d1SJeremy L Thompson       const CeedScalar J11  = J[0][0][i];
3044f0244d1SJeremy L Thompson       const CeedScalar J21  = J[0][1][i];
3054f0244d1SJeremy L Thompson       const CeedScalar J31  = J[0][2][i];
3064f0244d1SJeremy L Thompson       const CeedScalar J12  = J[1][0][i];
3074f0244d1SJeremy L Thompson       const CeedScalar J22  = J[1][1][i];
3084f0244d1SJeremy L Thompson       const CeedScalar J32  = J[1][2][i];
3094f0244d1SJeremy L Thompson       const CeedScalar J13  = J[2][0][i];
3104f0244d1SJeremy L Thompson       const CeedScalar J23  = J[2][1][i];
3114f0244d1SJeremy L Thompson       const CeedScalar J33  = J[2][2][i];
3124f0244d1SJeremy L Thompson       const CeedScalar A11  = J22 * J33 - J23 * J32;
3134f0244d1SJeremy L Thompson       const CeedScalar A12  = J13 * J32 - J12 * J33;
3144f0244d1SJeremy L Thompson       const CeedScalar A13  = J12 * J23 - J13 * J22;
3154f0244d1SJeremy L Thompson       const CeedScalar A21  = J23 * J31 - J21 * J33;
3164f0244d1SJeremy L Thompson       const CeedScalar A22  = J11 * J33 - J13 * J31;
3174f0244d1SJeremy L Thompson       const CeedScalar A23  = J13 * J21 - J11 * J23;
3184f0244d1SJeremy L Thompson       const CeedScalar A31  = J21 * J32 - J22 * J31;
3194f0244d1SJeremy L Thompson       const CeedScalar A32  = J12 * J31 - J11 * J32;
3204f0244d1SJeremy L Thompson       const CeedScalar A33  = J11 * J22 - J12 * J21;
3214f0244d1SJeremy L Thompson       const CeedScalar detJ = J11 * A11 + J21 * A12 + J31 * A13;
3224f0244d1SJeremy L Thompson 
3234f0244d1SJeremy L Thompson       dXdx[0][0] = A11 / detJ;
3244f0244d1SJeremy L Thompson       dXdx[0][1] = A12 / detJ;
3254f0244d1SJeremy L Thompson       dXdx[0][2] = A13 / detJ;
3264f0244d1SJeremy L Thompson       dXdx[1][0] = A21 / detJ;
3274f0244d1SJeremy L Thompson       dXdx[1][1] = A22 / detJ;
3284f0244d1SJeremy L Thompson       dXdx[1][2] = A23 / detJ;
3294f0244d1SJeremy L Thompson       dXdx[2][0] = A31 / detJ;
3304f0244d1SJeremy L Thompson       dXdx[2][1] = A32 / detJ;
3314f0244d1SJeremy L Thompson       dXdx[2][2] = A33 / detJ;
3324f0244d1SJeremy L Thompson     }
333d4e0f297SJames Wright 
334d4e0f297SJames Wright     CeedScalar h[3];
335d4e0f297SJames Wright     h[0] = dx;
3362b916ea7SJeremy L Thompson     for (CeedInt j = 1; j < 3; j++) h[j] = 2 / sqrt(Square(dXdx[0][j]) + Square(dXdx[1][j]) + Square(dXdx[2][j]));
337d4e0f297SJames Wright 
338d4e0f297SJames Wright     InterpolateProfile(x_i[1], ubar, cij, &eps, &lt, stg_ctx);
339d4e0f297SJames Wright     if (stg_ctx->use_fluctuating_IC) {
3403d65b166SJames Wright       CalcSpectrum(x_i[1], eps, lt, h, nu, qn, stg_ctx);
341d4e0f297SJames Wright       STGShur14_Calc(x_i, time, ubar, cij, qn, u, stg_ctx);
342d4e0f297SJames Wright     } else {
343d4e0f297SJames Wright       for (CeedInt j = 0; j < 3; j++) u[j] = ubar[j];
344d4e0f297SJames Wright     }
34543bff553SJames Wright 
3463636f6a4SJames Wright     switch (stg_ctx->newtonian_ctx.state_var) {
3473636f6a4SJames Wright       case STATEVAR_CONSERVATIVE:
34843bff553SJames Wright         q0[0][i] = rho;
34943bff553SJames Wright         q0[1][i] = u[0] * rho;
35043bff553SJames Wright         q0[2][i] = u[1] * rho;
35143bff553SJames Wright         q0[3][i] = u[2] * rho;
35243bff553SJames Wright         q0[4][i] = rho * (0.5 * Dot3(u, u) + cv * theta0);
3533636f6a4SJames Wright         break;
3543636f6a4SJames Wright 
3553636f6a4SJames Wright       case STATEVAR_PRIMITIVE:
3563636f6a4SJames Wright         q0[0][i] = P0;
3573636f6a4SJames Wright         q0[1][i] = u[0];
3583636f6a4SJames Wright         q0[2][i] = u[1];
3593636f6a4SJames Wright         q0[3][i] = u[2];
3603636f6a4SJames Wright         q0[4][i] = theta0;
3613636f6a4SJames Wright         break;
36288243482SJames Wright     }
36343bff553SJames Wright   }  // End of Quadrature Point Loop
36443bff553SJames Wright   return 0;
36543bff553SJames Wright }
36643bff553SJames Wright 
367493642f1SJames Wright /********************************************************************
368493642f1SJames Wright  * @brief QFunction to calculate the inflow boundary condition
369493642f1SJames Wright  *
370493642f1SJames Wright  * This will loop through quadrature points, calculate the wavemode amplitudes
371493642f1SJames Wright  * at each location, then calculate the actual velocity.
372493642f1SJames Wright  */
3732b916ea7SJeremy L Thompson CEED_QFUNCTION(STGShur14_Inflow)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
3743d65b166SJames Wright   const CeedScalar(*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[0];
3753d65b166SJames Wright   const CeedScalar(*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2];
3763d65b166SJames Wright   const CeedScalar(*X)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[3];
377493642f1SJames Wright 
3783d65b166SJames Wright   CeedScalar(*v)[CEED_Q_VLA]            = (CeedScalar(*)[CEED_Q_VLA])out[0];
3793d65b166SJames Wright   CeedScalar(*jac_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[1];
380493642f1SJames Wright 
381493642f1SJames Wright   const STGShur14Context stg_ctx = (STGShur14Context)ctx;
382493642f1SJames Wright   CeedScalar             qn[STG_NMODES_MAX], u[3], ubar[3], cij[6], eps, lt;
383493642f1SJames Wright   const bool             is_implicit = stg_ctx->is_implicit;
384493642f1SJames Wright   const bool             mean_only   = stg_ctx->mean_only;
385493642f1SJames Wright   const bool             prescribe_T = stg_ctx->prescribe_T;
386493642f1SJames Wright   const CeedScalar       dx          = stg_ctx->dx;
387493642f1SJames Wright   const CeedScalar       mu          = stg_ctx->newtonian_ctx.mu;
388493642f1SJames Wright   const CeedScalar       time        = stg_ctx->time;
389493642f1SJames Wright   const CeedScalar       theta0      = stg_ctx->theta0;
390493642f1SJames Wright   const CeedScalar       P0          = stg_ctx->P0;
391493642f1SJames Wright   const CeedScalar       cv          = stg_ctx->newtonian_ctx.cv;
3923d65b166SJames Wright   const CeedScalar       Rd          = GasConstant(&stg_ctx->newtonian_ctx);
3933d65b166SJames Wright   const CeedScalar       gamma       = HeatCapacityRatio(&stg_ctx->newtonian_ctx);
394493642f1SJames Wright 
3952b916ea7SJeremy L Thompson   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
396493642f1SJames Wright     const CeedScalar rho        = prescribe_T ? q[0][i] : P0 / (Rd * theta0);
397493642f1SJames Wright     const CeedScalar x[]        = {X[0][i], X[1][i], X[2][i]};
398493642f1SJames Wright     const CeedScalar dXdx[2][3] = {
399493642f1SJames Wright         {q_data_sur[4][i], q_data_sur[5][i], q_data_sur[6][i]},
400493642f1SJames Wright         {q_data_sur[7][i], q_data_sur[8][i], q_data_sur[9][i]}
401493642f1SJames Wright     };
402493642f1SJames Wright 
403493642f1SJames Wright     CeedScalar h[3];
404493642f1SJames Wright     h[0] = dx;
4052b916ea7SJeremy L Thompson     for (CeedInt j = 1; j < 3; j++) h[j] = 2 / sqrt(Square(dXdx[0][j]) + Square(dXdx[1][j]));
406493642f1SJames Wright 
407493642f1SJames Wright     InterpolateProfile(X[1][i], ubar, cij, &eps, &lt, stg_ctx);
408493642f1SJames Wright     if (!mean_only) {
409493642f1SJames Wright       CalcSpectrum(X[1][i], eps, lt, h, mu / rho, qn, stg_ctx);
410493642f1SJames Wright       STGShur14_Calc(x, time, ubar, cij, qn, u, stg_ctx);
411493642f1SJames Wright     } else {
412493642f1SJames Wright       for (CeedInt j = 0; j < 3; j++) u[j] = ubar[j];
413493642f1SJames Wright     }
414493642f1SJames Wright 
415a6e8f989SJames Wright     const CeedScalar E_kinetic = .5 * rho * Dot3(u, u);
416493642f1SJames Wright     CeedScalar       E_internal, P;
417493642f1SJames Wright     if (prescribe_T) {
418493642f1SJames Wright       // Temperature is being set weakly (theta0) and for constant cv this sets E_internal
419493642f1SJames Wright       E_internal = rho * cv * theta0;
420493642f1SJames Wright       // Find pressure using
421493642f1SJames Wright       P = rho * Rd * theta0;  // interior rho with exterior T
422493642f1SJames Wright     } else {
423493642f1SJames Wright       E_internal = q[4][i] - E_kinetic;  // uses prescribed rho and u, E from solution
424493642f1SJames Wright       P          = E_internal * (gamma - 1.);
425493642f1SJames Wright     }
426493642f1SJames Wright 
427493642f1SJames Wright     const CeedScalar wdetJb = (is_implicit ? -1. : 1.) * q_data_sur[0][i];
428493642f1SJames Wright     // ---- Normal vect
4292b916ea7SJeremy L Thompson     const CeedScalar norm[3] = {q_data_sur[1][i], q_data_sur[2][i], q_data_sur[3][i]};
430493642f1SJames Wright 
431493642f1SJames Wright     const CeedScalar E = E_internal + E_kinetic;
432493642f1SJames Wright 
433493642f1SJames Wright     // Velocity normal to the boundary
434a6e8f989SJames Wright     const CeedScalar u_normal = Dot3(norm, u);
435a6e8f989SJames Wright 
436493642f1SJames Wright     // The Physics
437493642f1SJames Wright     // Zero v so all future terms can safely sum into it
438493642f1SJames Wright     for (CeedInt j = 0; j < 5; j++) v[j][i] = 0.;
439493642f1SJames Wright 
440493642f1SJames Wright     // The Physics
441493642f1SJames Wright     // -- Density
442493642f1SJames Wright     v[0][i] -= wdetJb * rho * u_normal;
443493642f1SJames Wright 
444493642f1SJames Wright     // -- Momentum
4452b916ea7SJeremy L Thompson     for (CeedInt j = 0; j < 3; j++) v[j + 1][i] -= wdetJb * (rho * u_normal * u[j] + norm[j] * P);
446493642f1SJames Wright 
447493642f1SJames Wright     // -- Total Energy Density
448493642f1SJames Wright     v[4][i] -= wdetJb * u_normal * (E + P);
449a6e8f989SJames Wright 
450a6e8f989SJames Wright     jac_data_sur[0][i] = rho;
451a6e8f989SJames Wright     jac_data_sur[1][i] = u[0];
452a6e8f989SJames Wright     jac_data_sur[2][i] = u[1];
453a6e8f989SJames Wright     jac_data_sur[3][i] = u[2];
454a6e8f989SJames Wright     jac_data_sur[4][i] = E;
455a6e8f989SJames Wright     for (int j = 0; j < 6; j++) jac_data_sur[5 + j][i] = 0.;
456493642f1SJames Wright   }
457493642f1SJames Wright   return 0;
458493642f1SJames Wright }
459493642f1SJames Wright 
4602b916ea7SJeremy L Thompson CEED_QFUNCTION(STGShur14_Inflow_Jacobian)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
461a6e8f989SJames Wright   // Inputs
4623d65b166SJames Wright   const CeedScalar(*dq)[CEED_Q_VLA]           = (const CeedScalar(*)[CEED_Q_VLA])in[0];
4633d65b166SJames Wright   const CeedScalar(*q_data_sur)[CEED_Q_VLA]   = (const CeedScalar(*)[CEED_Q_VLA])in[2];
4643d65b166SJames Wright   const CeedScalar(*jac_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[4];
465a6e8f989SJames Wright   // Outputs
466a6e8f989SJames Wright   CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
4673d65b166SJames Wright 
468a6e8f989SJames Wright   const STGShur14Context stg_ctx  = (STGShur14Context)ctx;
469a6e8f989SJames Wright   const bool             implicit = stg_ctx->is_implicit;
470a6e8f989SJames Wright   const CeedScalar       cv       = stg_ctx->newtonian_ctx.cv;
4713d65b166SJames Wright   const CeedScalar       Rd       = GasConstant(&stg_ctx->newtonian_ctx);
4723d65b166SJames Wright   const CeedScalar       gamma    = HeatCapacityRatio(&stg_ctx->newtonian_ctx);
473a6e8f989SJames Wright 
474a6e8f989SJames Wright   const CeedScalar theta0      = stg_ctx->theta0;
475a6e8f989SJames Wright   const bool       prescribe_T = stg_ctx->prescribe_T;
476a6e8f989SJames Wright 
477a6e8f989SJames Wright   CeedPragmaSIMD
478a6e8f989SJames Wright       // Quadrature Point Loop
479a6e8f989SJames Wright       for (CeedInt i = 0; i < Q; i++) {
480a6e8f989SJames Wright     // Setup
481a6e8f989SJames Wright     // -- Interp-to-Interp q_data
482a6e8f989SJames Wright     // For explicit mode, the surface integral is on the RHS of ODE q_dot = f(q).
483a6e8f989SJames Wright     // For implicit mode, it gets pulled to the LHS of implicit ODE/DAE g(q_dot, q).
484a6e8f989SJames Wright     // We can effect this by swapping the sign on this weight
485a6e8f989SJames Wright     const CeedScalar wdetJb = (implicit ? -1. : 1.) * q_data_sur[0][i];
486a6e8f989SJames Wright 
487a6e8f989SJames Wright     // Calculate inflow values
488a6e8f989SJames Wright     CeedScalar velocity[3];
489a6e8f989SJames Wright     for (CeedInt j = 0; j < 3; j++) velocity[j] = jac_data_sur[5 + j][i];
490a6e8f989SJames Wright 
491a6e8f989SJames Wright     // enabling user to choose between weak T and weak rho inflow
492a6e8f989SJames Wright     CeedScalar drho, dE, dP;
493a6e8f989SJames Wright     if (prescribe_T) {
494a6e8f989SJames Wright       // rho should be from the current solution
495a6e8f989SJames Wright       drho                   = dq[0][i];
496a6e8f989SJames Wright       CeedScalar dE_internal = drho * cv * theta0;
497a6e8f989SJames Wright       CeedScalar dE_kinetic  = .5 * drho * Dot3(velocity, velocity);
498a6e8f989SJames Wright       dE                     = dE_internal + dE_kinetic;
499a6e8f989SJames Wright       dP                     = drho * Rd * theta0;  // interior rho with exterior T
500a6e8f989SJames Wright     } else {                                        // rho specified, E_internal from solution
501a6e8f989SJames Wright       drho = 0;
502a6e8f989SJames Wright       dE   = dq[4][i];
503a6e8f989SJames Wright       dP   = dE * (gamma - 1.);
504a6e8f989SJames Wright     }
5052b916ea7SJeremy L Thompson     const CeedScalar norm[3] = {q_data_sur[1][i], q_data_sur[2][i], q_data_sur[3][i]};
506a6e8f989SJames Wright 
507a6e8f989SJames Wright     const CeedScalar u_normal = Dot3(norm, velocity);
508a6e8f989SJames Wright 
509a6e8f989SJames Wright     v[0][i] = -wdetJb * drho * u_normal;
5102b916ea7SJeremy L Thompson     for (int j = 0; j < 3; j++) v[j + 1][i] = -wdetJb * (drho * u_normal * velocity[j] + norm[j] * dP);
511a6e8f989SJames Wright     v[4][i] = -wdetJb * u_normal * (dE + dP);
512a6e8f989SJames Wright   }  // End Quadrature Point Loop
513a6e8f989SJames Wright   return 0;
514a6e8f989SJames Wright }
515a6e8f989SJames Wright 
516b7190ff7SJames Wright /********************************************************************
517b7190ff7SJames Wright  * @brief QFunction to calculate the strongly enforce inflow BC
518b7190ff7SJames Wright  *
519b7190ff7SJames Wright  * This QF is for the strong application of STG via libCEED (rather than
520b7190ff7SJames Wright  * through the native PETSc `DMAddBoundary` -> `bcFunc` method.
521b7190ff7SJames Wright  */
5222b916ea7SJeremy L Thompson CEED_QFUNCTION(STGShur14_Inflow_StrongQF)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
5233d65b166SJames Wright   const CeedScalar(*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
5243d65b166SJames Wright   const CeedScalar(*coords)[CEED_Q_VLA]     = (const CeedScalar(*)[CEED_Q_VLA])in[1];
5253d65b166SJames Wright   const CeedScalar(*scale)                  = (const CeedScalar(*))in[2];
526*9ef62cddSJames Wright   const CeedScalar(*inv_Ektotal)            = (const CeedScalar(*))in[3];
527b7190ff7SJames Wright 
528b7190ff7SJames Wright   CeedScalar(*bcval)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
529b7190ff7SJames Wright 
530b7190ff7SJames Wright   const STGShur14Context stg_ctx = (STGShur14Context)ctx;
53170b0cb14SJames Wright   CeedScalar             u[3], ubar[3], cij[6], eps, lt;
532b7190ff7SJames Wright   const bool             mean_only = stg_ctx->mean_only;
533b7190ff7SJames Wright   const CeedScalar       dx        = stg_ctx->dx;
534b7190ff7SJames Wright   const CeedScalar       time      = stg_ctx->time;
535b7190ff7SJames Wright   const CeedScalar       theta0    = stg_ctx->theta0;
536b7190ff7SJames Wright   const CeedScalar       P0        = stg_ctx->P0;
5373d65b166SJames Wright   const CeedScalar       rho       = P0 / (GasConstant(&stg_ctx->newtonian_ctx) * theta0);
5383d65b166SJames Wright   const CeedScalar       nu        = stg_ctx->newtonian_ctx.mu / rho;
539b7190ff7SJames Wright 
5402b916ea7SJeremy L Thompson   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
541b7190ff7SJames Wright     const CeedScalar x[]        = {coords[0][i], coords[1][i], coords[2][i]};
542b7190ff7SJames Wright     const CeedScalar dXdx[2][3] = {
543b7190ff7SJames Wright         {q_data_sur[4][i], q_data_sur[5][i], q_data_sur[6][i]},
544b7190ff7SJames Wright         {q_data_sur[7][i], q_data_sur[8][i], q_data_sur[9][i]}
545b7190ff7SJames Wright     };
546b7190ff7SJames Wright 
547b7190ff7SJames Wright     CeedScalar h[3];
548b7190ff7SJames Wright     h[0] = dx;
5492b916ea7SJeremy L Thompson     for (CeedInt j = 1; j < 3; j++) h[j] = 2 / sqrt(Square(dXdx[0][j]) + Square(dXdx[1][j]));
550b7190ff7SJames Wright 
551b7190ff7SJames Wright     InterpolateProfile(coords[1][i], ubar, cij, &eps, &lt, stg_ctx);
552b7190ff7SJames Wright     if (!mean_only) {
55370b0cb14SJames Wright       if (1) {
554*9ef62cddSJames Wright         STGShur14_Calc_PrecompEktot(x, time, ubar, cij, inv_Ektotal[i], h, x[1], eps, lt, nu, u, stg_ctx);
55570b0cb14SJames Wright       } else {  // Original way
55670b0cb14SJames Wright         CeedScalar qn[STG_NMODES_MAX];
5573d65b166SJames Wright         CalcSpectrum(coords[1][i], eps, lt, h, nu, qn, stg_ctx);
55870b0cb14SJames Wright         STGShur14_Calc(x, time, ubar, cij, qn, u, stg_ctx);
55970b0cb14SJames Wright       }
560b7190ff7SJames Wright     } else {
561b7190ff7SJames Wright       for (CeedInt j = 0; j < 3; j++) u[j] = ubar[j];
562b7190ff7SJames Wright     }
563b7190ff7SJames Wright 
5643636f6a4SJames Wright     switch (stg_ctx->newtonian_ctx.state_var) {
5653636f6a4SJames Wright       case STATEVAR_CONSERVATIVE:
566b7190ff7SJames Wright         bcval[0][i] = scale[i] * rho;
567b7190ff7SJames Wright         bcval[1][i] = scale[i] * rho * u[0];
568b7190ff7SJames Wright         bcval[2][i] = scale[i] * rho * u[1];
569b7190ff7SJames Wright         bcval[3][i] = scale[i] * rho * u[2];
57066531c8bSJames Wright         bcval[4][i] = 0.;
5713636f6a4SJames Wright         break;
5723636f6a4SJames Wright 
5733636f6a4SJames Wright       case STATEVAR_PRIMITIVE:
5743636f6a4SJames Wright         bcval[0][i] = 0;
5753636f6a4SJames Wright         bcval[1][i] = scale[i] * u[0];
5763636f6a4SJames Wright         bcval[2][i] = scale[i] * u[1];
5773636f6a4SJames Wright         bcval[3][i] = scale[i] * u[2];
5783636f6a4SJames Wright         bcval[4][i] = scale[i] * theta0;
5793636f6a4SJames Wright         break;
580b7190ff7SJames Wright     }
58188243482SJames Wright   }
582b7190ff7SJames Wright   return 0;
583b7190ff7SJames Wright }
584b7190ff7SJames Wright 
585493642f1SJames Wright #endif  // stg_shur14_h
586