xref: /libCEED/examples/fluids/qfunctions/newtonian.h (revision 2c4e60d7b04bedb676cede9e08ff45710365b17b)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
388b783a1SJames Wright //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
588b783a1SJames Wright //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
788b783a1SJames Wright 
888b783a1SJames Wright /// @file
988b783a1SJames Wright /// Operator for Navier-Stokes example using PETSc
1088b783a1SJames Wright 
1188b783a1SJames Wright 
1288b783a1SJames Wright #ifndef newtonian_h
1388b783a1SJames Wright #define newtonian_h
1488b783a1SJames Wright 
1588b783a1SJames Wright #include <math.h>
1688b783a1SJames Wright #include <ceed.h>
17841e4c73SJed Brown #include "newtonian_types.h"
18c6e8c570SJames Wright #include "newtonian_state.h"
1988b783a1SJames Wright 
2088b783a1SJames Wright #ifndef M_PI
2188b783a1SJames Wright #define M_PI    3.14159265358979323846
2288b783a1SJames Wright #endif
2388b783a1SJames Wright 
2488b783a1SJames Wright // *****************************************************************************
2588b783a1SJames Wright // Helper function for computing flux Jacobian
2688b783a1SJames Wright // *****************************************************************************
2788b783a1SJames Wright CEED_QFUNCTION_HELPER void computeFluxJacobian_NS(CeedScalar dF[3][5][5],
2888b783a1SJames Wright     const CeedScalar rho, const CeedScalar u[3], const CeedScalar E,
2988626eedSJames Wright     const CeedScalar gamma, const CeedScalar g[3], const CeedScalar x[3]) {
3088b783a1SJames Wright   CeedScalar u_sq = u[0]*u[0] + u[1]*u[1] + u[2]*u[2]; // Velocity square
3188626eedSJames Wright   CeedScalar e_potential = -(g[0]*x[0] + g[1]*x[1] + g[2]*x[2]);
3288b783a1SJames Wright   for (CeedInt i=0; i<3; i++) { // Jacobian matrices for 3 directions
3388b783a1SJames Wright     for (CeedInt j=0; j<3; j++) { // Rows of each Jacobian matrix
3488626eedSJames Wright       dF[i][j+1][0] = ((i==j) ? ((gamma-1.)*(u_sq/2. - e_potential)) : 0.) -
3588626eedSJames Wright                       u[i]*u[j];
3688b783a1SJames Wright       for (CeedInt k=0; k<3; k++) { // Columns of each Jacobian matrix
3788b783a1SJames Wright         dF[i][0][k+1]   = ((i==k) ? 1. : 0.);
3888b783a1SJames Wright         dF[i][j+1][k+1] = ((j==k) ? u[i] : 0.) +
3988b783a1SJames Wright                           ((i==k) ? u[j] : 0.) -
4088b783a1SJames Wright                           ((i==j) ? u[k] : 0.) * (gamma-1.);
4188b783a1SJames Wright         dF[i][4][k+1]   = ((i==k) ? (E*gamma/rho - (gamma-1.)*u_sq/2.) : 0.) -
4288b783a1SJames Wright                           (gamma-1.)*u[i]*u[k];
4388b783a1SJames Wright       }
4488b783a1SJames Wright       dF[i][j+1][4] = ((i==j) ? (gamma-1.) : 0.);
4588b783a1SJames Wright     }
4688b783a1SJames Wright     dF[i][4][0] = u[i] * ((gamma-1.)*u_sq - E*gamma/rho);
4788b783a1SJames Wright     dF[i][4][4] = u[i] * gamma;
4888b783a1SJames Wright   }
4988b783a1SJames Wright }
5088b783a1SJames Wright 
5188b783a1SJames Wright // *****************************************************************************
5288626eedSJames Wright // Helper function for computing flux Jacobian of Primitive variables
5388626eedSJames Wright // *****************************************************************************
5488626eedSJames Wright CEED_QFUNCTION_HELPER void computeFluxJacobian_NSp(CeedScalar dF[3][5][5],
5588626eedSJames Wright     const CeedScalar rho, const CeedScalar u[3], const CeedScalar E,
5688626eedSJames Wright     const CeedScalar Rd, const CeedScalar cv) {
5788626eedSJames Wright   CeedScalar u_sq = u[0]*u[0] + u[1]*u[1] + u[2]*u[2]; // Velocity square
5888626eedSJames Wright   // TODO Add in gravity's contribution
5988626eedSJames Wright 
6088626eedSJames Wright   CeedScalar T    = ( E / rho - u_sq / 2. ) / cv;
6188626eedSJames Wright   CeedScalar drdT = -rho / T;
6288626eedSJames Wright   CeedScalar drdP = 1. / ( Rd * T);
6388626eedSJames Wright   CeedScalar etot =  E / rho ;
6488626eedSJames Wright   CeedScalar e2p  = drdP * etot + 1. ;
6588626eedSJames Wright   CeedScalar e3p  = ( E  + rho * Rd * T );
6688626eedSJames Wright   CeedScalar e4p  = drdT * etot + rho * cv ;
6788626eedSJames Wright 
6888626eedSJames Wright   for (CeedInt i=0; i<3; i++) { // Jacobian matrices for 3 directions
6988626eedSJames Wright     for (CeedInt j=0; j<3; j++) { // j counts F^{m_j}
7088626eedSJames Wright //        [row][col] of A_i
7188626eedSJames Wright       dF[i][j+1][0] = drdP * u[i] * u[j] + ((i==j) ? 1. : 0.); // F^{{m_j} wrt p
7288626eedSJames Wright       for (CeedInt k=0; k<3; k++) { // k counts the wrt vel_k
73871db79fSKenneth E. Jansen         dF[i][0][k+1]   =  ((i==k) ? rho  : 0.);   // F^c wrt u_k
7488626eedSJames Wright         dF[i][j+1][k+1] = (((j==k) ? u[i] : 0.) +  // F^m_j wrt u_k
7588626eedSJames Wright                            ((i==k) ? u[j] : 0.) ) * rho;
7688626eedSJames Wright         dF[i][4][k+1]   = rho * u[i] * u[k]
7788626eedSJames Wright                           + ((i==k) ? e3p  : 0.) ; // F^e wrt u_k
7888626eedSJames Wright       }
7988626eedSJames Wright       dF[i][j+1][4] = drdT * u[i] * u[j]; // F^{m_j} wrt T
8088626eedSJames Wright     }
8188626eedSJames Wright     dF[i][4][0] = u[i] * e2p; // F^e wrt p
8288626eedSJames Wright     dF[i][4][4] = u[i] * e4p; // F^e wrt T
8388626eedSJames Wright     dF[i][0][0] = u[i] * drdP; // F^c wrt p
8488626eedSJames Wright     dF[i][0][4] = u[i] * drdT; // F^c wrt T
8588626eedSJames Wright   }
8688626eedSJames Wright }
8788626eedSJames Wright 
8888626eedSJames Wright CEED_QFUNCTION_HELPER void PrimitiveToConservative_fwd(const CeedScalar rho,
8988626eedSJames Wright     const CeedScalar u[3], const CeedScalar E, const CeedScalar Rd,
9088626eedSJames Wright     const CeedScalar cv, const CeedScalar dY[5], CeedScalar dU[5]) {
9188626eedSJames Wright   CeedScalar u_sq = u[0]*u[0] + u[1]*u[1] + u[2]*u[2];
9288626eedSJames Wright   CeedScalar T    = ( E / rho - u_sq / 2. ) / cv;
9388626eedSJames Wright   CeedScalar drdT = -rho / T;
9488626eedSJames Wright   CeedScalar drdP = 1. / ( Rd * T);
9588626eedSJames Wright   dU[0] = drdP * dY[0] + drdT * dY[4];
9688626eedSJames Wright   CeedScalar de_kinetic = 0;
97ba6664aeSJames Wright   for (CeedInt i=0; i<3; i++) {
9888626eedSJames Wright     dU[1+i] = dU[0] * u[i] + rho * dY[1+i];
9988626eedSJames Wright     de_kinetic += u[i] * dY[1+i];
10088626eedSJames Wright   }
10188626eedSJames Wright   dU[4] = rho * cv * dY[4] + dU[0] * cv * T // internal energy: rho * e
10288626eedSJames Wright           + rho * de_kinetic + .5 * dU[0] * u_sq; // kinetic energy: .5 * rho * |u|^2
10388626eedSJames Wright }
10488626eedSJames Wright 
10588626eedSJames Wright // *****************************************************************************
10688626eedSJames Wright // Helper function for computing Tau elements (stabilization constant)
10788626eedSJames Wright //   Model from:
10888626eedSJames Wright //     PHASTA
10988626eedSJames Wright //
11088626eedSJames Wright //   Tau[i] = itau=0 which is diagonal-Shakib (3 values still but not spatial)
11188626eedSJames Wright //
11288626eedSJames Wright // Where NOT UPDATED YET
11388626eedSJames Wright // *****************************************************************************
11488626eedSJames Wright CEED_QFUNCTION_HELPER void Tau_diagPrim(CeedScalar Tau_d[3],
11588626eedSJames Wright                                         const CeedScalar dXdx[3][3], const CeedScalar u[3],
11688626eedSJames Wright                                         const CeedScalar cv, const NewtonianIdealGasContext newt_ctx,
11788626eedSJames Wright                                         const CeedScalar mu, const CeedScalar dt,
11888626eedSJames Wright                                         const CeedScalar rho) {
11988626eedSJames Wright   // Context
12088626eedSJames Wright   const CeedScalar Ctau_t = newt_ctx->Ctau_t;
12188626eedSJames Wright   const CeedScalar Ctau_v = newt_ctx->Ctau_v;
12288626eedSJames Wright   const CeedScalar Ctau_C = newt_ctx->Ctau_C;
12388626eedSJames Wright   const CeedScalar Ctau_M = newt_ctx->Ctau_M;
12488626eedSJames Wright   const CeedScalar Ctau_E = newt_ctx->Ctau_E;
12588626eedSJames Wright   CeedScalar gijd[6];
12688626eedSJames Wright   CeedScalar tau;
12788626eedSJames Wright   CeedScalar dts;
12888626eedSJames Wright   CeedScalar fact;
12988626eedSJames Wright 
13088626eedSJames Wright   //*INDENT-OFF*
13188626eedSJames Wright   gijd[0] =   dXdx[0][0] * dXdx[0][0]
13288626eedSJames Wright             + dXdx[1][0] * dXdx[1][0]
13388626eedSJames Wright             + dXdx[2][0] * dXdx[2][0];
13488626eedSJames Wright 
13588626eedSJames Wright   gijd[1] =   dXdx[0][0] * dXdx[0][1]
13688626eedSJames Wright             + dXdx[1][0] * dXdx[1][1]
13788626eedSJames Wright             + dXdx[2][0] * dXdx[2][1];
13888626eedSJames Wright 
13988626eedSJames Wright   gijd[2] =   dXdx[0][1] * dXdx[0][1]
14088626eedSJames Wright             + dXdx[1][1] * dXdx[1][1]
14188626eedSJames Wright             + dXdx[2][1] * dXdx[2][1];
14288626eedSJames Wright 
14388626eedSJames Wright   gijd[3] =   dXdx[0][0] * dXdx[0][2]
14488626eedSJames Wright             + dXdx[1][0] * dXdx[1][2]
14588626eedSJames Wright             + dXdx[2][0] * dXdx[2][2];
14688626eedSJames Wright 
14788626eedSJames Wright   gijd[4] =   dXdx[0][1] * dXdx[0][2]
14888626eedSJames Wright             + dXdx[1][1] * dXdx[1][2]
14988626eedSJames Wright             + dXdx[2][1] * dXdx[2][2];
15088626eedSJames Wright 
15188626eedSJames Wright   gijd[5] =   dXdx[0][2] * dXdx[0][2]
15288626eedSJames Wright             + dXdx[1][2] * dXdx[1][2]
15388626eedSJames Wright             + dXdx[2][2] * dXdx[2][2];
15488626eedSJames Wright   //*INDENT-ON*
15588626eedSJames Wright 
15688626eedSJames Wright   dts = Ctau_t / dt ;
15788626eedSJames Wright 
15888626eedSJames Wright   tau = rho*rho*((4. * dts * dts)
15988626eedSJames Wright                  + u[0] * ( u[0] * gijd[0] + 2. * ( u[1] * gijd[1] + u[2] * gijd[3]))
16088626eedSJames Wright                  + u[1] * ( u[1] * gijd[2] + 2. *   u[2] * gijd[4])
16188626eedSJames Wright                  + u[2] *   u[2] * gijd[5])
16288626eedSJames Wright         + Ctau_v* mu * mu *
16388626eedSJames Wright         (gijd[0]*gijd[0] + gijd[2]*gijd[2] + gijd[5]*gijd[5] +
16488626eedSJames Wright          + 2. * (gijd[1]*gijd[1] + gijd[3]*gijd[3] + gijd[4]*gijd[4]));
16588626eedSJames Wright 
16688626eedSJames Wright   fact=sqrt(tau);
16788626eedSJames Wright 
16888626eedSJames Wright   Tau_d[0] = Ctau_C * fact / (rho*(gijd[0] + gijd[2] + gijd[5]))*0.125;
16988626eedSJames Wright 
17088626eedSJames Wright   Tau_d[1] = Ctau_M / fact;
17188626eedSJames Wright   Tau_d[2] = Ctau_E / ( fact * cv );
17288626eedSJames Wright 
17388626eedSJames Wright // consider putting back the way I initially had it  Ctau_E * Tau_d[1] /cv
17488626eedSJames Wright //  to avoid a division if the compiler is smart enough to see that cv IS
17588626eedSJames Wright // a constant that it could invert once for all elements
17688626eedSJames Wright // but in that case energy tau is scaled by the product of Ctau_E * Ctau_M
17788626eedSJames Wright // OR we could absorb cv into Ctau_E but this puts more burden on user to
17888626eedSJames Wright // know how to change constants with a change of fluid or units.  Same for
17988626eedSJames Wright // Ctau_v * mu * mu IF AND ONLY IF we don't add viscosity law =f(T)
18088626eedSJames Wright }
18188626eedSJames Wright 
18288626eedSJames Wright // *****************************************************************************
18388b783a1SJames Wright // This QFunction sets a "still" initial condition for generic Newtonian IG problems
18488b783a1SJames Wright // *****************************************************************************
18588b783a1SJames Wright CEED_QFUNCTION(ICsNewtonianIG)(void *ctx, CeedInt Q,
18688b783a1SJames Wright                                const CeedScalar *const *in, CeedScalar *const *out) {
18788b783a1SJames Wright   // Inputs
18888b783a1SJames Wright   const CeedScalar (*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
18988b783a1SJames Wright 
19088b783a1SJames Wright   // Outputs
19188b783a1SJames Wright   CeedScalar (*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
19288b783a1SJames Wright 
19388626eedSJames Wright   // Context
19488626eedSJames Wright   const SetupContext context = (SetupContext)ctx;
19588626eedSJames Wright   const CeedScalar theta0    = context->theta0;
19688626eedSJames Wright   const CeedScalar P0        = context->P0;
19788626eedSJames Wright   const CeedScalar cv        = context->cv;
19888626eedSJames Wright   const CeedScalar cp        = context->cp;
19988626eedSJames Wright   const CeedScalar *g        = context->g;
20088626eedSJames Wright   const CeedScalar Rd        = cp - cv;
20188626eedSJames Wright 
20288b783a1SJames Wright   // Quadrature Point Loop
20388b783a1SJames Wright   CeedPragmaSIMD
20488b783a1SJames Wright   for (CeedInt i=0; i<Q; i++) {
20588b783a1SJames Wright     CeedScalar q[5] = {0.};
20688b783a1SJames Wright 
20788b783a1SJames Wright     // Setup
20888b783a1SJames Wright     // -- Coordinates
20988626eedSJames Wright     const CeedScalar x[3] = {X[0][i], X[1][i], X[2][i]};
21088626eedSJames Wright     const CeedScalar e_potential = -(g[0]*x[0] + g[1]*x[1] + g[2]*x[2]);
21188b783a1SJames Wright 
21288b783a1SJames Wright     // -- Density
21388626eedSJames Wright     const CeedScalar rho = P0 / (Rd*theta0);
21488b783a1SJames Wright 
21588b783a1SJames Wright     // Initial Conditions
21688b783a1SJames Wright     q[0] = rho;
21788b783a1SJames Wright     q[1] = 0.0;
21888b783a1SJames Wright     q[2] = 0.0;
21988b783a1SJames Wright     q[3] = 0.0;
22088626eedSJames Wright     q[4] = rho * (cv*theta0 + e_potential);
22188b783a1SJames Wright 
22288b783a1SJames Wright     for (CeedInt j=0; j<5; j++)
22388b783a1SJames Wright       q0[j][i] = q[j];
22488b783a1SJames Wright   } // End of Quadrature Point Loop
22588b783a1SJames Wright   return 0;
22688b783a1SJames Wright }
22788b783a1SJames Wright 
22888b783a1SJames Wright // *****************************************************************************
22988b783a1SJames Wright // This QFunction implements the following formulation of Navier-Stokes with
23088b783a1SJames Wright //   explicit time stepping method
23188b783a1SJames Wright //
23288b783a1SJames Wright // This is 3D compressible Navier-Stokes in conservation form with state
23388b783a1SJames Wright //   variables of density, momentum density, and total energy density.
23488b783a1SJames Wright //
23588b783a1SJames Wright // State Variables: q = ( rho, U1, U2, U3, E )
23688b783a1SJames Wright //   rho - Mass Density
23788b783a1SJames Wright //   Ui  - Momentum Density,      Ui = rho ui
23888b783a1SJames Wright //   E   - Total Energy Density,  E  = rho (cv T + (u u)/2 + g z)
23988b783a1SJames Wright //
24088b783a1SJames Wright // Navier-Stokes Equations:
24188b783a1SJames Wright //   drho/dt + div( U )                               = 0
24288b783a1SJames Wright //   dU/dt   + div( rho (u x u) + P I3 ) + rho g khat = div( Fu )
24388b783a1SJames Wright //   dE/dt   + div( (E + P) u )                       = div( Fe )
24488b783a1SJames Wright //
24588b783a1SJames Wright // Viscous Stress:
24688b783a1SJames Wright //   Fu = mu (grad( u ) + grad( u )^T + lambda div ( u ) I3)
24788b783a1SJames Wright //
24888b783a1SJames Wright // Thermal Stress:
24988b783a1SJames Wright //   Fe = u Fu + k grad( T )
25088626eedSJames Wright // Equation of State
25188b783a1SJames Wright //   P = (gamma - 1) (E - rho (u u) / 2 - rho g z)
25288b783a1SJames Wright //
25388b783a1SJames Wright // Stabilization:
25488b783a1SJames Wright //   Tau = diag(TauC, TauM, TauM, TauM, TauE)
25588b783a1SJames Wright //     f1 = rho  sqrt(ui uj gij)
25688b783a1SJames Wright //     gij = dXi/dX * dXi/dX
25788b783a1SJames Wright //     TauC = Cc f1 / (8 gii)
25888b783a1SJames Wright //     TauM = min( 1 , 1 / f1 )
25988b783a1SJames Wright //     TauE = TauM / (Ce cv)
26088b783a1SJames Wright //
26188b783a1SJames Wright //  SU   = Galerkin + grad(v) . ( Ai^T * Tau * (Aj q,j) )
26288b783a1SJames Wright //
26388b783a1SJames Wright // Constants:
26488b783a1SJames Wright //   lambda = - 2 / 3,  From Stokes hypothesis
26588b783a1SJames Wright //   mu              ,  Dynamic viscosity
26688b783a1SJames Wright //   k               ,  Thermal conductivity
26788b783a1SJames Wright //   cv              ,  Specific heat, constant volume
26888b783a1SJames Wright //   cp              ,  Specific heat, constant pressure
26988b783a1SJames Wright //   g               ,  Gravity
27088b783a1SJames Wright //   gamma  = cp / cv,  Specific heat ratio
27188b783a1SJames Wright //
27288b783a1SJames Wright // We require the product of the inverse of the Jacobian (dXdx_j,k) and
27388b783a1SJames Wright // its transpose (dXdx_k,j) to properly compute integrals of the form:
27488b783a1SJames Wright // int( gradv gradu )
27588b783a1SJames Wright //
27688b783a1SJames Wright // *****************************************************************************
2775c677226SJed Brown CEED_QFUNCTION(RHSFunction_Newtonian)(void *ctx, CeedInt Q,
27888b783a1SJames Wright                                       const CeedScalar *const *in, CeedScalar *const *out) {
27988b783a1SJames Wright   // *INDENT-OFF*
28088b783a1SJames Wright   // Inputs
28188b783a1SJames Wright   const CeedScalar (*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0],
282a3ae0734SJed Brown                    (*Grad_q)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1],
28388b783a1SJames Wright                    (*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2],
28488b783a1SJames Wright                    (*x)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[3];
28588b783a1SJames Wright   // Outputs
28688b783a1SJames Wright   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0],
287a3ae0734SJed Brown              (*Grad_v)[5][CEED_Q_VLA] = (CeedScalar(*)[5][CEED_Q_VLA])out[1];
28888b783a1SJames Wright   // *INDENT-ON*
28988b783a1SJames Wright 
29088b783a1SJames Wright   // Context
29188b783a1SJames Wright   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
29288b783a1SJames Wright   const CeedScalar mu     = context->mu;
29388b783a1SJames Wright   const CeedScalar cv     = context->cv;
29488b783a1SJames Wright   const CeedScalar cp     = context->cp;
29588626eedSJames Wright   const CeedScalar *g     = context->g;
29688626eedSJames Wright   const CeedScalar dt     = context->dt;
29788b783a1SJames Wright   const CeedScalar gamma  = cp / cv;
29888626eedSJames Wright   const CeedScalar Rd     = cp - cv;
29988b783a1SJames Wright 
30088b783a1SJames Wright   CeedPragmaSIMD
30188b783a1SJames Wright   // Quadrature Point Loop
30288b783a1SJames Wright   for (CeedInt i=0; i<Q; i++) {
3035c677226SJed Brown     CeedScalar U[5];
3045c677226SJed Brown     for (int j=0; j<5; j++) U[j] = q[j][i];
3055c677226SJed Brown     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
3065c677226SJed Brown     State s = StateFromU(context, U, x_i);
3075c677226SJed Brown 
30888b783a1SJames Wright     // -- Interp-to-Interp q_data
30988b783a1SJames Wright     const CeedScalar wdetJ      =   q_data[0][i];
31088b783a1SJames Wright     // -- Interp-to-Grad q_data
31188b783a1SJames Wright     // ---- Inverse of change of coordinate matrix: X_i,j
31288b783a1SJames Wright     // *INDENT-OFF*
31388b783a1SJames Wright     const CeedScalar dXdx[3][3] = {{q_data[1][i],
31488b783a1SJames Wright                                     q_data[2][i],
31588b783a1SJames Wright                                     q_data[3][i]},
31688b783a1SJames Wright                                    {q_data[4][i],
31788b783a1SJames Wright                                     q_data[5][i],
31888b783a1SJames Wright                                     q_data[6][i]},
31988b783a1SJames Wright                                    {q_data[7][i],
32088b783a1SJames Wright                                     q_data[8][i],
32188b783a1SJames Wright                                     q_data[9][i]}
32288b783a1SJames Wright                                   };
32388b783a1SJames Wright     // *INDENT-ON*
32488b783a1SJames Wright 
3255c677226SJed Brown     State grad_s[3];
3263c4b7af6SJed Brown     for (CeedInt j=0; j<3; j++) {
3276f00d0e6SJed Brown       CeedScalar dx_i[3] = {0}, dU[5];
32839c69132SJed Brown       for (CeedInt k=0; k<5; k++)
32939c69132SJed Brown         dU[k] = Grad_q[0][k][i] * dXdx[0][j] +
33039c69132SJed Brown                 Grad_q[1][k][i] * dXdx[1][j] +
33139c69132SJed Brown                 Grad_q[2][k][i] * dXdx[2][j];
3325c677226SJed Brown       dx_i[j] = 1.;
3336f00d0e6SJed Brown       grad_s[j] = StateFromU_fwd(context, s, dU, x_i, dx_i);
3345c677226SJed Brown     }
3355c677226SJed Brown 
3365c677226SJed Brown     CeedScalar strain_rate[6], kmstress[6], stress[3][3], Fe[3];
3375c677226SJed Brown     KMStrainRate(grad_s, strain_rate);
3385c677226SJed Brown     NewtonianStress(context, strain_rate, kmstress);
3395c677226SJed Brown     KMUnpack(kmstress, stress);
3405c677226SJed Brown     ViscousEnergyFlux(context, s.Y, grad_s, stress, Fe);
3415c677226SJed Brown 
3425c677226SJed Brown     StateConservative F_inviscid[3];
3435c677226SJed Brown     FluxInviscid(context, s, F_inviscid);
3445c677226SJed Brown 
3455c677226SJed Brown     // Total flux
3465c677226SJed Brown     CeedScalar Flux[5][3];
3473c4b7af6SJed Brown     for (CeedInt j=0; j<3; j++) {
3485c677226SJed Brown       Flux[0][j] = F_inviscid[j].density;
3493c4b7af6SJed Brown       for (CeedInt k=0; k<3; k++)
3505c677226SJed Brown         Flux[k+1][j] = F_inviscid[j].momentum[k] - stress[k][j];
3515c677226SJed Brown       Flux[4][j] = F_inviscid[j].E_total + Fe[j];
3525c677226SJed Brown     }
3535c677226SJed Brown 
3543c4b7af6SJed Brown     for (CeedInt j=0; j<3; j++) {
3553c4b7af6SJed Brown       for (CeedInt k=0; k<5; k++) {
356a3ae0734SJed Brown         Grad_v[j][k][i] = wdetJ * (dXdx[j][0] * Flux[k][0] +
3575c677226SJed Brown                                    dXdx[j][1] * Flux[k][1] +
3585c677226SJed Brown                                    dXdx[j][2] * Flux[k][2]);
3595c677226SJed Brown       }
3605c677226SJed Brown     }
3615c677226SJed Brown 
3625c677226SJed Brown     const CeedScalar body_force[5] = {0, s.U.density *g[0], s.U.density *g[1], s.U.density *g[2], 0};
3635c677226SJed Brown     for (int j=0; j<5; j++)
3645c677226SJed Brown       v[j][i] = wdetJ * body_force[j];
36588b783a1SJames Wright 
36688b783a1SJames Wright     // jacob_F_conv[3][5][5] = dF(convective)/dq at each direction
3675c677226SJed Brown     CeedScalar jacob_F_conv[3][5][5] = {0};
3685c677226SJed Brown     computeFluxJacobian_NS(jacob_F_conv, s.U.density, s.Y.velocity, s.U.E_total,
3695c677226SJed Brown                            gamma, g, x_i);
3705c677226SJed Brown     CeedScalar grad_U[5][3];
371ba6664aeSJames Wright     for (CeedInt j=0; j<3; j++) {
3725c677226SJed Brown       grad_U[0][j] = grad_s[j].U.density;
3733c4b7af6SJed Brown       for (CeedInt k=0; k<3; k++) grad_U[k+1][j] = grad_s[j].U.momentum[k];
3745c677226SJed Brown       grad_U[4][j] = grad_s[j].U.E_total;
37588b783a1SJames Wright     }
37688b783a1SJames Wright 
37788b783a1SJames Wright     // strong_conv = dF/dq * dq/dx    (Strong convection)
37888b783a1SJames Wright     CeedScalar strong_conv[5] = {0};
379ba6664aeSJames Wright     for (CeedInt j=0; j<3; j++)
380ba6664aeSJames Wright       for (CeedInt k=0; k<5; k++)
381ba6664aeSJames Wright         for (CeedInt l=0; l<5; l++)
3825c677226SJed Brown           strong_conv[k] += jacob_F_conv[j][k][l] * grad_U[l][j];
38388b783a1SJames Wright 
38488626eedSJames Wright     // -- Stabilization method: none, SU, or SUPG
38588626eedSJames Wright     CeedScalar stab[5][3] = {{0.}};
38688626eedSJames Wright     CeedScalar tau_strong_conv[5] = {0.}, tau_strong_conv_conservative[5] = {0};
38788626eedSJames Wright     CeedScalar Tau_d[3] = {0.};
38888b783a1SJames Wright     switch (context->stabilization) {
38988b783a1SJames Wright     case STAB_NONE:        // Galerkin
39088b783a1SJames Wright       break;
39188b783a1SJames Wright     case STAB_SU:        // SU
3925c677226SJed Brown       Tau_diagPrim(Tau_d, dXdx, s.Y.velocity, cv, context, mu, dt, s.U.density);
39388626eedSJames Wright       tau_strong_conv[0] = Tau_d[0] * strong_conv[0];
39488626eedSJames Wright       tau_strong_conv[1] = Tau_d[1] * strong_conv[1];
39588626eedSJames Wright       tau_strong_conv[2] = Tau_d[1] * strong_conv[2];
39688626eedSJames Wright       tau_strong_conv[3] = Tau_d[1] * strong_conv[3];
39788626eedSJames Wright       tau_strong_conv[4] = Tau_d[2] * strong_conv[4];
3985c677226SJed Brown       PrimitiveToConservative_fwd(s.U.density, s.Y.velocity, s.U.E_total, Rd, cv,
3995c677226SJed Brown                                   tau_strong_conv,
40088626eedSJames Wright                                   tau_strong_conv_conservative);
401ba6664aeSJames Wright       for (CeedInt j=0; j<3; j++)
402ba6664aeSJames Wright         for (CeedInt k=0; k<5; k++)
403ba6664aeSJames Wright           for (CeedInt l=0; l<5; l++)
40488626eedSJames Wright             stab[k][j] += jacob_F_conv[j][k][l] * tau_strong_conv_conservative[l];
40588b783a1SJames Wright 
406ba6664aeSJames Wright       for (CeedInt j=0; j<5; j++)
407ba6664aeSJames Wright         for (CeedInt k=0; k<3; k++)
408a3ae0734SJed Brown           Grad_v[k][j][i] -= wdetJ*(stab[j][0] * dXdx[k][0] +
40988b783a1SJames Wright                                     stab[j][1] * dXdx[k][1] +
41088b783a1SJames Wright                                     stab[j][2] * dXdx[k][2]);
41188b783a1SJames Wright       break;
41288b783a1SJames Wright     case STAB_SUPG:        // SUPG is not implemented for explicit scheme
41388b783a1SJames Wright       break;
41488b783a1SJames Wright     }
41588b783a1SJames Wright 
41688b783a1SJames Wright   } // End Quadrature Point Loop
41788b783a1SJames Wright 
41888b783a1SJames Wright   // Return
41988b783a1SJames Wright   return 0;
42088b783a1SJames Wright }
42188b783a1SJames Wright 
42288b783a1SJames Wright // *****************************************************************************
42388b783a1SJames Wright // This QFunction implements the Navier-Stokes equations (mentioned above) with
42488b783a1SJames Wright //   implicit time stepping method
42588b783a1SJames Wright //
42688b783a1SJames Wright //  SU   = Galerkin + grad(v) . ( Ai^T * Tau * (Aj q,j) )
42788b783a1SJames Wright //  SUPG = Galerkin + grad(v) . ( Ai^T * Tau * (q_dot + Aj q,j - body force) )
42888b783a1SJames Wright //                                       (diffussive terms will be added later)
42988b783a1SJames Wright //
43088b783a1SJames Wright // *****************************************************************************
43188b783a1SJames Wright CEED_QFUNCTION(IFunction_Newtonian)(void *ctx, CeedInt Q,
43288b783a1SJames Wright                                     const CeedScalar *const *in,
43388b783a1SJames Wright                                     CeedScalar *const *out) {
43488b783a1SJames Wright   // *INDENT-OFF*
43588b783a1SJames Wright   // Inputs
43688b783a1SJames Wright   const CeedScalar (*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0],
437a3ae0734SJed Brown                    (*Grad_q)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1],
43888b783a1SJames Wright                    (*q_dot)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2],
43988b783a1SJames Wright                    (*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[3],
44088b783a1SJames Wright                    (*x)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[4];
44188b783a1SJames Wright   // Outputs
44288b783a1SJames Wright   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0],
443a3ae0734SJed Brown              (*Grad_v)[5][CEED_Q_VLA] = (CeedScalar(*)[5][CEED_Q_VLA])out[1],
444a3ae0734SJed Brown              (*jac_data)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[2];
44588b783a1SJames Wright   // *INDENT-ON*
44688b783a1SJames Wright   // Context
44788b783a1SJames Wright   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
44888b783a1SJames Wright   const CeedScalar mu     = context->mu;
44988b783a1SJames Wright   const CeedScalar cv     = context->cv;
45088b783a1SJames Wright   const CeedScalar cp     = context->cp;
45188626eedSJames Wright   const CeedScalar *g     = context->g;
45288626eedSJames Wright   const CeedScalar dt     = context->dt;
45388b783a1SJames Wright   const CeedScalar gamma  = cp / cv;
45488626eedSJames Wright   const CeedScalar Rd     = cp-cv;
45588b783a1SJames Wright 
45688b783a1SJames Wright   CeedPragmaSIMD
45788b783a1SJames Wright   // Quadrature Point Loop
45888b783a1SJames Wright   for (CeedInt i=0; i<Q; i++) {
4595c677226SJed Brown     CeedScalar U[5];
4603c4b7af6SJed Brown     for (CeedInt j=0; j<5; j++) U[j] = q[j][i];
4615c677226SJed Brown     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
4625c677226SJed Brown     State s = StateFromU(context, U, x_i);
4635c677226SJed Brown 
46488b783a1SJames Wright     // -- Interp-to-Interp q_data
46588b783a1SJames Wright     const CeedScalar wdetJ      =   q_data[0][i];
46688b783a1SJames Wright     // -- Interp-to-Grad q_data
46788b783a1SJames Wright     // ---- Inverse of change of coordinate matrix: X_i,j
46888b783a1SJames Wright     // *INDENT-OFF*
46988b783a1SJames Wright     const CeedScalar dXdx[3][3] = {{q_data[1][i],
47088b783a1SJames Wright                                     q_data[2][i],
47188b783a1SJames Wright                                     q_data[3][i]},
47288b783a1SJames Wright                                    {q_data[4][i],
47388b783a1SJames Wright                                     q_data[5][i],
47488b783a1SJames Wright                                     q_data[6][i]},
47588b783a1SJames Wright                                    {q_data[7][i],
47688b783a1SJames Wright                                     q_data[8][i],
47788b783a1SJames Wright                                     q_data[9][i]}
47888b783a1SJames Wright                                   };
47988b783a1SJames Wright     // *INDENT-ON*
4805c677226SJed Brown     State grad_s[3];
481ba6664aeSJames Wright     for (CeedInt j=0; j<3; j++) {
4826f00d0e6SJed Brown       CeedScalar dx_i[3] = {0}, dU[5];
48339c69132SJed Brown       for (CeedInt k=0; k<5; k++)
48439c69132SJed Brown         dU[k] = Grad_q[0][k][i] * dXdx[0][j] +
48539c69132SJed Brown                 Grad_q[1][k][i] * dXdx[1][j] +
48639c69132SJed Brown                 Grad_q[2][k][i] * dXdx[2][j];
4875c677226SJed Brown       dx_i[j] = 1.;
4886f00d0e6SJed Brown       grad_s[j] = StateFromU_fwd(context, s, dU, x_i, dx_i);
48988b783a1SJames Wright     }
4905c677226SJed Brown 
4915c677226SJed Brown     CeedScalar strain_rate[6], kmstress[6], stress[3][3], Fe[3];
4925c677226SJed Brown     KMStrainRate(grad_s, strain_rate);
4935c677226SJed Brown     NewtonianStress(context, strain_rate, kmstress);
4945c677226SJed Brown     KMUnpack(kmstress, stress);
4955c677226SJed Brown     ViscousEnergyFlux(context, s.Y, grad_s, stress, Fe);
4965c677226SJed Brown 
4975c677226SJed Brown     StateConservative F_inviscid[3];
4985c677226SJed Brown     FluxInviscid(context, s, F_inviscid);
4995c677226SJed Brown 
5005c677226SJed Brown 
5015c677226SJed Brown     // Total flux
5025c677226SJed Brown     CeedScalar Flux[5][3];
5033c4b7af6SJed Brown     for (CeedInt j=0; j<3; j++) {
5045c677226SJed Brown       Flux[0][j] = F_inviscid[j].density;
505ba6664aeSJames Wright       for (CeedInt k=0; k<3; k++)
5065c677226SJed Brown         Flux[k+1][j] = F_inviscid[j].momentum[k] - stress[k][j];
5075c677226SJed Brown       Flux[4][j] = F_inviscid[j].E_total + Fe[j];
5085c677226SJed Brown     }
5095c677226SJed Brown 
5103c4b7af6SJed Brown     for (CeedInt j=0; j<3; j++) {
5113c4b7af6SJed Brown       for (CeedInt k=0; k<5; k++) {
512a3ae0734SJed Brown         Grad_v[j][k][i] = -wdetJ * (dXdx[j][0] * Flux[k][0] +
5135c677226SJed Brown                                     dXdx[j][1] * Flux[k][1] +
5145c677226SJed Brown                                     dXdx[j][2] * Flux[k][2]);
5155c677226SJed Brown       }
5165c677226SJed Brown     }
5175c677226SJed Brown 
5185c677226SJed Brown     const CeedScalar body_force[5] = {0, s.U.density *g[0], s.U.density *g[1], s.U.density *g[2], 0};
5193c4b7af6SJed Brown     for (CeedInt j=0; j<5; j++)
5205c677226SJed Brown       v[j][i] = wdetJ * (q_dot[j][i] - body_force[j]);
52188b783a1SJames Wright 
52288b783a1SJames Wright     // jacob_F_conv[3][5][5] = dF(convective)/dq at each direction
5235c677226SJed Brown     CeedScalar jacob_F_conv[3][5][5] = {0};
5245c677226SJed Brown     computeFluxJacobian_NS(jacob_F_conv, s.U.density, s.Y.velocity, s.U.E_total,
5255c677226SJed Brown                            gamma, g, x_i);
5265c677226SJed Brown     CeedScalar grad_U[5][3];
527ba6664aeSJames Wright     for (CeedInt j=0; j<3; j++) {
5285c677226SJed Brown       grad_U[0][j] = grad_s[j].U.density;
5293c4b7af6SJed Brown       for (CeedInt k=0; k<3; k++) grad_U[k+1][j] = grad_s[j].U.momentum[k];
5305c677226SJed Brown       grad_U[4][j] = grad_s[j].U.E_total;
53188b783a1SJames Wright     }
5325c677226SJed Brown 
53388b783a1SJames Wright     // strong_conv = dF/dq * dq/dx    (Strong convection)
53488b783a1SJames Wright     CeedScalar strong_conv[5] = {0};
535ba6664aeSJames Wright     for (CeedInt j=0; j<3; j++)
536ba6664aeSJames Wright       for (CeedInt k=0; k<5; k++)
537ba6664aeSJames Wright         for (CeedInt l=0; l<5; l++)
5385c677226SJed Brown           strong_conv[k] += jacob_F_conv[j][k][l] * grad_U[l][j];
53988b783a1SJames Wright 
54088b783a1SJames Wright     // Strong residual
54188b783a1SJames Wright     CeedScalar strong_res[5];
542ba6664aeSJames Wright     for (CeedInt j=0; j<5; j++)
54388b783a1SJames Wright       strong_res[j] = q_dot[j][i] + strong_conv[j] - body_force[j];
54488b783a1SJames Wright 
54588b783a1SJames Wright     // -- Stabilization method: none, SU, or SUPG
54688626eedSJames Wright     CeedScalar stab[5][3] = {{0.}};
54788626eedSJames Wright     CeedScalar tau_strong_res[5] = {0.}, tau_strong_res_conservative[5] = {0};
54888626eedSJames Wright     CeedScalar tau_strong_conv[5] = {0.}, tau_strong_conv_conservative[5] = {0};
54988626eedSJames Wright     CeedScalar Tau_d[3] = {0.};
55088b783a1SJames Wright     switch (context->stabilization) {
55188b783a1SJames Wright     case STAB_NONE:        // Galerkin
55288b783a1SJames Wright       break;
55388b783a1SJames Wright     case STAB_SU:        // SU
5545c677226SJed Brown       Tau_diagPrim(Tau_d, dXdx, s.Y.velocity, cv, context, mu, dt, s.U.density);
55588626eedSJames Wright       tau_strong_conv[0] = Tau_d[0] * strong_conv[0];
55688626eedSJames Wright       tau_strong_conv[1] = Tau_d[1] * strong_conv[1];
55788626eedSJames Wright       tau_strong_conv[2] = Tau_d[1] * strong_conv[2];
55888626eedSJames Wright       tau_strong_conv[3] = Tau_d[1] * strong_conv[3];
55988626eedSJames Wright       tau_strong_conv[4] = Tau_d[2] * strong_conv[4];
5605c677226SJed Brown       PrimitiveToConservative_fwd(s.U.density, s.Y.velocity, s.U.E_total, Rd, cv,
5615c677226SJed Brown                                   tau_strong_conv, tau_strong_conv_conservative);
562ba6664aeSJames Wright       for (CeedInt j=0; j<3; j++)
563ba6664aeSJames Wright         for (CeedInt k=0; k<5; k++)
564ba6664aeSJames Wright           for (CeedInt l=0; l<5; l++)
56588626eedSJames Wright             stab[k][j] += jacob_F_conv[j][k][l] * tau_strong_conv_conservative[l];
56688b783a1SJames Wright 
567ba6664aeSJames Wright       for (CeedInt j=0; j<5; j++)
568ba6664aeSJames Wright         for (CeedInt k=0; k<3; k++)
569a3ae0734SJed Brown           Grad_v[k][j][i] += wdetJ*(stab[j][0] * dXdx[k][0] +
57088b783a1SJames Wright                                     stab[j][1] * dXdx[k][1] +
57188b783a1SJames Wright                                     stab[j][2] * dXdx[k][2]);
5723c4b7af6SJed Brown 
57388b783a1SJames Wright       break;
57488b783a1SJames Wright     case STAB_SUPG:        // SUPG
5755c677226SJed Brown       Tau_diagPrim(Tau_d, dXdx, s.Y.velocity, cv, context, mu, dt, s.U.density);
57688626eedSJames Wright       tau_strong_res[0] = Tau_d[0] * strong_res[0];
57788626eedSJames Wright       tau_strong_res[1] = Tau_d[1] * strong_res[1];
57888626eedSJames Wright       tau_strong_res[2] = Tau_d[1] * strong_res[2];
57988626eedSJames Wright       tau_strong_res[3] = Tau_d[1] * strong_res[3];
58088626eedSJames Wright       tau_strong_res[4] = Tau_d[2] * strong_res[4];
58188626eedSJames Wright // Alternate route (useful later with primitive variable code)
58288626eedSJames Wright // this function was verified against PHASTA for as IC that was as close as possible
58388626eedSJames Wright //    computeFluxJacobian_NSp(jacob_F_conv_p, rho, u, E, Rd, cv);
58488626eedSJames Wright // it has also been verified to compute a correct through the following
58588626eedSJames Wright //   stab[k][j] += jacob_F_conv_p[j][k][l] * tau_strong_res[l] // flux Jacobian wrt primitive
58688626eedSJames Wright // applied in the triple loop below
58788626eedSJames Wright //  However, it is more flops than using the existing Jacobian wrt q after q_{,Y} viz
5885c677226SJed Brown       PrimitiveToConservative_fwd(s.U.density, s.Y.velocity, s.U.E_total, Rd, cv,
5895c677226SJed Brown                                   tau_strong_res, tau_strong_res_conservative);
590ba6664aeSJames Wright       for (CeedInt j=0; j<3; j++)
591ba6664aeSJames Wright         for (CeedInt k=0; k<5; k++)
592ba6664aeSJames Wright           for (CeedInt l=0; l<5; l++)
59388626eedSJames Wright             stab[k][j] += jacob_F_conv[j][k][l] * tau_strong_res_conservative[l];
59488b783a1SJames Wright 
595ba6664aeSJames Wright       for (CeedInt j=0; j<5; j++)
596ba6664aeSJames Wright         for (CeedInt k=0; k<3; k++)
597a3ae0734SJed Brown           Grad_v[k][j][i] += wdetJ*(stab[j][0] * dXdx[k][0] +
59888b783a1SJames Wright                                     stab[j][1] * dXdx[k][1] +
59988b783a1SJames Wright                                     stab[j][2] * dXdx[k][2]);
60088b783a1SJames Wright       break;
60188b783a1SJames Wright     }
6023c4b7af6SJed Brown     for (CeedInt j=0; j<5; j++) jac_data[j][i] = U[j];
6033c4b7af6SJed Brown     for (CeedInt j=0; j<6; j++) jac_data[5+j][i] = kmstress[j];
6043c4b7af6SJed Brown     for (CeedInt j=0; j<3; j++) jac_data[5+6+j][i] = Tau_d[j];
60588b783a1SJames Wright 
60688b783a1SJames Wright   } // End Quadrature Point Loop
60788b783a1SJames Wright 
60888b783a1SJames Wright   // Return
60988b783a1SJames Wright   return 0;
61088b783a1SJames Wright }
611e334ad8fSJed Brown 
612e334ad8fSJed Brown CEED_QFUNCTION(IJacobian_Newtonian)(void *ctx, CeedInt Q,
613e334ad8fSJed Brown                                     const CeedScalar *const *in,
614e334ad8fSJed Brown                                     CeedScalar *const *out) {
615e334ad8fSJed Brown   // *INDENT-OFF*
616e334ad8fSJed Brown   // Inputs
617e334ad8fSJed Brown   const CeedScalar (*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0],
618e334ad8fSJed Brown                    (*Grad_dq)[5][CEED_Q_VLA] = (const CeedScalar(*)[5][CEED_Q_VLA])in[1],
619e334ad8fSJed Brown                    (*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2],
620e334ad8fSJed Brown                    (*x)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[3],
621e334ad8fSJed Brown                    (*jac_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[4];
622e334ad8fSJed Brown   // Outputs
623e334ad8fSJed Brown   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0],
624e334ad8fSJed Brown              (*Grad_v)[5][CEED_Q_VLA] = (CeedScalar(*)[5][CEED_Q_VLA])out[1];
625e334ad8fSJed Brown   // *INDENT-ON*
626e334ad8fSJed Brown   // Context
627e334ad8fSJed Brown   NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
628e334ad8fSJed Brown   const CeedScalar *g = context->g;
629e334ad8fSJed Brown   const CeedScalar cp = context->cp;
630e334ad8fSJed Brown   const CeedScalar cv = context->cv;
631e334ad8fSJed Brown   const CeedScalar Rd = cp - cv;
632e334ad8fSJed Brown   const CeedScalar gamma = cp / cv;
633e334ad8fSJed Brown 
634e334ad8fSJed Brown   CeedPragmaSIMD
635e334ad8fSJed Brown   // Quadrature Point Loop
636e334ad8fSJed Brown   for (CeedInt i=0; i<Q; i++) {
637e334ad8fSJed Brown     // -- Interp-to-Interp q_data
638e334ad8fSJed Brown     const CeedScalar wdetJ      =   q_data[0][i];
639e334ad8fSJed Brown     // -- Interp-to-Grad q_data
640e334ad8fSJed Brown     // ---- Inverse of change of coordinate matrix: X_i,j
641e334ad8fSJed Brown     // *INDENT-OFF*
642e334ad8fSJed Brown     const CeedScalar dXdx[3][3] = {{q_data[1][i],
643e334ad8fSJed Brown                                     q_data[2][i],
644e334ad8fSJed Brown                                     q_data[3][i]},
645e334ad8fSJed Brown                                    {q_data[4][i],
646e334ad8fSJed Brown                                     q_data[5][i],
647e334ad8fSJed Brown                                     q_data[6][i]},
648e334ad8fSJed Brown                                    {q_data[7][i],
649e334ad8fSJed Brown                                     q_data[8][i],
650e334ad8fSJed Brown                                     q_data[9][i]}
651e334ad8fSJed Brown                                   };
652e334ad8fSJed Brown     // *INDENT-ON*
653e334ad8fSJed Brown 
654e334ad8fSJed Brown     CeedScalar U[5], kmstress[6], Tau_d[3] __attribute((unused));
655e334ad8fSJed Brown     for (int j=0; j<5; j++) U[j] = jac_data[j][i];
656e334ad8fSJed Brown     for (int j=0; j<6; j++) kmstress[j] = jac_data[5+j][i];
657e334ad8fSJed Brown     for (int j=0; j<3; j++) Tau_d[j] = jac_data[5+6+j][i];
658e334ad8fSJed Brown     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
659e334ad8fSJed Brown     State s = StateFromU(context, U, x_i);
660e334ad8fSJed Brown 
661e334ad8fSJed Brown     CeedScalar dU[5], dx0[3] = {0};
662e334ad8fSJed Brown     for (int j=0; j<5; j++) dU[j] = dq[j][i];
663e334ad8fSJed Brown     State ds = StateFromU_fwd(context, s, dU, x_i, dx0);
664e334ad8fSJed Brown 
665e334ad8fSJed Brown     State grad_ds[3];
666e334ad8fSJed Brown     for (int j=0; j<3; j++) {
667e334ad8fSJed Brown       CeedScalar dUj[5];
668e334ad8fSJed Brown       for (int k=0; k<5; k++) dUj[k] = Grad_dq[0][k][i] * dXdx[0][j]
669e334ad8fSJed Brown                                          + Grad_dq[1][k][i] * dXdx[1][j]
670e334ad8fSJed Brown                                          + Grad_dq[2][k][i] * dXdx[2][j];
671e334ad8fSJed Brown       grad_ds[j] = StateFromU_fwd(context, s, dUj, x_i, dx0);
672e334ad8fSJed Brown     }
673e334ad8fSJed Brown 
674e334ad8fSJed Brown     CeedScalar dstrain_rate[6], dkmstress[6], stress[3][3], dstress[3][3], dFe[3];
675e334ad8fSJed Brown     KMStrainRate(grad_ds, dstrain_rate);
676e334ad8fSJed Brown     NewtonianStress(context, dstrain_rate, dkmstress);
677e334ad8fSJed Brown     KMUnpack(dkmstress, dstress);
678e334ad8fSJed Brown     KMUnpack(kmstress, stress);
679e334ad8fSJed Brown     ViscousEnergyFlux_fwd(context, s.Y, ds.Y, grad_ds, stress, dstress, dFe);
680e334ad8fSJed Brown 
681e334ad8fSJed Brown     StateConservative dF_inviscid[3];
682e334ad8fSJed Brown     FluxInviscid_fwd(context, s, ds, dF_inviscid);
683e334ad8fSJed Brown 
684e334ad8fSJed Brown     // Total flux
685e334ad8fSJed Brown     CeedScalar dFlux[5][3];
686e334ad8fSJed Brown     for (int j=0; j<3; j++) {
687e334ad8fSJed Brown       dFlux[0][j] = dF_inviscid[j].density;
688e334ad8fSJed Brown       for (int k=0; k<3; k++)
689e334ad8fSJed Brown         dFlux[k+1][j] = dF_inviscid[j].momentum[k] - dstress[k][j];
690e334ad8fSJed Brown       dFlux[4][j] = dF_inviscid[j].E_total + dFe[j];
691e334ad8fSJed Brown     }
692e334ad8fSJed Brown 
693e334ad8fSJed Brown     for (int j=0; j<3; j++) {
694e334ad8fSJed Brown       for (int k=0; k<5; k++) {
695e334ad8fSJed Brown         Grad_v[j][k][i] = -wdetJ * (dXdx[j][0] * dFlux[k][0] +
696e334ad8fSJed Brown                                     dXdx[j][1] * dFlux[k][1] +
697e334ad8fSJed Brown                                     dXdx[j][2] * dFlux[k][2]);
698e334ad8fSJed Brown       }
699e334ad8fSJed Brown     }
700e334ad8fSJed Brown 
701e334ad8fSJed Brown     const CeedScalar dbody_force[5] = {0, ds.U.density *g[0], ds.U.density *g[1], ds.U.density *g[2], 0};
702e334ad8fSJed Brown     for (int j=0; j<5; j++)
703e334ad8fSJed Brown       v[j][i] = wdetJ * (context->ijacobian_time_shift * dU[j] - dbody_force[j]);
704e334ad8fSJed Brown 
705e334ad8fSJed Brown     if (1) {
706e334ad8fSJed Brown       CeedScalar jacob_F_conv[3][5][5] = {0};
707e334ad8fSJed Brown       computeFluxJacobian_NS(jacob_F_conv, s.U.density, s.Y.velocity, s.U.E_total,
708e334ad8fSJed Brown                              gamma, g, x_i);
709e334ad8fSJed Brown       CeedScalar grad_dU[5][3];
710e334ad8fSJed Brown       for (int j=0; j<3; j++) {
711e334ad8fSJed Brown         grad_dU[0][j] = grad_ds[j].U.density;
712e334ad8fSJed Brown         for (int k=0; k<3; k++) grad_dU[k+1][j] = grad_ds[j].U.momentum[k];
713e334ad8fSJed Brown         grad_dU[4][j] = grad_ds[j].U.E_total;
714e334ad8fSJed Brown       }
715e334ad8fSJed Brown       CeedScalar dstrong_conv[5] = {0};
716e334ad8fSJed Brown       for (int j=0; j<3; j++)
717e334ad8fSJed Brown         for (int k=0; k<5; k++)
718e334ad8fSJed Brown           for (int l=0; l<5; l++)
719e334ad8fSJed Brown             dstrong_conv[k] += jacob_F_conv[j][k][l] * grad_dU[l][j];
720e334ad8fSJed Brown       CeedScalar dstrong_res[5];
721e334ad8fSJed Brown       for (int j=0; j<5; j++)
722e334ad8fSJed Brown         dstrong_res[j] = context->ijacobian_time_shift * dU[j] + dstrong_conv[j] -
723e334ad8fSJed Brown                          dbody_force[j];
724e334ad8fSJed Brown       CeedScalar dtau_strong_res[5] = {0.}, dtau_strong_res_conservative[5] = {0};
725e334ad8fSJed Brown       dtau_strong_res[0] = Tau_d[0] * dstrong_res[0];
726e334ad8fSJed Brown       dtau_strong_res[1] = Tau_d[1] * dstrong_res[1];
727e334ad8fSJed Brown       dtau_strong_res[2] = Tau_d[1] * dstrong_res[2];
728e334ad8fSJed Brown       dtau_strong_res[3] = Tau_d[1] * dstrong_res[3];
729e334ad8fSJed Brown       dtau_strong_res[4] = Tau_d[2] * dstrong_res[4];
730e334ad8fSJed Brown       PrimitiveToConservative_fwd(s.U.density, s.Y.velocity, s.U.E_total, Rd, cv,
731e334ad8fSJed Brown                                   dtau_strong_res, dtau_strong_res_conservative);
732e334ad8fSJed Brown       CeedScalar dstab[5][3] = {0};
733e334ad8fSJed Brown       for (int j=0; j<3; j++)
734e334ad8fSJed Brown         for (int k=0; k<5; k++)
735e334ad8fSJed Brown           for (int l=0; l<5; l++)
736e334ad8fSJed Brown             dstab[k][j] += jacob_F_conv[j][k][l] * dtau_strong_res_conservative[l];
737e334ad8fSJed Brown       for (int j=0; j<5; j++)
738e334ad8fSJed Brown         for (int k=0; k<3; k++)
739e334ad8fSJed Brown           Grad_v[k][j][i] += wdetJ*(dstab[j][0] * dXdx[k][0] +
740e334ad8fSJed Brown                                     dstab[j][1] * dXdx[k][1] +
741e334ad8fSJed Brown                                     dstab[j][2] * dXdx[k][2]);
742e334ad8fSJed Brown 
743e334ad8fSJed Brown     }
744e334ad8fSJed Brown   } // End Quadrature Point Loop
745e334ad8fSJed Brown   return 0;
746e334ad8fSJed Brown }
74765dd5cafSJames Wright 
74865dd5cafSJames Wright // Compute boundary integral (ie. for strongly set inflows)
74965dd5cafSJames Wright CEED_QFUNCTION(BoundaryIntegral)(void *ctx, CeedInt Q,
75065dd5cafSJames Wright                                  const CeedScalar *const *in,
75165dd5cafSJames Wright                                  CeedScalar *const *out) {
75265dd5cafSJames Wright 
75365dd5cafSJames Wright   //*INDENT-OFF*
75465dd5cafSJames Wright   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[0],
755*2c4e60d7SJames Wright                    (*Grad_q)[5][CEED_Q_VLA]  = (const CeedScalar(*)[5][CEED_Q_VLA])in[1],
756*2c4e60d7SJames Wright                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2],
757*2c4e60d7SJames Wright                    (*x)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[3];
75865dd5cafSJames Wright 
75965dd5cafSJames Wright   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA]) out[0];
76065dd5cafSJames Wright 
76165dd5cafSJames Wright   //*INDENT-ON*
76265dd5cafSJames Wright 
763*2c4e60d7SJames Wright   const NewtonianIdealGasContext context = (NewtonianIdealGasContext) ctx;
764*2c4e60d7SJames Wright   const bool is_implicit  = context->is_implicit;
76565dd5cafSJames Wright 
76665dd5cafSJames Wright   CeedPragmaSIMD
76765dd5cafSJames Wright   for(CeedInt i=0; i<Q; i++) {
768*2c4e60d7SJames Wright     const CeedScalar U[5]   = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
769*2c4e60d7SJames Wright     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
770*2c4e60d7SJames Wright     const State      s      = StateFromU(context, U, x_i);
77165dd5cafSJames Wright 
77265dd5cafSJames Wright     const CeedScalar wdetJb  = (is_implicit ? -1. : 1.) * q_data_sur[0][i];
77365dd5cafSJames Wright     // ---- Normal vect
77465dd5cafSJames Wright     const CeedScalar norm[3] = {q_data_sur[1][i],
77565dd5cafSJames Wright                                 q_data_sur[2][i],
77665dd5cafSJames Wright                                 q_data_sur[3][i]
77765dd5cafSJames Wright                                };
77865dd5cafSJames Wright 
779*2c4e60d7SJames Wright     const CeedScalar dXdx[2][3] = {
780*2c4e60d7SJames Wright       {q_data_sur[4][i], q_data_sur[5][i], q_data_sur[6][i]},
781*2c4e60d7SJames Wright       {q_data_sur[7][i], q_data_sur[8][i], q_data_sur[9][i]}
782*2c4e60d7SJames Wright     };
78365dd5cafSJames Wright 
784*2c4e60d7SJames Wright     State grad_s[3];
785*2c4e60d7SJames Wright     for (CeedInt j=0; j<3; j++) {
786*2c4e60d7SJames Wright       CeedScalar dx_i[3] = {0}, dU[5];
787*2c4e60d7SJames Wright       for (CeedInt k=0; k<5; k++)
788*2c4e60d7SJames Wright         dU[k] = Grad_q[0][k][i] * dXdx[0][j] +
789*2c4e60d7SJames Wright                 Grad_q[1][k][i] * dXdx[1][j];
790*2c4e60d7SJames Wright       dx_i[j] = 1.;
791*2c4e60d7SJames Wright       grad_s[j] = StateFromU_fwd(context, s, dU, x_i, dx_i);
792*2c4e60d7SJames Wright     }
79365dd5cafSJames Wright 
794*2c4e60d7SJames Wright     CeedScalar strain_rate[6], kmstress[6], stress[3][3], Fe[3];
795*2c4e60d7SJames Wright     KMStrainRate(grad_s, strain_rate);
796*2c4e60d7SJames Wright     NewtonianStress(context, strain_rate, kmstress);
797*2c4e60d7SJames Wright     KMUnpack(kmstress, stress);
798*2c4e60d7SJames Wright     ViscousEnergyFlux(context, s.Y, grad_s, stress, Fe);
799*2c4e60d7SJames Wright 
800*2c4e60d7SJames Wright     StateConservative F_inviscid[3];
801*2c4e60d7SJames Wright     FluxInviscid(context, s, F_inviscid);
802*2c4e60d7SJames Wright 
803*2c4e60d7SJames Wright     CeedScalar Flux[5] = {0.};
804*2c4e60d7SJames Wright     for (int j=0; j<3; j++) {
805*2c4e60d7SJames Wright       Flux[0] += F_inviscid[j].density * norm[j];
806*2c4e60d7SJames Wright       for (int k=0; k<3; k++)
807*2c4e60d7SJames Wright         Flux[k+1] += (F_inviscid[j].momentum[k] - stress[k][j]) * norm[j];
808*2c4e60d7SJames Wright       Flux[4] += (F_inviscid[j].E_total + Fe[j])*norm[j];
809*2c4e60d7SJames Wright     }
810*2c4e60d7SJames Wright 
81165dd5cafSJames Wright     // -- Density
812*2c4e60d7SJames Wright     v[0][i] = -wdetJb * Flux[0];
81365dd5cafSJames Wright 
81465dd5cafSJames Wright     // -- Momentum
81565dd5cafSJames Wright     for (CeedInt j=0; j<3; j++)
816*2c4e60d7SJames Wright       v[j+1][i] = -wdetJb * Flux[j+1];
81765dd5cafSJames Wright 
81865dd5cafSJames Wright     // -- Total Energy Density
819*2c4e60d7SJames Wright     v[4][i] = -wdetJb * Flux[4];
82065dd5cafSJames Wright   }
82165dd5cafSJames Wright   return 0;
82265dd5cafSJames Wright }
82365dd5cafSJames Wright 
82430e9fa81SJames Wright // Outflow boundary condition, weakly setting a constant pressure
82530e9fa81SJames Wright CEED_QFUNCTION(PressureOutflow)(void *ctx, CeedInt Q,
82630e9fa81SJames Wright                                 const CeedScalar *const *in,
82730e9fa81SJames Wright                                 CeedScalar *const *out) {
82830e9fa81SJames Wright   // *INDENT-OFF*
82930e9fa81SJames Wright   // Inputs
83030e9fa81SJames Wright   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[0],
831ce9b5c20SJames Wright                    (*Grad_q)[5][CEED_Q_VLA]  = (const CeedScalar(*)[5][CEED_Q_VLA])in[1],
832ce9b5c20SJames Wright                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2],
833ce9b5c20SJames Wright                    (*x)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[3];
83430e9fa81SJames Wright   // Outputs
83530e9fa81SJames Wright   CeedScalar (*v)[CEED_Q_VLA]            = (CeedScalar(*)[CEED_Q_VLA])out[0],
83630e9fa81SJames Wright              (*jac_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[1];
83730e9fa81SJames Wright   // *INDENT-ON*
83830e9fa81SJames Wright 
83930e9fa81SJames Wright   const NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
84030e9fa81SJames Wright   const bool       implicit = context->is_implicit;
84130e9fa81SJames Wright   const CeedScalar P0       = context->P0;
84230e9fa81SJames Wright 
84330e9fa81SJames Wright   CeedPragmaSIMD
84430e9fa81SJames Wright   // Quadrature Point Loop
84530e9fa81SJames Wright   for (CeedInt i=0; i<Q; i++) {
84630e9fa81SJames Wright     // Setup
84730e9fa81SJames Wright     // -- Interp in
848ce9b5c20SJames Wright     const CeedScalar U[5]   = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]};
849ce9b5c20SJames Wright     const CeedScalar x_i[3] = {x[0][i], x[1][i], x[2][i]};
850ce9b5c20SJames Wright     State            s      = StateFromU(context, U, x_i);
851ce9b5c20SJames Wright     s.Y.pressure = P0;
85230e9fa81SJames Wright 
85330e9fa81SJames Wright     // -- Interp-to-Interp q_data
85430e9fa81SJames Wright     // For explicit mode, the surface integral is on the RHS of ODE q_dot = f(q).
85530e9fa81SJames Wright     // For implicit mode, it gets pulled to the LHS of implicit ODE/DAE g(q_dot, q).
85630e9fa81SJames Wright     // We can effect this by swapping the sign on this weight
85730e9fa81SJames Wright     const CeedScalar wdetJb  = (implicit ? -1. : 1.) * q_data_sur[0][i];
85830e9fa81SJames Wright 
85930e9fa81SJames Wright     // ---- Normal vect
86030e9fa81SJames Wright     const CeedScalar norm[3] = {q_data_sur[1][i],
86130e9fa81SJames Wright                                 q_data_sur[2][i],
86230e9fa81SJames Wright                                 q_data_sur[3][i]
86330e9fa81SJames Wright                                };
86430e9fa81SJames Wright 
865ce9b5c20SJames Wright     const CeedScalar dXdx[2][3] = {
866ce9b5c20SJames Wright       {q_data_sur[4][i], q_data_sur[5][i], q_data_sur[6][i]},
867ce9b5c20SJames Wright       {q_data_sur[7][i], q_data_sur[8][i], q_data_sur[9][i]}
868ce9b5c20SJames Wright     };
86930e9fa81SJames Wright 
870ce9b5c20SJames Wright     State grad_s[3];
871ce9b5c20SJames Wright     for (CeedInt j=0; j<3; j++) {
872ce9b5c20SJames Wright       CeedScalar dx_i[3] = {0}, dU[5];
873ce9b5c20SJames Wright       for (CeedInt k=0; k<5; k++)
874ce9b5c20SJames Wright         dU[k] = Grad_q[0][k][i] * dXdx[0][j] +
875ce9b5c20SJames Wright                 Grad_q[1][k][i] * dXdx[1][j];
876ce9b5c20SJames Wright       dx_i[j] = 1.;
877ce9b5c20SJames Wright       grad_s[j] = StateFromU_fwd(context, s, dU, x_i, dx_i);
878ce9b5c20SJames Wright     }
879ce9b5c20SJames Wright 
880ce9b5c20SJames Wright     CeedScalar strain_rate[6], kmstress[6], stress[3][3], Fe[3];
881ce9b5c20SJames Wright     KMStrainRate(grad_s, strain_rate);
882ce9b5c20SJames Wright     NewtonianStress(context, strain_rate, kmstress);
883ce9b5c20SJames Wright     KMUnpack(kmstress, stress);
884ce9b5c20SJames Wright     ViscousEnergyFlux(context, s.Y, grad_s, stress, Fe);
885ce9b5c20SJames Wright 
886ce9b5c20SJames Wright     StateConservative F_inviscid[3];
887ce9b5c20SJames Wright     FluxInviscid(context, s, F_inviscid);
888ce9b5c20SJames Wright 
889ce9b5c20SJames Wright     CeedScalar Flux[5] = {0.};
890ce9b5c20SJames Wright     for (int j=0; j<3; j++) {
891ce9b5c20SJames Wright       Flux[0] += F_inviscid[j].density * norm[j];
892ce9b5c20SJames Wright       for (int k=0; k<3; k++)
893ce9b5c20SJames Wright         Flux[k+1] += (F_inviscid[j].momentum[k] - stress[k][j]) * norm[j];
894ce9b5c20SJames Wright       Flux[4] += (F_inviscid[j].E_total + Fe[j])*norm[j];
895ce9b5c20SJames Wright     }
89630e9fa81SJames Wright 
89730e9fa81SJames Wright     // -- Density
898ce9b5c20SJames Wright     v[0][i] = -wdetJb * Flux[0];
89930e9fa81SJames Wright 
90030e9fa81SJames Wright     // -- Momentum
90130e9fa81SJames Wright     for (CeedInt j=0; j<3; j++)
902ce9b5c20SJames Wright       v[j+1][i] = -wdetJb * Flux[j+1];
90330e9fa81SJames Wright 
90430e9fa81SJames Wright     // -- Total Energy Density
905ce9b5c20SJames Wright     v[4][i] = -wdetJb * Flux[4];
90630e9fa81SJames Wright 
90730e9fa81SJames Wright     // Save values for Jacobian
908ce9b5c20SJames Wright     jac_data_sur[0][i] = s.U.density;
909ce9b5c20SJames Wright     jac_data_sur[1][i] = s.Y.velocity[0];
910ce9b5c20SJames Wright     jac_data_sur[2][i] = s.Y.velocity[1];
911ce9b5c20SJames Wright     jac_data_sur[3][i] = s.Y.velocity[2];
912ce9b5c20SJames Wright     jac_data_sur[4][i] = s.U.E_total;
91330e9fa81SJames Wright   } // End Quadrature Point Loop
91430e9fa81SJames Wright   return 0;
91530e9fa81SJames Wright }
91630e9fa81SJames Wright 
91730e9fa81SJames Wright // Jacobian for weak-pressure outflow boundary condition
91830e9fa81SJames Wright CEED_QFUNCTION(PressureOutflow_Jacobian)(void *ctx, CeedInt Q,
91930e9fa81SJames Wright     const CeedScalar *const *in,
92030e9fa81SJames Wright     CeedScalar *const *out) {
92130e9fa81SJames Wright   // *INDENT-OFF*
92230e9fa81SJames Wright   // Inputs
92330e9fa81SJames Wright   const CeedScalar (*dq)[CEED_Q_VLA]           = (const CeedScalar(*)[CEED_Q_VLA])in[0],
92430e9fa81SJames Wright                    (*q_data_sur)[CEED_Q_VLA]   = (const CeedScalar(*)[CEED_Q_VLA])in[1],
92530e9fa81SJames Wright                    (*jac_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2];
92630e9fa81SJames Wright   // Outputs
92730e9fa81SJames Wright   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
92830e9fa81SJames Wright   // *INDENT-ON*
92930e9fa81SJames Wright 
93030e9fa81SJames Wright   const NewtonianIdealGasContext context = (NewtonianIdealGasContext)ctx;
93130e9fa81SJames Wright   const bool implicit     = context->is_implicit;
93230e9fa81SJames Wright 
93330e9fa81SJames Wright   CeedPragmaSIMD
93430e9fa81SJames Wright   // Quadrature Point Loop
93530e9fa81SJames Wright   for (CeedInt i=0; i<Q; i++) {
93630e9fa81SJames Wright     const CeedScalar rho = jac_data_sur[0][i];
93730e9fa81SJames Wright     const CeedScalar u[3] = {jac_data_sur[1][i], jac_data_sur[2][i], jac_data_sur[3][i]};
93830e9fa81SJames Wright     const CeedScalar E = jac_data_sur[4][i];
93930e9fa81SJames Wright 
94030e9fa81SJames Wright     const CeedScalar drho      =  dq[0][i];
94130e9fa81SJames Wright     const CeedScalar dmomentum[3] = {dq[1][i], dq[2][i], dq[3][i]};
94230e9fa81SJames Wright     const CeedScalar dE        =  dq[4][i];
94330e9fa81SJames Wright 
94430e9fa81SJames Wright     const CeedScalar wdetJb  = (implicit ? -1. : 1.) * q_data_sur[0][i];
94530e9fa81SJames Wright     const CeedScalar norm[3] = {q_data_sur[1][i],
94630e9fa81SJames Wright                                 q_data_sur[2][i],
94730e9fa81SJames Wright                                 q_data_sur[3][i]
94830e9fa81SJames Wright                                };
94930e9fa81SJames Wright 
95030e9fa81SJames Wright     CeedScalar du[3];
95130e9fa81SJames Wright     for (int j=0; j<3; j++) du[j] = (dmomentum[j] - u[j] * drho) / rho;
95230e9fa81SJames Wright     const CeedScalar u_normal  = Dot3(norm, u);
95330e9fa81SJames Wright     const CeedScalar du_normal = Dot3(norm, du);
95430e9fa81SJames Wright     const CeedScalar dmomentum_normal = drho * u_normal + rho * du_normal;
95530e9fa81SJames Wright     const CeedScalar P = context->P0;
95630e9fa81SJames Wright     const CeedScalar dP = 0;
95730e9fa81SJames Wright 
95830e9fa81SJames Wright     v[0][i] = -wdetJb * dmomentum_normal;
95930e9fa81SJames Wright     for (int j=0; j<3; j++)
96030e9fa81SJames Wright       v[j+1][i] = -wdetJb * (dmomentum_normal * u[j] + rho * u_normal * du[j]);
96130e9fa81SJames Wright     v[4][i] = -wdetJb * (du_normal * (E + P) + u_normal * (dE + dP));
96230e9fa81SJames Wright   } // End Quadrature Point Loop
96330e9fa81SJames Wright   return 0;
96430e9fa81SJames Wright }
96530e9fa81SJames Wright 
96688b783a1SJames Wright // *****************************************************************************
96788b783a1SJames Wright #endif // newtonian_h
968