Theseus
Compressible flow solver
Loading...
Searching...
No Matches
HLLFlux.hpp
Go to the documentation of this file.
1// Copyright (c) 2025-2026 Board of Trustees of the University of Illinois
2//
3// This file is part of Theseus.
4//
5// SPDX-License-Identifier: BSD-3-Clause
6#pragma once
7
8#include "mfem.hpp"
10#include "theseus_kernels.hpp"
11
12namespace Theseus
13{
14
15 namespace HLLFlux
16 {
17 // This is a central flux method: also used by LLF, needs centralized
18 // TODO: Centralize the central flux method
19 template<typename GasT>
20 MFEM_HOST_DEVICE
21 inline static void ComputeVolumeFluxKernel(const GasT &gas,
22 const mfem::real_t* q1,
23 const mfem::real_t* q2,
24 const mfem::real_t* met1,
25 const mfem::real_t* met2,
26 mfem::real_t* F_tilde)
27 {
28 const int dim = gas.dim();
29 const int neq = gas.num_equations();
30
31 // mean metric row
32 mfem::real_t met[3] = {0,0,0};
33 Kernels::ComputeMeanVec(met1, met2, met, dim);
34 mfem::real_t inv_flux_1[Theseus::MAXEQ][Theseus::MAXDIM];
35 mfem::real_t inv_flux_2[Theseus::MAXEQ][Theseus::MAXDIM];
36 mfem::real_t inv_flux_bar[Theseus::MAXEQ];
37
38 NavierStokesFlux::ComputeInviscidFluxKernel(gas, q1, inv_flux_1);
39 NavierStokesFlux::ComputeInviscidFluxKernel(gas, q2, inv_flux_2);
40 for(int ieq=0;ieq < neq;ieq++){
41 inv_flux_bar[ieq] = 0;
42 for(int idim = 0;idim < dim;idim++){
43 inv_flux_bar[ieq] += 0.5*(inv_flux_1[ieq][idim] + inv_flux_2[ieq][idim])*met[idim];
44 }
45 }
46
47 for(int ieq = 0;ieq < neq;ieq++){
48 F_tilde[ieq] = inv_flux_bar[ieq];
49 }
50
51 }
52
53 template<typename GasModelT>
54 MFEM_HOST_DEVICE inline static void
55 ComputeFaceFluxKernel(const GasModelT &gasModel,
56 const mfem::real_t *state1,
57 const mfem::real_t *state2,
58 const mfem::real_t *nor,
59 mfem::real_t *flux)
60 {
61 const int dim = gasModel.dim();
62 const int neq = gasModel.num_equations();
63
64 Theseus::PointStateView S1{state1};
65 Theseus::PointStateView S2{state2};
66
67 mfem::real_t inv_flux_1[Theseus::MAXEQ][Theseus::MAXDIM];
68 mfem::real_t inv_flux_2[Theseus::MAXEQ][Theseus::MAXDIM];
69
70 NavierStokesFlux::ComputeInviscidFluxKernel(gasModel, state1, inv_flux_1);
71 NavierStokesFlux::ComputeInviscidFluxKernel(gasModel, state2, inv_flux_2);
72
73 mfem::real_t un1 = 0.0;
74 mfem::real_t un2 = 0.0;
75 mfem::real_t nor_mag2 = 0.0;
76
77 for (int d = 0; d < dim; ++d)
78 {
79 un1 += gasModel.velocity(S1, d) * nor[d];
80 un2 += gasModel.velocity(S2, d) * nor[d];
81 nor_mag2 += nor[d] * nor[d];
82 }
83
84 const mfem::real_t nor_mag = Theseus::Kernels::rsqrt(nor_mag2);
85
86 const mfem::real_t c1 = gasModel.sound_speed(S1) * nor_mag;
87 const mfem::real_t c2 = gasModel.sound_speed(S2) * nor_mag;
88
89 const mfem::real_t sL1 = un1 - c1;
90 const mfem::real_t sL2 = un2 - c2;
91 const mfem::real_t sR1 = un1 + c1;
92 const mfem::real_t sR2 = un2 + c2;
93
94 const mfem::real_t sL = (sL1 < sL2) ? sL1 : sL2;
95 const mfem::real_t sR = (sR1 > sR2) ? sR1 : sR2;
96
97 for (int ieq = 0; ieq < neq; ++ieq)
98 {
99 mfem::real_t fn1 = 0.0;
100 mfem::real_t fn2 = 0.0;
101 for (int d = 0; d < dim; ++d)
102 {
103 fn1 += inv_flux_1[ieq][d] * nor[d];
104 fn2 += inv_flux_2[ieq][d] * nor[d];
105 }
106 if (sL >= 0.0)
107 {
108 flux[ieq] = fn1;
109 }
110 else if (sR <= 0.0)
111 {
112 flux[ieq] = fn2;
113 }
114 else
115 {
116 flux[ieq] =
117 (sR * fn1 - sL * fn2 + sL * sR * (state2[ieq] - state1[ieq]))
118 / (sR - sL);
119 }
120 }
121
122 }
123
125 template<typename GasModelT>
126 MFEM_HOST_DEVICE inline void ComputeVolumeFlux(const GasModelT &gasModel,
127 const mfem::real_t *q1, const mfem::real_t *q2,
128 const mfem::real_t *met1, const mfem::real_t *met2,
129 mfem::real_t *F_tilde) const{
130 ComputeVolumeFluxKernel(gasModel, q1, q2, met1, met2, F_tilde);
131 }
132 template<typename GasModelT>
133 MFEM_HOST_DEVICE inline void ComputeFaceFlux(const GasModelT &gasModel,const mfem::real_t *qminus,
134 const mfem::real_t *qplus, const mfem::real_t *nor,
135 mfem::real_t *flux) const {
136 ComputeFaceFluxKernel(gasModel, qminus, qplus, nor, flux);
137 }
138 };
139 };
140}
MFEM_HOST_DEVICE void ComputeMeanVec(const mfem::real_t *a, const mfem::real_t *b, mfem::real_t *out, int n)
Definition theseus_kernels.hpp:101
MFEM_HOST_DEVICE mfem::real_t rsqrt(mfem::real_t x)
Definition theseus_kernels.hpp:19
Definition AxisymmetricGeometry.hpp:15
constexpr const int MAXDIM
Definition theseus_kernels.hpp:14
constexpr const int MAXEQ
Definition theseus_kernels.hpp:13
Definition HLLFlux.hpp:124
MFEM_HOST_DEVICE void ComputeVolumeFlux(const GasModelT &gasModel, const mfem::real_t *q1, const mfem::real_t *q2, const mfem::real_t *met1, const mfem::real_t *met2, mfem::real_t *F_tilde) const
Definition HLLFlux.hpp:126
MFEM_HOST_DEVICE void ComputeFaceFlux(const GasModelT &gasModel, const mfem::real_t *qminus, const mfem::real_t *qplus, const mfem::real_t *nor, mfem::real_t *flux) const
Definition HLLFlux.hpp:133
Definition GasState.hpp:127