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 12475b2820SJames Wright #ifndef newtonian_state_h 13475b2820SJames Wright #define newtonian_state_h 14475b2820SJames Wright 15475b2820SJames Wright #include <ceed.h> 16d0cce58aSJeremy L Thompson #include <math.h> 177b530f2aSAdelekeBankole #include "ceed/types.h" 18475b2820SJames Wright #include "newtonian_types.h" 19704b8bbeSJames Wright #include "utils.h" 20475b2820SJames Wright 21475b2820SJames Wright typedef struct { 22475b2820SJames Wright CeedScalar pressure; 23475b2820SJames Wright CeedScalar velocity[3]; 24475b2820SJames Wright CeedScalar temperature; 25475b2820SJames Wright } StatePrimitive; 26475b2820SJames Wright 27475b2820SJames Wright typedef struct { 28475b2820SJames Wright CeedScalar density; 29475b2820SJames Wright CeedScalar momentum[3]; 30475b2820SJames Wright CeedScalar E_total; 31475b2820SJames Wright } StateConservative; 32475b2820SJames Wright 33475b2820SJames Wright typedef struct { 34475b2820SJames Wright StateConservative U; 35475b2820SJames Wright StatePrimitive Y; 36475b2820SJames Wright } State; 37475b2820SJames Wright 38d1b9ef12SLeila Ghaffari CEED_QFUNCTION_HELPER void UnpackState_U(StateConservative s, CeedScalar U[5]) { 39d1b9ef12SLeila Ghaffari U[0] = s.density; 40d1b9ef12SLeila Ghaffari for (int i=0; i<3; i++) U[i+1] = s.momentum[i]; 41d1b9ef12SLeila Ghaffari U[4] = s.E_total; 42d1b9ef12SLeila Ghaffari } 43d1b9ef12SLeila Ghaffari 44d1b9ef12SLeila Ghaffari CEED_QFUNCTION_HELPER void UnpackState_Y(StatePrimitive s, CeedScalar Y[5]) { 45d1b9ef12SLeila Ghaffari Y[0] = s.pressure; 46d1b9ef12SLeila Ghaffari for (int i=0; i<3; i++) Y[i+1] = s.velocity[i]; 47d1b9ef12SLeila Ghaffari Y[4] = s.temperature; 48d1b9ef12SLeila Ghaffari } 49d1b9ef12SLeila Ghaffari 50e0d1a4dfSLeila Ghaffari CEED_QFUNCTION_HELPER CeedScalar HeatCapacityRatio( 51e0d1a4dfSLeila Ghaffari NewtonianIdealGasContext gas) { 52e0d1a4dfSLeila Ghaffari return gas->cp / gas->cv; 53e0d1a4dfSLeila Ghaffari } 54e0d1a4dfSLeila Ghaffari 55e0d1a4dfSLeila Ghaffari CEED_QFUNCTION_HELPER CeedScalar GasConstant( 56e0d1a4dfSLeila Ghaffari NewtonianIdealGasContext gas) { 57e0d1a4dfSLeila Ghaffari return gas->cp - gas->cv; 58e0d1a4dfSLeila Ghaffari } 59e0d1a4dfSLeila Ghaffari 60e0d1a4dfSLeila Ghaffari CEED_QFUNCTION_HELPER CeedScalar Prandtl(NewtonianIdealGasContext gas) { 61e0d1a4dfSLeila Ghaffari return gas->cp * gas->mu / gas->k; 62e0d1a4dfSLeila Ghaffari } 63e0d1a4dfSLeila Ghaffari 64e0d1a4dfSLeila Ghaffari CEED_QFUNCTION_HELPER CeedScalar SoundSpeed(NewtonianIdealGasContext gas, 65e0d1a4dfSLeila Ghaffari CeedScalar T) { 66e0d1a4dfSLeila Ghaffari return sqrt(gas->cp * (HeatCapacityRatio(gas) - 1.) * T); 67e0d1a4dfSLeila Ghaffari } 68e0d1a4dfSLeila Ghaffari 69e0d1a4dfSLeila Ghaffari CEED_QFUNCTION_HELPER CeedScalar Mach(NewtonianIdealGasContext gas, 70e0d1a4dfSLeila Ghaffari CeedScalar T, CeedScalar u) { 71e0d1a4dfSLeila Ghaffari return u / SoundSpeed(gas, T); 72e0d1a4dfSLeila Ghaffari } 73e0d1a4dfSLeila Ghaffari 74*c50f56e5SJames Wright CEED_QFUNCTION_HELPER CeedScalar TotalSpecificEnthalpy( 75*c50f56e5SJames Wright NewtonianIdealGasContext gas, const State s) { 76*c50f56e5SJames Wright // Ignoring potential energy 77*c50f56e5SJames Wright CeedScalar e_internal = gas->cv*s.Y.temperature; 78*c50f56e5SJames Wright CeedScalar e_kinetic = 0.5*Dot3(s.Y.velocity, s.Y.velocity); 79*c50f56e5SJames Wright return e_internal + e_kinetic + s.Y.pressure/s.U.density; 80*c50f56e5SJames Wright } 81*c50f56e5SJames Wright 82*c50f56e5SJames Wright CEED_QFUNCTION_HELPER CeedScalar TotalSpecificEnthalpy_fwd( 83*c50f56e5SJames Wright NewtonianIdealGasContext gas, const State s, const State ds) { 84*c50f56e5SJames Wright // Ignoring potential energy 85*c50f56e5SJames Wright CeedScalar de_kinetic = Dot3(ds.Y.velocity, s.Y.velocity); 86*c50f56e5SJames Wright CeedScalar de_internal = gas->cv * ds.Y.temperature; 87*c50f56e5SJames Wright return de_internal + de_kinetic + ds.Y.pressure/s.U.density 88*c50f56e5SJames Wright - s.Y.pressure/Square(s.U.density)*ds.U.density; 89*c50f56e5SJames Wright } 90*c50f56e5SJames Wright 91475b2820SJames Wright CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromConservative( 92475b2820SJames Wright NewtonianIdealGasContext gas, StateConservative U, const CeedScalar x[3]) { 93475b2820SJames Wright StatePrimitive Y; 94475b2820SJames Wright for (CeedInt i=0; i<3; i++) Y.velocity[i] = U.momentum[i] / U.density; 95475b2820SJames Wright CeedScalar e_kinetic = .5 * Dot3(Y.velocity, Y.velocity); 96475b2820SJames Wright CeedScalar e_potential = -Dot3(gas->g, x); 97475b2820SJames Wright CeedScalar e_total = U.E_total / U.density; 98475b2820SJames Wright CeedScalar e_internal = e_total - e_kinetic - e_potential; 99475b2820SJames Wright Y.temperature = e_internal / gas->cv; 100e0d1a4dfSLeila Ghaffari Y.pressure = (HeatCapacityRatio(gas) - 1) * U.density * e_internal; 101475b2820SJames Wright return Y; 102475b2820SJames Wright } 103475b2820SJames Wright 104475b2820SJames Wright CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromConservative_fwd( 105475b2820SJames Wright NewtonianIdealGasContext gas, State s, StateConservative dU, 106475b2820SJames Wright const CeedScalar x[3], const CeedScalar dx[3]) { 107475b2820SJames Wright StatePrimitive dY; 108475b2820SJames Wright for (CeedInt i=0; i<3; i++) { 109475b2820SJames Wright dY.velocity[i] = (dU.momentum[i] - s.Y.velocity[i] * dU.density) / s.U.density; 110475b2820SJames Wright } 111475b2820SJames Wright CeedScalar e_kinetic = .5 * Dot3(s.Y.velocity, s.Y.velocity); 112475b2820SJames Wright CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 113475b2820SJames Wright CeedScalar e_potential = -Dot3(gas->g, x); 114475b2820SJames Wright CeedScalar de_potential = -Dot3(gas->g, dx); 115475b2820SJames Wright CeedScalar e_total = s.U.E_total / s.U.density; 116475b2820SJames Wright CeedScalar de_total = (dU.E_total - e_total * dU.density) / s.U.density; 117475b2820SJames Wright CeedScalar e_internal = e_total - e_kinetic - e_potential; 118475b2820SJames Wright CeedScalar de_internal = de_total - de_kinetic - de_potential; 119475b2820SJames Wright dY.temperature = de_internal / gas->cv; 120e0d1a4dfSLeila Ghaffari dY.pressure = (HeatCapacityRatio(gas) - 1) 121475b2820SJames Wright * (dU.density * e_internal + s.U.density * de_internal); 122475b2820SJames Wright return dY; 123475b2820SJames Wright } 124475b2820SJames Wright 125cbe60e31SLeila Ghaffari CEED_QFUNCTION_HELPER StateConservative StateConservativeFromPrimitive( 126cbe60e31SLeila Ghaffari NewtonianIdealGasContext gas, StatePrimitive Y, const CeedScalar x[3]) { 127cbe60e31SLeila Ghaffari StateConservative U; 128e0d1a4dfSLeila Ghaffari U.density = Y.pressure / (GasConstant(gas) * Y.temperature); 129cbe60e31SLeila Ghaffari for (int i=0; i<3; i++) U.momentum[i] = U.density*Y.velocity[i]; 130cbe60e31SLeila Ghaffari CeedScalar e_internal = gas->cv * Y.temperature; 131cbe60e31SLeila Ghaffari CeedScalar e_kinetic = .5 * Dot3(Y.velocity, Y.velocity); 132cbe60e31SLeila Ghaffari CeedScalar e_potential = -Dot3(gas->g, x); 133cbe60e31SLeila Ghaffari CeedScalar e_total = e_internal + e_kinetic + e_potential; 134cbe60e31SLeila Ghaffari U.E_total = U.density*e_total; 135cbe60e31SLeila Ghaffari return U; 136cbe60e31SLeila Ghaffari } 137cbe60e31SLeila Ghaffari 138cbe60e31SLeila Ghaffari CEED_QFUNCTION_HELPER StateConservative StateConservativeFromPrimitive_fwd( 139cbe60e31SLeila Ghaffari NewtonianIdealGasContext gas, State s, StatePrimitive dY, 140cbe60e31SLeila Ghaffari const CeedScalar x[3], const CeedScalar dx[3]) { 141cbe60e31SLeila Ghaffari StateConservative dU; 142cbe60e31SLeila Ghaffari dU.density = (dY.pressure * s.Y.temperature - s.Y.pressure * dY.temperature) / 143e0d1a4dfSLeila Ghaffari (GasConstant(gas) * s.Y.temperature * s.Y.temperature); 144cbe60e31SLeila Ghaffari for (int i=0; i<3; i++) { 145cbe60e31SLeila Ghaffari dU.momentum[i] = dU.density * s.Y.velocity[i] + s.U.density * dY.velocity[i]; 146cbe60e31SLeila Ghaffari } 147cbe60e31SLeila Ghaffari CeedScalar e_kinetic = .5 * Dot3(s.Y.velocity, s.Y.velocity); 148cbe60e31SLeila Ghaffari CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 149cbe60e31SLeila Ghaffari CeedScalar e_potential = -Dot3(gas->g, x); 150cbe60e31SLeila Ghaffari CeedScalar de_potential = -Dot3(gas->g, dx); 151cbe60e31SLeila Ghaffari CeedScalar e_internal = gas->cv * s.Y.temperature; 152cbe60e31SLeila Ghaffari CeedScalar de_internal = gas->cv * dY.temperature; 153cbe60e31SLeila Ghaffari CeedScalar e_total = e_internal + e_kinetic + e_potential; 154cbe60e31SLeila Ghaffari CeedScalar de_total = de_internal + de_kinetic + de_potential; 155cbe60e31SLeila Ghaffari dU.E_total = dU.density*e_total + s.U.density*de_total; 156cbe60e31SLeila Ghaffari return dU; 157cbe60e31SLeila Ghaffari } 158cbe60e31SLeila Ghaffari 159d4559bbeSJames Wright // Function pointer types for generic state array -> State struct functions 160d4559bbeSJames Wright typedef State (*StateFromQi_t)(NewtonianIdealGasContext gas, 161d4559bbeSJames Wright const CeedScalar qi[5], const CeedScalar x[3]); 162d4559bbeSJames Wright typedef State (*StateFromQi_fwd_t)(NewtonianIdealGasContext gas, 163d4559bbeSJames Wright State s, const CeedScalar dqi[5], 164d4559bbeSJames Wright const CeedScalar x[3], const CeedScalar dx[3]); 165d4559bbeSJames Wright 166475b2820SJames Wright CEED_QFUNCTION_HELPER State StateFromU(NewtonianIdealGasContext gas, 167475b2820SJames Wright const CeedScalar U[5], const CeedScalar x[3]) { 168475b2820SJames Wright State s; 169475b2820SJames Wright s.U.density = U[0]; 170475b2820SJames Wright s.U.momentum[0] = U[1]; 171475b2820SJames Wright s.U.momentum[1] = U[2]; 172475b2820SJames Wright s.U.momentum[2] = U[3]; 173475b2820SJames Wright s.U.E_total = U[4]; 174475b2820SJames Wright s.Y = StatePrimitiveFromConservative(gas, s.U, x); 175475b2820SJames Wright return s; 176475b2820SJames Wright } 177475b2820SJames Wright 178475b2820SJames Wright CEED_QFUNCTION_HELPER State StateFromU_fwd(NewtonianIdealGasContext gas, 179475b2820SJames Wright State s, const CeedScalar dU[5], 180475b2820SJames Wright const CeedScalar x[3], const CeedScalar dx[3]) { 181475b2820SJames Wright State ds; 182475b2820SJames Wright ds.U.density = dU[0]; 183475b2820SJames Wright ds.U.momentum[0] = dU[1]; 184475b2820SJames Wright ds.U.momentum[1] = dU[2]; 185475b2820SJames Wright ds.U.momentum[2] = dU[3]; 186475b2820SJames Wright ds.U.E_total = dU[4]; 187475b2820SJames Wright ds.Y = StatePrimitiveFromConservative_fwd(gas, s, ds.U, x, dx); 188475b2820SJames Wright return ds; 189475b2820SJames Wright } 190475b2820SJames Wright 191cbe60e31SLeila Ghaffari CEED_QFUNCTION_HELPER State StateFromY(NewtonianIdealGasContext gas, 192cbe60e31SLeila Ghaffari const CeedScalar Y[5], const CeedScalar x[3]) { 193cbe60e31SLeila Ghaffari State s; 194cbe60e31SLeila Ghaffari s.Y.pressure = Y[0]; 195cbe60e31SLeila Ghaffari s.Y.velocity[0] = Y[1]; 196cbe60e31SLeila Ghaffari s.Y.velocity[1] = Y[2]; 197cbe60e31SLeila Ghaffari s.Y.velocity[2] = Y[3]; 198cbe60e31SLeila Ghaffari s.Y.temperature = Y[4]; 199cbe60e31SLeila Ghaffari s.U = StateConservativeFromPrimitive(gas, s.Y, x); 200cbe60e31SLeila Ghaffari return s; 201cbe60e31SLeila Ghaffari } 202cbe60e31SLeila Ghaffari 203cbe60e31SLeila Ghaffari CEED_QFUNCTION_HELPER State StateFromY_fwd(NewtonianIdealGasContext gas, 204cbe60e31SLeila Ghaffari State s, const CeedScalar dY[5], 205cbe60e31SLeila Ghaffari const CeedScalar x[3], const CeedScalar dx[3]) { 206cbe60e31SLeila Ghaffari State ds; 207cbe60e31SLeila Ghaffari ds.Y.pressure = dY[0]; 208cbe60e31SLeila Ghaffari ds.Y.velocity[0] = dY[1]; 209cbe60e31SLeila Ghaffari ds.Y.velocity[1] = dY[2]; 210cbe60e31SLeila Ghaffari ds.Y.velocity[2] = dY[3]; 211cbe60e31SLeila Ghaffari ds.Y.temperature = dY[4]; 212cbe60e31SLeila Ghaffari ds.U = StateConservativeFromPrimitive_fwd(gas, s, ds.Y, x, dx); 213cbe60e31SLeila Ghaffari return ds; 214cbe60e31SLeila Ghaffari } 215cbe60e31SLeila Ghaffari 216335cfff3SJames Wright // Function pointer types for State struct -> generic state array 217335cfff3SJames Wright typedef void (*StateToQi_t)(NewtonianIdealGasContext gas, 218335cfff3SJames Wright const State input, CeedScalar qi[5]); 219335cfff3SJames Wright 220335cfff3SJames Wright CEED_QFUNCTION_HELPER void StateToU(NewtonianIdealGasContext gas, 221335cfff3SJames Wright const State input, CeedScalar U[5]) { 222335cfff3SJames Wright UnpackState_U(input.U, U); 223335cfff3SJames Wright } 224335cfff3SJames Wright 225335cfff3SJames Wright CEED_QFUNCTION_HELPER void StateToY(NewtonianIdealGasContext gas, 226335cfff3SJames Wright const State input, CeedScalar Y[5]) { 227335cfff3SJames Wright UnpackState_Y(input.Y, Y); 228335cfff3SJames Wright } 229335cfff3SJames Wright 230475b2820SJames Wright CEED_QFUNCTION_HELPER void FluxInviscid(NewtonianIdealGasContext gas, State s, 231475b2820SJames Wright StateConservative Flux[3]) { 232475b2820SJames Wright for (CeedInt i=0; i<3; i++) { 233475b2820SJames Wright Flux[i].density = s.U.momentum[i]; 234475b2820SJames Wright for (CeedInt j=0; j<3; j++) 235475b2820SJames Wright Flux[i].momentum[j] = s.U.momentum[i] * s.Y.velocity[j] 236475b2820SJames Wright + s.Y.pressure * (i == j); 237475b2820SJames Wright Flux[i].E_total = (s.U.E_total + s.Y.pressure) * s.Y.velocity[i]; 238475b2820SJames Wright } 239475b2820SJames Wright } 240475b2820SJames Wright 241*c50f56e5SJames Wright CEED_QFUNCTION_HELPER void FluxInviscid_fwd(NewtonianIdealGasContext gas, 242*c50f56e5SJames Wright State s, State ds, StateConservative dFlux[3]) { 243*c50f56e5SJames Wright for (CeedInt i=0; i<3; i++) { 244*c50f56e5SJames Wright dFlux[i].density = ds.U.momentum[i]; 245*c50f56e5SJames Wright for (CeedInt j=0; j<3; j++) 246*c50f56e5SJames Wright dFlux[i].momentum[j] = ds.U.momentum[i] * s.Y.velocity[j] + 247*c50f56e5SJames Wright s.U.momentum[i] * ds.Y.velocity[j] + ds.Y.pressure * (i == j); 248*c50f56e5SJames Wright dFlux[i].E_total = (ds.U.E_total + ds.Y.pressure) * s.Y.velocity[i] + 249*c50f56e5SJames Wright (s.U.E_total + s.Y.pressure) * ds.Y.velocity[i]; 250*c50f56e5SJames Wright } 251*c50f56e5SJames Wright } 252*c50f56e5SJames Wright 2538789e95fSJames Wright CEED_QFUNCTION_HELPER StateConservative FluxInviscidDotNormal( 2548789e95fSJames Wright NewtonianIdealGasContext gas, State s, const CeedScalar normal[3]) { 2557b530f2aSAdelekeBankole StateConservative Flux[3], Flux_dot_n = {0}; 2567b530f2aSAdelekeBankole FluxInviscid(gas, s, Flux); 2577b530f2aSAdelekeBankole for (CeedInt i=0; i<3; i++) { 2587b530f2aSAdelekeBankole Flux_dot_n.density += Flux[i].density * normal[i]; 2597b530f2aSAdelekeBankole for (CeedInt j=0; j<3; j++) 2607b530f2aSAdelekeBankole Flux_dot_n.momentum[j] += Flux[i].momentum[j] * normal[i]; 2617b530f2aSAdelekeBankole Flux_dot_n.E_total += Flux[i].E_total * normal[i]; 2627b530f2aSAdelekeBankole } 2637b530f2aSAdelekeBankole return Flux_dot_n; 2647b530f2aSAdelekeBankole } 2657b530f2aSAdelekeBankole 266*c50f56e5SJames Wright CEED_QFUNCTION_HELPER StateConservative FluxInviscidDotNormal_fwd( 267*c50f56e5SJames Wright NewtonianIdealGasContext gas, State s, State ds, const CeedScalar normal[3]) { 268*c50f56e5SJames Wright StateConservative dFlux[3], Flux_dot_n = {0}; 269*c50f56e5SJames Wright FluxInviscid_fwd(gas, s, ds, dFlux); 270475b2820SJames Wright for (CeedInt i=0; i<3; i++) { 271*c50f56e5SJames Wright Flux_dot_n.density += dFlux[i].density * normal[i]; 272475b2820SJames Wright for (CeedInt j=0; j<3; j++) 273*c50f56e5SJames Wright Flux_dot_n.momentum[j] += dFlux[i].momentum[j] * normal[i]; 274*c50f56e5SJames Wright Flux_dot_n.E_total += dFlux[i].E_total * normal[i]; 275475b2820SJames Wright } 276*c50f56e5SJames Wright return Flux_dot_n; 277475b2820SJames Wright } 278475b2820SJames Wright 279d1b9ef12SLeila Ghaffari CEED_QFUNCTION_HELPER void FluxInviscidStrong(NewtonianIdealGasContext gas, 280d1b9ef12SLeila Ghaffari State s, State ds[3], CeedScalar strong_conv[5]) { 281d1b9ef12SLeila Ghaffari for (CeedInt i=0; i<5; i++) strong_conv[i] = 0; 282d1b9ef12SLeila Ghaffari for (CeedInt i=0; i<3; i++) { 283d1b9ef12SLeila Ghaffari StateConservative dF[3]; 284d1b9ef12SLeila Ghaffari FluxInviscid_fwd(gas, s, ds[i], dF); 285d1b9ef12SLeila Ghaffari CeedScalar dF_i[5]; 286d1b9ef12SLeila Ghaffari UnpackState_U(dF[i], dF_i); 287d1b9ef12SLeila Ghaffari for (CeedInt j=0; j<5; j++) 288d1b9ef12SLeila Ghaffari strong_conv[j] += dF_i[j]; 289d1b9ef12SLeila Ghaffari } 290d1b9ef12SLeila Ghaffari } 291d1b9ef12SLeila Ghaffari 292d4559bbeSJames Wright CEED_QFUNCTION_HELPER void FluxTotal(const StateConservative F_inviscid[3], 293d1b9ef12SLeila Ghaffari CeedScalar stress[3][3], CeedScalar Fe[3], CeedScalar Flux[5][3]) { 294d1b9ef12SLeila Ghaffari for (CeedInt j=0; j<3; j++) { 295d1b9ef12SLeila Ghaffari Flux[0][j] = F_inviscid[j].density; 296d1b9ef12SLeila Ghaffari for (CeedInt k=0; k<3; k++) 297d1b9ef12SLeila Ghaffari Flux[k+1][j] = F_inviscid[j].momentum[k] - stress[k][j]; 298d1b9ef12SLeila Ghaffari Flux[4][j] = F_inviscid[j].E_total + Fe[j]; 299d1b9ef12SLeila Ghaffari } 300d1b9ef12SLeila Ghaffari } 301d1b9ef12SLeila Ghaffari 302c5740391SJames Wright CEED_QFUNCTION_HELPER void FluxTotal_Boundary( 303c5740391SJames Wright const StateConservative F_inviscid[3], const CeedScalar stress[3][3], 304c5740391SJames Wright const CeedScalar Fe[3], const CeedScalar normal[3], CeedScalar Flux[5]) { 305c5740391SJames Wright 306c5740391SJames Wright for (CeedInt j=0; j<5; j++) Flux[j] = 0.; 307c5740391SJames Wright for (CeedInt j=0; j<3; j++) { 308c5740391SJames Wright Flux[0] += F_inviscid[j].density * normal[j]; 309c5740391SJames Wright for (CeedInt k=0; k<3; k++) { 310c5740391SJames Wright Flux[k+1] += (F_inviscid[j].momentum[k] - stress[k][j]) * normal[j]; 311c5740391SJames Wright } 312c5740391SJames Wright Flux[4] += (F_inviscid[j].E_total + Fe[j]) * normal[j]; 313c5740391SJames Wright } 314c5740391SJames Wright } 315c5740391SJames Wright 316475b2820SJames Wright // Kelvin-Mandel notation 317475b2820SJames Wright CEED_QFUNCTION_HELPER void KMStrainRate(const State grad_s[3], 318475b2820SJames Wright CeedScalar strain_rate[6]) { 319475b2820SJames Wright const CeedScalar weight = 1 / sqrt(2.); 320475b2820SJames Wright strain_rate[0] = grad_s[0].Y.velocity[0]; 321475b2820SJames Wright strain_rate[1] = grad_s[1].Y.velocity[1]; 322475b2820SJames Wright strain_rate[2] = grad_s[2].Y.velocity[2]; 323475b2820SJames Wright strain_rate[3] = weight * (grad_s[2].Y.velocity[1] + grad_s[1].Y.velocity[2]); 324475b2820SJames Wright strain_rate[4] = weight * (grad_s[2].Y.velocity[0] + grad_s[0].Y.velocity[2]); 325475b2820SJames Wright strain_rate[5] = weight * (grad_s[1].Y.velocity[0] + grad_s[0].Y.velocity[1]); 326475b2820SJames Wright } 327475b2820SJames Wright 328475b2820SJames Wright CEED_QFUNCTION_HELPER void NewtonianStress(NewtonianIdealGasContext gas, 329475b2820SJames Wright const CeedScalar strain_rate[6], CeedScalar stress[6]) { 330475b2820SJames Wright CeedScalar div_u = strain_rate[0] + strain_rate[1] + strain_rate[2]; 331475b2820SJames Wright for (CeedInt i=0; i<6; i++) { 332475b2820SJames Wright stress[i] = gas->mu * (2 * strain_rate[i] + gas->lambda * div_u * (i < 3)); 333475b2820SJames Wright } 334475b2820SJames Wright } 335475b2820SJames Wright 336475b2820SJames Wright CEED_QFUNCTION_HELPER void ViscousEnergyFlux(NewtonianIdealGasContext gas, 337475b2820SJames Wright StatePrimitive Y, const State grad_s[3], const CeedScalar stress[3][3], 338475b2820SJames Wright CeedScalar Fe[3]) { 339475b2820SJames Wright for (CeedInt i=0; i<3; i++) { 340475b2820SJames Wright Fe[i] = - Y.velocity[0] * stress[0][i] 341475b2820SJames Wright - Y.velocity[1] * stress[1][i] 342475b2820SJames Wright - Y.velocity[2] * stress[2][i] 343475b2820SJames Wright - gas->k * grad_s[i].Y.temperature; 344475b2820SJames Wright } 345475b2820SJames Wright } 346475b2820SJames Wright 347475b2820SJames Wright CEED_QFUNCTION_HELPER void ViscousEnergyFlux_fwd(NewtonianIdealGasContext gas, 348475b2820SJames Wright StatePrimitive Y, StatePrimitive dY, const State grad_ds[3], 3498789e95fSJames Wright const CeedScalar stress[3][3], const CeedScalar dstress[3][3], 350475b2820SJames Wright CeedScalar dFe[3]) { 351475b2820SJames Wright for (CeedInt i=0; i<3; i++) { 352475b2820SJames Wright dFe[i] = - Y.velocity[0] * dstress[0][i] - dY.velocity[0] * stress[0][i] 353475b2820SJames Wright - Y.velocity[1] * dstress[1][i] - dY.velocity[1] * stress[1][i] 354475b2820SJames Wright - Y.velocity[2] * dstress[2][i] - dY.velocity[2] * stress[2][i] 355475b2820SJames Wright - gas->k * grad_ds[i].Y.temperature; 356475b2820SJames Wright } 357475b2820SJames Wright } 358475b2820SJames Wright 359475b2820SJames Wright #endif // newtonian_state_h 360