1 #ifndef SRC_SNAP_IMPLICIT_FLUX_DECOMPOSITION_HPP_
2 #define SRC_SNAP_IMPLICIT_FLUX_DECOMPOSITION_HPP_
5 #include <athena/athena.hpp>
12 #include <Eigen/Dense>
15 int k,
int j,
int i, CoordinateDirection dir) {
17 for (
int n = 0; n < NHYDRO; ++n) {
18 wl[n] = w(n, k,
j, i - 1);
19 wr[n] = w(n, k,
j, i);
21 }
else if (dir == X2DIR) {
22 for (
int n = 0; n < NHYDRO; ++n) {
23 wl[n] = w(n,
j, i - 1, k);
24 wr[n] = w(n,
j, i, k);
27 for (
int n = 0; n < NHYDRO; ++n) {
28 wl[n] = w(n, i - 1, k,
j);
29 wr[n] = w(n, i, k,
j);
34 inline void RoeAverage(Real prim[], Real gm1, Real wl[], Real wr[]) {
35 Real sqrtdl = sqrt(wl[IDN]);
36 Real sqrtdr = sqrt(wr[IDN]);
37 Real isdlpdr = 1.0 / (sqrtdl + sqrtdr);
44 prim[IDN] = sqrtdl * sqrtdr;
45 prim[IVX] = (sqrtdl * wl[IVX] + sqrtdr * wr[IVX]) * isdlpdr;
46 prim[IVY] = (sqrtdl * wl[IVY] + sqrtdr * wr[IVY]) * isdlpdr;
47 prim[IVZ] = (sqrtdl * wl[IVZ] + sqrtdr * wr[IVZ]) * isdlpdr;
49 for (
int i = 1; i <= NVAPOR; ++i)
50 prim[i] = (sqrtdl * wl[i] + sqrtdr * wr[i]) * isdlpdr;
53 Real el = wl[IPR] / gm1 +
54 0.5 * wl[IDN] * (
sqr(wl[IVX]) +
sqr(wl[IVY]) +
sqr(wl[IVZ]));
57 Real er = wr[IPR] / gm1 +
58 0.5 * wr[IDN] * (
sqr(wr[IVX]) +
sqr(wr[IVY]) +
sqr(wr[IVZ]));
61 Real hbar = ((el + wl[IPR]) / sqrtdl + (er + wr[IPR]) / sqrtdr) * isdlpdr;
65 (hbar - 0.5 * (
sqr(prim[IVX]) +
sqr(prim[IVY]) +
sqr(prim[IVZ]))) * gm1 /
66 (gm1 + 1.) * prim[IDN];
69 template <
typename Derived>
70 inline void Eigenvalue(Eigen::MatrixBase<Derived>& Lambda, Real u, Real cs) {
71 Lambda << u - cs, 0., 0., 0., 0., 0., u, 0., 0., 0., 0., 0., u + cs, 0., 0.,
72 0., 0., 0., u, 0., 0., 0., 0., 0., u;
74 Lambda = Lambda.cwiseAbs();
77 template <
typename Derived1,
typename Derived2>
79 Eigen::DenseBase<Derived2>& Rimat, Real prim[], Real cs,
80 Real gm1, CoordinateDirection dir) {
82 Real u = prim[IVX + dir];
83 Real v = prim[IVX + (IVY - IVX + dir) % 3];
84 Real w = prim[IVX + (IVZ - IVX + dir) % 3];
87 Real ke = 0.5 * (u * u + v * v + w * w);
88 Real hp = (gm1 + 1.) / gm1 *
p /
r;
91 Rmat << 1., 1., 1., 0., 0., u - cs, u, u + cs, 0., 0., v, v, v, 1., 0., w, w,
92 w, 0., 1., h - u * cs, ke, h + u * cs, v, w;
94 Rimat << (cs * ke + u * hp) / (2. * cs * hp), (-hp - cs * u) / (2. * cs * hp),
95 -v / (2. * hp), -w / (2. * hp), 1. / (2. * hp), (hp - ke) / hp, u / hp,
96 v / hp, w / hp, -1. / hp, (cs * ke - u * hp) / (2. * cs * hp),
97 (hp - cs * u) / (2. * cs * hp), -v / (2. * hp), -w / (2. * hp),
98 1. / (2. * hp), -v, 0., 1., 0., 0., -w, 0., 0., 1., 0.;
101 template <
typename Derived1>
102 inline void FluxJacobian(Eigen::DenseBase<Derived1>& dfdq, Real gm1, Real w[],
103 CoordinateDirection dir) {
107 Real v1 = w[IVX + dir];
108 Real v2 = w[IVX + (IVY - IVX + dir) % 3];
109 Real v3 = w[IVX + (IVZ - IVX + dir) % 3];
112 Real s2 = v1 * v1 + v2 * v2 + v3 * v3;
114 Real c1 = ((gm1 - 1) * s2 / 2 - (gm1 + 1) / gm1 * pres / rho) * v1;
115 Real c2 = (gm1 + 1) / gm1 * pres / rho + s2 / 2 - gm1 * v1 * v1;
117 dfdq << 0, 1., 0., 0., 0., gm1 * s2 / 2 - v1 * v1, (2. - gm1) * v1, -gm1 * v2,
118 -gm1 * v3, gm1, -v1 * v2, v2, v1, 0., 0., -v1 * v3, v3, 0., v1, 0., c1,
119 c2, -gm1 * v2 * v1, -gm1 * v3 * v1, (gm1 + 1) * v1;
void Eigenvector(Eigen::DenseBase< Derived1 > &Rmat, Eigen::DenseBase< Derived2 > &Rimat, Real prim[], Real cs, Real gm1, CoordinateDirection dir)
void CopyPrimitives(Real wl[], Real wr[], AthenaArray< Real > const &w, int k, int j, int i, CoordinateDirection dir)
void FluxJacobian(Eigen::DenseBase< Derived1 > &dfdq, Real gm1, Real w[], CoordinateDirection dir)
void RoeAverage(Real prim[], Real gm1, Real wl[], Real wr[])
void Eigenvalue(Eigen::MatrixBase< Derived > &Lambda, Real u, Real cs)