1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3475b2820SJames Wright 4475b2820SJames Wright /// @file 5475b2820SJames Wright /// Structs and helper functions regarding the state of a newtonian simulation 6c7ece6efSJeremy L Thompson #pragma once 7475b2820SJames Wright 83e17a7a1SJames Wright #include <ceed/types.h> 92b916ea7SJeremy L Thompson 10475b2820SJames Wright #include "newtonian_types.h" 11704b8bbeSJames Wright #include "utils.h" 12475b2820SJames Wright 13475b2820SJames Wright typedef struct { 14475b2820SJames Wright CeedScalar density; 15475b2820SJames Wright CeedScalar momentum[3]; 16475b2820SJames Wright CeedScalar E_total; 17475b2820SJames Wright } StateConservative; 18475b2820SJames Wright 19475b2820SJames Wright typedef struct { 20475b2820SJames Wright StateConservative U; 21475b2820SJames Wright StatePrimitive Y; 22475b2820SJames Wright } State; 23475b2820SJames Wright 24d1b9ef12SLeila Ghaffari CEED_QFUNCTION_HELPER void UnpackState_U(StateConservative s, CeedScalar U[5]) { 25d1b9ef12SLeila Ghaffari U[0] = s.density; 26d1b9ef12SLeila Ghaffari for (int i = 0; i < 3; i++) U[i + 1] = s.momentum[i]; 27d1b9ef12SLeila Ghaffari U[4] = s.E_total; 28d1b9ef12SLeila Ghaffari } 29d1b9ef12SLeila Ghaffari 30d1b9ef12SLeila Ghaffari CEED_QFUNCTION_HELPER void UnpackState_Y(StatePrimitive s, CeedScalar Y[5]) { 31d1b9ef12SLeila Ghaffari Y[0] = s.pressure; 32d1b9ef12SLeila Ghaffari for (int i = 0; i < 3; i++) Y[i + 1] = s.velocity[i]; 33d1b9ef12SLeila Ghaffari Y[4] = s.temperature; 34d1b9ef12SLeila Ghaffari } 35d1b9ef12SLeila Ghaffari 36c62f7daeSJames Wright CEED_QFUNCTION_HELPER void UnpackState_V(StateEntropy s, CeedScalar V[5]) { 37c62f7daeSJames Wright V[0] = s.S_density; 38c62f7daeSJames Wright for (int i = 0; i < 3; i++) V[i + 1] = s.S_momentum[i]; 39c62f7daeSJames Wright V[4] = s.S_energy; 40c62f7daeSJames Wright } 41c62f7daeSJames Wright 42*cde3d787SJames Wright CEED_QFUNCTION_HELPER CeedScalar HeatCapacityRatio(NewtonianIGProperties gas) { return gas.cp / gas.cv; } 43e0d1a4dfSLeila Ghaffari 44*cde3d787SJames Wright CEED_QFUNCTION_HELPER CeedScalar GasConstant(NewtonianIGProperties gas) { return gas.cp - gas.cv; } 45e0d1a4dfSLeila Ghaffari 46*cde3d787SJames Wright CEED_QFUNCTION_HELPER CeedScalar Prandtl(NewtonianIGProperties gas) { return gas.cp * gas.mu / gas.k; } 47e0d1a4dfSLeila Ghaffari 48*cde3d787SJames Wright CEED_QFUNCTION_HELPER CeedScalar SoundSpeed(NewtonianIGProperties gas, CeedScalar T) { return sqrt(gas.cp * (HeatCapacityRatio(gas) - 1.) * T); } 49e0d1a4dfSLeila Ghaffari 50*cde3d787SJames Wright CEED_QFUNCTION_HELPER CeedScalar Mach(NewtonianIGProperties gas, CeedScalar T, CeedScalar u) { return u / SoundSpeed(gas, T); } 51e0d1a4dfSLeila Ghaffari 52*cde3d787SJames Wright CEED_QFUNCTION_HELPER CeedScalar TotalSpecificEnthalpy(NewtonianIGProperties gas, const State s) { 53c50f56e5SJames Wright CeedScalar e_kinetic = 0.5 * Dot3(s.Y.velocity, s.Y.velocity); 54*cde3d787SJames Wright CeedScalar e_internal = gas.cv * s.Y.temperature; 55c50f56e5SJames Wright return e_internal + e_kinetic + s.Y.pressure / s.U.density; 56c50f56e5SJames Wright } 57c50f56e5SJames Wright 58*cde3d787SJames Wright CEED_QFUNCTION_HELPER CeedScalar TotalSpecificEnthalpy_fwd(NewtonianIGProperties gas, const State s, const State ds) { 59c50f56e5SJames Wright CeedScalar de_kinetic = Dot3(ds.Y.velocity, s.Y.velocity); 60*cde3d787SJames Wright CeedScalar de_internal = gas.cv * ds.Y.temperature; 612b916ea7SJeremy L Thompson return de_internal + de_kinetic + ds.Y.pressure / s.U.density - s.Y.pressure / Square(s.U.density) * ds.U.density; 62c50f56e5SJames Wright } 63c50f56e5SJames Wright 64*cde3d787SJames Wright CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromConservative(NewtonianIGProperties gas, StateConservative U) { 65475b2820SJames Wright StatePrimitive Y; 66475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) Y.velocity[i] = U.momentum[i] / U.density; 67475b2820SJames Wright CeedScalar e_kinetic = .5 * Dot3(Y.velocity, Y.velocity); 68475b2820SJames Wright CeedScalar e_total = U.E_total / U.density; 69edcfef1bSKenneth E. Jansen CeedScalar e_internal = e_total - e_kinetic; 70*cde3d787SJames Wright Y.temperature = e_internal / gas.cv; 71e0d1a4dfSLeila Ghaffari Y.pressure = (HeatCapacityRatio(gas) - 1) * U.density * e_internal; 72475b2820SJames Wright return Y; 73475b2820SJames Wright } 74475b2820SJames Wright 75*cde3d787SJames Wright CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromConservative_fwd(NewtonianIGProperties gas, State s, StateConservative dU) { 76475b2820SJames Wright StatePrimitive dY; 77475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 78475b2820SJames Wright dY.velocity[i] = (dU.momentum[i] - s.Y.velocity[i] * dU.density) / s.U.density; 79475b2820SJames Wright } 80475b2820SJames Wright CeedScalar e_kinetic = .5 * Dot3(s.Y.velocity, s.Y.velocity); 81475b2820SJames Wright CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 82475b2820SJames Wright CeedScalar e_total = s.U.E_total / s.U.density; 83475b2820SJames Wright CeedScalar de_total = (dU.E_total - e_total * dU.density) / s.U.density; 84edcfef1bSKenneth E. Jansen CeedScalar e_internal = e_total - e_kinetic; 85edcfef1bSKenneth E. Jansen CeedScalar de_internal = de_total - de_kinetic; 86*cde3d787SJames Wright dY.temperature = de_internal / gas.cv; 872b916ea7SJeremy L Thompson dY.pressure = (HeatCapacityRatio(gas) - 1) * (dU.density * e_internal + s.U.density * de_internal); 88475b2820SJames Wright return dY; 89475b2820SJames Wright } 90475b2820SJames Wright 91*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateEntropy StateEntropyFromPrimitive(NewtonianIGProperties gas, StatePrimitive Y) { 92a6654c3eSJames Wright StateEntropy V; 93a6654c3eSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 94a6654c3eSJames Wright const CeedScalar rho = Y.pressure / (GasConstant(gas) * Y.temperature); 95a6654c3eSJames Wright const CeedScalar entropy = log(Y.pressure) - gamma * log(rho); 96a6654c3eSJames Wright const CeedScalar rho_div_p = rho / Y.pressure; 97a6654c3eSJames Wright const CeedScalar e_kinetic = 0.5 * Dot3(Y.velocity, Y.velocity); 98a6654c3eSJames Wright 99a6654c3eSJames Wright V.S_density = (gamma - entropy) / (gamma - 1) - rho_div_p * e_kinetic; 100a6654c3eSJames Wright for (int i = 0; i < 3; i++) V.S_momentum[i] = rho_div_p * Y.velocity[i]; 101a6654c3eSJames Wright V.S_energy = -rho_div_p; 102a6654c3eSJames Wright return V; 103a6654c3eSJames Wright } 104a6654c3eSJames Wright 105*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateEntropy StateEntropyFromPrimitive_fwd(NewtonianIGProperties gas, State s, StatePrimitive dY) { 106a6654c3eSJames Wright StateEntropy dV; 107a6654c3eSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 108a6654c3eSJames Wright CeedScalar drho = (dY.pressure * s.Y.temperature - s.Y.pressure * dY.temperature) / (GasConstant(gas) * s.Y.temperature * s.Y.temperature); 109a6654c3eSJames Wright 110a6654c3eSJames Wright const CeedScalar e_kinetic = .5 * Dot3(s.Y.velocity, s.Y.velocity); 111a6654c3eSJames Wright const CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 112a6654c3eSJames Wright const CeedScalar rho_div_p = s.U.density / s.Y.pressure; 113a6654c3eSJames Wright const CeedScalar drho_div_p = (drho * s.Y.pressure - s.U.density * dY.pressure) / Square(s.Y.pressure); 114a6654c3eSJames Wright 115a6654c3eSJames Wright CeedScalar dentropy = dY.pressure / s.Y.pressure - gamma * drho / s.U.density; 116a6654c3eSJames Wright 117a6654c3eSJames Wright dV.S_density = -dentropy / (gamma - 1) - de_kinetic * rho_div_p - e_kinetic * drho_div_p; 118a6654c3eSJames Wright for (CeedInt i = 0; i < 3; i++) dV.S_momentum[i] = rho_div_p * dY.velocity[i] + drho_div_p * s.Y.velocity[i]; 119a6654c3eSJames Wright dV.S_energy = -drho_div_p; 120a6654c3eSJames Wright return dV; 121a6654c3eSJames Wright } 122a6654c3eSJames Wright 123*cde3d787SJames Wright CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromEntropy(NewtonianIGProperties gas, StateEntropy V) { 124a6654c3eSJames Wright StatePrimitive Y; 125a6654c3eSJames Wright for (int i = 0; i < 3; i++) Y.velocity[i] = -V.S_momentum[i] / V.S_energy; 126a6654c3eSJames Wright Y.temperature = -1 / (GasConstant(gas) * V.S_energy); 127a6654c3eSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 128a6654c3eSJames Wright const CeedScalar e_kinetic = 0.5 * Dot3(Y.velocity, Y.velocity); 129a6654c3eSJames Wright const CeedScalar entropy = gamma - (gamma - 1) * (V.S_density - e_kinetic * V.S_energy); 130a6654c3eSJames Wright const CeedScalar log_P = -(entropy + gamma * log(-V.S_energy)) / (gamma - 1); 131a6654c3eSJames Wright Y.pressure = exp(log_P); 132a6654c3eSJames Wright return Y; 133a6654c3eSJames Wright } 134a6654c3eSJames Wright 135*cde3d787SJames Wright CEED_QFUNCTION_HELPER StatePrimitive StatePrimitiveFromEntropy_fwd(NewtonianIGProperties gas, State s, StateEntropy dV) { 136a6654c3eSJames Wright StatePrimitive dY; 137a6654c3eSJames Wright StateEntropy V = StateEntropyFromPrimitive(gas, s.Y); 138a6654c3eSJames Wright for (int i = 0; i < 3; i++) dY.velocity[i] = -(dV.S_momentum[i] - V.S_momentum[i] * dV.S_energy / V.S_energy) / V.S_energy; 139a6654c3eSJames Wright dY.temperature = dV.S_energy / (GasConstant(gas) * V.S_energy * V.S_energy); 140a6654c3eSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 141a6654c3eSJames Wright const CeedScalar e_kinetic = 0.5 * Dot3(s.Y.velocity, s.Y.velocity); 142a6654c3eSJames Wright const CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 143a6654c3eSJames Wright const CeedScalar dentropy = (1 - gamma) * (dV.S_density - e_kinetic * dV.S_energy - de_kinetic * V.S_energy); 144a6654c3eSJames Wright dY.pressure = s.Y.pressure * (-dentropy - gamma * dV.S_energy / V.S_energy) / (gamma - 1); 145a6654c3eSJames Wright return dY; 146a6654c3eSJames Wright } 147a6654c3eSJames Wright 148*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateConservative StateConservativeFromPrimitive(NewtonianIGProperties gas, StatePrimitive Y) { 149cbe60e31SLeila Ghaffari StateConservative U; 150e0d1a4dfSLeila Ghaffari U.density = Y.pressure / (GasConstant(gas) * Y.temperature); 151cbe60e31SLeila Ghaffari for (int i = 0; i < 3; i++) U.momentum[i] = U.density * Y.velocity[i]; 152*cde3d787SJames Wright CeedScalar e_internal = gas.cv * Y.temperature; 153cbe60e31SLeila Ghaffari CeedScalar e_kinetic = .5 * Dot3(Y.velocity, Y.velocity); 154edcfef1bSKenneth E. Jansen CeedScalar e_total = e_internal + e_kinetic; 155cbe60e31SLeila Ghaffari U.E_total = U.density * e_total; 156cbe60e31SLeila Ghaffari return U; 157cbe60e31SLeila Ghaffari } 158cbe60e31SLeila Ghaffari 159*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateConservative StateConservativeFromPrimitive_fwd(NewtonianIGProperties gas, State s, StatePrimitive dY) { 160cbe60e31SLeila Ghaffari StateConservative dU; 1612b916ea7SJeremy L Thompson dU.density = (dY.pressure * s.Y.temperature - s.Y.pressure * dY.temperature) / (GasConstant(gas) * s.Y.temperature * s.Y.temperature); 162cbe60e31SLeila Ghaffari for (int i = 0; i < 3; i++) { 163cbe60e31SLeila Ghaffari dU.momentum[i] = dU.density * s.Y.velocity[i] + s.U.density * dY.velocity[i]; 164cbe60e31SLeila Ghaffari } 165cbe60e31SLeila Ghaffari CeedScalar e_kinetic = .5 * Dot3(s.Y.velocity, s.Y.velocity); 166cbe60e31SLeila Ghaffari CeedScalar de_kinetic = Dot3(dY.velocity, s.Y.velocity); 167*cde3d787SJames Wright CeedScalar e_internal = gas.cv * s.Y.temperature; 168*cde3d787SJames Wright CeedScalar de_internal = gas.cv * dY.temperature; 169edcfef1bSKenneth E. Jansen CeedScalar e_total = e_internal + e_kinetic; 170edcfef1bSKenneth E. Jansen CeedScalar de_total = de_internal + de_kinetic; 171cbe60e31SLeila Ghaffari dU.E_total = dU.density * e_total + s.U.density * de_total; 172cbe60e31SLeila Ghaffari return dU; 173cbe60e31SLeila Ghaffari } 174cbe60e31SLeila Ghaffari 175*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateEntropy StateEntropyFromConservative(NewtonianIGProperties gas, StateConservative U) { 176c62f7daeSJames Wright StateEntropy V; 177c62f7daeSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 178c62f7daeSJames Wright const CeedScalar e_kinetic = .5 * Dot3(U.momentum, U.momentum) / U.density; 179c62f7daeSJames Wright const CeedScalar e_internal = U.E_total - e_kinetic; 180c62f7daeSJames Wright const CeedScalar p = (gamma - 1) * e_internal; 181c62f7daeSJames Wright const CeedScalar entropy = log(p) - gamma * log(U.density); 182c62f7daeSJames Wright 183c62f7daeSJames Wright V.S_density = (gamma - entropy) / (gamma - 1) - e_kinetic / p; 184c62f7daeSJames Wright for (int i = 0; i < 3; i++) V.S_momentum[i] = U.momentum[i] / p; 185c62f7daeSJames Wright V.S_energy = -U.density / p; 186c62f7daeSJames Wright return V; 187c62f7daeSJames Wright } 188c62f7daeSJames Wright 189*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateEntropy StateEntropyFromConservative_fwd(NewtonianIGProperties gas, State s, StateConservative dU) { 190c62f7daeSJames Wright StateEntropy dV; 191c62f7daeSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 192c62f7daeSJames Wright const CeedScalar e_kinetic = .5 * Dot3(s.U.momentum, s.U.momentum) / s.U.density; 193c62f7daeSJames Wright const CeedScalar de_kinetic = (Dot3(s.U.momentum, dU.momentum) - e_kinetic * dU.density) / s.U.density; 194c62f7daeSJames Wright const CeedScalar de_internal = dU.E_total - de_kinetic; 195c62f7daeSJames Wright const CeedScalar p = s.Y.pressure; 196c62f7daeSJames Wright const CeedScalar dp = (gamma - 1) * de_internal; 197c62f7daeSJames Wright 198c62f7daeSJames Wright CeedScalar dentropy = dp / p - gamma * dU.density / s.U.density; 199c62f7daeSJames Wright 200c62f7daeSJames Wright dV.S_density = -dentropy / (gamma - 1) - de_kinetic / p + dp * e_kinetic / Square(p); 201c62f7daeSJames Wright for (CeedInt i = 0; i < 3; i++) { 202c62f7daeSJames Wright dV.S_momentum[i] = (dU.momentum[i] - s.U.momentum[i] * dp / p) / p; 203c62f7daeSJames Wright } 204c62f7daeSJames Wright dV.S_energy = -(dU.density - s.U.density * dp / p) / p; 205c62f7daeSJames Wright return dV; 206c62f7daeSJames Wright } 207c62f7daeSJames Wright 208*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateConservative StateConservativeFromEntropy(NewtonianIGProperties gas, StateEntropy V) { 209c62f7daeSJames Wright StateConservative U; 210c62f7daeSJames Wright CeedScalar velocity[3]; 211c62f7daeSJames Wright for (int i = 0; i < 3; i++) velocity[i] = -V.S_momentum[i] / V.S_energy; 212c62f7daeSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 213c62f7daeSJames Wright const CeedScalar e_kinetic = 0.5 * Dot3(velocity, velocity); 214c62f7daeSJames Wright const CeedScalar entropy = gamma - (gamma - 1) * (V.S_density - e_kinetic * V.S_energy); 215c62f7daeSJames Wright const CeedScalar log_rho = -(entropy + log(-V.S_energy)) / (gamma - 1); 216c62f7daeSJames Wright U.density = exp(log_rho); 217c62f7daeSJames Wright for (int i = 0; i < 3; i++) U.momentum[i] = U.density * velocity[i]; 218c62f7daeSJames Wright 219*cde3d787SJames Wright const CeedScalar e_internal = -gas.cv / (GasConstant(gas) * V.S_energy); 220c62f7daeSJames Wright U.E_total = U.density * (e_internal + e_kinetic); 221c62f7daeSJames Wright return U; 222c62f7daeSJames Wright } 223c62f7daeSJames Wright 224*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateConservative StateConservativeFromEntropy_fwd(NewtonianIGProperties gas, State s, StateEntropy dV) { 225c62f7daeSJames Wright StateConservative dU; 226c62f7daeSJames Wright CeedScalar dvelocity[3]; 227a6654c3eSJames Wright StateEntropy V = StateEntropyFromPrimitive(gas, s.Y); 228a6654c3eSJames Wright for (int i = 0; i < 3; i++) dvelocity[i] = (-dV.S_momentum[i] - s.Y.velocity[i] * dV.S_energy) / V.S_energy; 229c62f7daeSJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 230c62f7daeSJames Wright const CeedScalar e_kinetic = 0.5 * Dot3(s.Y.velocity, s.Y.velocity); 231c62f7daeSJames Wright const CeedScalar de_kinetic = Dot3(dvelocity, s.Y.velocity); 232a6654c3eSJames Wright const CeedScalar entropy = gamma - (gamma - 1) * (V.S_density - e_kinetic * V.S_energy); 233a6654c3eSJames Wright const CeedScalar dentropy = -(gamma - 1) * (dV.S_density - (de_kinetic * V.S_energy + e_kinetic * dV.S_energy)); 234a6654c3eSJames Wright const CeedScalar log_rho = -(entropy + log(-V.S_energy)) / (gamma - 1); 235c62f7daeSJames Wright const CeedScalar rho = exp(log_rho); 236a6654c3eSJames Wright dU.density = -rho / (gamma - 1) * (dentropy + dV.S_energy / V.S_energy); 237c62f7daeSJames Wright for (int i = 0; i < 3; i++) dU.momentum[i] = dU.density * s.Y.velocity[i] + s.U.density * dvelocity[i]; 238c62f7daeSJames Wright 239*cde3d787SJames Wright const CeedScalar e_internal = -gas.cv / (GasConstant(gas) * V.S_energy); 240*cde3d787SJames Wright const CeedScalar de_internal = gas.cv * dV.S_energy / (GasConstant(gas) * V.S_energy * V.S_energy); 241c62f7daeSJames Wright const CeedScalar e_total = e_internal + e_kinetic; 242c62f7daeSJames Wright dU.E_total = dU.density * e_total + s.U.density * (de_internal + de_kinetic); 243c62f7daeSJames Wright return dU; 244c62f7daeSJames Wright } 245c62f7daeSJames Wright 246*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromPrimitive(NewtonianIGProperties gas, StatePrimitive Y) { 247edcfef1bSKenneth E. Jansen StateConservative U = StateConservativeFromPrimitive(gas, Y); 248b8fb7609SAdeleke O. Bankole State s; 249b8fb7609SAdeleke O. Bankole s.U = U; 250b8fb7609SAdeleke O. Bankole s.Y = Y; 251b8fb7609SAdeleke O. Bankole return s; 252b8fb7609SAdeleke O. Bankole } 253b8fb7609SAdeleke O. Bankole 254*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromPrimitive_fwd(NewtonianIGProperties gas, State s, StatePrimitive dY) { 255edcfef1bSKenneth E. Jansen StateConservative dU = StateConservativeFromPrimitive_fwd(gas, s, dY); 256c8c30d87SJed Brown State ds; 257c8c30d87SJed Brown ds.U = dU; 258c8c30d87SJed Brown ds.Y = dY; 259c8c30d87SJed Brown return ds; 260c8c30d87SJed Brown } 261c8c30d87SJed Brown 262c2c93676SJed Brown // linear combination of n states 263c2c93676SJed Brown CEED_QFUNCTION_HELPER StateConservative StateConservativeMult(CeedInt n, const CeedScalar a[], const StateConservative X[]) { 264c2c93676SJed Brown StateConservative R = {0}; 265c2c93676SJed Brown for (CeedInt i = 0; i < n; i++) { 266c2c93676SJed Brown R.density += a[i] * X[i].density; 267c2c93676SJed Brown for (int j = 0; j < 3; j++) R.momentum[j] += a[i] * X[i].momentum[j]; 268c2c93676SJed Brown R.E_total += a[i] * X[i].E_total; 269c2c93676SJed Brown } 270dbb62a19SJed Brown return R; 271dbb62a19SJed Brown } 272dbb62a19SJed Brown 273dbb62a19SJed Brown CEED_QFUNCTION_HELPER StateConservative StateConservativeAXPBYPCZ(CeedScalar a, StateConservative X, CeedScalar b, StateConservative Y, CeedScalar c, 274dbb62a19SJed Brown StateConservative Z) { 275dbb62a19SJed Brown StateConservative R; 276dbb62a19SJed Brown R.density = a * X.density + b * Y.density + c * Z.density; 277dbb62a19SJed Brown for (int i = 0; i < 3; i++) R.momentum[i] = a * X.momentum[i] + b * Y.momentum[i] + c * Z.momentum[i]; 278dbb62a19SJed Brown R.E_total = a * X.E_total + b * Y.E_total + c * Z.E_total; 279dbb62a19SJed Brown return R; 280dbb62a19SJed Brown } 281dbb62a19SJed Brown 282*cde3d787SJames Wright CEED_QFUNCTION_HELPER void StateToU(NewtonianIGProperties gas, const State input, CeedScalar U[5]) { UnpackState_U(input.U, U); } 283b8fb7609SAdeleke O. Bankole 284*cde3d787SJames Wright CEED_QFUNCTION_HELPER void StateToY(NewtonianIGProperties gas, const State input, CeedScalar Y[5]) { UnpackState_Y(input.Y, Y); } 285a8bca8acSJames Wright 286*cde3d787SJames Wright CEED_QFUNCTION_HELPER void StateToV(NewtonianIGProperties gas, const State input, CeedScalar V[5]) { 287a6654c3eSJames Wright StateEntropy state_V = StateEntropyFromPrimitive(gas, input.Y); 288a6654c3eSJames Wright UnpackState_V(state_V, V); 289a6654c3eSJames Wright } 290c62f7daeSJames Wright 291*cde3d787SJames Wright CEED_QFUNCTION_HELPER void StateToQ(NewtonianIGProperties gas, const State input, CeedScalar Q[5], StateVariable state_var) { 2928fff8293SJames Wright switch (state_var) { 2938fff8293SJames Wright case STATEVAR_CONSERVATIVE: 2948fff8293SJames Wright StateToU(gas, input, Q); 2958fff8293SJames Wright break; 2968fff8293SJames Wright case STATEVAR_PRIMITIVE: 2978fff8293SJames Wright StateToY(gas, input, Q); 2988fff8293SJames Wright break; 299c62f7daeSJames Wright case STATEVAR_ENTROPY: 300c62f7daeSJames Wright StateToV(gas, input, Q); 301c62f7daeSJames Wright break; 30230ff0608SJames Wright default: 30330ff0608SJames Wright SetValueN(Q, -1, 5); 30430ff0608SJames Wright break; 3058fff8293SJames Wright } 3068fff8293SJames Wright } 307d4559bbeSJames Wright 308*cde3d787SJames Wright CEED_QFUNCTION_HELPER void StateToQ_fwd(NewtonianIGProperties gas, const State input, const State dinput, CeedScalar dQ[5], StateVariable state_var) { 309a6654c3eSJames Wright switch (state_var) { 310a6654c3eSJames Wright case STATEVAR_CONSERVATIVE: 311a6654c3eSJames Wright case STATEVAR_PRIMITIVE: 312a6654c3eSJames Wright StateToQ(gas, dinput, dQ, state_var); 313a6654c3eSJames Wright break; 314a6654c3eSJames Wright case STATEVAR_ENTROPY: { 315a6654c3eSJames Wright StateEntropy dstate_v; 316a6654c3eSJames Wright 317a6654c3eSJames Wright dstate_v = StateEntropyFromPrimitive_fwd(gas, input, dinput.Y); 318a6654c3eSJames Wright UnpackState_V(dstate_v, dQ); 319a6654c3eSJames Wright } break; 320a6654c3eSJames Wright } 321a6654c3eSJames Wright } 322a6654c3eSJames Wright 323*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromU(NewtonianIGProperties gas, const CeedScalar U[5]) { 324475b2820SJames Wright State s; 325475b2820SJames Wright s.U.density = U[0]; 326475b2820SJames Wright s.U.momentum[0] = U[1]; 327475b2820SJames Wright s.U.momentum[1] = U[2]; 328475b2820SJames Wright s.U.momentum[2] = U[3]; 329475b2820SJames Wright s.U.E_total = U[4]; 330edcfef1bSKenneth E. Jansen s.Y = StatePrimitiveFromConservative(gas, s.U); 331475b2820SJames Wright return s; 332475b2820SJames Wright } 333475b2820SJames Wright 334*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromU_fwd(NewtonianIGProperties gas, State s, const CeedScalar dU[5]) { 335475b2820SJames Wright State ds; 336475b2820SJames Wright ds.U.density = dU[0]; 337475b2820SJames Wright ds.U.momentum[0] = dU[1]; 338475b2820SJames Wright ds.U.momentum[1] = dU[2]; 339475b2820SJames Wright ds.U.momentum[2] = dU[3]; 340475b2820SJames Wright ds.U.E_total = dU[4]; 341edcfef1bSKenneth E. Jansen ds.Y = StatePrimitiveFromConservative_fwd(gas, s, ds.U); 342475b2820SJames Wright return ds; 343475b2820SJames Wright } 344475b2820SJames Wright 345*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromY(NewtonianIGProperties gas, const CeedScalar Y[5]) { 346cbe60e31SLeila Ghaffari State s; 347cbe60e31SLeila Ghaffari s.Y.pressure = Y[0]; 348cbe60e31SLeila Ghaffari s.Y.velocity[0] = Y[1]; 349cbe60e31SLeila Ghaffari s.Y.velocity[1] = Y[2]; 350cbe60e31SLeila Ghaffari s.Y.velocity[2] = Y[3]; 351cbe60e31SLeila Ghaffari s.Y.temperature = Y[4]; 352edcfef1bSKenneth E. Jansen s.U = StateConservativeFromPrimitive(gas, s.Y); 353cbe60e31SLeila Ghaffari return s; 354cbe60e31SLeila Ghaffari } 355cbe60e31SLeila Ghaffari 356*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromY_fwd(NewtonianIGProperties gas, State s, const CeedScalar dY[5]) { 357cbe60e31SLeila Ghaffari State ds; 358cbe60e31SLeila Ghaffari ds.Y.pressure = dY[0]; 359cbe60e31SLeila Ghaffari ds.Y.velocity[0] = dY[1]; 360cbe60e31SLeila Ghaffari ds.Y.velocity[1] = dY[2]; 361cbe60e31SLeila Ghaffari ds.Y.velocity[2] = dY[3]; 362cbe60e31SLeila Ghaffari ds.Y.temperature = dY[4]; 363edcfef1bSKenneth E. Jansen ds.U = StateConservativeFromPrimitive_fwd(gas, s, ds.Y); 364c62f7daeSJames Wright return ds; 365c62f7daeSJames Wright } 366c62f7daeSJames Wright 367*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromV(NewtonianIGProperties gas, const CeedScalar V[5]) { 368c62f7daeSJames Wright State s; 369a6654c3eSJames Wright StateEntropy state_V; 370a6654c3eSJames Wright state_V.S_density = V[0]; 371a6654c3eSJames Wright state_V.S_momentum[0] = V[1]; 372a6654c3eSJames Wright state_V.S_momentum[1] = V[2]; 373a6654c3eSJames Wright state_V.S_momentum[2] = V[3]; 374a6654c3eSJames Wright state_V.S_energy = V[4]; 375a6654c3eSJames Wright s.U = StateConservativeFromEntropy(gas, state_V); 376a6654c3eSJames Wright s.Y = StatePrimitiveFromEntropy(gas, state_V); 377c62f7daeSJames Wright return s; 378c62f7daeSJames Wright } 379c62f7daeSJames Wright 380*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromV_fwd(NewtonianIGProperties gas, State s, const CeedScalar dV[5]) { 381c62f7daeSJames Wright State ds; 382a6654c3eSJames Wright StateEntropy state_dV; 383a6654c3eSJames Wright state_dV.S_density = dV[0]; 384a6654c3eSJames Wright state_dV.S_momentum[0] = dV[1]; 385a6654c3eSJames Wright state_dV.S_momentum[1] = dV[2]; 386a6654c3eSJames Wright state_dV.S_momentum[2] = dV[3]; 387a6654c3eSJames Wright state_dV.S_energy = dV[4]; 388a6654c3eSJames Wright ds.U = StateConservativeFromEntropy_fwd(gas, s, state_dV); 389a6654c3eSJames Wright ds.Y = StatePrimitiveFromEntropy_fwd(gas, s, state_dV); 390cbe60e31SLeila Ghaffari return ds; 391cbe60e31SLeila Ghaffari } 392cbe60e31SLeila Ghaffari 393*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromQ(NewtonianIGProperties gas, const CeedScalar Q[5], StateVariable state_var) { 3948fff8293SJames Wright State s; 3958fff8293SJames Wright switch (state_var) { 3968fff8293SJames Wright case STATEVAR_CONSERVATIVE: 397edcfef1bSKenneth E. Jansen s = StateFromU(gas, Q); 3988fff8293SJames Wright break; 3998fff8293SJames Wright case STATEVAR_PRIMITIVE: 400edcfef1bSKenneth E. Jansen s = StateFromY(gas, Q); 4018fff8293SJames Wright break; 402c62f7daeSJames Wright case STATEVAR_ENTROPY: 403c62f7daeSJames Wright s = StateFromV(gas, Q); 404c62f7daeSJames Wright break; 4058fff8293SJames Wright } 4068fff8293SJames Wright return s; 4078fff8293SJames Wright } 4088fff8293SJames Wright 409*cde3d787SJames Wright CEED_QFUNCTION_HELPER State StateFromQ_fwd(NewtonianIGProperties gas, State s, const CeedScalar dQ[5], StateVariable state_var) { 4108fff8293SJames Wright State ds; 4118fff8293SJames Wright switch (state_var) { 4128fff8293SJames Wright case STATEVAR_CONSERVATIVE: 413edcfef1bSKenneth E. Jansen ds = StateFromU_fwd(gas, s, dQ); 4148fff8293SJames Wright break; 4158fff8293SJames Wright case STATEVAR_PRIMITIVE: 416edcfef1bSKenneth E. Jansen ds = StateFromY_fwd(gas, s, dQ); 4178fff8293SJames Wright break; 418c62f7daeSJames Wright case STATEVAR_ENTROPY: 419c62f7daeSJames Wright ds = StateFromV_fwd(gas, s, dQ); 420c62f7daeSJames Wright break; 4218fff8293SJames Wright } 4228fff8293SJames Wright return ds; 4238fff8293SJames Wright } 4248fff8293SJames Wright 425*cde3d787SJames Wright CEED_QFUNCTION_HELPER void FluxInviscid(const NewtonianIGProperties gas, const State s, StateConservative Flux[3]) { 426475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 427475b2820SJames Wright Flux[i].density = s.U.momentum[i]; 4282b916ea7SJeremy 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); 429475b2820SJames Wright Flux[i].E_total = (s.U.E_total + s.Y.pressure) * s.Y.velocity[i]; 430475b2820SJames Wright } 431475b2820SJames Wright } 432475b2820SJames Wright 433*cde3d787SJames Wright CEED_QFUNCTION_HELPER void FluxInviscid_fwd(const NewtonianIGProperties gas, const State s, const State ds, StateConservative dFlux[3]) { 434c50f56e5SJames Wright for (CeedInt i = 0; i < 3; i++) { 435c50f56e5SJames Wright dFlux[i].density = ds.U.momentum[i]; 4362b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 3; j++) { 4372b916ea7SJeremy 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); 4382b916ea7SJeremy L Thompson } 4392b916ea7SJeremy 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]; 440c50f56e5SJames Wright } 441c50f56e5SJames Wright } 442c50f56e5SJames Wright 443*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateConservative FluxInviscidDotNormal(const NewtonianIGProperties gas, const State s, const CeedScalar normal[3]) { 4447b530f2aSAdelekeBankole StateConservative Flux[3], Flux_dot_n = {0}; 4457b530f2aSAdelekeBankole FluxInviscid(gas, s, Flux); 4467b530f2aSAdelekeBankole for (CeedInt i = 0; i < 3; i++) { 4477b530f2aSAdelekeBankole Flux_dot_n.density += Flux[i].density * normal[i]; 4482b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 3; j++) Flux_dot_n.momentum[j] += Flux[i].momentum[j] * normal[i]; 4497b530f2aSAdelekeBankole Flux_dot_n.E_total += Flux[i].E_total * normal[i]; 4507b530f2aSAdelekeBankole } 4517b530f2aSAdelekeBankole return Flux_dot_n; 4527b530f2aSAdelekeBankole } 4537b530f2aSAdelekeBankole 454*cde3d787SJames Wright CEED_QFUNCTION_HELPER StateConservative FluxInviscidDotNormal_fwd(const NewtonianIGProperties gas, const State s, const State ds, 4557e084dbeSJames Wright const CeedScalar normal[3]) { 456c50f56e5SJames Wright StateConservative dFlux[3], Flux_dot_n = {0}; 457c50f56e5SJames Wright FluxInviscid_fwd(gas, s, ds, dFlux); 458475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 459c50f56e5SJames Wright Flux_dot_n.density += dFlux[i].density * normal[i]; 4602b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 3; j++) Flux_dot_n.momentum[j] += dFlux[i].momentum[j] * normal[i]; 461c50f56e5SJames Wright Flux_dot_n.E_total += dFlux[i].E_total * normal[i]; 462475b2820SJames Wright } 463c50f56e5SJames Wright return Flux_dot_n; 464475b2820SJames Wright } 465475b2820SJames Wright 466*cde3d787SJames Wright CEED_QFUNCTION_HELPER void FluxInviscidStrong(const NewtonianIGProperties gas, const State s, const State ds[3], CeedScalar strong_conv[5]) { 467d1b9ef12SLeila Ghaffari for (CeedInt i = 0; i < 5; i++) strong_conv[i] = 0; 468d1b9ef12SLeila Ghaffari for (CeedInt i = 0; i < 3; i++) { 469d1b9ef12SLeila Ghaffari StateConservative dF[3]; 470d1b9ef12SLeila Ghaffari FluxInviscid_fwd(gas, s, ds[i], dF); 471d1b9ef12SLeila Ghaffari CeedScalar dF_i[5]; 472d1b9ef12SLeila Ghaffari UnpackState_U(dF[i], dF_i); 4732b916ea7SJeremy L Thompson for (CeedInt j = 0; j < 5; j++) strong_conv[j] += dF_i[j]; 474d1b9ef12SLeila Ghaffari } 475d1b9ef12SLeila Ghaffari } 476d1b9ef12SLeila Ghaffari 4777e084dbeSJames Wright CEED_QFUNCTION_HELPER void FluxTotal(const StateConservative F_inviscid[3], const CeedScalar stress[3][3], const CeedScalar Fe[3], 4787e084dbeSJames Wright CeedScalar Flux[5][3]) { 479d1b9ef12SLeila Ghaffari for (CeedInt j = 0; j < 3; j++) { 480d1b9ef12SLeila Ghaffari Flux[0][j] = F_inviscid[j].density; 4812b916ea7SJeremy L Thompson for (CeedInt k = 0; k < 3; k++) Flux[k + 1][j] = F_inviscid[j].momentum[k] - stress[k][j]; 482d1b9ef12SLeila Ghaffari Flux[4][j] = F_inviscid[j].E_total + Fe[j]; 483d1b9ef12SLeila Ghaffari } 484d1b9ef12SLeila Ghaffari } 485d1b9ef12SLeila Ghaffari 4862b916ea7SJeremy L Thompson CEED_QFUNCTION_HELPER void FluxTotal_Boundary(const StateConservative F_inviscid[3], const CeedScalar stress[3][3], const CeedScalar Fe[3], 4872b916ea7SJeremy L Thompson const CeedScalar normal[3], CeedScalar Flux[5]) { 488c5740391SJames Wright for (CeedInt j = 0; j < 5; j++) Flux[j] = 0.; 489c5740391SJames Wright for (CeedInt j = 0; j < 3; j++) { 490c5740391SJames Wright Flux[0] += F_inviscid[j].density * normal[j]; 491c5740391SJames Wright for (CeedInt k = 0; k < 3; k++) { 492c5740391SJames Wright Flux[k + 1] += (F_inviscid[j].momentum[k] - stress[k][j]) * normal[j]; 493c5740391SJames Wright } 494c5740391SJames Wright Flux[4] += (F_inviscid[j].E_total + Fe[j]) * normal[j]; 495c5740391SJames Wright } 496c5740391SJames Wright } 497c5740391SJames Wright 498c8c30d87SJed Brown CEED_QFUNCTION_HELPER void FluxTotal_RiemannBoundary(const StateConservative F_inviscid_normal, const CeedScalar stress[3][3], const CeedScalar Fe[3], 499c8c30d87SJed Brown const CeedScalar normal[3], CeedScalar Flux[5]) { 500c8c30d87SJed Brown Flux[0] = F_inviscid_normal.density; 501c8c30d87SJed Brown for (CeedInt k = 0; k < 3; k++) Flux[k + 1] = F_inviscid_normal.momentum[k]; 502c8c30d87SJed Brown Flux[4] = F_inviscid_normal.E_total; 503c8c30d87SJed Brown for (CeedInt j = 0; j < 3; j++) { 504c8c30d87SJed Brown for (CeedInt k = 0; k < 3; k++) { 505c8c30d87SJed Brown Flux[k + 1] -= stress[k][j] * normal[j]; 506c8c30d87SJed Brown } 507c8c30d87SJed Brown Flux[4] += Fe[j] * normal[j]; 508c8c30d87SJed Brown } 509c8c30d87SJed Brown } 510c8c30d87SJed Brown 51140a33f2dSJames Wright CEED_QFUNCTION_HELPER void VelocityGradient(const State grad_s[3], CeedScalar grad_velocity[3][3]) { 51240a33f2dSJames Wright grad_velocity[0][0] = grad_s[0].Y.velocity[0]; 51340a33f2dSJames Wright grad_velocity[0][1] = grad_s[1].Y.velocity[0]; 51440a33f2dSJames Wright grad_velocity[0][2] = grad_s[2].Y.velocity[0]; 51540a33f2dSJames Wright grad_velocity[1][0] = grad_s[0].Y.velocity[1]; 51640a33f2dSJames Wright grad_velocity[1][1] = grad_s[1].Y.velocity[1]; 51740a33f2dSJames Wright grad_velocity[1][2] = grad_s[2].Y.velocity[1]; 51840a33f2dSJames Wright grad_velocity[2][0] = grad_s[0].Y.velocity[2]; 51940a33f2dSJames Wright grad_velocity[2][1] = grad_s[1].Y.velocity[2]; 52040a33f2dSJames Wright grad_velocity[2][2] = grad_s[2].Y.velocity[2]; 52140a33f2dSJames Wright } 52240a33f2dSJames Wright 52340a33f2dSJames Wright CEED_QFUNCTION_HELPER void KMStrainRate(const CeedScalar grad_velocity[3][3], CeedScalar strain_rate[6]) { 52440a33f2dSJames Wright const CeedScalar weight = 1 / sqrt(2.); // Really sqrt(2.) / 2 52540a33f2dSJames Wright strain_rate[0] = grad_velocity[0][0]; 52640a33f2dSJames Wright strain_rate[1] = grad_velocity[1][1]; 52740a33f2dSJames Wright strain_rate[2] = grad_velocity[2][2]; 52840a33f2dSJames Wright strain_rate[3] = weight * (grad_velocity[1][2] + grad_velocity[2][1]); 52940a33f2dSJames Wright strain_rate[4] = weight * (grad_velocity[0][2] + grad_velocity[2][0]); 53040a33f2dSJames Wright strain_rate[5] = weight * (grad_velocity[0][1] + grad_velocity[1][0]); 53140a33f2dSJames Wright } 53240a33f2dSJames Wright 533475b2820SJames Wright // Kelvin-Mandel notation 53440a33f2dSJames Wright CEED_QFUNCTION_HELPER void KMStrainRate_State(const State grad_s[3], CeedScalar strain_rate[6]) { 53540a33f2dSJames Wright CeedScalar grad_velocity[3][3]; 53640a33f2dSJames Wright VelocityGradient(grad_s, grad_velocity); 53740a33f2dSJames Wright KMStrainRate(grad_velocity, strain_rate); 53840a33f2dSJames Wright } 53940a33f2dSJames Wright 540f6ac214eSJames Wright //@brief Given velocity gradient du_i/dx_j, return 0.5*(du_i/dx_j - du_j/dx_i) 54140a33f2dSJames Wright CEED_QFUNCTION_HELPER void RotationRate(const CeedScalar grad_velocity[3][3], CeedScalar rotation_rate[3][3]) { 54240a33f2dSJames Wright rotation_rate[0][0] = 0; 54340a33f2dSJames Wright rotation_rate[1][1] = 0; 54440a33f2dSJames Wright rotation_rate[2][2] = 0; 54540a33f2dSJames Wright rotation_rate[1][2] = 0.5 * (grad_velocity[1][2] - grad_velocity[2][1]); 54640a33f2dSJames Wright rotation_rate[0][2] = 0.5 * (grad_velocity[0][2] - grad_velocity[2][0]); 54740a33f2dSJames Wright rotation_rate[0][1] = 0.5 * (grad_velocity[0][1] - grad_velocity[1][0]); 54840a33f2dSJames Wright rotation_rate[2][1] = -rotation_rate[1][2]; 54940a33f2dSJames Wright rotation_rate[2][0] = -rotation_rate[0][2]; 55040a33f2dSJames Wright rotation_rate[1][0] = -rotation_rate[0][1]; 551475b2820SJames Wright } 552475b2820SJames Wright 553*cde3d787SJames Wright CEED_QFUNCTION_HELPER void NewtonianStress(NewtonianIGProperties gas, const CeedScalar strain_rate[6], CeedScalar stress[6]) { 554475b2820SJames Wright CeedScalar div_u = strain_rate[0] + strain_rate[1] + strain_rate[2]; 555475b2820SJames Wright for (CeedInt i = 0; i < 6; i++) { 556*cde3d787SJames Wright stress[i] = gas.mu * (2 * strain_rate[i] + gas.lambda * div_u * (i < 3)); 557475b2820SJames Wright } 558475b2820SJames Wright } 559475b2820SJames Wright 560*cde3d787SJames Wright CEED_QFUNCTION_HELPER void ViscousEnergyFlux(NewtonianIGProperties gas, StatePrimitive Y, const State grad_s[3], const CeedScalar stress[3][3], 561475b2820SJames Wright CeedScalar Fe[3]) { 562475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 563*cde3d787SJames Wright 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; 564475b2820SJames Wright } 565475b2820SJames Wright } 566475b2820SJames Wright 567*cde3d787SJames Wright CEED_QFUNCTION_HELPER void ViscousEnergyFlux_fwd(NewtonianIGProperties gas, StatePrimitive Y, StatePrimitive dY, const State grad_ds[3], 5682b916ea7SJeremy L Thompson const CeedScalar stress[3][3], const CeedScalar dstress[3][3], CeedScalar dFe[3]) { 569475b2820SJames Wright for (CeedInt i = 0; i < 3; i++) { 5702b916ea7SJeremy 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] - 571*cde3d787SJames Wright Y.velocity[2] * dstress[2][i] - dY.velocity[2] * stress[2][i] - gas.k * grad_ds[i].Y.temperature; 572475b2820SJames Wright } 573475b2820SJames Wright } 574475b2820SJames Wright 57540a33f2dSJames Wright CEED_QFUNCTION_HELPER void Vorticity(const State grad_s[3], CeedScalar vorticity[3]) { 57640a33f2dSJames Wright CeedScalar grad_velocity[3][3]; 57740a33f2dSJames Wright VelocityGradient(grad_s, grad_velocity); 57840a33f2dSJames Wright Curl3(grad_velocity, vorticity); 57940a33f2dSJames Wright } 58040a33f2dSJames Wright 581*cde3d787SJames Wright CEED_QFUNCTION_HELPER void StatePhysicalGradientFromReference(CeedInt Q, CeedInt i, NewtonianIGProperties gas, State s, StateVariable state_var, 5822e7597b6SKenneth E. Jansen const CeedScalar *grad_q, const CeedScalar dXdx[3][3], State grad_s[3]) { 58306f0a019SJames Wright CeedScalar grad_qi[5][3], dq[5][3] = {{0.}}; 58406f0a019SJames Wright 58506f0a019SJames Wright GradUnpack3(Q, i, 5, grad_q, grad_qi); 58606f0a019SJames Wright MatMatNM((CeedScalar *)grad_qi, (CeedScalar *)dXdx, (CeedScalar *)dq, 5, 3, 3); 58706f0a019SJames Wright for (CeedInt j = 0; j < 3; j++) { 588edcfef1bSKenneth E. Jansen CeedScalar dqi[5]; 58906f0a019SJames Wright 59006f0a019SJames Wright for (CeedInt k = 0; k < 5; k++) dqi[k] = dq[k][j]; 59106f0a019SJames Wright grad_s[j] = StateFromQ_fwd(gas, s, dqi, state_var); 59287bd45e7SJames Wright } 59387bd45e7SJames Wright } 59487bd45e7SJames Wright 595*cde3d787SJames Wright CEED_QFUNCTION_HELPER void StatePhysicalGradientFromReference_Boundary(CeedInt Q, CeedInt i, NewtonianIGProperties gas, State s, 5962e7597b6SKenneth E. Jansen StateVariable state_var, const CeedScalar *grad_q, const CeedScalar dXdx[2][3], 5972e7597b6SKenneth E. Jansen State grad_s[3]) { 59887bd45e7SJames Wright for (CeedInt k = 0; k < 3; k++) { 599edcfef1bSKenneth E. Jansen CeedScalar dqi[5]; 60087bd45e7SJames Wright for (CeedInt j = 0; j < 5; j++) { 60187bd45e7SJames Wright dqi[j] = grad_q[(Q * 5) * 0 + Q * j + i] * dXdx[0][k] + grad_q[(Q * 5) * 1 + Q * j + i] * dXdx[1][k]; 60287bd45e7SJames Wright } 603edcfef1bSKenneth E. Jansen grad_s[k] = StateFromQ_fwd(gas, s, dqi, state_var); 60487bd45e7SJames Wright } 60587bd45e7SJames Wright } 606