1475b2820SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2475b2820SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3475b2820SJames Wright // 4475b2820SJames Wright // SPDX-License-Identifier: BSD-2-Clause 5475b2820SJames Wright // 6475b2820SJames Wright // This file is part of CEED: http://github.com/ceed 7475b2820SJames Wright 8475b2820SJames Wright /// @file 9475b2820SJames Wright /// Structs and helper functions regarding the state of a newtonian simulation 10475b2820SJames Wright 11475b2820SJames Wright #ifndef newtonian_state_h 12475b2820SJames Wright #define newtonian_state_h 13475b2820SJames Wright 14475b2820SJames Wright #include <ceed.h> 15d0cce58aSJeremy L Thompson #include <math.h> 162b916ea7SJeremy L Thompson 17475b2820SJames Wright #include "newtonian_types.h" 18704b8bbeSJames Wright #include "utils.h" 19475b2820SJames Wright 20475b2820SJames Wright typedef struct { 21475b2820SJames Wright CeedScalar density; 22475b2820SJames Wright CeedScalar momentum[3]; 23475b2820SJames Wright CeedScalar E_total; 24475b2820SJames Wright } StateConservative; 25475b2820SJames Wright 26475b2820SJames Wright typedef struct { 27475b2820SJames Wright StateConservative U; 28475b2820SJames Wright StatePrimitive Y; 29475b2820SJames Wright } State; 30475b2820SJames Wright 31d1b9ef12SLeila Ghaffari CEED_QFUNCTION_HELPER void UnpackState_U(StateConservative s, CeedScalar U[5]) { 32d1b9ef12SLeila Ghaffari U[0] = s.density; 33d1b9ef12SLeila Ghaffari for (int i = 0; i < 3; i++) U[i + 1] = s.momentum[i]; 34d1b9ef12SLeila Ghaffari U[4] = s.E_total; 35d1b9ef12SLeila Ghaffari } 36d1b9ef12SLeila Ghaffari 37d1b9ef12SLeila Ghaffari CEED_QFUNCTION_HELPER void UnpackState_Y(StatePrimitive s, CeedScalar Y[5]) { 38d1b9ef12SLeila Ghaffari Y[0] = s.pressure; 39d1b9ef12SLeila Ghaffari for (int i = 0; i < 3; i++) Y[i + 1] = s.velocity[i]; 40d1b9ef12SLeila Ghaffari Y[4] = s.temperature; 41d1b9ef12SLeila Ghaffari } 42d1b9ef12SLeila Ghaffari 432b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar HeatCapacityRatio(NewtonianIdealGasContext gas) { return gas->cp / gas->cv; } 44e0d1a4dfSLeila Ghaffari 452b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar GasConstant(NewtonianIdealGasContext gas) { return gas->cp - gas->cv; } 46e0d1a4dfSLeila Ghaffari 472b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar Prandtl(NewtonianIdealGasContext gas) { return gas->cp * gas->mu / gas->k; } 48e0d1a4dfSLeila Ghaffari 492b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar SoundSpeed(NewtonianIdealGasContext gas, CeedScalar T) { return sqrt(gas->cp * (HeatCapacityRatio(gas) - 1.) * T); } 50e0d1a4dfSLeila Ghaffari 512b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar Mach(NewtonianIdealGasContext gas, CeedScalar T, CeedScalar u) { return u / SoundSpeed(gas, T); } 52e0d1a4dfSLeila Ghaffari 532b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar TotalSpecificEnthalpy(NewtonianIdealGasContext gas, const State s) { 54c50f56e5SJames Wright // Ignoring potential energy 55c50f56e5SJames Wright CeedScalar e_internal = gas->cv * s.Y.temperature; 56c50f56e5SJames Wright CeedScalar e_kinetic = 0.5 * Dot3(s.Y.velocity, s.Y.velocity); 57c50f56e5SJames Wright return e_internal + e_kinetic + s.Y.pressure / s.U.density; 58c50f56e5SJames Wright } 59c50f56e5SJames Wright 602b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER CeedScalar TotalSpecificEnthalpy_fwd(NewtonianIdealGasContext gas, const State s, const State ds) { 61c50f56e5SJames Wright // Ignoring potential energy 62c50f56e5SJames Wright CeedScalar de_kinetic = Dot3(ds.Y.velocity, s.Y.velocity); 63c50f56e5SJames Wright CeedScalar de_internal = gas->cv * ds.Y.temperature; 642b916ea7SJeremy L Thompson return de_internal + de_kinetic + ds.Y.pressure / s.U.density - s.Y.pressure / Square(s.U.density) * ds.U.density; 65c50f56e5SJames Wright } 66c50f56e5SJames Wright 672b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromConservative(NewtonianIdealGasContext gas, StateConservative U, const CeedScalar x[3]) { 68475b2820SJames Wright StatePrimitive Y; 69475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) Y.velocity[i] = U.momentum[i] / U.density; 70475b2820SJames Wright CeedScalar e_kinetic = .5 * Dot3(Y.velocity, Y.velocity); 71475b2820SJames Wright CeedScalar e_potential = -Dot3(gas->g, x); 72475b2820SJames Wright CeedScalar e_total = U.E_total / U.density; 73475b2820SJames Wright CeedScalar e_internal = e_total - e_kinetic - e_potential; 74475b2820SJames Wright Y.temperature = e_internal / gas->cv; 75e0d1a4dfSLeila Ghaffari Y.pressure = (HeatCapacityRatio(gas) - 1) * U.density * e_internal; 76475b2820SJames Wright return Y; 77475b2820SJames Wright } 78475b2820SJames Wright 792b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromConservative_fwd(NewtonianIdealGasContext gas, State s, StateConservative dU, 80475b2820SJames Wright const CeedScalar x[3], const CeedScalar dx[3]) { 81475b2820SJames Wright StatePrimitive dY; 82475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 83475b2820SJames Wright dY.velocity[i] = (dU.momentum[i] - s.Y.velocity[i] * dU.density) / s.U.density; 84475b2820SJames Wright } 85475b2820SJames Wright CeedScalar e_kinetic = .5 * Dot3(s.Y.velocity, s.Y.velocity); 86475b2820SJames Wright CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 87475b2820SJames Wright CeedScalar e_potential = -Dot3(gas->g, x); 88475b2820SJames Wright CeedScalar de_potential = -Dot3(gas->g, dx); 89475b2820SJames Wright CeedScalar e_total = s.U.E_total / s.U.density; 90475b2820SJames Wright CeedScalar de_total = (dU.E_total - e_total * dU.density) / s.U.density; 91475b2820SJames Wright CeedScalar e_internal = e_total - e_kinetic - e_potential; 92475b2820SJames Wright CeedScalar de_internal = de_total - de_kinetic - de_potential; 93475b2820SJames Wright dY.temperature = de_internal / gas->cv; 942b916ea7SJeremy L Thompson dY.pressure = (HeatCapacityRatio(gas) - 1) * (dU.density * e_internal + s.U.density * de_internal); 95475b2820SJames Wright return dY; 96475b2820SJames Wright } 97475b2820SJames Wright 982b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER StateConservative StateConservativeFromPrimitive(NewtonianIdealGasContext gas, StatePrimitive Y, const CeedScalar x[3]) { 99cbe60e31SLeila Ghaffari StateConservative U; 100e0d1a4dfSLeila Ghaffari U.density = Y.pressure / (GasConstant(gas) * Y.temperature); 101cbe60e31SLeila Ghaffari for (int i = 0; i < 3; i++) U.momentum[i] = U.density * Y.velocity[i]; 102cbe60e31SLeila Ghaffari CeedScalar e_internal = gas->cv * Y.temperature; 103cbe60e31SLeila Ghaffari CeedScalar e_kinetic = .5 * Dot3(Y.velocity, Y.velocity); 104cbe60e31SLeila Ghaffari CeedScalar e_potential = -Dot3(gas->g, x); 105cbe60e31SLeila Ghaffari CeedScalar e_total = e_internal + e_kinetic + e_potential; 106cbe60e31SLeila Ghaffari U.E_total = U.density * e_total; 107cbe60e31SLeila Ghaffari return U; 108cbe60e31SLeila Ghaffari } 109cbe60e31SLeila Ghaffari 1102b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER StateConservative StateConservativeFromPrimitive_fwd(NewtonianIdealGasContext gas, State s, StatePrimitive dY, 111cbe60e31SLeila Ghaffari const CeedScalar x[3], const CeedScalar dx[3]) { 112cbe60e31SLeila Ghaffari StateConservative dU; 1132b916ea7SJeremy L Thompson dU.density = (dY.pressure * s.Y.temperature - s.Y.pressure * dY.temperature) / (GasConstant(gas) * s.Y.temperature * s.Y.temperature); 114cbe60e31SLeila Ghaffari for (int i = 0; i < 3; i++) { 115cbe60e31SLeila Ghaffari dU.momentum[i] = dU.density * s.Y.velocity[i] + s.U.density * dY.velocity[i]; 116cbe60e31SLeila Ghaffari } 117cbe60e31SLeila Ghaffari CeedScalar e_kinetic = .5 * Dot3(s.Y.velocity, s.Y.velocity); 118cbe60e31SLeila Ghaffari CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 119cbe60e31SLeila Ghaffari CeedScalar e_potential = -Dot3(gas->g, x); 120cbe60e31SLeila Ghaffari CeedScalar de_potential = -Dot3(gas->g, dx); 121cbe60e31SLeila Ghaffari CeedScalar e_internal = gas->cv * s.Y.temperature; 122cbe60e31SLeila Ghaffari CeedScalar de_internal = gas->cv * dY.temperature; 123cbe60e31SLeila Ghaffari CeedScalar e_total = e_internal + e_kinetic + e_potential; 124cbe60e31SLeila Ghaffari CeedScalar de_total = de_internal + de_kinetic + de_potential; 125cbe60e31SLeila Ghaffari dU.E_total = dU.density * e_total + s.U.density * de_total; 126cbe60e31SLeila Ghaffari return dU; 127cbe60e31SLeila Ghaffari } 128cbe60e31SLeila Ghaffari 129b8fb7609SAdeleke O. Bankole CEED_QFUNCTION_HELPER State StateFromPrimitive(NewtonianIdealGasContext gas, StatePrimitive Y, const CeedScalar x[3]) { 130b8fb7609SAdeleke O. Bankole StateConservative U = StateConservativeFromPrimitive(gas, Y, x); 131b8fb7609SAdeleke O. Bankole State s; 132b8fb7609SAdeleke O. Bankole s.U = U; 133b8fb7609SAdeleke O. Bankole s.Y = Y; 134b8fb7609SAdeleke O. Bankole return s; 135b8fb7609SAdeleke O. Bankole } 136b8fb7609SAdeleke O. Bankole 137*c8c30d87SJed Brown CEED_QFUNCTION_HELPER State StateFromPrimitive_fwd(NewtonianIdealGasContext gas, State s, StatePrimitive dY, const CeedScalar x[3], 138*c8c30d87SJed Brown const CeedScalar dx[3]) { 139*c8c30d87SJed Brown StateConservative dU = StateConservativeFromPrimitive_fwd(gas, s, dY, x, dx); 140*c8c30d87SJed Brown State ds; 141*c8c30d87SJed Brown ds.U = dU; 142*c8c30d87SJed Brown ds.Y = dY; 143*c8c30d87SJed Brown return ds; 144*c8c30d87SJed Brown } 145*c8c30d87SJed Brown 146c2c93676SJed Brown // linear combination of n states 147c2c93676SJed Brown CEED_QFUNCTION_HELPER StateConservative StateConservativeMult(CeedInt n, const CeedScalar a[], const StateConservative X[]) { 148c2c93676SJed Brown StateConservative R = {0}; 149c2c93676SJed Brown for (CeedInt i = 0; i < n; i++) { 150c2c93676SJed Brown R.density += a[i] * X[i].density; 151c2c93676SJed Brown for (int j = 0; j < 3; j++) R.momentum[j] += a[i] * X[i].momentum[j]; 152c2c93676SJed Brown R.E_total += a[i] * X[i].E_total; 153c2c93676SJed Brown } 154dbb62a19SJed Brown return R; 155dbb62a19SJed Brown } 156dbb62a19SJed Brown 157dbb62a19SJed Brown CEED_QFUNCTION_HELPER StateConservative StateConservativeAXPBYPCZ(CeedScalar a, StateConservative X, CeedScalar b, StateConservative Y, CeedScalar c, 158dbb62a19SJed Brown StateConservative Z) { 159dbb62a19SJed Brown StateConservative R; 160dbb62a19SJed Brown R.density = a * X.density + b * Y.density + c * Z.density; 161dbb62a19SJed Brown for (int i = 0; i < 3; i++) R.momentum[i] = a * X.momentum[i] + b * Y.momentum[i] + c * Z.momentum[i]; 162dbb62a19SJed Brown R.E_total = a * X.E_total + b * Y.E_total + c * Z.E_total; 163dbb62a19SJed Brown return R; 164dbb62a19SJed Brown } 165dbb62a19SJed Brown 166d4559bbeSJames Wright // Function pointer types for generic state array -> State struct functions 1672b916ea7SJeremy L Thompson typedef State (*StateFromQi_t)(NewtonianIdealGasContext gas, const CeedScalar qi[5], const CeedScalar x[3]); 168b8fb7609SAdeleke O. Bankole // Function pointer types for State struct -> generic state array 169b8fb7609SAdeleke O. Bankole typedef void (*StateToQi_t)(NewtonianIdealGasContext gas, const State input, CeedScalar qi[5]); 170b8fb7609SAdeleke O. Bankole 171b8fb7609SAdeleke O. Bankole CEED_QFUNCTION_HELPER void StateToU(NewtonianIdealGasContext gas, const State input, CeedScalar U[5]) { UnpackState_U(input.U, U); } 172b8fb7609SAdeleke O. Bankole 173b8fb7609SAdeleke O. Bankole CEED_QFUNCTION_HELPER void StateToY(NewtonianIdealGasContext gas, const State input, CeedScalar Y[5]) { UnpackState_Y(input.Y, Y); } 1742b916ea7SJeremy L Thompson typedef State (*StateFromQi_fwd_t)(NewtonianIdealGasContext gas, State s, const CeedScalar dqi[5], const CeedScalar x[3], const CeedScalar dx[3]); 175d4559bbeSJames Wright 1762b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER State StateFromU(NewtonianIdealGasContext gas, const CeedScalar U[5], const CeedScalar x[3]) { 177475b2820SJames Wright State s; 178475b2820SJames Wright s.U.density = U[0]; 179475b2820SJames Wright s.U.momentum[0] = U[1]; 180475b2820SJames Wright s.U.momentum[1] = U[2]; 181475b2820SJames Wright s.U.momentum[2] = U[3]; 182475b2820SJames Wright s.U.E_total = U[4]; 183475b2820SJames Wright s.Y = StatePrimitiveFromConservative(gas, s.U, x); 184475b2820SJames Wright return s; 185475b2820SJames Wright } 186475b2820SJames Wright 1872b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER State StateFromU_fwd(NewtonianIdealGasContext gas, State s, const CeedScalar dU[5], const CeedScalar x[3], 1882b916ea7SJeremy L Thompson const CeedScalar dx[3]) { 189475b2820SJames Wright State ds; 190475b2820SJames Wright ds.U.density = dU[0]; 191475b2820SJames Wright ds.U.momentum[0] = dU[1]; 192475b2820SJames Wright ds.U.momentum[1] = dU[2]; 193475b2820SJames Wright ds.U.momentum[2] = dU[3]; 194475b2820SJames Wright ds.U.E_total = dU[4]; 195475b2820SJames Wright ds.Y = StatePrimitiveFromConservative_fwd(gas, s, ds.U, x, dx); 196475b2820SJames Wright return ds; 197475b2820SJames Wright } 198475b2820SJames Wright 1992b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER State StateFromY(NewtonianIdealGasContext gas, const CeedScalar Y[5], const CeedScalar x[3]) { 200cbe60e31SLeila Ghaffari State s; 201cbe60e31SLeila Ghaffari s.Y.pressure = Y[0]; 202cbe60e31SLeila Ghaffari s.Y.velocity[0] = Y[1]; 203cbe60e31SLeila Ghaffari s.Y.velocity[1] = Y[2]; 204cbe60e31SLeila Ghaffari s.Y.velocity[2] = Y[3]; 205cbe60e31SLeila Ghaffari s.Y.temperature = Y[4]; 206cbe60e31SLeila Ghaffari s.U = StateConservativeFromPrimitive(gas, s.Y, x); 207cbe60e31SLeila Ghaffari return s; 208cbe60e31SLeila Ghaffari } 209cbe60e31SLeila Ghaffari 2102b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER State StateFromY_fwd(NewtonianIdealGasContext gas, State s, const CeedScalar dY[5], const CeedScalar x[3], 2112b916ea7SJeremy L Thompson const CeedScalar dx[3]) { 212cbe60e31SLeila Ghaffari State ds; 213cbe60e31SLeila Ghaffari ds.Y.pressure = dY[0]; 214cbe60e31SLeila Ghaffari ds.Y.velocity[0] = dY[1]; 215cbe60e31SLeila Ghaffari ds.Y.velocity[1] = dY[2]; 216cbe60e31SLeila Ghaffari ds.Y.velocity[2] = dY[3]; 217cbe60e31SLeila Ghaffari ds.Y.temperature = dY[4]; 218cbe60e31SLeila Ghaffari ds.U = StateConservativeFromPrimitive_fwd(gas, s, ds.Y, x, dx); 219cbe60e31SLeila Ghaffari return ds; 220cbe60e31SLeila Ghaffari } 221cbe60e31SLeila Ghaffari 2222b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void FluxInviscid(NewtonianIdealGasContext gas, State s, StateConservative Flux[3]) { 223475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 224475b2820SJames Wright Flux[i].density = s.U.momentum[i]; 2252b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 3; j++) Flux[i].momentum[j] = s.U.momentum[i] * s.Y.velocity[j] + s.Y.pressure * (i == j); 226475b2820SJames Wright Flux[i].E_total = (s.U.E_total + s.Y.pressure) * s.Y.velocity[i]; 227475b2820SJames Wright } 228475b2820SJames Wright } 229475b2820SJames Wright 2302b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void FluxInviscid_fwd(NewtonianIdealGasContext gas, State s, State ds, StateConservative dFlux[3]) { 231c50f56e5SJames Wright for (CeedInt i = 0; i < 3; i++) { 232c50f56e5SJames Wright dFlux[i].density = ds.U.momentum[i]; 2332b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 3; j++) { 2342b916ea7SJeremy L Thompson dFlux[i].momentum[j] = ds.U.momentum[i] * s.Y.velocity[j] + s.U.momentum[i] * ds.Y.velocity[j] + ds.Y.pressure * (i == j); 2352b916ea7SJeremy L Thompson } 2362b916ea7SJeremy L Thompson dFlux[i].E_total = (ds.U.E_total + ds.Y.pressure) * s.Y.velocity[i] + (s.U.E_total + s.Y.pressure) * ds.Y.velocity[i]; 237c50f56e5SJames Wright } 238c50f56e5SJames Wright } 239c50f56e5SJames Wright 2402b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER StateConservative FluxInviscidDotNormal(NewtonianIdealGasContext gas, State s, const CeedScalar normal[3]) { 2417b530f2aSAdelekeBankole StateConservative Flux[3], Flux_dot_n = {0}; 2427b530f2aSAdelekeBankole FluxInviscid(gas, s, Flux); 2437b530f2aSAdelekeBankole for (CeedInt i = 0; i < 3; i++) { 2447b530f2aSAdelekeBankole Flux_dot_n.density += Flux[i].density * normal[i]; 2452b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 3; j++) Flux_dot_n.momentum[j] += Flux[i].momentum[j] * normal[i]; 2467b530f2aSAdelekeBankole Flux_dot_n.E_total += Flux[i].E_total * normal[i]; 2477b530f2aSAdelekeBankole } 2487b530f2aSAdelekeBankole return Flux_dot_n; 2497b530f2aSAdelekeBankole } 2507b530f2aSAdelekeBankole 2512b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER StateConservative FluxInviscidDotNormal_fwd(NewtonianIdealGasContext gas, State s, State ds, const CeedScalar normal[3]) { 252c50f56e5SJames Wright StateConservative dFlux[3], Flux_dot_n = {0}; 253c50f56e5SJames Wright FluxInviscid_fwd(gas, s, ds, dFlux); 254475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 255c50f56e5SJames Wright Flux_dot_n.density += dFlux[i].density * normal[i]; 2562b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 3; j++) Flux_dot_n.momentum[j] += dFlux[i].momentum[j] * normal[i]; 257c50f56e5SJames Wright Flux_dot_n.E_total += dFlux[i].E_total * normal[i]; 258475b2820SJames Wright } 259c50f56e5SJames Wright return Flux_dot_n; 260475b2820SJames Wright } 261475b2820SJames Wright 2622b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void FluxInviscidStrong(NewtonianIdealGasContext gas, State s, State ds[3], CeedScalar strong_conv[5]) { 263d1b9ef12SLeila Ghaffari for (CeedInt i = 0; i < 5; i++) strong_conv[i] = 0; 264d1b9ef12SLeila Ghaffari for (CeedInt i = 0; i < 3; i++) { 265d1b9ef12SLeila Ghaffari StateConservative dF[3]; 266d1b9ef12SLeila Ghaffari FluxInviscid_fwd(gas, s, ds[i], dF); 267d1b9ef12SLeila Ghaffari CeedScalar dF_i[5]; 268d1b9ef12SLeila Ghaffari UnpackState_U(dF[i], dF_i); 2692b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 5; j++) strong_conv[j] += dF_i[j]; 270d1b9ef12SLeila Ghaffari } 271d1b9ef12SLeila Ghaffari } 272d1b9ef12SLeila Ghaffari 2732b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void FluxTotal(const StateConservative F_inviscid[3], CeedScalar stress[3][3], CeedScalar Fe[3], CeedScalar Flux[5][3]) { 274d1b9ef12SLeila Ghaffari for (CeedInt j = 0; j < 3; j++) { 275d1b9ef12SLeila Ghaffari Flux[0][j] = F_inviscid[j].density; 2762b916ea7SJeremy L Thompson for (CeedInt k = 0; k < 3; k++) Flux[k + 1][j] = F_inviscid[j].momentum[k] - stress[k][j]; 277d1b9ef12SLeila Ghaffari Flux[4][j] = F_inviscid[j].E_total + Fe[j]; 278d1b9ef12SLeila Ghaffari } 279d1b9ef12SLeila Ghaffari } 280d1b9ef12SLeila Ghaffari 2812b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void FluxTotal_Boundary(const StateConservative F_inviscid[3], const CeedScalar stress[3][3], const CeedScalar Fe[3], 2822b916ea7SJeremy L Thompson const CeedScalar normal[3], CeedScalar Flux[5]) { 283c5740391SJames Wright for (CeedInt j = 0; j < 5; j++) Flux[j] = 0.; 284c5740391SJames Wright for (CeedInt j = 0; j < 3; j++) { 285c5740391SJames Wright Flux[0] += F_inviscid[j].density * normal[j]; 286c5740391SJames Wright for (CeedInt k = 0; k < 3; k++) { 287c5740391SJames Wright Flux[k + 1] += (F_inviscid[j].momentum[k] - stress[k][j]) * normal[j]; 288c5740391SJames Wright } 289c5740391SJames Wright Flux[4] += (F_inviscid[j].E_total + Fe[j]) * normal[j]; 290c5740391SJames Wright } 291c5740391SJames Wright } 292c5740391SJames Wright 293*c8c30d87SJed Brown CEED_QFUNCTION_HELPER void FluxTotal_RiemannBoundary(const StateConservative F_inviscid_normal, const CeedScalar stress[3][3], const CeedScalar Fe[3], 294*c8c30d87SJed Brown const CeedScalar normal[3], CeedScalar Flux[5]) { 295*c8c30d87SJed Brown Flux[0] = F_inviscid_normal.density; 296*c8c30d87SJed Brown for (CeedInt k = 0; k < 3; k++) Flux[k + 1] = F_inviscid_normal.momentum[k]; 297*c8c30d87SJed Brown Flux[4] = F_inviscid_normal.E_total; 298*c8c30d87SJed Brown for (CeedInt j = 0; j < 3; j++) { 299*c8c30d87SJed Brown for (CeedInt k = 0; k < 3; k++) { 300*c8c30d87SJed Brown Flux[k + 1] -= stress[k][j] * normal[j]; 301*c8c30d87SJed Brown } 302*c8c30d87SJed Brown Flux[4] += Fe[j] * normal[j]; 303*c8c30d87SJed Brown } 304*c8c30d87SJed Brown } 305*c8c30d87SJed Brown 306475b2820SJames Wright // Kelvin-Mandel notation 3072b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void KMStrainRate(const State grad_s[3], CeedScalar strain_rate[6]) { 308475b2820SJames Wright const CeedScalar weight = 1 / sqrt(2.); 309475b2820SJames Wright strain_rate[0] = grad_s[0].Y.velocity[0]; 310475b2820SJames Wright strain_rate[1] = grad_s[1].Y.velocity[1]; 311475b2820SJames Wright strain_rate[2] = grad_s[2].Y.velocity[2]; 312475b2820SJames Wright strain_rate[3] = weight * (grad_s[2].Y.velocity[1] + grad_s[1].Y.velocity[2]); 313475b2820SJames Wright strain_rate[4] = weight * (grad_s[2].Y.velocity[0] + grad_s[0].Y.velocity[2]); 314475b2820SJames Wright strain_rate[5] = weight * (grad_s[1].Y.velocity[0] + grad_s[0].Y.velocity[1]); 315475b2820SJames Wright } 316475b2820SJames Wright 3172b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void NewtonianStress(NewtonianIdealGasContext gas, const CeedScalar strain_rate[6], CeedScalar stress[6]) { 318475b2820SJames Wright CeedScalar div_u = strain_rate[0] + strain_rate[1] + strain_rate[2]; 319475b2820SJames Wright for (CeedInt i = 0; i < 6; i++) { 320475b2820SJames Wright stress[i] = gas->mu * (2 * strain_rate[i] + gas->lambda * div_u * (i < 3)); 321475b2820SJames Wright } 322475b2820SJames Wright } 323475b2820SJames Wright 3242b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void ViscousEnergyFlux(NewtonianIdealGasContext gas, StatePrimitive Y, const State grad_s[3], const CeedScalar stress[3][3], 325475b2820SJames Wright CeedScalar Fe[3]) { 326475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 3272b916ea7SJeremy L Thompson Fe[i] = -Y.velocity[0] * stress[0][i] - Y.velocity[1] * stress[1][i] - Y.velocity[2] * stress[2][i] - gas->k * grad_s[i].Y.temperature; 328475b2820SJames Wright } 329475b2820SJames Wright } 330475b2820SJames Wright 3312b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void ViscousEnergyFlux_fwd(NewtonianIdealGasContext gas, StatePrimitive Y, StatePrimitive dY, const State grad_ds[3], 3322b916ea7SJeremy L Thompson const CeedScalar stress[3][3], const CeedScalar dstress[3][3], CeedScalar dFe[3]) { 333475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 3342b916ea7SJeremy L Thompson dFe[i] = -Y.velocity[0] * dstress[0][i] - dY.velocity[0] * stress[0][i] - Y.velocity[1] * dstress[1][i] - dY.velocity[1] * stress[1][i] - 3352b916ea7SJeremy L Thompson Y.velocity[2] * dstress[2][i] - dY.velocity[2] * stress[2][i] - gas->k * grad_ds[i].Y.temperature; 336475b2820SJames Wright } 337475b2820SJames Wright } 338475b2820SJames Wright 339475b2820SJames Wright #endif // newtonian_state_h 340