Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/PDE/CompFlow/CGCompFlow.hpp
4 : : \copyright 2012-2015 J. Bakosi,
5 : : 2016-2018 Los Alamos National Security, LLC.,
6 : : 2019-2021 Triad National Security, LLC.
7 : : All rights reserved. See the LICENSE file for details.
8 : : \brief Compressible single-material flow using continuous Galerkin
9 : : \details This file implements the physics operators governing compressible
10 : : single-material flow using continuous Galerkin discretization.
11 : : */
12 : : // *****************************************************************************
13 : : #ifndef CGCompFlow_h
14 : : #define CGCompFlow_h
15 : :
16 : : #include <cmath>
17 : : #include <algorithm>
18 : : #include <unordered_set>
19 : : #include <unordered_map>
20 : :
21 : : #include "DerivedData.hpp"
22 : : #include "Exception.hpp"
23 : : #include "Vector.hpp"
24 : : #include "Mesh/Around.hpp"
25 : : #include "Reconstruction.hpp"
26 : : #include "Problem/FieldOutput.hpp"
27 : : #include "Problem/BoxInitialization.hpp"
28 : : #include "Riemann/Rusanov.hpp"
29 : : #include "NodeBC.hpp"
30 : : #include "EoS/EOS.hpp"
31 : : #include "History.hpp"
32 : : #include "Table.hpp"
33 : :
34 : : namespace inciter {
35 : :
36 : : extern ctr::InputDeck g_inputdeck;
37 : :
38 : : namespace cg {
39 : :
40 : : //! \brief CompFlow used polymorphically with tk::CGPDE
41 : : //! \details The template arguments specify policies and are used to configure
42 : : //! the behavior of the class. The policies are:
43 : : //! - Physics - physics configuration, see PDE/CompFlow/Physics.h
44 : : //! - Problem - problem configuration, see PDE/CompFlow/Problems.h
45 : : //! \note The default physics is Euler, set in inciter::deck::check_compflow()
46 : : template< class Physics, class Problem >
47 [ - - ][ - - ]: 105 : class CompFlow {
[ - - ][ - - ]
[ - - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
48 : :
49 : : private:
50 : : using ncomp_t = tk::ncomp_t;
51 : : using eq = tag::compflow;
52 : : using real = tk::real;
53 : :
54 : : static constexpr std::size_t m_ncomp = 5;
55 : : static constexpr real muscl_eps = 1.0e-9;
56 : : static constexpr real muscl_const = 1.0/3.0;
57 : : static constexpr real muscl_m1 = 1.0 - muscl_const;
58 : : static constexpr real muscl_p1 = 1.0 + muscl_const;
59 : :
60 : : public:
61 : : //! \brief Constructor
62 : 105 : explicit CompFlow() :
63 : : m_physics(),
64 : : m_problem(),
65 : : m_fr(),
66 : : m_fp(),
67 [ + - ]: 105 : m_fu()
68 : : {
69 : : Assert( g_inputdeck.get< tag::ncomp >() == m_ncomp,
70 : : "Number of CompFlow PDE components must be " + std::to_string(m_ncomp) );
71 : :
72 : : // EoS initialization
73 : : const auto& matprop =
74 : : g_inputdeck.get< tag::material >();
75 : : const auto& matidxmap =
76 : : g_inputdeck.get< tag::matidxmap >();
77 [ + - ]: 105 : auto mateos = matprop[matidxmap.get< tag::eosidx >()[0]].get<tag::eos>();
78 [ + - ]: 105 : m_mat_blk.emplace_back( mateos, EqType::compflow, 0 );
79 : :
80 : : // Boundary condition configurations
81 [ + + ]: 218 : for (const auto& bci : g_inputdeck.get< tag::bc >()) {
82 : : // freestream quantities
83 : 113 : m_fr = bci.get< tag::density >();
84 [ + - ]: 113 : m_fp = bci.get< tag::pressure >();
85 [ + - ]: 113 : m_fu = bci.get< tag::velocity >();
86 : : }
87 : 105 : }
88 : :
89 : : //! Determine nodes that lie inside the user-defined IC box and mesh blocks
90 : : //! \param[in] coord Mesh node coordinates
91 : : //! \param[in] inpoel Element node connectivity
92 : : //! \param[in,out] inbox List of nodes at which box user ICs are set for
93 : : //! each IC box
94 : : //! \param[in] elemblkid Element ids associated with mesh block ids where
95 : : //! user ICs are set
96 : : //! \param[in,out] nodeblkid Node ids associated to mesh block ids, where
97 : : //! user ICs are set
98 : : //! \param[in,out] nuserblk number of mesh blocks where user ICs are set
99 [ + + ]: 138 : void IcBoxNodes( const tk::UnsMesh::Coords& coord,
100 : : const std::vector< std::size_t >& inpoel,
101 : : const std::unordered_map< std::size_t, std::set< std::size_t > >& elemblkid,
102 : : std::vector< std::unordered_set< std::size_t > >& inbox,
103 : : std::unordered_map< std::size_t, std::set< std::size_t > >& nodeblkid,
104 : : std::size_t& nuserblk ) const
105 : : {
106 : : const auto& x = coord[0];
107 : : const auto& y = coord[1];
108 : : const auto& z = coord[2];
109 : :
110 : : // Detect if user has configured IC boxes
111 : : const auto& icbox = g_inputdeck.get<tag::ic, tag::box>();
112 [ + + ]: 138 : if (!icbox.empty()) {
113 : : std::size_t bcnt = 0;
114 [ + + ]: 11 : for (const auto& b : icbox) { // for all boxes for this eq
115 [ + - ]: 6 : inbox.emplace_back();
116 [ + - ]: 6 : std::vector< tk::real > box
117 : : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
118 : : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
119 : : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
120 : :
121 : : // Determine orientation of box
122 : 6 : std::array< tk::real, 3 > b_orientn{{
123 : : b.template get< tag::orientation >()[0],
124 : : b.template get< tag::orientation >()[1],
125 : : b.template get< tag::orientation >()[2] }};
126 : 6 : std::array< tk::real, 3 > b_centroid{{ 0.5*(box[0]+box[1]),
127 : 6 : 0.5*(box[2]+box[3]), 0.5*(box[4]+box[5]) }};
128 : :
129 : : const auto eps = std::numeric_limits< tk::real >::epsilon();
130 : : // Determine which nodes lie in the IC box
131 [ + - ]: 6 : if ( std::any_of( begin(box), end(box), [=](auto p)
132 : : { return abs(p) > eps; } ) )
133 : : {
134 : : // Transform box to reference space
135 : 6 : std::array< tk::real, 3 > b_min{{box[0], box[2], box[4]}};
136 : 6 : std::array< tk::real, 3 > b_max{{box[1], box[3], box[5]}};
137 : : tk::movePoint(b_centroid, b_min);
138 : : tk::movePoint(b_centroid, b_max);
139 : :
140 [ + + ]: 5137 : for (ncomp_t i=0; i<x.size(); ++i) {
141 : 5131 : std::array< tk::real, 3 > node{{ x[i], y[i], z[i] }};
142 : : // Transform node to reference space of box
143 : : tk::movePoint(b_centroid, node);
144 : 5131 : tk::rotatePoint({{-b_orientn[0], -b_orientn[1], -b_orientn[2]}},
145 : : node);
146 [ + + ]: 1840 : if ( node[0]>b_min[0] && node[0]<b_max[0] &&
147 [ + + ][ + + ]: 1598 : node[1]>b_min[1] && node[1]<b_max[1] &&
148 [ + + ][ + + ]: 6004 : node[2]>b_min[2] && node[2]<b_max[2] )
[ + + ]
149 : : {
150 [ + - ]: 759 : inbox[bcnt].insert( i );
151 : : }
152 : : }
153 : : }
154 [ + - ]: 6 : ++bcnt;
155 : : }
156 : : }
157 : :
158 : : // size IC mesh blocks volume vector
159 : : const auto& mblks = g_inputdeck.get< tag::ic, tag::meshblock >();
160 : : // if mesh blocks have been specified for this system
161 [ - + ]: 138 : if (!mblks.empty()) {
162 : 0 : std::size_t idMax(0);
163 [ - - ]: 0 : for (const auto& imb : mblks) {
164 : 0 : idMax = std::max(idMax, imb.get< tag::blockid >());
165 : : }
166 : : // size is idMax+1 since block ids are usually 1-based
167 : 0 : nuserblk = nuserblk+idMax+1;
168 : : }
169 : :
170 : : // determine node set for IC mesh blocks
171 [ + + ]: 282 : for (const auto& [blid, elset] : elemblkid) {
172 [ + - ]: 144 : if (!elset.empty()) {
173 : : auto& ndset = nodeblkid[blid];
174 [ + + ]: 152550 : for (auto ie : elset) {
175 [ + + ]: 762030 : for (std::size_t i=0; i<4; ++i) ndset.insert(inpoel[4*ie+i]);
176 : : }
177 : : }
178 : : }
179 : 138 : }
180 : :
181 : : //! Initalize the compressible flow equations, prepare for time integration
182 : : //! \param[in] coord Mesh node coordinates
183 : : //! \param[in,out] unk Array of unknowns
184 : : //! \param[in] t Physical time
185 : : //! \param[in] V Discrete volume of user-defined IC box
186 : : //! \param[in] inbox List of nodes at which box user ICs are set (for each
187 : : //! box IC)
188 : : //! \param[in] nodeblkid Node ids associated to mesh block ids, where
189 : : //! user ICs are set
190 : : //! \param[in] blkvols Vector of discrete volumes of each block where user
191 : : //! ICs are set
192 : 154 : void initialize(
193 : : const std::array< std::vector< real >, 3 >& coord,
194 : : tk::Fields& unk,
195 : : real t,
196 : : real V,
197 : : const std::vector< std::unordered_set< std::size_t > >& inbox,
198 : : const std::vector< tk::real >& blkvols,
199 : : const std::unordered_map< std::size_t, std::set< std::size_t > >&
200 : : nodeblkid ) const
201 : : {
202 : : Assert( coord[0].size() == unk.nunk(), "Size mismatch" );
203 : :
204 : : const auto& x = coord[0];
205 : : const auto& y = coord[1];
206 : : const auto& z = coord[2];
207 : :
208 : : const auto& ic = g_inputdeck.get< tag::ic >();
209 : : const auto& icbox = ic.get< tag::box >();
210 : : const auto& mblks = ic.get< tag::meshblock >();
211 : :
212 : : const auto eps = 1000.0 * std::numeric_limits< tk::real >::epsilon();
213 : :
214 : 154 : tk::real bgpre = ic.get< tag::pressure >();
215 : :
216 : 154 : auto c_v = getmatprop< tag::cv >();
217 : :
218 : : // Set initial and boundary conditions using problem policy
219 [ + + ]: 50932 : for (ncomp_t i=0; i<x.size(); ++i) {
220 [ + - ]: 50778 : auto s = Problem::initialize( m_ncomp, m_mat_blk, x[i], y[i], z[i], t );
221 : :
222 : : // initialize the user-defined box IC
223 [ + + ]: 50778 : if (!icbox.empty()) {
224 : : std::size_t bcnt = 0;
225 [ + + ]: 9771 : for (const auto& b : icbox) { // for all boxes
226 [ + - ][ + + ]: 10262 : if (inbox.size() > bcnt && inbox[bcnt].find(i) != inbox[bcnt].end())
227 : : {
228 [ + - ][ - - ]: 759 : std::vector< tk::real > box
229 : : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
230 : : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
231 : : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
232 : 759 : auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
233 [ - + ]: 759 : if (V_ex < eps) V = 1.0;
234 [ + - ]: 759 : initializeBox<ctr::boxList>( m_mat_blk, V_ex/V,
235 : : V_ex, t, b, bgpre, c_v, s );
236 : : }
237 : 5131 : ++bcnt;
238 : : }
239 : : }
240 : :
241 : : // initialize user-defined mesh block ICs
242 [ - + ]: 50778 : for (const auto& b : mblks) { // for all blocks
243 : 0 : auto blid = b.get< tag::blockid >();
244 : 0 : auto V_ex = b.get< tag::volume >();
245 [ - - ][ - - ]: 0 : if (blid >= blkvols.size()) Throw("Block volume not found");
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ]
246 [ - - ]: 0 : if (nodeblkid.find(blid) != nodeblkid.end()) {
247 : : const auto& ndset = tk::cref_find(nodeblkid, blid);
248 [ - - ]: 0 : if (ndset.find(i) != ndset.end()) {
249 [ - - ]: 0 : initializeBox<ctr::meshblockList>( m_mat_blk,
250 : : V_ex/blkvols[blid], V_ex, t, b, bgpre, c_v, s );
251 : : }
252 : : }
253 : : }
254 : :
255 : 50778 : unk(i,0) = s[0]; // rho
256 : 50778 : unk(i,1) = s[1]; // rho * u
257 : 50778 : unk(i,2) = s[2]; // rho * v
258 : 50778 : unk(i,3) = s[3]; // rho * w
259 : 50778 : unk(i,4) = s[4]; // rho * e, e: total = kinetic + internal
260 : : }
261 : 154 : }
262 : :
263 : : //! Query the fluid velocity
264 : : //! \param[in] u Solution vector of conserved variables
265 : : //! \param[in,out] v Velocity components
266 : 19409 : void velocity( const tk::Fields& u, tk::UnsMesh::Coords& v ) const {
267 [ + + ]: 77636 : for (std::size_t j=0; j<3; ++j) {
268 : : // extract momentum
269 : 116454 : v[j] = u.extract_comp( 1+j );
270 : : Assert( v[j].size() == u.nunk(), "Size mismatch" );
271 : : // divide by density
272 [ + + ]: 10274370 : for (std::size_t i=0; i<u.nunk(); ++i) v[j][i] /= u(i,0);
273 : : }
274 : 19409 : }
275 : :
276 : : //! Query the sound speed
277 : : //! \param[in] U Solution vector of conserved variables
278 : : //! \param[in,out] s Speed of sound in mesh nodes
279 : 19409 : void soundspeed( const tk::Fields& U, std::vector< tk::real >& s ) const {
280 : 19409 : s.resize( U.nunk() );
281 [ + + ]: 3424790 : for (std::size_t i=0; i<U.nunk(); ++i) {
282 : 3405381 : auto r = U(i,0);
283 : 3405381 : auto ru = U(i,1);
284 : 3405381 : auto rv = U(i,2);
285 : 3405381 : auto rw = U(i,3);
286 : 3405381 : auto re = U(i,4);
287 : 3405381 : auto p = m_mat_blk[0].compute< EOS::pressure >(r, ru/r, rv/r, rw/r, re);
288 : 3405381 : s[i] = m_mat_blk[0].compute< EOS::soundspeed >( r, p );
289 : : }
290 : 19409 : }
291 : :
292 : : //! Return analytic solution (if defined by Problem) at xi, yi, zi, t
293 : : //! \param[in] xi X-coordinate
294 : : //! \param[in] yi Y-coordinate
295 : : //! \param[in] zi Z-coordinate
296 : : //! \param[in] t Physical time
297 : : //! \return Vector of analytic solution at given location and time
298 : : std::vector< real >
299 : : analyticSolution( real xi, real yi, real zi, real t ) const
300 : 25005 : { return Problem::analyticSolution( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
301 : :
302 : : //! Return analytic solution for conserved variables
303 : : //! \param[in] xi X-coordinate at which to evaluate the analytic solution
304 : : //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
305 : : //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
306 : : //! \param[in] t Physical time at which to evaluate the analytic solution
307 : : //! \return Vector of analytic solution at given location and time
308 : : std::vector< tk::real >
309 : : solution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
310 : 768306 : { return Problem::initialize( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
311 : :
312 : : //! \brief Compute nodal gradients of primitive variables for ALECG along
313 : : //! chare-boundary
314 : : //! \param[in] coord Mesh node coordinates
315 : : //! \param[in] inpoel Mesh element connectivity
316 : : //! \param[in] bndel List of elements contributing to chare-boundary nodes
317 : : //! \param[in] gid Local->global node id map
318 : : //! \param[in] bid Local chare-boundary node ids (value) associated to
319 : : //! global node ids (key)
320 : : //! \param[in] U Solution vector at recent time step
321 : : //! \param[in,out] G Nodal gradients of primitive variables
322 : : //! \details This function only computes local contributions to gradients
323 : : //! at chare-boundary nodes. Internal node gradients are calculated as
324 : : //! required, and do not need to be stored.
325 : 19506 : void chBndGrad( const std::array< std::vector< real >, 3 >& coord,
326 : : const std::vector< std::size_t >& inpoel,
327 : : const std::vector< std::size_t >& bndel,
328 : : const std::vector< std::size_t >& gid,
329 : : const std::unordered_map< std::size_t, std::size_t >& bid,
330 : : const tk::Fields& U,
331 : : tk::Fields& G ) const
332 : : {
333 : : Assert( U.nunk() == coord[0].size(), "Number of unknowns in solution "
334 : : "vector at recent time step incorrect" );
335 : :
336 : : // compute gradients of primitive variables in points
337 : : G.fill( 0.0 );
338 : :
339 : : // access node cooordinates
340 : : const auto& x = coord[0];
341 : : const auto& y = coord[1];
342 : : const auto& z = coord[2];
343 : :
344 [ + + ]: 4034316 : for (auto e : bndel) { // elements contributing to chare boundary nodes
345 : : // access node IDs
346 [ - + ]: 4014810 : std::size_t N[4] =
347 : : { inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3] };
348 : : // compute element Jacobi determinant, J = 6V
349 : 4014810 : real bax = x[N[1]]-x[N[0]];
350 : 4014810 : real bay = y[N[1]]-y[N[0]];
351 : 4014810 : real baz = z[N[1]]-z[N[0]];
352 : 4014810 : real cax = x[N[2]]-x[N[0]];
353 : 4014810 : real cay = y[N[2]]-y[N[0]];
354 : 4014810 : real caz = z[N[2]]-z[N[0]];
355 : 4014810 : real dax = x[N[3]]-x[N[0]];
356 : 4014810 : real day = y[N[3]]-y[N[0]];
357 [ - + ]: 4014810 : real daz = z[N[3]]-z[N[0]];
358 : : auto J = tk::triple( bax, bay, baz, cax, cay, caz, dax, day, daz );
359 [ - + ][ - - ]: 4014810 : ErrChk( J > 0, "Element Jacobian non-positive" );
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ]
360 : 4014810 : auto J24 = J/24.0;
361 : : // shape function derivatives, nnode*ndim [4][3]
362 : : real g[4][3];
363 : : tk::crossdiv( cax, cay, caz, dax, day, daz, J,
364 : : g[1][0], g[1][1], g[1][2] );
365 : : tk::crossdiv( dax, day, daz, bax, bay, baz, J,
366 : : g[2][0], g[2][1], g[2][2] );
367 : : tk::crossdiv( bax, bay, baz, cax, cay, caz, J,
368 : : g[3][0], g[3][1], g[3][2] );
369 [ + + ]: 16059240 : for (std::size_t i=0; i<3; ++i)
370 : 12044430 : g[0][i] = -g[1][i] - g[2][i] - g[3][i];
371 : : // scatter-add gradient contributions to boundary nodes
372 [ + + ]: 20074050 : for (std::size_t a=0; a<4; ++a) {
373 : 16059240 : auto i = bid.find( gid[N[a]] );
374 [ + + ]: 16059240 : if (i != end(bid)) {
375 : : real u[5];
376 [ + + ]: 51590640 : for (std::size_t b=0; b<4; ++b) {
377 : 41272512 : u[0] = U(N[b],0);
378 : 41272512 : u[1] = U(N[b],1)/u[0];
379 : 41272512 : u[2] = U(N[b],2)/u[0];
380 : 41272512 : u[3] = U(N[b],3)/u[0];
381 : 41272512 : u[4] = U(N[b],4)/u[0]
382 : 41272512 : - 0.5*(u[1]*u[1] + u[2]*u[2] + u[3]*u[3]);
383 [ + + ]: 247635072 : for (std::size_t c=0; c<5; ++c)
384 [ + + ]: 825450240 : for (std::size_t j=0; j<3; ++j)
385 : 619087680 : G(i->second,c*3+j) += J24 * g[b][j] * u[c];
386 : : }
387 : : }
388 : : }
389 : : }
390 : 19506 : }
391 : :
392 : : //! Compute right hand side for ALECG
393 : : //! \param[in] t Physical time
394 : : //! \param[in] coord Mesh node coordinates
395 : : //! \param[in] inpoel Mesh element connectivity
396 : : //! \param[in] triinpoel Boundary triangle face connecitivity with local ids
397 : : //! \param[in] bid Local chare-boundary node ids (value) associated to
398 : : //! global node ids (key)
399 : : //! \param[in] gid Local->glocal node ids
400 : : //! \param[in] lid Global->local node ids
401 : : //! \param[in] dfn Dual-face normals
402 : : //! \param[in] psup Points surrounding points
403 : : //! \param[in] esup Elements surrounding points
404 : : //! \param[in] symbctri Vector with 1 at symmetry BC boundary triangles
405 : : //! \param[in] vol Nodal volumes
406 : : //! \param[in] edgenode Local node IDs of edges
407 : : //! \param[in] edgeid Edge ids in the order of access
408 : : //! \param[in] boxnodes Mesh node ids within user-defined IC boxes
409 : : //! \param[in] G Nodal gradients for chare-boundary nodes
410 : : //! \param[in] U Solution vector at recent time step
411 : : //! \param[in] W Mesh velocity
412 : : //! \param[in] tp Physical time for each mesh node
413 : : //! \param[in] V Total box volume
414 : : //! \param[in,out] R Right-hand side vector computed
415 : 19506 : void rhs( real t,
416 : : const std::array< std::vector< real >, 3 >& coord,
417 : : const std::vector< std::size_t >& inpoel,
418 : : const std::vector< std::size_t >& triinpoel,
419 : : const std::vector< std::size_t >& gid,
420 : : const std::unordered_map< std::size_t, std::size_t >& bid,
421 : : const std::unordered_map< std::size_t, std::size_t >& lid,
422 : : const std::vector< real >& dfn,
423 : : const std::pair< std::vector< std::size_t >,
424 : : std::vector< std::size_t > >& psup,
425 : : const std::pair< std::vector< std::size_t >,
426 : : std::vector< std::size_t > >& esup,
427 : : const std::vector< int >& symbctri,
428 : : const std::vector< real >& vol,
429 : : const std::vector< std::size_t >& edgenode,
430 : : const std::vector< std::size_t >& edgeid,
431 : : const std::vector< std::unordered_set< std::size_t > >& boxnodes,
432 : : const tk::Fields& G,
433 : : const tk::Fields& U,
434 : : const tk::Fields& W,
435 : : const std::vector< tk::real >& tp,
436 : : real V,
437 : : tk::Fields& R ) const
438 : : {
439 : : Assert( G.nprop() == m_ncomp*3,
440 : : "Number of components in gradient vector incorrect" );
441 : : Assert( U.nunk() == coord[0].size(), "Number of unknowns in solution "
442 : : "vector at recent time step incorrect" );
443 : : Assert( R.nunk() == coord[0].size(),
444 : : "Number of unknowns and/or number of components in right-hand "
445 : : "side vector incorrect" );
446 : : Assert( W.nunk() == coord[0].size(), "Size mismatch " );
447 : :
448 : : // compute/assemble gradients in points
449 : 19506 : auto Grad = nodegrad( coord, inpoel, lid, bid, vol, esup, U, G );
450 : :
451 : : // zero right hand side for all components
452 [ + + ]: 117036 : for (ncomp_t c=0; c<m_ncomp; ++c) R.fill( c, 0.0 );
453 : :
454 : : // compute domain-edge integral
455 [ + - ]: 19506 : domainint( coord, gid, edgenode, edgeid, psup, dfn, U, W, Grad, R );
456 : :
457 : : // compute boundary integrals
458 [ + - ]: 19506 : bndint( coord, triinpoel, symbctri, U, W, R );
459 : :
460 : : // compute external (energy) sources
461 : : const auto& icbox = g_inputdeck.get< tag::ic, tag::box >();
462 : :
463 [ + + ][ + - ]: 19506 : if (!icbox.empty() && !boxnodes.empty()) {
464 : : std::size_t bcnt = 0;
465 [ + + ]: 2490 : for (const auto& b : icbox) { // for all boxes for this eq
466 [ + - ]: 1260 : std::vector< tk::real > box
467 : : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
468 : : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
469 : : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
470 : :
471 : : const auto& initiate = b.template get< tag::initiate >();
472 [ + + ]: 1260 : if (initiate == ctr::InitiateType::LINEAR) {
473 [ + - ]: 1200 : boxSrc( V, t, inpoel, esup, boxnodes[bcnt], coord, R );
474 : : }
475 [ + - ]: 1260 : ++bcnt;
476 : : }
477 : : }
478 : :
479 : : // compute optional source integral
480 [ + - ]: 19506 : src( coord, inpoel, t, tp, R );
481 : 19506 : }
482 : :
483 : : //! Compute boundary pressure integrals (force) for rigid body motion
484 : : //! \param[in] coord Mesh node coordinates
485 : : //! \param[in] triinpoel Boundary triangle face connecitivity with local ids
486 : : //! \param[in] symbctri Vector with 1 at symmetry BC boundary triangles
487 : : //! \param[in] U Solution vector at recent time step
488 : : //! \param[in] CM Center of mass
489 : : //! \param[in,out] F Force vector (appended with torque vector) computed
490 : 0 : void bndPressureInt(
491 : : const std::array< std::vector< real >, 3 >& coord,
492 : : const std::vector< std::size_t >& triinpoel,
493 : : const std::vector< int >& symbctri,
494 : : const tk::Fields& U,
495 : : const std::array< tk::real, 3 >& CM,
496 : : std::vector< real >& F ) const
497 : : {
498 : :
499 : : // access node coordinates
500 : : const auto& x = coord[0];
501 : : const auto& y = coord[1];
502 : : const auto& z = coord[2];
503 : :
504 : : // boundary integrals: compute surface integral of pressure (=force)
505 [ - - ]: 0 : for (std::size_t e=0; e<triinpoel.size()/3; ++e) {
506 [ - - ]: 0 : if (symbctri[e]) {
507 : : // access node IDs
508 : 0 : std::size_t N[3] =
509 : : { triinpoel[e*3+0], triinpoel[e*3+1], triinpoel[e*3+2] };
510 : : // access solution at element nodes
511 : 0 : real rA = U(N[0],0);
512 : 0 : real rB = U(N[1],0);
513 : 0 : real rC = U(N[2],0);
514 : 0 : real ruA = U(N[0],1);
515 : 0 : real ruB = U(N[1],1);
516 : 0 : real ruC = U(N[2],1);
517 : 0 : real rvA = U(N[0],2);
518 : 0 : real rvB = U(N[1],2);
519 : 0 : real rvC = U(N[2],2);
520 : 0 : real rwA = U(N[0],3);
521 : 0 : real rwB = U(N[1],3);
522 : 0 : real rwC = U(N[2],3);
523 : 0 : real reA = U(N[0],4);
524 : 0 : real reB = U(N[1],4);
525 : 0 : real reC = U(N[2],4);
526 : : // compute face normal
527 : : real nx, ny, nz;
528 : 0 : tk::normal( x[N[0]], x[N[1]], x[N[2]],
529 : : y[N[0]], y[N[1]], y[N[2]],
530 : : z[N[0]], z[N[1]], z[N[2]],
531 : : nx, ny, nz );
532 : : // compute boundary pressures
533 : 0 : auto p = (
534 [ - - ]: 0 : m_mat_blk[0].compute< EOS::pressure >(rA, ruA/rA, rvA/rA, rwA/rA, reA) +
535 [ - - ]: 0 : m_mat_blk[0].compute< EOS::pressure >(rB, ruB/rB, rvB/rB, rwB/rB, reB) +
536 [ - - ]: 0 : m_mat_blk[0].compute< EOS::pressure >(rC, ruC/rC, rvC/rC, rwC/rC, reC)
537 : : ) / 3.0;
538 : : // compute face area
539 : 0 : auto Ae = tk::area( x[N[0]], x[N[1]], x[N[2]],
540 : : y[N[0]], y[N[1]], y[N[2]],
541 : : z[N[0]], z[N[1]], z[N[2]] );
542 : : // contribute to force vector
543 : 0 : F[0] += p * Ae * nx;
544 : 0 : F[1] += p * Ae * ny;
545 : 0 : F[2] += p * Ae * nz;
546 : :
547 : : // contribute to torque vector
548 : : std::array< tk::real, 3 > rCM{{
549 : 0 : (x[N[0]]+x[N[1]]+x[N[2]])/3.0 - CM[0],
550 : 0 : (y[N[0]]+y[N[1]]+y[N[2]])/3.0 - CM[1],
551 : 0 : (z[N[0]]+z[N[1]]+z[N[2]])/3.0 - CM[2] }};
552 : :
553 : 0 : auto torque = tk::cross(rCM, {{p*Ae*nx, p*Ae*ny, p*Ae*nz}});
554 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i) F[i+3] += torque[i];
555 : : }
556 : : }
557 : 0 : }
558 : :
559 : : //! Compute the minimum time step size (for unsteady time stepping)
560 : : //! \param[in] coord Mesh node coordinates
561 : : //! \param[in] inpoel Mesh element connectivity
562 : : //! \param[in] t Physical time
563 : : //! \param[in] dtn Time step size at the previous time step
564 : : //! \param[in] U Solution vector at recent time step
565 : : //! \param[in] vol Nodal volume (with contributions from other chares)
566 : : //! \param[in] voln Nodal volume (with contributions from other chares) at
567 : : //! the previous time step
568 : : //! \return Minimum time step size
569 : 6302 : real dt( const std::array< std::vector< real >, 3 >& coord,
570 : : const std::vector< std::size_t >& inpoel,
571 : : tk::real t,
572 : : tk::real dtn,
573 : : const tk::Fields& U,
574 : : const std::vector< tk::real >& vol,
575 : : const std::vector< tk::real >& voln ) const
576 : : {
577 : : Assert( U.nunk() == coord[0].size(), "Number of unknowns in solution "
578 : : "vector at recent time step incorrect" );
579 : :
580 : : // energy source propagation time and velocity
581 : : const auto& icbox = g_inputdeck.get< tag::ic, tag::box >();
582 : :
583 : : const auto& x = coord[0];
584 : : const auto& y = coord[1];
585 : : const auto& z = coord[2];
586 : :
587 : : // ratio of specific heats
588 : 6302 : auto g = getmatprop< tag::gamma >();
589 : : // compute the minimum dt across all elements we own
590 : 6302 : real mindt = std::numeric_limits< real >::max();
591 [ + + ]: 3597107 : for (std::size_t e=0; e<inpoel.size()/4; ++e) {
592 : 3590805 : const std::array< std::size_t, 4 > N{{ inpoel[e*4+0], inpoel[e*4+1],
593 : : inpoel[e*4+2], inpoel[e*4+3] }};
594 : : // compute cubic root of element volume as the characteristic length
595 : : const std::array< real, 3 >
596 : 3590805 : ba{{ x[N[1]]-x[N[0]], y[N[1]]-y[N[0]], z[N[1]]-z[N[0]] }},
597 : 3590805 : ca{{ x[N[2]]-x[N[0]], y[N[2]]-y[N[0]], z[N[2]]-z[N[0]] }},
598 : 3590805 : da{{ x[N[3]]-x[N[0]], y[N[3]]-y[N[0]], z[N[3]]-z[N[0]] }};
599 : 3590805 : const auto L = std::cbrt( tk::triple( ba, ca, da ) / 6.0 );
600 : : // access solution at element nodes at recent time step
601 : : std::array< std::array< real, 4 >, m_ncomp > u;
602 [ + + ]: 21544830 : for (ncomp_t c=0; c<m_ncomp; ++c) u[c] = U.extract( c, N );
603 : : // compute the maximum length of the characteristic velocity (fluid
604 : : // velocity + sound velocity) across the four element nodes
605 : : real maxvel = 0.0;
606 [ + + ]: 17954025 : for (std::size_t j=0; j<4; ++j) {
607 : : auto& r = u[0][j]; // rho
608 : : auto& ru = u[1][j]; // rho * u
609 : : auto& rv = u[2][j]; // rho * v
610 : : auto& rw = u[3][j]; // rho * w
611 : : auto& re = u[4][j]; // rho * e
612 : 14363220 : auto p = m_mat_blk[0].compute< EOS::pressure >( r, ru/r, rv/r, rw/r,
613 : : re );
614 [ - + ]: 14363220 : if (p < 0) p = 0.0;
615 : 14363220 : auto c = m_mat_blk[0].compute< EOS::soundspeed >( r, p );
616 [ + + ]: 14363220 : auto v = std::sqrt((ru*ru + rv*rv + rw*rw)/r/r) + c; // char. velocity
617 : :
618 : : // energy source propagation velocity (in all IC boxes configured)
619 [ + + ]: 14363220 : if (!icbox.empty()) {
620 [ + + ]: 9987520 : for (const auto& b : icbox) { // for all boxes for this eq
621 : : const auto& initiate = b.template get< tag::initiate >();
622 : 5024080 : auto iv = b.template get< tag::front_speed >();
623 [ + + ]: 5024080 : if (initiate == ctr::InitiateType::LINEAR) {
624 : 4902800 : auto zmin = b.template get< tag::zmin >();
625 : 4902800 : auto zmax = b.template get< tag::zmax >();
626 : : auto wFront = 0.08;
627 : : auto tInit = 0.0;
628 : 4902800 : auto tFinal = tInit + (zmax - zmin - 2.0*wFront) /
629 : 4902800 : std::fabs(iv);
630 [ + - ][ + + ]: 4902800 : if (t >= tInit && t <= tFinal)
631 [ + - ]: 8825040 : v = std::max(v, std::fabs(iv));
632 : : }
633 : : }
634 : : }
635 : :
636 [ + + ]: 14363220 : if (v > maxvel) maxvel = v;
637 : : }
638 : : // compute element dt for the Euler equations
639 : 3590805 : auto euler_dt = L / maxvel;
640 : : // compute element dt based on the viscous force
641 : 3590805 : auto viscous_dt = m_physics.viscous_dt( L, u );
642 : : // compute element dt based on thermal diffusion
643 [ - + ]: 3590805 : auto conduct_dt = m_physics.conduct_dt( L, g, u );
644 : : // compute minimum element dt
645 [ + + ]: 3590805 : auto elemdt = std::min( euler_dt, std::min( viscous_dt, conduct_dt ) );
646 : : // find minimum dt across all elements
647 : 3590805 : mindt = std::min( elemdt, mindt );
648 : : }
649 : 6302 : mindt *= g_inputdeck.get< tag::cfl >();
650 : :
651 : : // compute the minimum dt across all nodes we contribute to due to volume
652 : : // change in time
653 : 6302 : auto dvcfl = g_inputdeck.get< tag::ale, tag::dvcfl >();
654 [ + + ][ + + ]: 6302 : if (dtn > 0.0 && dvcfl > 0.0) {
655 : : Assert( vol.size() == voln.size(), "Size mismatch" );
656 [ + + ]: 375342 : for (std::size_t p=0; p<vol.size(); ++p) {
657 : 375044 : auto vol_dt = dtn *
658 [ + + ][ + - ]: 477649 : std::min(voln[p],vol[p]) / std::abs(voln[p]-vol[p]+1.0e-14);
659 : 375044 : mindt = std::min( vol_dt, mindt );
660 : : }
661 : 298 : mindt *= dvcfl;
662 : : }
663 : :
664 : 6302 : return mindt;
665 : : }
666 : :
667 : : //! Compute a time step size for each mesh node (for steady time stepping)
668 : : //! \param[in] U Solution vector at recent time step
669 : : //! \param[in] vol Nodal volume (with contributions from other chares)
670 : : //! \param[in,out] dtp Time step size for each mesh node
671 : 200 : void dt( uint64_t,
672 : : const std::vector< tk::real >& vol,
673 : : const tk::Fields& U,
674 : : std::vector< tk::real >& dtp ) const
675 : : {
676 [ + + ]: 22520 : for (std::size_t i=0; i<U.nunk(); ++i) {
677 : : // compute cubic root of element volume as the characteristic length
678 : 22320 : const auto L = std::cbrt( vol[i] );
679 : : // access solution at node p at recent time step
680 : : const auto u = U[i];
681 : : // compute pressure
682 [ + - ]: 22320 : auto p = m_mat_blk[0].compute< EOS::pressure >( u[0], u[1]/u[0],
683 [ + - ][ - - ]: 22320 : u[2]/u[0], u[3]/u[0], u[4] );
684 [ - + ]: 22320 : if (p < 0) p = 0.0;
685 [ + - ]: 22320 : auto c = m_mat_blk[0].compute< EOS::soundspeed >( u[0], p );
686 : : // characteristic velocity
687 : 22320 : auto v = std::sqrt((u[1]*u[1] + u[2]*u[2] + u[3]*u[3])/u[0]/u[0]) + c;
688 : : // compute dt for node
689 [ + - ]: 22320 : dtp[i] = L / v * g_inputdeck.get< tag::cfl >();
690 : : }
691 : 200 : }
692 : :
693 : : //! \brief Query Dirichlet boundary condition value on a given side set for
694 : : //! all components in this PDE system
695 : : //! \param[in] t Physical time
696 : : //! \param[in] deltat Time step size
697 : : //! \param[in] tp Physical time for each mesh node
698 : : //! \param[in] dtp Time step size for each mesh node
699 : : //! \param[in] ss Pair of side set ID and (local) node IDs on the side set
700 : : //! \param[in] coord Mesh node coordinates
701 : : //! \param[in] increment If true, evaluate the solution increment between
702 : : //! t and t+dt for Dirichlet BCs. If false, evlauate the solution instead.
703 : : //! \return Vector of pairs of bool and boundary condition value associated
704 : : //! to mesh node IDs at which Dirichlet boundary conditions are set. Note
705 : : //! that if increment is true, instead of the actual boundary condition
706 : : //! value, we return the increment between t+deltat and t, since,
707 : : //! depending on client code and solver, that may be what the solution
708 : : //! requires.
709 : : std::map< std::size_t, std::vector< std::pair<bool,real> > >
710 : 50667 : dirbc( real t,
711 : : real deltat,
712 : : const std::vector< tk::real >& tp,
713 : : const std::vector< tk::real >& dtp,
714 : : const std::pair< const int, std::vector< std::size_t > >& ss,
715 : : const std::array< std::vector< real >, 3 >& coord,
716 : : bool increment ) const
717 : : {
718 : : using NodeBC = std::vector< std::pair< bool, real > >;
719 : : std::map< std::size_t, NodeBC > bc;
720 : :
721 : : // collect sidesets across all meshes
722 : : std::vector< std::size_t > ubc;
723 [ + + ]: 101385 : for (const auto& ibc : g_inputdeck.get< tag::bc >()) {
724 [ + - ][ - - ]: 50718 : ubc.insert(ubc.end(), ibc.get< tag::dirichlet >().begin(),
725 : : ibc.get< tag::dirichlet >().end());
726 : : }
727 : :
728 [ + + ]: 50667 : const auto steady = g_inputdeck.get< tag::steady_state >();
729 [ + + ]: 50667 : if (!ubc.empty()) {
730 : : Assert( ubc.size() > 0, "Indexing out of Dirichlet BC eq-vector" );
731 : : const auto& x = coord[0];
732 : : const auto& y = coord[1];
733 : : const auto& z = coord[2];
734 [ + + ]: 292047 : for (const auto& b : ubc)
735 [ + + ]: 250326 : if (static_cast<int>(b) == ss.first)
736 [ + + ]: 1141077 : for (auto n : ss.second) {
737 : : Assert( x.size() > n, "Indexing out of coordinate array" );
738 [ + + ]: 1099365 : if (steady) { t = tp[n]; deltat = dtp[n]; }
739 [ - + ][ - - ]: 1099365 : auto s = increment ?
[ - - ]
740 [ - - ]: 0 : solinc( m_ncomp, m_mat_blk, x[n], y[n], z[n],
741 : : t, deltat, Problem::initialize ) :
742 [ + - ]: 1099365 : Problem::initialize( m_ncomp, m_mat_blk, x[n], y[n],
743 : : z[n], t+deltat );
744 [ + - ][ + - ]: 2198730 : bc[n] = {{ {true,s[0]}, {true,s[1]}, {true,s[2]}, {true,s[3]},
[ + - ][ - - ]
745 : : {true,s[4]} }};
746 : : }
747 : : }
748 : 50667 : return bc;
749 : : }
750 : :
751 : : //! Set symmetry boundary conditions at nodes
752 : : //! \param[in] U Solution vector at recent time step
753 : : //! \param[in] bnorm Face normals in boundary points, key local node id,
754 : : //! first 3 reals of value: unit normal, outer key: side set id
755 : : //! \param[in] nodes Unique set of node ids at which to set symmetry BCs
756 : : void
757 : 25693 : symbc( tk::Fields& U,
758 : : const std::array< std::vector< real >, 3 >&,
759 : : const std::unordered_map< int,
760 : : std::unordered_map< std::size_t, std::array< real, 4 > > >& bnorm,
761 : : const std::unordered_set< std::size_t >& nodes ) const
762 : : {
763 : : // collect sidesets across all meshes
764 : : std::vector< std::size_t > sbc;
765 [ + + ]: 51410 : for (const auto& ibc : g_inputdeck.get< tag::bc >()) {
766 [ + - ][ - - ]: 25717 : sbc.insert(sbc.end(), ibc.get< tag::symmetry >().begin(),
767 : : ibc.get< tag::symmetry >().end());
768 : : }
769 : :
770 [ + + ]: 25693 : if (sbc.size() > 0) { // use symbcs for this system
771 [ + + ]: 1564907 : for (auto p : nodes) { // for all symbc nodes
772 : : // for all user-def symbc sets
773 [ + + ]: 5947246 : for (std::size_t s=0; s<sbc.size(); ++s) {
774 : : // find nodes & normals for side
775 : 4385750 : auto j = bnorm.find(static_cast<int>(sbc[s]));
776 [ + + ]: 4385750 : if (j != end(bnorm)) {
777 : : auto i = j->second.find(p); // find normal for node
778 [ + + ]: 3557040 : if (i != end(j->second)) {
779 : : std::array< real, 3 >
780 : 1662800 : n{ i->second[0], i->second[1], i->second[2] },
781 : 1662800 : v{ U(p,1), U(p,2), U(p,3) };
782 : : auto v_dot_n = tk::dot( v, n );
783 : : // symbc: remove normal component of velocity
784 : 1662800 : U(p,1) -= v_dot_n * n[0];
785 : 1662800 : U(p,2) -= v_dot_n * n[1];
786 : 1662800 : U(p,3) -= v_dot_n * n[2];
787 : : }
788 : : }
789 : : }
790 : : }
791 : : }
792 : 25693 : }
793 : :
794 : : //! Set farfield boundary conditions at nodes
795 : : //! \param[in] U Solution vector at recent time step
796 : : //! \param[in] bnorm Face normals in boundary points, key local node id,
797 : : //! first 3 reals of value: unit normal, outer key: side set id
798 : : //! \param[in] nodes Unique set of node ids at which to set farfield BCs
799 : : void
800 : 25684 : farfieldbc(
801 : : tk::Fields& U,
802 : : const std::array< std::vector< real >, 3 >&,
803 : : const std::unordered_map< int,
804 : : std::unordered_map< std::size_t, std::array< real, 4 > > >& bnorm,
805 : : const std::unordered_set< std::size_t >& nodes ) const
806 : : {
807 : : // collect sidesets across all meshes
808 : : std::vector< std::size_t > fbc;
809 [ + + ]: 51383 : for (const auto& ibc : g_inputdeck.get< tag::bc >()) {
810 [ + - ][ - - ]: 25699 : fbc.insert(fbc.end(), ibc.get< tag::farfield >().begin(),
811 : : ibc.get< tag::farfield >().end());
812 : : }
813 : :
814 [ + + ]: 25684 : if (fbc.size() > 0) // use farbcs for this system
815 [ + + ]: 174276 : for (auto p : nodes) // for all farfieldbc nodes
816 [ + + ]: 1041912 : for (const auto& s : fbc) {// for all user-def farbc sets
817 : 868086 : auto j = bnorm.find(static_cast<int>(s));// find nodes & normals for side
818 [ + + ]: 868086 : if (j != end(bnorm)) {
819 : : auto i = j->second.find(p); // find normal for node
820 [ + + ]: 866091 : if (i != end(j->second)) {
821 : : auto& r = U(p,0);
822 : : auto& ru = U(p,1);
823 : : auto& rv = U(p,2);
824 : : auto& rw = U(p,3);
825 : : auto& re = U(p,4);
826 : 236791 : auto vn =
827 : 236791 : (ru*i->second[0] + rv*i->second[1] + rw*i->second[2]) / r;
828 : 236791 : auto a = m_mat_blk[0].compute< EOS::soundspeed >( r,
829 [ + - ][ + - ]: 236791 : m_mat_blk[0].compute< EOS::pressure >( r, ru/r, rv/r, rw/r,
830 : : re ) );
831 : 236791 : auto M = vn / a;
832 [ - + ]: 236791 : if (M <= -1.0) { // supersonic inflow
833 : 0 : r = m_fr;
834 : 0 : ru = m_fr * m_fu[0];
835 : 0 : rv = m_fr * m_fu[1];
836 : 0 : rw = m_fr * m_fu[2];
837 : 0 : re = m_mat_blk[0].compute< EOS::totalenergy >( m_fr,
838 [ - - ]: 0 : m_fu[0], m_fu[1], m_fu[2], m_fp );
839 [ + - ][ + + ]: 236791 : } else if (M > -1.0 && M < 0.0) { // subsonic inflow
840 : 83112 : auto pr = m_mat_blk[0].compute< EOS::pressure >
841 [ + - ]: 83112 : ( r, ru/r, rv/r, rw/r, re );
842 : 83112 : r = m_fr;
843 : 83112 : ru = m_fr * m_fu[0];
844 : 83112 : rv = m_fr * m_fu[1];
845 : 83112 : rw = m_fr * m_fu[2];
846 [ + - ]: 83112 : re = m_mat_blk[0].compute< EOS::totalenergy >( m_fr,
847 : 83112 : m_fu[0], m_fu[1], m_fu[2], pr );
848 [ + - ][ + - ]: 153679 : } else if (M >= 0.0 && M < 1.0) { // subsonic outflow
849 : 307358 : re = m_mat_blk[0].compute< EOS::totalenergy >( r, ru/r,
850 [ + - ]: 153679 : rv/r, rw/r, m_fp );
851 : : }
852 : : }
853 : : }
854 : : }
855 : 25684 : }
856 : :
857 : : //! Apply user defined time dependent BCs
858 : : //! \param[in] t Physical time
859 : : //! \param[in,out] U Solution vector at recent time step
860 : : //! \param[in] nodes Vector of unique sets of node ids at which to apply BCs
861 : : //! \details This function applies user defined time dependent boundary
862 : : //! conditions on groups of side sets specified in the input file.
863 : : //! The user specifies pressure, density, and velocity as discrete
864 : : //! functions of time, in the control file, associated with a group of
865 : : //! side sets. Several such groups can be specified, each with their
866 : : //! own discrete function: p(t), rho(t), vx(t), vy(t), vz(t).
867 : : void
868 : 19637 : timedepbc( tk::real t,
869 : : tk::Fields& U,
870 : : const std::vector< std::unordered_set< std::size_t > >& nodes,
871 : : const std::vector< tk::Table<5> >& timedepfn ) const
872 : : {
873 [ + + ]: 20058 : for (std::size_t ib=0; ib<nodes.size(); ++ib) {
874 [ + + ]: 5052 : for (auto p:nodes[ib]) {
875 : : // sample primitive vars from discrete data at time t
876 : 4631 : auto unk = tk::sample<5>(t, timedepfn[ib]);
877 : :
878 : : // apply BCs after converting to conserved vars
879 : 4631 : U(p,0) = unk[1];
880 : 4631 : U(p,1) = unk[1]*unk[2];
881 : 4631 : U(p,2) = unk[1]*unk[3];
882 : 4631 : U(p,3) = unk[1]*unk[4];
883 : 4631 : U(p,4) = m_mat_blk[0].compute< EOS::totalenergy >( unk[1], unk[2],
884 : : unk[3], unk[4], unk[0]);
885 : : }
886 : : }
887 : 19637 : }
888 : :
889 : : //! Return a map that associates user-specified strings to functions
890 : : //! \return Map that associates user-specified strings to functions that
891 : : //! compute relevant quantities to be output to file
892 : : std::map< std::string, tk::GetVarFn > OutVarFn() const
893 : 802 : { return CompFlowOutVarFn(); }
894 : :
895 : : //! Return analytic field names to be output to file
896 : : //! \return Vector of strings labelling analytic fields output in file
897 : : std::vector< std::string > analyticFieldNames() const
898 : 630 : { return m_problem.analyticFieldNames( m_ncomp ); }
899 : :
900 : : //! Return surface field names to be output to file
901 : : //! \return Vector of strings labelling surface fields output in file
902 : : std::vector< std::string > surfNames() const
903 : 802 : { return CompFlowSurfNames(); }
904 : :
905 : : //! Return time history field names to be output to file
906 : : //! \return Vector of strings labelling time history fields output in file
907 : : std::vector< std::string > histNames() const
908 : 22 : { return CompFlowHistNames(); }
909 : :
910 : : //! Return nodal surface field output going to file
911 : : std::vector< std::vector< real > >
912 : : surfOutput( const std::map< int, std::vector< std::size_t > >& bnd,
913 : : const tk::Fields& U ) const
914 : 802 : { return CompFlowSurfOutput( m_mat_blk, bnd, U ); }
915 : :
916 : : //! Return elemental surface field output (on triangle faces) going to file
917 : : std::vector< std::vector< real > >
918 : : elemSurfOutput( const std::map< int, std::vector< std::size_t > >& bface,
919 : : const std::vector< std::size_t >& triinpoel,
920 : : const tk::Fields& U ) const
921 : : {
922 : 802 : return CompFlowElemSurfOutput( m_mat_blk, bface, triinpoel, U );
923 : : }
924 : :
925 : : //! Return time history field output evaluated at time history points
926 : : std::vector< std::vector< real > >
927 : : histOutput( const std::vector< HistData >& h,
928 : : const std::vector< std::size_t >& inpoel,
929 : : const tk::Fields& U ) const
930 : 214 : { return CompFlowHistOutput( m_mat_blk, h, inpoel, U ); }
931 : :
932 : : //! Return names of integral variables to be output to diagnostics file
933 : : //! \return Vector of strings labelling integral variables output
934 : : std::vector< std::string > names() const
935 : 33 : { return m_problem.names( m_ncomp ); }
936 : :
937 : : private:
938 : : const Physics m_physics; //!< Physics policy
939 : : const Problem m_problem; //!< Problem policy
940 : : real m_fr; //!< Farfield density
941 : : real m_fp; //!< Farfield pressure
942 : : std::vector< real > m_fu; //!< Farfield velocity
943 : : //! EOS material block
944 : : std::vector< EOS > m_mat_blk;
945 : :
946 : : //! \brief Compute/assemble nodal gradients of primitive variables for
947 : : //! ALECG in all points
948 : : //! \param[in] coord Mesh node coordinates
949 : : //! \param[in] inpoel Mesh element connectivity
950 : : //! \param[in] lid Global->local node ids
951 : : //! \param[in] bid Local chare-boundary node ids (value) associated to
952 : : //! global node ids (key)
953 : : //! \param[in] vol Nodal volumes
954 : : //! \param[in] esup Elements surrounding points
955 : : //! \param[in] U Solution vector at recent time step
956 : : //! \param[in] G Nodal gradients of primitive variables in chare-boundary
957 : : //! nodes
958 : : //! \return Gradients of primitive variables in all mesh points
959 : : tk::Fields
960 : 19506 : nodegrad( const std::array< std::vector< real >, 3 >& coord,
961 : : const std::vector< std::size_t >& inpoel,
962 : : const std::unordered_map< std::size_t, std::size_t >& lid,
963 : : const std::unordered_map< std::size_t, std::size_t >& bid,
964 : : const std::vector< real >& vol,
965 : : const std::pair< std::vector< std::size_t >,
966 : : std::vector< std::size_t > >& esup,
967 : : const tk::Fields& U,
968 : : const tk::Fields& G ) const
969 : : {
970 : : // allocate storage for nodal gradients of primitive variables
971 : 19506 : tk::Fields Grad( U.nunk(), m_ncomp*3 );
972 : : Grad.fill( 0.0 );
973 : :
974 : : // access node cooordinates
975 : : const auto& x = coord[0];
976 : : const auto& y = coord[1];
977 : : const auto& z = coord[2];
978 : :
979 : : // compute gradients of primitive variables in points
980 : 19506 : auto npoin = U.nunk();
981 : : #pragma omp simd
982 [ + + ]: 3505782 : for (std::size_t p=0; p<npoin; ++p)
983 [ + + ]: 47276736 : for (auto e : tk::Around(esup,p)) {
984 : : // access node IDs
985 : 43790460 : std::size_t N[4] =
986 : : { inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3] };
987 : : // compute element Jacobi determinant, J = 6V
988 : 43790460 : real bax = x[N[1]]-x[N[0]];
989 : 43790460 : real bay = y[N[1]]-y[N[0]];
990 : 43790460 : real baz = z[N[1]]-z[N[0]];
991 : 43790460 : real cax = x[N[2]]-x[N[0]];
992 : 43790460 : real cay = y[N[2]]-y[N[0]];
993 : 43790460 : real caz = z[N[2]]-z[N[0]];
994 : 43790460 : real dax = x[N[3]]-x[N[0]];
995 : 43790460 : real day = y[N[3]]-y[N[0]];
996 : 43790460 : real daz = z[N[3]]-z[N[0]];
997 : : auto J = tk::triple( bax, bay, baz, cax, cay, caz, dax, day, daz );
998 : 43790460 : auto J24 = J/24.0;
999 : : // shape function derivatives, nnode*ndim [4][3]
1000 : : real g[4][3];
1001 : : tk::crossdiv( cax, cay, caz, dax, day, daz, J,
1002 : : g[1][0], g[1][1], g[1][2] );
1003 : : tk::crossdiv( dax, day, daz, bax, bay, baz, J,
1004 : : g[2][0], g[2][1], g[2][2] );
1005 : : tk::crossdiv( bax, bay, baz, cax, cay, caz, J,
1006 : : g[3][0], g[3][1], g[3][2] );
1007 [ + + ]: 175161840 : for (std::size_t i=0; i<3; ++i)
1008 : 131371380 : g[0][i] = -g[1][i] - g[2][i] - g[3][i];
1009 : : // scatter-add gradient contributions to boundary nodes
1010 : : real u[m_ncomp];
1011 [ + + ]: 218952300 : for (std::size_t b=0; b<4; ++b) {
1012 : 175161840 : u[0] = U(N[b],0);
1013 : 175161840 : u[1] = U(N[b],1)/u[0];
1014 : 175161840 : u[2] = U(N[b],2)/u[0];
1015 : 175161840 : u[3] = U(N[b],3)/u[0];
1016 : 175161840 : u[4] = U(N[b],4)/u[0]
1017 : 175161840 : - 0.5*(u[1]*u[1] + u[2]*u[2] + u[3]*u[3]);
1018 [ + + ]: 1050971040 : for (std::size_t c=0; c<m_ncomp; ++c)
1019 [ + + ]: 3503236800 : for (std::size_t i=0; i<3; ++i)
1020 : 2627427600 : Grad(p,c*3+i) += J24 * g[b][i] * u[c];
1021 : : }
1022 : : }
1023 : :
1024 : : // put in nodal gradients of chare-boundary points
1025 [ + + ]: 1306215 : for (const auto& [g,b] : bid) {
1026 : 1286709 : auto i = tk::cref_find( lid, g );
1027 [ + + ]: 20587344 : for (ncomp_t c=0; c<Grad.nprop(); ++c)
1028 : 19300635 : Grad(i,c) = G(b,c);
1029 : : }
1030 : :
1031 : : // divide weak result in gradients by nodal volume
1032 [ + + ]: 3505782 : for (std::size_t p=0; p<npoin; ++p)
1033 [ + + ]: 55780416 : for (std::size_t c=0; c<m_ncomp*3; ++c)
1034 : 52294140 : Grad(p,c) /= vol[p];
1035 : :
1036 : 19506 : return Grad;
1037 : : }
1038 : :
1039 : : //! Compute domain-edge integral for ALECG
1040 : : //! \param[in] coord Mesh node coordinates
1041 : : //! \param[in] gid Local->glocal node ids
1042 : : //! \param[in] edgenode Local node ids of edges
1043 : : //! \param[in] edgeid Local node id pair -> edge id map
1044 : : //! \param[in] psup Points surrounding points
1045 : : //! \param[in] dfn Dual-face normals
1046 : : //! \param[in] U Solution vector at recent time step
1047 : : //! \param[in] W Mesh velocity
1048 : : //! \param[in] G Nodal gradients
1049 : : //! \param[in,out] R Right-hand side vector computed
1050 : 19506 : void domainint( const std::array< std::vector< real >, 3 >& coord,
1051 : : const std::vector< std::size_t >& gid,
1052 : : const std::vector< std::size_t >& edgenode,
1053 : : const std::vector< std::size_t >& edgeid,
1054 : : const std::pair< std::vector< std::size_t >,
1055 : : std::vector< std::size_t > >& psup,
1056 : : const std::vector< real >& dfn,
1057 : : const tk::Fields& U,
1058 : : const tk::Fields& W,
1059 : : const tk::Fields& G,
1060 : : tk::Fields& R ) const
1061 : : {
1062 : : // domain-edge integral: compute fluxes in edges
1063 : 19506 : std::vector< real > dflux( edgenode.size()/2 * m_ncomp );
1064 : :
1065 : : #pragma omp simd
1066 [ + + ]: 17178876 : for (std::size_t e=0; e<edgenode.size()/2; ++e) {
1067 : 17159370 : auto p = edgenode[e*2+0];
1068 : 17159370 : auto q = edgenode[e*2+1];
1069 : :
1070 : : // compute primitive variables at edge-end points
1071 : 17159370 : real rL = U(p,0);
1072 : 17159370 : real ruL = U(p,1) / rL;
1073 : 17159370 : real rvL = U(p,2) / rL;
1074 : 17159370 : real rwL = U(p,3) / rL;
1075 : 17159370 : real reL = U(p,4) / rL - 0.5*(ruL*ruL + rvL*rvL + rwL*rwL);
1076 : 17159370 : real w1L = W(p,0);
1077 : 17159370 : real w2L = W(p,1);
1078 : 17159370 : real w3L = W(p,2);
1079 : 17159370 : real rR = U(q,0);
1080 : 17159370 : real ruR = U(q,1) / rR;
1081 : 17159370 : real rvR = U(q,2) / rR;
1082 : 17159370 : real rwR = U(q,3) / rR;
1083 : 17159370 : real reR = U(q,4) / rR - 0.5*(ruR*ruR + rvR*rvR + rwR*rwR);
1084 : 17159370 : real w1R = W(q,0);
1085 : 17159370 : real w2R = W(q,1);
1086 : 17159370 : real w3R = W(q,2);
1087 : :
1088 : : // compute MUSCL reconstruction in edge-end points
1089 : 17159370 : muscl( p, q, coord, G,
1090 : : rL, ruL, rvL, rwL, reL, rR, ruR, rvR, rwR, reR );
1091 : :
1092 : : // convert back to conserved variables
1093 : 17159370 : reL = (reL + 0.5*(ruL*ruL + rvL*rvL + rwL*rwL)) * rL;
1094 : 17159370 : ruL *= rL;
1095 : 17159370 : rvL *= rL;
1096 : 17159370 : rwL *= rL;
1097 : 17159370 : reR = (reR + 0.5*(ruR*ruR + rvR*rvR + rwR*rwR)) * rR;
1098 : 17159370 : ruR *= rR;
1099 : 17159370 : rvR *= rR;
1100 : 17159370 : rwR *= rR;
1101 : :
1102 : : // evaluate pressure at edge-end points
1103 : 34318740 : real pL = m_mat_blk[0].compute< EOS::pressure >( rL, ruL/rL, rvL/rL,
1104 [ + - ]: 17159370 : rwL/rL, reL );
1105 : 34318740 : real pR = m_mat_blk[0].compute< EOS::pressure >( rR, ruR/rR, rvR/rR,
1106 [ + - ][ - - ]: 17159370 : rwR/rR, reR );
1107 : :
1108 : : // compute Riemann flux using edge-end point states
1109 : : real f[m_ncomp];
1110 : 17159370 : Rusanov::flux( m_mat_blk,
1111 : : dfn[e*6+0], dfn[e*6+1], dfn[e*6+2],
1112 [ + - ]: 17159370 : dfn[e*6+3], dfn[e*6+4], dfn[e*6+5],
1113 : : rL, ruL, rvL, rwL, reL,
1114 : : rR, ruR, rvR, rwR, reR,
1115 : : w1L, w2L, w3L, w1R, w2R, w3R,
1116 : : pL, pR,
1117 : : f[0], f[1], f[2], f[3], f[4] );
1118 : : // store flux in edges
1119 [ + + ]: 102956220 : for (std::size_t c=0; c<m_ncomp; ++c) dflux[e*m_ncomp+c] = f[c];
1120 : : }
1121 : :
1122 : : // access pointer to right hand side at component
1123 : : std::array< const real*, m_ncomp > r;
1124 [ + + ]: 117036 : for (ncomp_t c=0; c<m_ncomp; ++c) r[c] = R.cptr( c );
1125 : :
1126 : : // domain-edge integral: sum flux contributions to points
1127 [ + + ]: 3505782 : for (std::size_t p=0,k=0; p<U.nunk(); ++p)
1128 [ + + ]: 37805016 : for (auto q : tk::Around(psup,p)) {
1129 [ + + ]: 34318740 : auto s = gid[p] > gid[q] ? -1.0 : 1.0;
1130 : 34318740 : auto e = edgeid[k++];
1131 : : // the 2.0 in the following expression is so that the RHS contribution
1132 : : // conforms with Eq 12 (Waltz et al. Computers & fluids (92) 2014);
1133 : : // The 1/2 in Eq 12 is extracted from the flux function (Rusanov).
1134 : : // However, Rusanov::flux computes the flux with the 1/2. This 2
1135 : : // cancels with the 1/2 in Rusanov::flux, so that the 1/2 can be
1136 : : // extracted out and multiplied as in Eq 12
1137 [ + + ]: 205912440 : for (std::size_t c=0; c<m_ncomp; ++c)
1138 : 171593700 : R.var(r[c],p) -= 2.0*s*dflux[e*m_ncomp+c];
1139 : : }
1140 : :
1141 : : tk::destroy(dflux);
1142 : 19506 : }
1143 : :
1144 : : //! \brief Compute MUSCL reconstruction in edge-end points using a MUSCL
1145 : : //! procedure with van Leer limiting
1146 : : //! \param[in] p Left node id of edge-end
1147 : : //! \param[in] q Right node id of edge-end
1148 : : //! \param[in] coord Array of nodal coordinates
1149 : : //! \param[in] G Gradient of all unknowns in mesh points
1150 : : //! \param[in,out] rL Left density
1151 : : //! \param[in,out] uL Left X velocity
1152 : : //! \param[in,out] vL Left Y velocity
1153 : : //! \param[in,out] wL Left Z velocity
1154 : : //! \param[in,out] eL Left internal energy
1155 : : //! \param[in,out] rR Right density
1156 : : //! \param[in,out] uR Right X velocity
1157 : : //! \param[in,out] vR Right Y velocity
1158 : : //! \param[in,out] wR Right Z velocity
1159 : : //! \param[in,out] eR Right internal energy
1160 : 17159370 : void muscl( std::size_t p,
1161 : : std::size_t q,
1162 : : const tk::UnsMesh::Coords& coord,
1163 : : const tk::Fields& G,
1164 : : real& rL, real& uL, real& vL, real& wL, real& eL,
1165 : : real& rR, real& uR, real& vR, real& wR, real& eR ) const
1166 : : {
1167 : : // access node coordinates
1168 : : const auto& x = coord[0];
1169 : : const auto& y = coord[1];
1170 : : const auto& z = coord[2];
1171 : :
1172 : : // edge vector
1173 : 17159370 : std::array< real, 3 > vw{ x[q]-x[p], y[q]-y[p], z[q]-z[p] };
1174 : :
1175 : : real delta1[5], delta2[5], delta3[5];
1176 : 17159370 : std::array< real, 5 > ls{ rL, uL, vL, wL, eL };
1177 : 17159370 : std::array< real, 5 > rs{ rR, uR, vR, wR, eR };
1178 : 17159370 : auto url = ls;
1179 : 17159370 : auto urr = rs;
1180 : :
1181 : : // MUSCL reconstruction of edge-end-point primitive variables
1182 [ + + ]: 102956220 : for (std::size_t c=0; c<5; ++c) {
1183 : : // gradients
1184 [ + + ]: 85796850 : std::array< real, 3 > g1{ G(p,c*3+0), G(p,c*3+1), G(p,c*3+2) },
1185 : 85796850 : g2{ G(q,c*3+0), G(q,c*3+1), G(q,c*3+2) };
1186 : :
1187 [ + + ]: 85796850 : delta2[c] = rs[c] - ls[c];
1188 : 85796850 : delta1[c] = 2.0 * tk::dot(g1,vw) - delta2[c];
1189 : 85796850 : delta3[c] = 2.0 * tk::dot(g2,vw) - delta2[c];
1190 : :
1191 : : // MUSCL extrapolation option 1:
1192 : : // ---------------------------------------------------------------------
1193 : : // Uncomment the following 3 blocks of code if this version is required.
1194 : : // this reconstruction is from the following paper:
1195 : : // Waltz, J., Morgan, N. R., Canfield, T. R., Charest, M. R.,
1196 : : // Risinger, L. D., & Wohlbier, J. G. (2014). A three-dimensional
1197 : : // finite element arbitrary Lagrangian–Eulerian method for shock
1198 : : // hydrodynamics on unstructured grids. Computers & Fluids, 92,
1199 : : // 172-187.
1200 : :
1201 : : //// form limiters
1202 : : //auto rcL = (delta2[c] + muscl_eps) / (delta1[c] + muscl_eps);
1203 : : //auto rcR = (delta2[c] + muscl_eps) / (delta3[c] + muscl_eps);
1204 : : //auto rLinv = (delta1[c] + muscl_eps) / (delta2[c] + muscl_eps);
1205 : : //auto rRinv = (delta3[c] + muscl_eps) / (delta2[c] + muscl_eps);
1206 : :
1207 : : //// van Leer limiter
1208 : : //// any other symmetric limiter could be used instead too
1209 : : //auto phiL = (std::abs(rcL) + rcL) / (std::abs(rcL) + 1.0);
1210 : : //auto phiR = (std::abs(rcR) + rcR) / (std::abs(rcR) + 1.0);
1211 : : //auto phi_L_inv = (std::abs(rLinv) + rLinv) / (std::abs(rLinv) + 1.0);
1212 : : //auto phi_R_inv = (std::abs(rRinv) + rRinv) / (std::abs(rRinv) + 1.0);
1213 : :
1214 : : //// update unknowns with reconstructed unknowns
1215 : : //url[c] += 0.25*(delta1[c]*muscl_m1*phiL + delta2[c]*muscl_p1*phi_L_inv);
1216 : : //urr[c] -= 0.25*(delta3[c]*muscl_m1*phiR + delta2[c]*muscl_p1*phi_R_inv);
1217 : :
1218 : : // ---------------------------------------------------------------------
1219 : :
1220 : : // MUSCL extrapolation option 2:
1221 : : // ---------------------------------------------------------------------
1222 : : // The following 2 blocks of code.
1223 : : // this reconstruction is from the following paper:
1224 : : // Luo, H., Baum, J. D., & Lohner, R. (1994). Edge-based finite element
1225 : : // scheme for the Euler equations. AIAA journal, 32(6), 1183-1190.
1226 : : // Van Leer, B. (1974). Towards the ultimate conservative difference
1227 : : // scheme. II. Monotonicity and conservation combined in a second-order
1228 : : // scheme. Journal of computational physics, 14(4), 361-370.
1229 : :
1230 : : // get Van Albada limiter
1231 : : // the following form is derived from the flux limiter phi as:
1232 : : // s = phi_inv - (1 - phi)
1233 : 171593700 : auto sL = std::max(0.0, (2.0*delta1[c]*delta2[c] + muscl_eps)
1234 [ + + ]: 85796850 : /(delta1[c]*delta1[c] + delta2[c]*delta2[c] + muscl_eps));
1235 : 171593700 : auto sR = std::max(0.0, (2.0*delta3[c]*delta2[c] + muscl_eps)
1236 [ + + ]: 85796850 : /(delta3[c]*delta3[c] + delta2[c]*delta2[c] + muscl_eps));
1237 : :
1238 : : // update unknowns with reconstructed unknowns
1239 : 85796850 : url[c] += 0.25*sL*(delta1[c]*(1.0-muscl_const*sL)
1240 : 85796850 : + delta2[c]*(1.0+muscl_const*sL));
1241 : 85796850 : urr[c] -= 0.25*sR*(delta3[c]*(1.0-muscl_const*sR)
1242 : 85796850 : + delta2[c]*(1.0+muscl_const*sR));
1243 : :
1244 : : // ---------------------------------------------------------------------
1245 : : }
1246 : :
1247 : : // force first order if the reconstructions for density or internal energy
1248 : : // would have allowed negative values
1249 [ + + ][ + + ]: 17159370 : if (ls[0] < delta1[0] || ls[4] < delta1[4]) url = ls;
1250 [ + + ][ + + ]: 17159370 : if (rs[0] < -delta3[0] || rs[4] < -delta3[4]) urr = rs;
1251 : :
1252 : 17159370 : rL = url[0];
1253 : 17159370 : uL = url[1];
1254 : 17159370 : vL = url[2];
1255 : 17159370 : wL = url[3];
1256 : 17159370 : eL = url[4];
1257 : :
1258 : 17159370 : rR = urr[0];
1259 : 17159370 : uR = urr[1];
1260 : 17159370 : vR = urr[2];
1261 : 17159370 : wR = urr[3];
1262 : 17159370 : eR = urr[4];
1263 : 17159370 : }
1264 : :
1265 : : //! Compute boundary integrals for ALECG
1266 : : //! \param[in] coord Mesh node coordinates
1267 : : //! \param[in] triinpoel Boundary triangle face connecitivity with local ids
1268 : : //! \param[in] symbctri Vector with 1 at symmetry BC boundary triangles
1269 : : //! \param[in] U Solution vector at recent time step
1270 : : //! \param[in] W Mesh velocity
1271 : : //! \param[in,out] R Right-hand side vector computed
1272 : 19506 : void bndint( const std::array< std::vector< real >, 3 >& coord,
1273 : : const std::vector< std::size_t >& triinpoel,
1274 : : const std::vector< int >& symbctri,
1275 : : const tk::Fields& U,
1276 : : const tk::Fields& W,
1277 : : tk::Fields& R ) const
1278 : : {
1279 : :
1280 : : // access node coordinates
1281 : : const auto& x = coord[0];
1282 : : const auto& y = coord[1];
1283 : : const auto& z = coord[2];
1284 : :
1285 : : // boundary integrals: compute fluxes in edges
1286 : 19506 : std::vector< real > bflux( triinpoel.size() * m_ncomp * 2 );
1287 : :
1288 : : #pragma omp simd
1289 [ + + ]: 3388932 : for (std::size_t e=0; e<triinpoel.size()/3; ++e) {
1290 : : // access node IDs
1291 : 3369426 : std::size_t N[3] =
1292 : : { triinpoel[e*3+0], triinpoel[e*3+1], triinpoel[e*3+2] };
1293 : : // access solution at element nodes
1294 : 3369426 : real rA = U(N[0],0);
1295 : 3369426 : real rB = U(N[1],0);
1296 : 3369426 : real rC = U(N[2],0);
1297 : 3369426 : real ruA = U(N[0],1);
1298 : 3369426 : real ruB = U(N[1],1);
1299 : 3369426 : real ruC = U(N[2],1);
1300 : 3369426 : real rvA = U(N[0],2);
1301 : 3369426 : real rvB = U(N[1],2);
1302 : 3369426 : real rvC = U(N[2],2);
1303 : 3369426 : real rwA = U(N[0],3);
1304 : 3369426 : real rwB = U(N[1],3);
1305 : 3369426 : real rwC = U(N[2],3);
1306 : 3369426 : real reA = U(N[0],4);
1307 : 3369426 : real reB = U(N[1],4);
1308 : 3369426 : real reC = U(N[2],4);
1309 : 3369426 : real w1A = W(N[0],0);
1310 : 3369426 : real w2A = W(N[0],1);
1311 : 3369426 : real w3A = W(N[0],2);
1312 : 3369426 : real w1B = W(N[1],0);
1313 : 3369426 : real w2B = W(N[1],1);
1314 : 3369426 : real w3B = W(N[1],2);
1315 : 3369426 : real w1C = W(N[2],0);
1316 : 3369426 : real w2C = W(N[2],1);
1317 : 3369426 : real w3C = W(N[2],2);
1318 : : // compute face normal
1319 : : real nx, ny, nz;
1320 : 3369426 : tk::normal( x[N[0]], x[N[1]], x[N[2]],
1321 : : y[N[0]], y[N[1]], y[N[2]],
1322 : : z[N[0]], z[N[1]], z[N[2]],
1323 : : nx, ny, nz );
1324 : : // compute boundary flux
1325 : : real f[m_ncomp][3];
1326 : : real p, vn;
1327 [ + - ]: 3369426 : int sym = symbctri[e];
1328 [ + - ]: 3369426 : p = m_mat_blk[0].compute< EOS::pressure >( rA, ruA/rA, rvA/rA, rwA/rA,
1329 : : reA );
1330 [ + + ]: 3369426 : vn = sym ? 0.0 : (nx*(ruA/rA-w1A) + ny*(rvA/rA-w2A) + nz*(rwA/rA-w3A));
1331 : 3369426 : f[0][0] = rA*vn;
1332 : 3369426 : f[1][0] = ruA*vn + p*nx;
1333 : 3369426 : f[2][0] = rvA*vn + p*ny;
1334 : 3369426 : f[3][0] = rwA*vn + p*nz;
1335 [ + + ]: 3369426 : f[4][0] = reA*vn + p*(sym ? 0.0 : (nx*ruA + ny*rvA + nz*rwA)/rA);
1336 [ + - ]: 3369426 : p = m_mat_blk[0].compute< EOS::pressure >( rB, ruB/rB, rvB/rB, rwB/rB,
1337 : : reB );
1338 [ + + ]: 3369426 : vn = sym ? 0.0 : (nx*(ruB/rB-w1B) + ny*(rvB/rB-w2B) + nz*(rwB/rB-w3B));
1339 : 3369426 : f[0][1] = rB*vn;
1340 : 3369426 : f[1][1] = ruB*vn + p*nx;
1341 : 3369426 : f[2][1] = rvB*vn + p*ny;
1342 : 3369426 : f[3][1] = rwB*vn + p*nz;
1343 [ + + ]: 3369426 : f[4][1] = reB*vn + p*(sym ? 0.0 : (nx*ruB + ny*rvB + nz*rwB)/rB);
1344 [ + - ][ - - ]: 3369426 : p = m_mat_blk[0].compute< EOS::pressure >( rC, ruC/rC, rvC/rC, rwC/rC,
1345 : : reC );
1346 [ + + ]: 3369426 : vn = sym ? 0.0 : (nx*(ruC/rC-w1C) + ny*(rvC/rC-w2C) + nz*(rwC/rC-w3C));
1347 : 3369426 : f[0][2] = rC*vn;
1348 : 3369426 : f[1][2] = ruC*vn + p*nx;
1349 : 3369426 : f[2][2] = rvC*vn + p*ny;
1350 : 3369426 : f[3][2] = rwC*vn + p*nz;
1351 [ + + ]: 3369426 : f[4][2] = reC*vn + p*(sym ? 0.0 : (nx*ruC + ny*rvC + nz*rwC)/rC);
1352 : : // compute face area
1353 : 3369426 : auto A6 = tk::area( x[N[0]], x[N[1]], x[N[2]],
1354 : : y[N[0]], y[N[1]], y[N[2]],
1355 : : z[N[0]], z[N[1]], z[N[2]] ) / 6.0;
1356 : 3369426 : auto A24 = A6/4.0;
1357 : : // store flux in boundary elements
1358 [ + + ]: 20216556 : for (std::size_t c=0; c<m_ncomp; ++c) {
1359 : 16847130 : auto eb = (e*m_ncomp+c)*6;
1360 : 16847130 : auto Bab = A24 * (f[c][0] + f[c][1]);
1361 : 16847130 : bflux[eb+0] = Bab + A6 * f[c][0];
1362 : 16847130 : bflux[eb+1] = Bab;
1363 : 16847130 : Bab = A24 * (f[c][1] + f[c][2]);
1364 : 16847130 : bflux[eb+2] = Bab + A6 * f[c][1];
1365 : 16847130 : bflux[eb+3] = Bab;
1366 : 16847130 : Bab = A24 * (f[c][2] + f[c][0]);
1367 : 16847130 : bflux[eb+4] = Bab + A6 * f[c][2];
1368 : 16847130 : bflux[eb+5] = Bab;
1369 : : }
1370 : : }
1371 : :
1372 : : // access pointer to right hand side at component
1373 : : std::array< const real*, m_ncomp > r;
1374 [ + + ]: 117036 : for (ncomp_t c=0; c<m_ncomp; ++c) r[c] = R.cptr( c );
1375 : :
1376 : : // boundary integrals: sum flux contributions to points
1377 [ + + ]: 3388932 : for (std::size_t e=0; e<triinpoel.size()/3; ++e)
1378 [ + + ]: 20216556 : for (std::size_t c=0; c<m_ncomp; ++c) {
1379 : 16847130 : auto eb = (e*m_ncomp+c)*6;
1380 : 16847130 : R.var(r[c],triinpoel[e*3+0]) -= bflux[eb+0] + bflux[eb+5];
1381 : 16847130 : R.var(r[c],triinpoel[e*3+1]) -= bflux[eb+1] + bflux[eb+2];
1382 : 16847130 : R.var(r[c],triinpoel[e*3+2]) -= bflux[eb+3] + bflux[eb+4];
1383 : : }
1384 : :
1385 : : tk::destroy(bflux);
1386 : 19506 : }
1387 : :
1388 : : //! Compute optional source integral
1389 : : //! \param[in] coord Mesh node coordinates
1390 : : //! \param[in] inpoel Mesh element connectivity
1391 : : //! \param[in] t Physical time
1392 : : //! \param[in] tp Physical time for each mesh node
1393 : : //! \param[in,out] R Right-hand side vector computed
1394 : 19506 : void src( const std::array< std::vector< real >, 3 >& coord,
1395 : : const std::vector< std::size_t >& inpoel,
1396 : : real t,
1397 : : const std::vector< tk::real >& tp,
1398 : : tk::Fields& R ) const
1399 : : {
1400 : : // access node coordinates
1401 : : const auto& x = coord[0];
1402 : : const auto& y = coord[1];
1403 : : const auto& z = coord[2];
1404 : :
1405 : : // access pointer to right hand side at component
1406 : : std::array< const real*, m_ncomp > r;
1407 [ + + ]: 117036 : for (ncomp_t c=0; c<m_ncomp; ++c) r[c] = R.cptr( c );
1408 : :
1409 : : // source integral
1410 [ + + ]: 10967121 : for (std::size_t e=0; e<inpoel.size()/4; ++e) {
1411 : 10947615 : std::size_t N[4] =
1412 : : { inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3] };
1413 : : // compute element Jacobi determinant, J = 6V
1414 : 10947615 : auto J24 = tk::triple(
1415 : : x[N[1]]-x[N[0]], y[N[1]]-y[N[0]], z[N[1]]-z[N[0]],
1416 : : x[N[2]]-x[N[0]], y[N[2]]-y[N[0]], z[N[2]]-z[N[0]],
1417 : 10947615 : x[N[3]]-x[N[0]], y[N[3]]-y[N[0]], z[N[3]]-z[N[0]] ) / 24.0;
1418 : : // sum source contributions to nodes
1419 [ + + ]: 54738075 : for (std::size_t a=0; a<4; ++a) {
1420 [ + - ]: 43790460 : std::vector< real > s(m_ncomp);
1421 [ + + ]: 5968020 : if (g_inputdeck.get< tag::steady_state >()) t = tp[N[a]];
1422 [ + - ]: 43790460 : Problem::src( 1, m_mat_blk, x[N[a]], y[N[a]], z[N[a]], t, s );
1423 [ + + ]: 262742760 : for (std::size_t c=0; c<m_ncomp; ++c)
1424 : 218952300 : R.var(r[c],N[a]) += J24 * s[c];
1425 : : }
1426 : : }
1427 : 19506 : }
1428 : :
1429 : : //! Compute sources corresponding to a propagating front in user-defined box
1430 : : //! \param[in] V Total box volume
1431 : : //! \param[in] t Physical time
1432 : : //! \param[in] inpoel Element point connectivity
1433 : : //! \param[in] esup Elements surrounding points
1434 : : //! \param[in] boxnodes Mesh node ids within user-defined box
1435 : : //! \param[in] coord Mesh node coordinates
1436 : : //! \param[in] R Right-hand side vector
1437 : : //! \details This function add the energy source corresponding to a planar
1438 : : //! wave-front propagating along the z-direction with a user-specified
1439 : : //! velocity, within a box initial condition, configured by the user.
1440 : : //! Example (SI) units of the quantities involved:
1441 : : //! * internal energy content (energy per unit volume): J/m^3
1442 : : //! * specific energy (internal energy per unit mass): J/kg
1443 [ + - ]: 1200 : void boxSrc( real V,
1444 : : real t,
1445 : : const std::vector< std::size_t >& inpoel,
1446 : : const std::pair< std::vector< std::size_t >,
1447 : : std::vector< std::size_t > >& esup,
1448 : : const std::unordered_set< std::size_t >& boxnodes,
1449 : : const std::array< std::vector< real >, 3 >& coord,
1450 : : tk::Fields& R ) const
1451 : : {
1452 : : const auto& icbox = g_inputdeck.get< tag::ic, tag::box >();
1453 : :
1454 [ + - ]: 1200 : if (!icbox.empty()) {
1455 [ + + ]: 2400 : for (const auto& b : icbox) { // for all boxes for this eq
1456 : 1200 : std::vector< tk::real > box
1457 : : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
1458 : : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
1459 : : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
1460 : :
1461 : 1200 : auto boxenc = b.template get< tag::energy_content >();
1462 : : Assert( boxenc > 0.0, "Box energy content must be nonzero" );
1463 : :
1464 : 1200 : auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
1465 : :
1466 : : // determine times at which sourcing is initialized and terminated
1467 : 1200 : auto iv = b.template get< tag::front_speed >();
1468 : 1200 : auto wFront = b.template get< tag::front_width >();
1469 : 1200 : auto tInit = b.template get< tag::init_time >();
1470 : 1200 : auto tFinal = tInit + (box[5] - box[4] - wFront) / std::fabs(iv);
1471 : : auto aBox = (box[1]-box[0]) * (box[3]-box[2]);
1472 : :
1473 : : const auto& x = coord[0];
1474 : : const auto& y = coord[1];
1475 : : const auto& z = coord[2];
1476 : :
1477 [ + - ][ + + ]: 1200 : if (t >= tInit && t <= tFinal) {
1478 : : // The energy front is assumed to have a half-sine-wave shape. The
1479 : : // half wave-length is the width of the front. At t=0, the center of
1480 : : // this front (i.e. the peak of the partial-sine-wave) is at X_0 +
1481 : : // W_0. W_0 is calculated based on the width of the front and the
1482 : : // direction of propagation (which is assumed to be along the
1483 : : // z-direction). If the front propagation velocity is positive, it
1484 : : // is assumed that the initial position of the energy source is the
1485 : : // minimum z-coordinate of the box; whereas if this velocity is
1486 : : // negative, the initial position is the maximum z-coordinate of the
1487 : : // box.
1488 : :
1489 : : // Orientation of box
1490 : 1084 : std::array< tk::real, 3 > b_orientn{{
1491 : : b.template get< tag::orientation >()[0],
1492 : : b.template get< tag::orientation >()[1],
1493 : : b.template get< tag::orientation >()[2] }};
1494 : 1084 : std::array< tk::real, 3 > b_centroid{{ 0.5*(box[0]+box[1]),
1495 : 1084 : 0.5*(box[2]+box[3]), 0.5*(box[4]+box[5]) }};
1496 : : // Transform box to reference space
1497 : 1084 : std::array< tk::real, 3 > b_min{{box[0], box[2], box[4]}};
1498 : 1084 : std::array< tk::real, 3 > b_max{{box[1], box[3], box[5]}};
1499 : : tk::movePoint(b_centroid, b_min);
1500 : : tk::movePoint(b_centroid, b_max);
1501 : :
1502 : : // initial center of front
1503 : 1084 : tk::real zInit(b_min[2]);
1504 [ + - ]: 1084 : if (iv < 0.0) zInit = b_max[2];
1505 : : // current location of front
1506 : 1084 : auto z0 = zInit + iv * (t-tInit);
1507 : 1084 : auto z1 = z0 + std::copysign(wFront, iv);
1508 : : tk::real s0(z0), s1(z1);
1509 : : // if velocity of propagation is negative, initial position is z1
1510 [ + - ]: 1084 : if (iv < 0.0) {
1511 : : s0 = z1;
1512 : : s1 = z0;
1513 : : }
1514 : : // Sine-wave (positive part of the wave) source term amplitude
1515 : : auto pi = 4.0 * std::atan(1.0);
1516 : 1084 : auto amplE = boxenc * V_ex * pi
1517 : 1084 : / (aBox * wFront * 2.0 * (tFinal-tInit));
1518 : : //// Square wave (constant) source term amplitude
1519 : : //auto amplE = boxenc * V_ex
1520 : : // / (aBox * wFront * (tFinal-tInit));
1521 : : //// arbitrary shape form
1522 : : //auto amplE = boxenc * std::abs(iv) / wFront;
1523 : 1084 : amplE *= V_ex / V;
1524 : :
1525 : : // add source
1526 [ + + ]: 73712 : for (auto p : boxnodes) {
1527 : 72628 : std::array< tk::real, 3 > node{{ x[p], y[p], z[p] }};
1528 : : // Transform node to reference space of box
1529 : : tk::movePoint(b_centroid, node);
1530 : 72628 : tk::rotatePoint({{-b_orientn[0], -b_orientn[1], -b_orientn[2]}},
1531 : : node);
1532 : :
1533 [ + + ][ + + ]: 72628 : if (node[2] >= s0 && node[2] <= s1) {
1534 : 930 : auto S = amplE * std::sin(pi*(node[2]-s0)/wFront);
1535 : : //// arbitrary shape form
1536 : : //auto S = amplE;
1537 [ + + ]: 13307 : for (auto e : tk::Around(esup,p)) {
1538 : : // access node IDs
1539 : 12377 : std::size_t N[4] =
1540 : : {inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3]};
1541 : : // compute element Jacobi determinant, J = 6V
1542 : 12377 : real bax = x[N[1]]-x[N[0]];
1543 : 12377 : real bay = y[N[1]]-y[N[0]];
1544 : 12377 : real baz = z[N[1]]-z[N[0]];
1545 : 12377 : real cax = x[N[2]]-x[N[0]];
1546 : 12377 : real cay = y[N[2]]-y[N[0]];
1547 : 12377 : real caz = z[N[2]]-z[N[0]];
1548 : 12377 : real dax = x[N[3]]-x[N[0]];
1549 : 12377 : real day = y[N[3]]-y[N[0]];
1550 : 12377 : real daz = z[N[3]]-z[N[0]];
1551 : : auto J =
1552 : : tk::triple( bax, bay, baz, cax, cay, caz, dax, day, daz );
1553 : 12377 : auto J24 = J/24.0;
1554 : 12377 : R(p,4) += J24 * S;
1555 : : }
1556 : : }
1557 : : }
1558 : : }
1559 : : }
1560 : : }
1561 : 1200 : }
1562 : :
1563 : : };
1564 : :
1565 : : } // cg::
1566 : :
1567 : : } // inciter::
1568 : :
1569 : : #endif // CGCompFlow_h
|