xref: /libCEED/examples/fluids/qfunctions/blasius.h (revision cefa2673c9b7c6fb97d32b63fbbfb5d237e3c796)
1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 /// @file
9 /// Operator for Navier-Stokes example using PETSc
10 
11 
12 #ifndef blasius_h
13 #define blasius_h
14 
15 #include <math.h>
16 #include <ceed.h>
17 #include "newtonian_types.h"
18 
19 typedef struct BlasiusContext_ *BlasiusContext;
20 struct BlasiusContext_ {
21   bool       implicit;  // !< Using implicit timesteping or not
22   bool       weakT;     // !< flag to set Temperature weakly at inflow
23   CeedScalar delta0;    // !< Boundary layer height at inflow
24   CeedScalar Uinf;      // !< Velocity at boundary layer edge
25   CeedScalar P0;        // !< Pressure at outflow
26   CeedScalar theta0;    // !< Temperature at inflow
27   CeedScalar x_inflow;  // !< Location of inflow in x
28   struct NewtonianIdealGasContext_ newtonian_ctx;
29 };
30 
31 #ifndef M_PI
32 #define M_PI    3.14159265358979323846
33 #endif
34 
35 void CEED_QFUNCTION_HELPER(BlasiusSolution)(const CeedScalar y,
36     const CeedScalar Uinf, const CeedScalar x0, const CeedScalar x,
37     const CeedScalar rho, CeedScalar *u, CeedScalar *v, CeedScalar *t12,
38     const NewtonianIdealGasContext newt_ctx) {
39 
40   CeedInt nprofs = 50;
41   // *INDENT-OFF*
42   CeedScalar eta_table[] = {
43     0.000000000000000000e+00, 1.282051282051281937e-01, 2.564102564102563875e-01, 3.846153846153845812e-01, 5.128205128205127750e-01,
44     6.410256410256409687e-01, 7.692307692307691624e-01, 8.974358974358973562e-01, 1.025641025641025550e+00, 1.153846153846153744e+00,
45     1.282051282051281937e+00, 1.410256410256410131e+00, 1.538461538461538325e+00, 1.666666666666666519e+00, 1.794871794871794712e+00,
46     1.923076923076922906e+00, 2.051282051282051100e+00, 2.179487179487179294e+00, 2.307692307692307487e+00, 2.435897435897435681e+00,
47     2.564102564102563875e+00, 2.692307692307692069e+00, 2.820512820512820262e+00, 2.948717948717948456e+00, 3.076923076923076650e+00,
48     3.205128205128204844e+00, 3.333333333333333037e+00, 3.461538461538461231e+00, 3.589743589743589425e+00, 3.717948717948717618e+00,
49     3.846153846153845812e+00, 3.974358974358974006e+00, 4.102564102564102200e+00, 4.230769230769229949e+00, 4.358974358974358587e+00,
50     4.487179487179487225e+00, 4.615384615384614975e+00, 4.743589743589742724e+00, 4.871794871794871362e+00, 5.000000000000000000e+00,
51     5.500000000000000000e+00, 6.000000000000000000e+00, 6.500000000000000000e+00, 7.000000000000000000e+00, 7.500000000000000000e+00,
52     8.000000000000000000e+00, 8.500000000000000000e+00, 9.000000000000000000e+00, 9.500000000000000000e+00, 1.000000000000000000e+01};
53 
54   CeedScalar f_table[] = {
55     0.000000000000000000e+00, 2.728923405566200267e-03, 1.091524811461423369e-02, 2.455658828897525764e-02, 4.364674649279581820e-02,
56     6.817382707725749835e-02, 9.811838418932711248e-02, 1.334516294237205192e-01, 1.741337304561980659e-01, 2.201122374410622862e-01,
57     2.713206781625860375e-01, 3.276773654929600599e-01, 3.890844612583744255e-01, 4.554273387986328414e-01, 5.265742820946719416e-01,
58     6.023765522220410062e-01, 6.826688421431770237e-01, 7.672701287583111318e-01, 8.559849171804534418e-01, 9.486048570979430661e-01,
59     1.044910695686512625e+00, 1.144674516826549082e+00, 1.247662203367335465e+00, 1.353636048811749593e+00, 1.462357437868362364e+00,
60     1.573589512396551759e+00, 1.687099740622293842e+00, 1.802662313062363353e+00, 1.920060297987626230e+00, 2.039087501786055245e+00,
61     2.159549994377929050e+00, 2.281267275838891884e+00, 2.404073076539093190e+00, 2.527815798402052838e+00, 2.652358618452637540e+00,
62     2.777579287003750341e+00, 2.903369661199559637e+00, 3.029635020019957992e+00, 3.156293209307130088e+00, 3.283273665161465349e+00,
63     3.780571892998292771e+00, 4.279620922520262383e+00, 4.779322325882148448e+00, 5.279238811036782053e+00, 5.779218028455369804e+00,
64     6.279213431354994768e+00, 6.779212528163703233e+00, 7.279212370655419484e+00, 7.779212346288013613e+00, 8.279212342945751146e+00};
65 
66   CeedScalar fp_table[] = {
67     0.000000000000000000e+00, 4.257083277988830267e-02, 8.513297869782740501e-02, 1.276641169537044151e-01, 1.701271279078802878e-01,
68     2.124702831905590783e-01, 2.546276046951935212e-01, 2.965194442747576264e-01, 3.380533304776729975e-01, 3.791251204629754179e-01,
69     4.196204840172004791e-01, 4.594167322894788796e-01, 4.983849866855867838e-01, 5.363926638765821320e-01, 5.733062319885513514e-01,
70     6.089941719927144392e-01, 6.433300586189647507e-01, 6.761956584341198839e-01, 7.074839307288774970e-01, 7.371018110314454530e-01,
71     7.649726585225528064e-01, 7.910382579383948842e-01, 8.152602836158657773e-01, 8.376211573266827415e-01, 8.581242609418713307e-01,
72     8.767934976651666767e-01, 8.936722290953328374e-01, 9.088216471306606037e-01, 9.223186672607004422e-01, 9.342534510898168332e-01,
73     9.447266795705382414e-01, 9.538467037387058367e-01, 9.617266968332524035e-01, 9.684819213624265011e-01, 9.742272083384174719e-01,
74     9.790747253056680810e-01, 9.831320868743089747e-01, 9.865008381344084754e-01, 9.892753192614093249e-01, 9.915419001656551323e-01,
75     9.968788209317821503e-01, 9.989728724371175206e-01, 9.996990677381791812e-01, 9.999216041491896245e-01, 9.999818594083667023e-01,
76     9.999962745365539307e-01, 9.999993214550036980e-01, 9.999998904550418954e-01, 9.999999843329338001e-01, 9.999999980166356384e-01};
77 
78   CeedScalar fpp_table[] = {
79     3.320573362157903663e-01, 3.320379743512646420e-01, 3.319024760665882368e-01, 3.315350015070190337e-01, 3.308206767975666041e-01,
80     3.296466995822193158e-01, 3.279038639411161471e-01, 3.254884713737624113e-01, 3.223045750196085746e-01, 3.182664816607024272e-01,
81     3.133014118810801829e-01, 3.073521951089355775e-01, 3.003798556086043625e-01, 2.923659305537876785e-01, 2.833143548208253981e-01,
82     2.732527514995234941e-01, 2.622329840371728227e-01, 2.503308560706500874e-01, 2.376448876931176457e-01, 2.242941499773744018e-01,
83     2.104151994284793603e-01, 1.961582158440171031e-01, 1.816825052623964043e-01, 1.671515786102889534e-01, 1.527280512426029968e-01,
84     1.385686249977987894e-01, 1.248194106805364800e-01, 1.116118251613979206e-01, 9.905925581301598670e-02, 8.725462988794610575e-02,
85     7.626896310981794158e-02, 6.615089622448211415e-02, 5.692716644118058639e-02, 4.860390768479891377e-02, 4.116863313890323922e-02,
86     3.459272784597366285e-02, 2.883426862493499582e-02, 2.384099224121952881e-02, 1.955324839409207718e-02, 1.590679868531958210e-02,
87     6.578593141419011685e-03, 2.402039843751689954e-03, 7.741093231657678389e-04, 2.201689553063347941e-04, 5.526217815680267893e-05,
88     1.224092624232004387e-05, 2.392841910090350858e-06, 4.127879363882133676e-07, 6.284244603762621373e-08, 8.442944409712819646e-09};
89   // *INDENT-ON*
90 
91   CeedScalar nu = newt_ctx->mu / rho;
92   CeedScalar eta = y*sqrt(Uinf/(nu*(x0+x)));
93   CeedInt idx=-1;
94 
95   for(CeedInt i=0; i<nprofs; i++) {
96     if (eta < eta_table[i]) {
97       idx = i;
98       break;
99     }
100   }
101   CeedScalar f, fp, fpp;
102 
103   if (idx > 0) { // eta within the bounds of eta_table
104     CeedScalar coeff = (eta - eta_table[idx-1]) / (eta_table[idx] - eta_table[idx
105                        -1]);
106 
107     f   = f_table[idx-1]   + coeff*( f_table[idx]   - f_table[idx-1] );
108     fp  = fp_table[idx-1]  + coeff*( fp_table[idx]  - fp_table[idx-1] );
109     fpp = fpp_table[idx-1] + coeff*( fpp_table[idx] - fpp_table[idx-1] );
110   } else { // eta outside bounds of eta_table
111     f   = f_table[nprofs-1];
112     fp  = fp_table[nprofs-1];
113     fpp = fpp_table[nprofs-1];
114     eta = eta_table[nprofs-1];
115   }
116 
117   *u = Uinf*fp;
118   *t12 = rho*nu*Uinf*fpp*sqrt(Uinf/(nu*(x0+x)));
119   *v = 0.5*sqrt(nu*Uinf/(x0+x))*(eta*fp - f);
120 }
121 
122 // *****************************************************************************
123 // This QFunction sets a Blasius boundary layer for the initial condition
124 // *****************************************************************************
125 CEED_QFUNCTION(ICsBlasius)(void *ctx, CeedInt Q,
126                            const CeedScalar *const *in, CeedScalar *const *out) {
127   // Inputs
128   const CeedScalar (*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
129 
130   // Outputs
131   CeedScalar (*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
132 
133   const BlasiusContext context = (BlasiusContext)ctx;
134   const CeedScalar cv     = context->newtonian_ctx.cv;
135   const CeedScalar cp     = context->newtonian_ctx.cp;
136   const CeedScalar gamma  = cp/cv;
137   const CeedScalar mu     = context->newtonian_ctx.mu;
138 
139   const CeedScalar theta0 = context->theta0;
140   const CeedScalar P0     = context->P0;
141   const CeedScalar delta0 = context->delta0;
142   const CeedScalar Uinf   = context->Uinf;
143   const CeedScalar x_inflow   = context->x_inflow;
144 
145   const CeedScalar e_internal = cv * theta0;
146   const CeedScalar rho        = P0 / ((gamma - 1) * e_internal);
147   const CeedScalar x0         = Uinf*rho / (mu*25/ (delta0*delta0) );
148   CeedScalar u, v, t12;
149 
150   // Quadrature Point Loop
151   CeedPragmaSIMD
152   for (CeedInt i=0; i<Q; i++) {
153     const CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
154 
155     BlasiusSolution(x[1], Uinf, x0, x[0] - x_inflow, rho, &u, &v, &t12,
156                     &context->newtonian_ctx);
157 
158     q0[0][i] = rho;
159     q0[1][i] = u * rho;
160     q0[2][i] = v * rho;
161     q0[3][i] = 0.;
162     q0[4][i] = rho * e_internal + 0.5*(u*u + v*v)*rho;
163   } // End of Quadrature Point Loop
164   return 0;
165 }
166 
167 // *****************************************************************************
168 CEED_QFUNCTION(Blasius_Inflow)(void *ctx, CeedInt Q,
169                                const CeedScalar *const *in,
170                                CeedScalar *const *out) {
171   // *INDENT-OFF*
172   // Inputs
173   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[0],
174                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1],
175                    (*X)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[2];
176 
177   // Outputs
178   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
179   // *INDENT-ON*
180   const BlasiusContext context = (BlasiusContext)ctx;
181   const bool implicit     = context->implicit;
182   const CeedScalar mu     = context->newtonian_ctx.mu;
183   const CeedScalar cv     = context->newtonian_ctx.cv;
184   const CeedScalar cp     = context->newtonian_ctx.cp;
185   const CeedScalar Rd     = cp - cv;
186   const CeedScalar gamma  = cp/cv;
187 
188   const CeedScalar theta0   = context->theta0;
189   const CeedScalar P0       = context->P0;
190   const CeedScalar delta0   = context->delta0;
191   const CeedScalar Uinf     = context->Uinf;
192   const CeedScalar x_inflow = context->x_inflow;
193   const bool       weakT    = context->weakT;
194   const CeedScalar rho_0    = P0 / (Rd * theta0);
195   const CeedScalar x0       = Uinf*rho_0 / (mu*25/ (delta0*delta0) );
196 
197   CeedPragmaSIMD
198   // Quadrature Point Loop
199   for (CeedInt i=0; i<Q; i++) {
200     // Setup
201     // -- Interp-to-Interp q_data
202     // For explicit mode, the surface integral is on the RHS of ODE q_dot = f(q).
203     // For implicit mode, it gets pulled to the LHS of implicit ODE/DAE g(q_dot, q).
204     // We can effect this by swapping the sign on this weight
205     const CeedScalar wdetJb  = (implicit ? -1. : 1.) * q_data_sur[0][i];
206 
207     // Calculate inflow values
208     const CeedScalar x[3] = {X[0][i], X[1][i], X[2][i]};
209     CeedScalar velocity[3] = {0.};
210     CeedScalar t12;
211     BlasiusSolution(x[1], Uinf, x0, x[0] - x_inflow, rho_0, &velocity[0],
212                     &velocity[1], &t12, &context->newtonian_ctx);
213 
214     // enabling user to choose between weak T and weak rho inflow
215     CeedScalar rho,E_internal, P, E_kinetic;
216     if (weakT) {
217       // rho should be from the current solution
218       rho = q[0][i];
219       // Temperature is being set weakly (theta0) and for constant cv this sets E_internal
220       E_internal = rho * cv * theta0;
221       // Find pressure using
222       P = rho*Rd*theta0; // interior rho with exterior T
223       E_kinetic = .5 * rho * Dot3(velocity, velocity);
224     } else {
225       //  Fixing rho weakly on the inflow to a value  consistent with theta0 and P0
226       rho =  rho_0;
227       E_kinetic = .5 * rho * Dot3(velocity, velocity);
228       E_internal = q[4][i] - E_kinetic; // uses set rho and u but E from solution
229       P = E_internal * (gamma - 1.);
230     }
231     const CeedScalar E = E_internal + E_kinetic;
232     // ---- Normal vect
233     const CeedScalar norm[3] = {q_data_sur[1][i],
234                                 q_data_sur[2][i],
235                                 q_data_sur[3][i]
236                                };
237 
238     // The Physics
239     // Zero v so all future terms can safely sum into it
240     for (CeedInt j=0; j<5; j++) v[j][i] = 0.;
241 
242     const CeedScalar u_normal = Dot3(norm, velocity);
243     const CeedScalar viscous_flux[3] = {-t12 *norm[1], -t12 *norm[0], 0};
244 
245     // The Physics
246     // -- Density
247     v[0][i] -= wdetJb * rho * u_normal; // interior rho
248 
249     // -- Momentum
250     for (CeedInt j=0; j<3; j++)
251       v[j+1][i] -= wdetJb * (rho * u_normal * velocity[j] // interior rho
252                              + norm[j] * P // mixed P
253                              + viscous_flux[j]);
254 
255     // -- Total Energy Density
256     v[4][i] -= wdetJb * (u_normal * (E + P) + Dot3(viscous_flux, velocity));
257 
258   } // End Quadrature Point Loop
259   return 0;
260 }
261 
262 CEED_QFUNCTION(Blasius_Inflow_Jacobian)(void *ctx, CeedInt Q,
263                                         const CeedScalar *const *in,
264                                         CeedScalar *const *out) {
265   // *INDENT-OFF*
266   // Inputs
267   const CeedScalar (*dq)[CEED_Q_VLA]         = (const CeedScalar(*)[CEED_Q_VLA])in[0],
268                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1],
269                    (*X)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[2];
270 
271   // Outputs
272   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
273   // *INDENT-ON*
274   const BlasiusContext context = (BlasiusContext)ctx;
275   const bool implicit     = context->implicit;
276   const CeedScalar mu     = context->newtonian_ctx.mu;
277   const CeedScalar cv     = context->newtonian_ctx.cv;
278   const CeedScalar cp     = context->newtonian_ctx.cp;
279   const CeedScalar Rd     = cp - cv;
280   const CeedScalar gamma  = cp/cv;
281 
282   const CeedScalar theta0 = context->theta0;
283   const CeedScalar P0     = context->P0;
284   const CeedScalar delta0 = context->delta0;
285   const CeedScalar Uinf   = context->Uinf;
286   const bool weakT        = context->weakT;
287   const CeedScalar rho_0  = P0 / (Rd * theta0);
288   const CeedScalar x0     = Uinf*rho_0 / (mu*25/ (delta0*delta0) );
289 
290   CeedPragmaSIMD
291   // Quadrature Point Loop
292   for (CeedInt i=0; i<Q; i++) {
293     // Setup
294     // -- Interp-to-Interp q_data
295     // For explicit mode, the surface integral is on the RHS of ODE q_dot = f(q).
296     // For implicit mode, it gets pulled to the LHS of implicit ODE/DAE g(q_dot, q).
297     // We can effect this by swapping the sign on this weight
298     const CeedScalar wdetJb  = (implicit ? -1. : 1.) * q_data_sur[0][i];
299 
300     // Calculate inflow values
301     const CeedScalar x[3] = {X[0][i], X[1][i], X[2][i]};
302     CeedScalar velocity[3] = {0};
303     CeedScalar t12;
304     BlasiusSolution(x[1], Uinf, x0, x[0], rho_0, &velocity[0], &velocity[1],
305                     &t12, &context->newtonian_ctx);
306 
307     // enabling user to choose between weak T and weak rho inflow
308     CeedScalar drho, dE, dP;
309     if (weakT) {
310       // rho should be from the current solution
311       drho = dq[0][i];
312       CeedScalar dE_internal = drho * cv * theta0;
313       CeedScalar dE_kinetic = .5 * drho * Dot3(velocity, velocity);
314       dE = dE_internal + dE_kinetic;
315       dP = drho * Rd * theta0; // interior rho with exterior T
316     } else { // rho specified, E_internal from solution
317       drho = 0;
318       dE = dq[4][i];
319       dP = dE * (gamma - 1.);
320     }
321     const CeedScalar norm[3] = {q_data_sur[1][i],
322                                 q_data_sur[2][i],
323                                 q_data_sur[3][i]
324                                };
325 
326     const CeedScalar u_normal = Dot3(norm, velocity);
327 
328     v[0][i] = - wdetJb * drho * u_normal;
329     for (int j=0; j<3; j++)
330       v[j+1][i] = -wdetJb * (drho * u_normal * velocity[j] + norm[j] * dP);
331     v[4][i] = - wdetJb * u_normal * (dE + dP);
332   } // End Quadrature Point Loop
333   return 0;
334 }
335 
336 // *****************************************************************************
337 CEED_QFUNCTION(Blasius_Outflow)(void *ctx, CeedInt Q,
338                                 const CeedScalar *const *in,
339                                 CeedScalar *const *out) {
340   // *INDENT-OFF*
341   // Inputs
342   const CeedScalar (*q)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[0],
343                    (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1],
344                    (*X)[CEED_Q_VLA]          = (const CeedScalar(*)[CEED_Q_VLA])in[2];
345   // Outputs
346   CeedScalar (*v)[CEED_Q_VLA]            = (CeedScalar(*)[CEED_Q_VLA])out[0],
347              (*jac_data_sur)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[1];
348   // *INDENT-ON*
349 
350   const BlasiusContext context = (BlasiusContext)ctx;
351   const bool implicit     = context->implicit;
352   const CeedScalar mu     = context->newtonian_ctx.mu;
353   const CeedScalar cv     = context->newtonian_ctx.cv;
354   const CeedScalar cp     = context->newtonian_ctx.cp;
355   const CeedScalar Rd     = cp - cv;
356 
357   const CeedScalar theta0   = context->theta0;
358   const CeedScalar P0       = context->P0;
359   const CeedScalar rho_0    = P0 / (Rd*theta0);
360   const CeedScalar delta0   = context->delta0;
361   const CeedScalar Uinf     = context->Uinf;
362   const CeedScalar x0       = Uinf*rho_0 / (mu*25/ (delta0*delta0) );
363   const CeedScalar x_inflow = context->x_inflow;
364 
365   CeedPragmaSIMD
366   // Quadrature Point Loop
367   for (CeedInt i=0; i<Q; i++) {
368     // Setup
369     // -- Interp in
370     const CeedScalar rho      =  q[0][i];
371     const CeedScalar u[3]     = {q[1][i] / rho,
372                                  q[2][i] / rho,
373                                  q[3][i] / rho
374                                 };
375     const CeedScalar E        =  q[4][i];
376 
377     // -- Interp-to-Interp q_data
378     // For explicit mode, the surface integral is on the RHS of ODE q_dot = f(q).
379     // For implicit mode, it gets pulled to the LHS of implicit ODE/DAE g(q_dot, q).
380     // We can effect this by swapping the sign on this weight
381     const CeedScalar wdetJb  = (implicit ? -1. : 1.) * q_data_sur[0][i];
382 
383     // ---- Normal vect
384     const CeedScalar norm[3] = {q_data_sur[1][i],
385                                 q_data_sur[2][i],
386                                 q_data_sur[3][i]
387                                };
388 
389     // Implementing outflow condition
390     const CeedScalar P         = P0; // pressure
391     const CeedScalar u_normal  = Dot3(norm, u); // Normal velocity
392 
393     // Calculate prescribed outflow traction values
394     const CeedScalar x[3] = {X[0][i], X[1][i], X[2][i]};
395     CeedScalar velocity[3] = {0.};
396     CeedScalar t12;
397     BlasiusSolution(x[1], Uinf, x0, x[0] - x_inflow, rho_0, &velocity[0],
398                     &velocity[1], &t12, &context->newtonian_ctx);
399     const CeedScalar viscous_flux[3] = {-t12 *norm[1], -t12 *norm[0], 0};
400 
401     // -- Density
402     v[0][i] = -wdetJb * rho * u_normal;
403 
404     // -- Momentum
405     for (CeedInt j=0; j<3; j++)
406       v[j+1][i] = -wdetJb * (rho * u_normal * u[j]
407                              + norm[j] * P + viscous_flux[j]);
408 
409     // -- Total Energy Density
410     v[4][i] = -wdetJb * (u_normal * (E + P)
411                          + Dot3(viscous_flux, velocity));
412 
413     // Save values for Jacobian
414     jac_data_sur[0][i] = rho;
415     jac_data_sur[1][i] = u[0];
416     jac_data_sur[2][i] = u[1];
417     jac_data_sur[3][i] = u[2];
418     jac_data_sur[4][i] = E;
419   } // End Quadrature Point Loop
420   return 0;
421 }
422 
423 CEED_QFUNCTION(Blasius_Outflow_Jacobian)(void *ctx, CeedInt Q,
424     const CeedScalar *const *in,
425     CeedScalar *const *out) {
426   // *INDENT-OFF*
427   // Inputs
428   const CeedScalar (*dq)[CEED_Q_VLA]           = (const CeedScalar(*)[CEED_Q_VLA])in[0],
429                    (*q_data_sur)[CEED_Q_VLA]   = (const CeedScalar(*)[CEED_Q_VLA])in[1],
430                    (*jac_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2];
431   // Outputs
432   CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
433   // *INDENT-ON*
434 
435   const BlasiusContext context = (BlasiusContext)ctx;
436   const bool implicit     = context->implicit;
437 
438   CeedPragmaSIMD
439   // Quadrature Point Loop
440   for (CeedInt i=0; i<Q; i++) {
441     const CeedScalar rho = jac_data_sur[0][i];
442     const CeedScalar u[3] = {jac_data_sur[1][i], jac_data_sur[2][i], jac_data_sur[3][i]};
443     const CeedScalar E = jac_data_sur[4][i];
444 
445     const CeedScalar drho      =  dq[0][i];
446     const CeedScalar dmomentum[3] = {dq[1][i], dq[2][i], dq[3][i]};
447     const CeedScalar dE        =  dq[4][i];
448 
449     const CeedScalar wdetJb  = (implicit ? -1. : 1.) * q_data_sur[0][i];
450     const CeedScalar norm[3] = {q_data_sur[1][i],
451                                 q_data_sur[2][i],
452                                 q_data_sur[3][i]
453                                };
454 
455     CeedScalar du[3];
456     for (int j=0; j<3; j++) du[j] = (dmomentum[j] - u[j] * drho) / rho;
457     const CeedScalar u_normal  = Dot3(norm, u);
458     const CeedScalar du_normal = Dot3(norm, du);
459     const CeedScalar dmomentum_normal = drho * u_normal + rho * du_normal;
460     const CeedScalar P = context->P0;
461     const CeedScalar dP = 0;
462 
463     v[0][i] = -wdetJb * dmomentum_normal;
464     for (int j=0; j<3; j++)
465       v[j+1][i] = -wdetJb * (dmomentum_normal * u[j] + rho * u_normal * du[j]);
466     v[4][i] = -wdetJb * (du_normal * (E + P) + u_normal * (dE + dP));
467   } // End Quadrature Point Loop
468   return 0;
469 }
470 
471 #endif // blasius_h
472