1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 | // *****************************************************************************
/*!
\file src/Physics/Kozak.cpp
\copyright 2012-2015 J. Bakosi,
2016-2018 Los Alamos National Security, LLC.,
2019-2021 Triad National Security, LLC.,
2022-2025 J. Bakosi
All rights reserved. See the LICENSE file for details.
\brief KozCG: Taylor-Galerkin, FCT, element-based continuous Galerkin
*/
// *****************************************************************************
#include "Vector.hpp"
#include "EOS.hpp"
#include "Kozak.hpp"
#include "Problems.hpp"
#include "InciterConfig.hpp"
namespace inciter {
extern ctr::Config g_cfg;
} // ::inciter
namespace kozak {
using inciter::g_cfg;
void
rhs( const std::vector< std::size_t >& inpoel,
const std::array< std::vector< tk::real >, 3 >& coord,
tk::real t,
tk::real dt,
const std::vector< tk::real >& tp,
const std::vector< tk::real >& dtp,
const tk::Fields& U,
tk::Fields& R )
// *****************************************************************************
// Compute right hand side
//! \param[in] inpoel Tetrahedron connectivity
//! \param[in] coord Mesh node coordinates
//! \param[in] U Unknowns/solution vector in mesh nodes
//! \param[in] t Physical time
//! \param[in] dt Physical time size
//! \param[in] tp Phisical time step size for each mesh node (if steady state)
//! \param[in] dtp Time step size for each mesh node (if steady state)
//! \param[in,out] R Right-hand side vector computed
// *****************************************************************************
{
Assert( U.nunk() == coord[0].size(), "Size mismatch" );
Assert( R.nunk() == coord[0].size(), "Size mismatch" );
// zero right hand side for all components
R.fill( 0.0 );
const auto steady = g_cfg.get< tag::steady >();
const auto ncomp = U.nprop();
const auto& x = coord[0];
const auto& y = coord[1];
const auto& z = coord[2];
auto src = problems::SRC();
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvla"
#pragma clang diagnostic ignored "-Wvla-extension"
#elif defined(STRICT_GNUC)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wvla"
#endif
for (std::size_t e=0; e<inpoel.size()/4; ++e) {
// Element gradients and Jacobian
const auto N = inpoel.data() + e*4;
const std::array< tk::real, 3 >
ba{{ x[N[1]]-x[N[0]], y[N[1]]-y[N[0]], z[N[1]]-z[N[0]] }},
ca{{ x[N[2]]-x[N[0]], y[N[2]]-y[N[0]], z[N[2]]-z[N[0]] }},
da{{ x[N[3]]-x[N[0]], y[N[3]]-y[N[0]], z[N[3]]-z[N[0]] }};
const auto J = tk::triple( ba, ca, da );
std::array< std::array< tk::real, 3 >, 4 > grad;
grad[1] = tk::cross( ca, da );
grad[2] = tk::cross( da, ba );
grad[3] = tk::cross( ba, ca );
for (std::size_t i=0; i<3; ++i) {
grad[0][i] = -grad[1][i]-grad[2][i]-grad[3][i];
}
// Taylor-Galerkin first half step
tk::real p[4];
for (std::size_t a=0; a<4; ++a) {
auto r = U(N[a],0);
auto ru = U(N[a],1);
auto rv = U(N[a],2);
auto rw = U(N[a],3);
p[a] = eos::pressure( U(N[a],4) - 0.5*(ru*ru + rv*rv + rw*rw)/r );
}
tk::real ue[ncomp];
for (std::size_t c=0; c<ncomp; ++c) {
ue[c] = (U(N[0],c) + U(N[1],c) + U(N[2],c) + U(N[3],c))/4.0;
}
if (steady) dt = (dtp[N[0]] + dtp[N[1]] + dtp[N[2]] + dtp[N[3]])/4.0;
auto coef = dt/J/2.0;
for (std::size_t j=0; j<3; ++j) {
for (std::size_t a=0; a<4; ++a) {
auto cg = coef * grad[a][j];
auto uj = U(N[a],j+1) / U(N[a],0);
ue[0] -= cg * U(N[a],j+1);
ue[1] -= cg * U(N[a],1) * uj;
ue[2] -= cg * U(N[a],2) * uj;
ue[3] -= cg * U(N[a],3) * uj;
ue[j+1] -= cg * p[a];
ue[4] -= cg * (U(N[a],4) + p[a]) * uj;
for (std::size_t c=5; c<ncomp; ++c) {
ue[c] -= cg * U(N[a],c) * uj;
}
}
}
if (src) {
coef = dt/8.0;
if (steady) t = (tp[N[0]] + tp[N[1]] + tp[N[2]] + tp[N[3]])/4.0;
for (std::size_t a=0; a<4; ++a) {
auto s = src( x[N[a]], y[N[a]], z[N[a]], t, /*meshid=*/0 );
for (std::size_t c=0; c<ncomp; ++c) {
ue[c] += coef * s[c];
}
}
}
// Taylor-Galerkin: second half step
auto r = ue[0];
auto ru = ue[1];
auto rv = ue[2];
auto rw = ue[3];
auto pr = eos::pressure( ue[4] - 0.5*(ru*ru + rv*rv + rw*rw)/r );
coef = 1.0/6.0;
for (std::size_t j=0; j<3; ++j) {
auto uj = ue[j+1] / ue[0];
for (std::size_t a=0; a<4; ++a) {
auto cg = coef * grad[a][j];
R(N[a],0) += cg * ue[j+1];
R(N[a],1) += cg * ue[1] * uj;
R(N[a],2) += cg * ue[2] * uj;
R(N[a],3) += cg * ue[3] * uj;
R(N[a],j+1) += cg * pr;
R(N[a],4) += cg * (ue[4] + pr) * uj;
for (std::size_t c=5; c<ncomp; ++c) {
R(N[a],c) += cg * ue[c] * uj;
}
}
}
if (src) {
auto xe = (x[N[0]] + x[N[1]] + x[N[2]] + x[N[3]])/4.0;
auto ye = (y[N[0]] + y[N[1]] + y[N[2]] + y[N[3]])/4.0;
auto ze = (z[N[0]] + z[N[1]] + z[N[2]] + z[N[3]])/4.0;
auto se = src( xe, ye, ze, t+dt/2.0, /*meshid=*/0 );
coef = J/24.0;
for (std::size_t a=0; a<4; ++a) {
for (std::size_t c=0; c<ncomp; ++c) {
R(N[a],c) += coef * se[c];
}
}
}
}
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(STRICT_GNUC)
#pragma GCC diagnostic pop
#endif
}
} // kozak::
|