Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/PDE/MultiSpecies/DGMultiSpecies.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 multi-species flow using discontinuous Galerkin
9 : : finite elements
10 : : \details This file implements calls to the physics operators governing
11 : : compressible multi-species flow using discontinuous Galerkin discretization.
12 : : */
13 : : // *****************************************************************************
14 : : #ifndef DGMultiSpecies_h
15 : : #define DGMultiSpecies_h
16 : :
17 : : #include <cmath>
18 : : #include <algorithm>
19 : : #include <unordered_set>
20 : : #include <map>
21 : : #include <array>
22 : :
23 : : #include "Macro.hpp"
24 : : #include "Exception.hpp"
25 : : #include "Vector.hpp"
26 : : #include "ContainerUtil.hpp"
27 : : #include "UnsMesh.hpp"
28 : : #include "Inciter/InputDeck/InputDeck.hpp"
29 : : #include "Integrate/Basis.hpp"
30 : : #include "Integrate/Quadrature.hpp"
31 : : #include "Integrate/Initialize.hpp"
32 : : #include "Integrate/Mass.hpp"
33 : : #include "Integrate/Surface.hpp"
34 : : #include "Integrate/Boundary.hpp"
35 : : #include "Integrate/Volume.hpp"
36 : : #include "Integrate/Source.hpp"
37 : : #include "Integrate/SolidTerms.hpp"
38 : : #include "RiemannChoice.hpp"
39 : : #include "MultiSpecies/MultiSpeciesIndexing.hpp"
40 : : #include "Reconstruction.hpp"
41 : : #include "Limiter.hpp"
42 : : #include "Problem/FieldOutput.hpp"
43 : : #include "Problem/BoxInitialization.hpp"
44 : : #include "PrefIndicator.hpp"
45 : : #include "MultiSpecies/BCFunctions.hpp"
46 : : #include "MultiSpecies/MiscMultiSpeciesFns.hpp"
47 : : #include "EoS/GetMatProp.hpp"
48 : :
49 : : namespace inciter {
50 : :
51 : : extern ctr::InputDeck g_inputdeck;
52 : :
53 : : namespace dg {
54 : :
55 : : //! \brief MultiSpecies used polymorphically with tk::DGPDE
56 : : //! \details The template arguments specify policies and are used to configure
57 : : //! the behavior of the class. The policies are:
58 : : //! - Physics - physics configuration, see PDE/MultiSpecies/Physics.h
59 : : //! - Problem - problem configuration, see PDE/MultiSpecies/Problem.h
60 : : //! \note The default physics is Euler, which is set in
61 : : //! inciter::LuaParser::storeInputDeck()
62 : : template< class Physics, class Problem >
63 : : class MultiSpecies {
64 : :
65 : : private:
66 : : using eq = tag::multispecies;
67 : :
68 : : public:
69 : : //! Constructor
70 : 24 : explicit MultiSpecies() :
71 : : m_physics(),
72 : : m_ncomp( g_inputdeck.get< tag::ncomp >() ),
73 : : m_nprim(nprim()),
74 [ + - ]: 24 : m_riemann( multispeciesRiemannSolver( g_inputdeck.get< tag::flux >() ) )
75 : : {
76 : : // associate boundary condition configurations with state functions
77 [ + - ][ + - ]: 312 : brigand::for_each< ctr::bclist::Keys >( ConfigBC( m_bc,
[ + - ][ + + ]
[ + - ][ + + ]
[ + - ][ - - ]
[ - - ][ - - ]
[ - - ]
78 : : // BC State functions
79 : : { dirichlet
80 : : , symmetry
81 : : , invalidBC // Outlet BC not implemented
82 : : , farfield
83 : : , extrapolate
84 : : , noslipwall },
85 : : // BC Gradient functions
86 : : { noOpGrad
87 : : , symmetryGrad
88 : : , noOpGrad
89 : : , noOpGrad
90 : : , noOpGrad
91 : : , noOpGrad }
92 : : ) );
93 : :
94 : : // EoS initialization
95 [ + - ]: 24 : initializeSpeciesEoS( m_mat_blk );
96 : 24 : }
97 : :
98 : : //! Find the number of primitive quantities required for this PDE system
99 : : //! \return The number of primitive quantities required to be stored for
100 : : //! this PDE system (zero for multi-species)
101 : : std::size_t nprim() const { return 0; }
102 : :
103 : : //! Find the number of materials set up for this PDE system
104 : : //! \return The number of materials set up for this PDE system
105 : : std::size_t nmat() const { return 1; }
106 : :
107 : : //! Assign number of DOFs per equation in the PDE system
108 : : //! \param[in,out] numEqDof Array storing number of Dofs for each PDE
109 : : //! equation
110 : : void numEquationDofs(std::vector< std::size_t >& numEqDof) const
111 : : {
112 : : // all equation-dofs initialized to ndofs
113 [ + + ]: 572 : for (std::size_t i=0; i<m_ncomp; ++i) {
114 : 484 : numEqDof.push_back(g_inputdeck.get< tag::ndof >());
115 : : }
116 : : }
117 : :
118 : : //! Determine elements that lie inside the user-defined IC box
119 : : //! \param[in] geoElem Element geometry array
120 : : //! \param[in] nielem Number of internal elements
121 : : //! \param[in,out] inbox List of nodes at which box user ICs are set for
122 : : //! each IC box
123 : : void IcBoxElems( const tk::Fields& geoElem,
124 : : std::size_t nielem,
125 : : std::vector< std::unordered_set< std::size_t > >& inbox ) const
126 : : {
127 : 88 : tk::BoxElems< eq >(geoElem, nielem, inbox);
128 : : }
129 : :
130 : : //! Find how many 'stiff equations' in this PDE system
131 : : //! \return number of stiff equations. Zero for now, but will need to change
132 : : //! as chemical non-equilibrium is added
133 : : std::size_t nstiffeq() const
134 : : {
135 : : return 0;
136 : : }
137 : :
138 : : //! Find how many 'non-stiff equations' in this PDE system
139 : : //! \return number of non-stiff equations
140 : : std::size_t nnonstiffeq() const
141 : : {
142 : : return m_ncomp-nstiffeq();
143 : : }
144 : :
145 : : //! Locate the stiff equations.
146 : : //! \param[out] stiffEqIdx list with pointers to stiff equations. Empty
147 : : //! for now but will have to index to chemical non-equilibrium when added
148 : : void setStiffEqIdx( std::vector< std::size_t >& stiffEqIdx ) const
149 : : {
150 : 0 : stiffEqIdx.resize(0);
151 : : }
152 : :
153 : : //! Locate the nonstiff equations.
154 : : //! \param[out] nonStiffEqIdx list with pointers to nonstiff equations
155 : : void setNonStiffEqIdx( std::vector< std::size_t >& nonStiffEqIdx ) const
156 : : {
157 : 0 : nonStiffEqIdx.resize(0);
158 : : }
159 : :
160 : : //! Initialize the compressible flow equations, prepare for time integration
161 : : //! \param[in] L Block diagonal mass matrix
162 : : //! \param[in] inpoel Element-node connectivity
163 : : //! \param[in] coord Array of nodal coordinates
164 : : //! \param[in] inbox List of elements at which box user ICs are set for
165 : : //! each IC box
166 : : //! \param[in] elemblkid Element ids associated with mesh block ids where
167 : : //! user ICs are set
168 : : //! \param[in,out] unk Array of unknowns
169 : : //! \param[in] t Physical time
170 : : //! \param[in] nielem Number of internal elements
171 [ + - ]: 88 : void initialize( const tk::Fields& L,
172 : : const std::vector< std::size_t >& inpoel,
173 : : const tk::UnsMesh::Coords& coord,
174 : : const std::vector< std::unordered_set< std::size_t > >& inbox,
175 : : const std::unordered_map< std::size_t, std::set< std::size_t > >&
176 : : elemblkid,
177 : : tk::Fields& unk,
178 : : tk::real t,
179 : : const std::size_t nielem ) const
180 : : {
181 [ + - ]: 88 : tk::initialize( m_ncomp, m_mat_blk, L, inpoel, coord,
182 : : Problem::initialize, unk, t, nielem );
183 : :
184 : 88 : const auto rdof = g_inputdeck.get< tag::rdof >();
185 : : const auto& ic = g_inputdeck.get< tag::ic >();
186 : : const auto& icbox = ic.get< tag::box >();
187 : : const auto& icmbk = ic.get< tag::meshblock >();
188 : :
189 : : // Set initial conditions inside user-defined IC boxes and mesh blocks
190 : 88 : std::vector< tk::real > s(m_ncomp, 0.0);
191 [ + + ]: 9184 : for (std::size_t e=0; e<nielem; ++e) {
192 : : // inside user-defined box
193 [ + - ]: 9096 : if (!icbox.empty()) {
194 : : std::size_t bcnt = 0;
195 [ + + ]: 18192 : for (const auto& b : icbox) { // for all boxes
196 [ + - ][ + + ]: 18192 : if (inbox.size() > bcnt && inbox[bcnt].find(e) != inbox[bcnt].end())
197 : : {
198 [ + - ][ - - ]: 4548 : std::vector< tk::real > box
199 : : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
200 : : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
201 : : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
202 : 4548 : auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
203 [ + + ]: 29562 : for (std::size_t c=0; c<m_ncomp; ++c) {
204 : 25014 : auto mark = c*rdof;
205 : 25014 : s[c] = unk(e,mark);
206 : : // set high-order DOFs to zero
207 [ + + ]: 100056 : for (std::size_t i=1; i<rdof; ++i)
208 : 75042 : unk(e,mark+i) = 0.0;
209 : : }
210 [ + - ]: 4548 : initializeBox<ctr::boxList>( m_mat_blk, V_ex, t, b, s );
211 : : // store box-initialization in solution vector
212 [ + + ]: 29562 : for (std::size_t c=0; c<m_ncomp; ++c) {
213 : 25014 : auto mark = c*rdof;
214 : 25014 : unk(e,mark) = s[c];
215 : : }
216 : : }
217 : 9096 : ++bcnt;
218 : : }
219 : : }
220 : :
221 : : // inside user-specified mesh blocks
222 [ - + ]: 9096 : if (!icmbk.empty()) {
223 [ - - ]: 0 : for (const auto& b : icmbk) { // for all blocks
224 : 0 : auto blid = b.get< tag::blockid >();
225 : 0 : auto V_ex = b.get< tag::volume >();
226 [ - - ]: 0 : if (elemblkid.find(blid) != elemblkid.end()) {
227 : : const auto& elset = tk::cref_find(elemblkid, blid);
228 [ - - ]: 0 : if (elset.find(e) != elset.end()) {
229 [ - - ]: 0 : initializeBox<ctr::meshblockList>( m_mat_blk, V_ex, t, b, s );
230 : : // store initialization in solution vector
231 [ - - ]: 0 : for (std::size_t c=0; c<m_ncomp; ++c) {
232 : 0 : auto mark = c*rdof;
233 : 0 : unk(e,mark) = s[c];
234 : : }
235 : : }
236 : : }
237 : : }
238 : : }
239 : : }
240 : 88 : }
241 : :
242 : : //! Compute density constraint for a given material. No-op
243 : : // //! \param[in] nelem Number of elements
244 : : // //! \param[in] unk Array of unknowns
245 : : //! \param[out] densityConstr Density Constraint: rho/(rho0*det(g))
246 : : void computeDensityConstr( std::size_t /*nelem*/,
247 : : tk::Fields& /*unk*/,
248 : : std::vector< tk::real >& densityConstr) const
249 : : {
250 : 176 : densityConstr.resize(0);
251 : : }
252 : :
253 : : //! Compute the left hand side block-diagonal mass matrix
254 : : //! \param[in] geoElem Element geometry array
255 : : //! \param[in,out] l Block diagonal mass matrix
256 : : void lhs( const tk::Fields& geoElem, tk::Fields& l ) const {
257 : 88 : const auto ndof = g_inputdeck.get< tag::ndof >();
258 : 88 : tk::mass( m_ncomp, ndof, geoElem, l );
259 : : }
260 : :
261 : : //! Update the interface cells to first order dofs. No-op.
262 : : // //! \param[in] unk Array of unknowns
263 : : // //! \param[in] nielem Number of internal elements
264 : : // //! \param[in,out] ndofel Array of dofs
265 : : // //! \param[in,out] interface Vector of interface marker
266 : : void updateInterfaceCells( tk::Fields& /*unk*/,
267 : : std::size_t /*nielem*/,
268 : : std::vector< std::size_t >& /*ndofel*/,
269 : : std::vector< std::size_t >& /*interface*/ ) const {}
270 : :
271 : : //! Update the primitives for this PDE system. No-op.
272 : : // //! \param[in] unk Array of unknowns
273 : : // //! \param[in] L The left hand side block-diagonal mass matrix
274 : : // //! \param[in] geoElem Element geometry array
275 : : // //! \param[in,out] prim Array of primitives
276 : : // //! \param[in] nielem Number of internal elements
277 : : // //! \param[in] ndofel Array of dofs
278 : : void updatePrimitives( const tk::Fields& /*unk*/,
279 : : const tk::Fields& /*L*/,
280 : : const tk::Fields& /*geoElem*/,
281 : : tk::Fields& /*prim*/,
282 : : std::size_t /*nielem*/,
283 : : std::vector< std::size_t >& /*ndofel*/ ) const {}
284 : :
285 : : //! Clean up the state of trace materials for this PDE system. No-op.
286 : : // //! \param[in] t Physical time
287 : : // //! \param[in] geoElem Element geometry array
288 : : // //! \param[in,out] unk Array of unknowns
289 : : // //! \param[in,out] prim Array of primitives
290 : : // //! \param[in] nielem Number of internal elements
291 : : void cleanTraceMaterial( tk::real /*t*/,
292 : : const tk::Fields& /*geoElem*/,
293 : : tk::Fields& /*unk*/,
294 : : tk::Fields& /*prim*/,
295 : : std::size_t /*nielem*/ ) const {}
296 : :
297 : : //! Reconstruct second-order solution from first-order
298 : : //! \param[in] geoElem Element geometry array
299 : : //! \param[in] fd Face connectivity and boundary conditions object
300 : : //! \param[in] esup Elements-surrounding-nodes connectivity
301 : : //! \param[in] inpoel Element-node connectivity
302 : : //! \param[in] coord Array of nodal coordinates
303 : : //! \param[in,out] U Solution vector at recent time step
304 : : // //! \param[in,out] P Vector of primitives at recent time step
305 : : //! \param[in] pref Indicator for p-adaptive algorithm
306 : : //! \param[in] ndofel Vector of local number of degrees of freedome
307 : 6600 : void reconstruct( tk::real,
308 : : const tk::Fields&,
309 : : const tk::Fields& geoElem,
310 : : const inciter::FaceData& fd,
311 : : const std::map< std::size_t, std::vector< std::size_t > >&
312 : : esup,
313 : : const std::vector< std::size_t >& inpoel,
314 : : const tk::UnsMesh::Coords& coord,
315 : : tk::Fields& U,
316 : : tk::Fields& /*P*/,
317 : : const bool pref,
318 : : const std::vector< std::size_t >& ndofel ) const
319 : : {
320 : 6600 : const auto rdof = g_inputdeck.get< tag::rdof >();
321 : 6600 : const auto ndof = g_inputdeck.get< tag::ndof >();
322 : :
323 : : bool is_p0p1(false);
324 [ + - ]: 6600 : if (rdof == 4 && ndof == 1)
325 : : is_p0p1 = true;
326 : :
327 : 6600 : const auto nelem = fd.Esuel().size()/4;
328 : :
329 : : Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
330 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
331 : :
332 : : //----- reconstruction of conserved quantities -----
333 : : //--------------------------------------------------
334 : :
335 [ + + ]: 688800 : for (std::size_t e=0; e<nelem; ++e)
336 : : {
337 : : std::vector< std::size_t > vars;
338 : : // check if element is marked as p0p1
339 [ - + ][ - - ]: 682200 : if ( (pref && ndofel[e] == 1) || is_p0p1 ) {
[ + - ]
340 : : // 1. specify how many variables need to be reconstructed
341 [ + + ][ + - ]: 4434300 : for (std::size_t c=0; c<m_ncomp; ++c) vars.push_back(c);
342 : :
343 : : // 2. solve 3x3 least-squares system
344 : : // Reconstruct second-order dofs in Taylor space using nodal-stencils
345 [ + - ]: 682200 : tk::recoLeastSqExtStencil( rdof, e, esup, inpoel, geoElem, U, vars );
346 : :
347 : : // 3. transform reconstructed derivatives to Dubiner dofs
348 [ + - ]: 682200 : tk::transform_P0P1( rdof, e, inpoel, coord, U, vars );
349 : : }
350 : : }
351 : 6600 : }
352 : :
353 : : //! Limit second-order solution, and primitive quantities separately
354 : : // //! \param[in] pref Indicator for p-adaptive algorithm
355 : : //! \param[in] geoFace Face geometry array
356 : : //! \param[in] geoElem Element geometry array
357 : : //! \param[in] fd Face connectivity and boundary conditions object
358 : : //! \param[in] esup Elements-surrounding-nodes connectivity
359 : : //! \param[in] inpoel Element-node connectivity
360 : : //! \param[in] coord Array of nodal coordinates
361 : : //! \param[in] ndofel Vector of local number of degrees of freedome
362 : : // //! \param[in] gid Local->global node id map
363 : : // //! \param[in] bid Local chare-boundary node ids (value) associated to
364 : : // //! global node ids (key)
365 : : // //! \param[in] uNodalExtrm Chare-boundary nodal extrema for conservative
366 : : // //! variables
367 : : // //! \param[in] pNodalExtrm Chare-boundary nodal extrema for primitive
368 : : // //! variables
369 : : // //! \param[in] mtInv Inverse of Taylor mass matrix
370 : : //! \param[in,out] U Solution vector at recent time step
371 : : // //! \param[in,out] P Vector of primitives at recent time step
372 : : //! \param[in,out] shockmarker Vector of shock-marker values
373 : 6600 : void limit( [[maybe_unused]] tk::real,
374 : : const bool /*pref*/,
375 : : const tk::Fields& geoFace,
376 : : const tk::Fields& geoElem,
377 : : const inciter::FaceData& fd,
378 : : const std::map< std::size_t, std::vector< std::size_t > >& esup,
379 : : const std::vector< std::size_t >& inpoel,
380 : : const tk::UnsMesh::Coords& coord,
381 : : const std::vector< std::size_t >& ndofel,
382 : : const std::vector< std::size_t >& /*gid*/,
383 : : const std::unordered_map< std::size_t, std::size_t >& /*bid*/,
384 : : const std::vector< std::vector<tk::real> >& /*uNodalExtrm*/,
385 : : const std::vector< std::vector<tk::real> >& /*pNodalExtrm*/,
386 : : const std::vector< std::vector<tk::real> >& /*mtInv*/,
387 : : tk::Fields& U,
388 : : tk::Fields& /*P*/,
389 : : std::vector< std::size_t >& shockmarker ) const
390 : : {
391 : 6600 : const auto limiter = g_inputdeck.get< tag::limiter >();
392 : 6600 : auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
393 : 6600 : const auto rdof = g_inputdeck.get< tag::rdof >();
394 : :
395 : : // limit vectors of conserved and primitive quantities
396 [ + - ]: 6600 : if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 4)
397 : : {
398 : 6600 : VertexBasedMultiSpecies_P1( esup, inpoel, ndofel, fd.Esuel().size()/4,
399 [ + - ]: 6600 : m_mat_blk, fd, geoFace, geoElem, coord, flux, U, nspec, shockmarker );
400 : : }
401 : : //else if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 10)
402 : : //{
403 : : // VertexBasedMultiSpecies_P2( pref, esup, inpoel, ndofel, fd.Esuel().size()/4,
404 : : // m_mat_blk, fd, geoFace, geoElem, coord, gid, bid,
405 : : // uNodalExtrm, pNodalExtrm, mtInv, flux, solidx, U, P, nmat,
406 : : // shockmarker );
407 : : //}
408 [ - - ]: 0 : else if (limiter != ctr::LimiterType::NOLIMITER)
409 : : {
410 [ - - ][ - - ]: 0 : Throw("Limiter type not configured for multispecies.");
[ - - ][ - - ]
[ - - ][ - - ]
411 : : }
412 : 6600 : }
413 : :
414 : : //! Apply CPL to the conservative variable solution for this PDE system
415 : : // //! \param[in] prim Array of primitive variables
416 : : // //! \param[in] geoElem Element geometry array
417 : : // //! \param[in] inpoel Element-node connectivity
418 : : // //! \param[in] coord Array of nodal coordinates
419 : : // //! \param[in,out] unk Array of conservative variables
420 : : // //! \param[in] nielem Number of internal elements
421 : : //! \details This function applies CPL to obtain consistent dofs for
422 : : //! conservative quantities based on the limited primitive quantities.
423 : : //! No-op for now, but might need in the future, see appendix of paper.
424 : : //! See Pandare et al. (2023). On the Design of Stable,
425 : : //! Consistent, and Conservative High-Order Methods for Multi-Material
426 : : //! Hydrodynamics. J Comp Phys, 112313.
427 : : void CPL( const tk::Fields& /*prim*/,
428 : : const tk::Fields& /*geoElem*/,
429 : : const std::vector< std::size_t >& /*inpoel*/,
430 : : const tk::UnsMesh::Coords& /*coord*/,
431 : : tk::Fields& /*unk*/,
432 : : std::size_t /*nielem*/ ) const {}
433 : :
434 : : //! Return cell-average deformation gradient tensor. No-op.
435 : : std::array< std::vector< tk::real >, 9 > cellAvgDeformGrad(
436 : : const tk::Fields&,
437 : : std::size_t ) const
438 : : { return {}; }
439 : :
440 : : //! Reset the high order solution for p-adaptive scheme
441 : : //! \param[in] fd Face connectivity and boundary conditions object
442 : : //! \param[in,out] unk Solution vector at recent time step
443 : : //! \param[in,out] prim Primitive vector at recent time step
444 : : //! \param[in] ndofel Vector of local number of degrees of freedome
445 : : //! \details This function reset the high order coefficient for p-adaptive
446 : : //! solution polynomials. Unlike compflow class, the high order of fv
447 : : //! solution will not be reset since p0p1 is the base scheme for
448 : : //! multi-species p-adaptive DG method.
449 : 0 : void resetAdapSol( const inciter::FaceData& fd,
450 : : tk::Fields& unk,
451 : : tk::Fields& prim,
452 : : const std::vector< std::size_t >& ndofel ) const
453 : : {
454 : 0 : const auto rdof = g_inputdeck.get< tag::rdof >();
455 : 0 : const auto ncomp = unk.nprop() / rdof;
456 : 0 : const auto nprim = prim.nprop() / rdof;
457 : :
458 [ - - ]: 0 : for(std::size_t e = 0; e < fd.Esuel().size()/4; e++)
459 : : {
460 [ - - ]: 0 : if(ndofel[e] < 10)
461 : : {
462 [ - - ]: 0 : for (std::size_t c=0; c<ncomp; ++c)
463 : : {
464 : 0 : auto mark = c*rdof;
465 : 0 : unk(e, mark+4) = 0.0;
466 : 0 : unk(e, mark+5) = 0.0;
467 : 0 : unk(e, mark+6) = 0.0;
468 : 0 : unk(e, mark+7) = 0.0;
469 : 0 : unk(e, mark+8) = 0.0;
470 : 0 : unk(e, mark+9) = 0.0;
471 : : }
472 [ - - ]: 0 : for (std::size_t c=0; c<nprim; ++c)
473 : : {
474 : 0 : auto mark = c*rdof;
475 : 0 : prim(e, mark+4) = 0.0;
476 : 0 : prim(e, mark+5) = 0.0;
477 : 0 : prim(e, mark+6) = 0.0;
478 : 0 : prim(e, mark+7) = 0.0;
479 : 0 : prim(e, mark+8) = 0.0;
480 : 0 : prim(e, mark+9) = 0.0;
481 : : }
482 : : }
483 : : }
484 : 0 : }
485 : :
486 : : //! Compute right hand side
487 : : //! \param[in] t Physical time
488 : : //! \param[in] pref Indicator for p-adaptive algorithm
489 : : //! \param[in] geoFace Face geometry array
490 : : //! \param[in] geoElem Element geometry array
491 : : //! \param[in] fd Face connectivity and boundary conditions object
492 : : //! \param[in] inpoel Element-node connectivity
493 : : //! \param[in] coord Array of nodal coordinates
494 : : //! \param[in] U Solution vector at recent time step
495 : : //! \param[in] P Primitive vector at recent time step
496 : : //! \param[in] ndofel Vector of local number of degrees of freedom
497 : : //! \param[in] dt Delta time
498 : : //! \param[in,out] R Right-hand side vector computed
499 : 6600 : void rhs( tk::real t,
500 : : const bool pref,
501 : : const tk::Fields& geoFace,
502 : : const tk::Fields& geoElem,
503 : : const inciter::FaceData& fd,
504 : : const std::vector< std::size_t >& inpoel,
505 : : const std::vector< std::unordered_set< std::size_t > >&,
506 : : const tk::UnsMesh::Coords& coord,
507 : : const tk::Fields& U,
508 : : const tk::Fields& P,
509 : : const std::vector< std::size_t >& ndofel,
510 : : const tk::real dt,
511 : : tk::Fields& R ) const
512 : : {
513 : 6600 : const auto ndof = g_inputdeck.get< tag::ndof >();
514 : 6600 : const auto rdof = g_inputdeck.get< tag::rdof >();
515 : : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
516 : :
517 : 6600 : const auto nelem = fd.Esuel().size()/4;
518 : :
519 : : Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
520 : : "vector and primitive vector at recent time step incorrect" );
521 : : Assert( U.nunk() == R.nunk(), "Number of unknowns in solution "
522 : : "vector and right-hand side at recent time step incorrect" );
523 : : Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
524 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
525 : : Assert( P.nprop() == rdof*m_nprim, "Number of components in primitive "
526 : : "vector must equal "+ std::to_string(rdof*m_nprim) );
527 : : Assert( R.nprop() == ndof*m_ncomp, "Number of components in right-hand "
528 : : "side vector must equal "+ std::to_string(ndof*m_ncomp) );
529 : : Assert( fd.Inpofa().size()/3 == fd.Esuf().size()/2,
530 : : "Mismatch in inpofa size" );
531 : :
532 : : // set rhs to zero
533 : : R.fill(0.0);
534 : :
535 : : // empty vector for non-conservative terms. This vector is unused for
536 : : // multi-species flow since, there are no non-conservative terms
537 : : // in the system of PDEs.
538 : 6600 : std::vector< std::vector< tk::real > > riemannDeriv;
539 : :
540 : 6600 : std::vector< std::vector< tk::real > > vriem;
541 : 6600 : std::vector< std::vector< tk::real > > riemannLoc;
542 : :
543 : : // configure a no-op lambda for prescribed velocity
544 : : auto velfn = []( ncomp_t, tk::real, tk::real, tk::real, tk::real ){
545 : : return tk::VelFn::result_type(); };
546 : :
547 : : // compute internal surface flux integrals
548 [ + - ]: 6600 : tk::surfInt( pref, 1, m_mat_blk, t, ndof, rdof, inpoel, solidx,
549 [ + - ]: 6600 : coord, fd, geoFace, geoElem, m_riemann, velfn, U, P, ndofel,
550 : : dt, R, riemannDeriv );
551 : :
552 : : // compute optional source term
553 [ + - ]: 6600 : tk::srcInt( m_mat_blk, t, ndof, fd.Esuel().size()/4, inpoel,
554 : : coord, geoElem, Problem::src, ndofel, R );
555 : :
556 [ - + ]: 6600 : if(ndof > 1)
557 : : // compute volume integrals
558 [ - - ][ - - ]: 0 : tk::volInt( 1, t, m_mat_blk, ndof, rdof, nelem, inpoel, coord, geoElem,
[ - - ]
559 : : flux, velfn, U, P, ndofel, R );
560 : :
561 : : // compute boundary surface flux integrals
562 [ + + ]: 46200 : for (const auto& b : m_bc)
563 [ + - ]: 79200 : tk::bndSurfInt( pref, 1, m_mat_blk, ndof, rdof, std::get<0>(b), fd,
564 : : geoFace, geoElem, inpoel, coord, t, m_riemann, velfn,
565 : : std::get<1>(b), U, P, ndofel, R, riemannDeriv );
566 : :
567 : : // compute external (energy) sources
568 : : //m_physics.physSrc(nspec, t, geoElem, {}, R, {});
569 : 6600 : }
570 : :
571 : : //! Evaluate the adaptive indicator and mark the ndof for each element
572 : : //! \param[in] nunk Number of unknowns
573 : : //! \param[in] coord Array of nodal coordinates
574 : : //! \param[in] inpoel Element-node connectivity
575 : : //! \param[in] fd Face connectivity and boundary conditions object
576 : : //! \param[in] unk Array of unknowns
577 : : // //! \param[in] prim Array of primitive quantities
578 : : //! \param[in] indicator p-refinement indicator type
579 : : //! \param[in] ndof Number of degrees of freedom in the solution
580 : : //! \param[in] ndofmax Max number of degrees of freedom for p-refinement
581 : : //! \param[in] tolref Tolerance for p-refinement
582 : : //! \param[in,out] ndofel Vector of local number of degrees of freedome
583 [ - - ]: 0 : void eval_ndof( std::size_t nunk,
584 : : [[maybe_unused]] const tk::UnsMesh::Coords& coord,
585 : : [[maybe_unused]] const std::vector< std::size_t >& inpoel,
586 : : const inciter::FaceData& fd,
587 : : const tk::Fields& unk,
588 : : const tk::Fields& /*prim*/,
589 : : inciter::ctr::PrefIndicatorType indicator,
590 : : std::size_t ndof,
591 : : std::size_t ndofmax,
592 : : tk::real tolref,
593 : : std::vector< std::size_t >& ndofel ) const
594 : : {
595 : : const auto& esuel = fd.Esuel();
596 : :
597 [ - - ]: 0 : if(indicator == inciter::ctr::PrefIndicatorType::SPECTRAL_DECAY)
598 : 0 : spectral_decay(1, nunk, esuel, unk, ndof, ndofmax, tolref, ndofel);
599 : : else
600 [ - - ][ - - ]: 0 : Throw( "No such adaptive indicator type" );
[ - - ][ - - ]
[ - - ][ - - ]
601 : 0 : }
602 : :
603 : : //! Compute the minimum time step size
604 : : //! \param[in] fd Face connectivity and boundary conditions object
605 : : //! \param[in] geoFace Face geometry array
606 : : //! \param[in] geoElem Element geometry array
607 : : // //! \param[in] ndofel Vector of local number of degrees of freedom
608 : : //! \param[in] U Solution vector at recent time step
609 : : //! \param[in] P Vector of primitive quantities at recent time step
610 : : //! \param[in] nielem Number of internal elements
611 : : //! \return Minimum time step size
612 : : //! \details The allowable dt is calculated by looking at the maximum
613 : : //! wave-speed in elements surrounding each face, times the area of that
614 : : //! face. Once the maximum of this quantity over the mesh is determined,
615 : : //! the volume of each cell is divided by this quantity. A minimum of this
616 : : //! ratio is found over the entire mesh, which gives the allowable dt.
617 : : tk::real dt( const std::array< std::vector< tk::real >, 3 >&,
618 : : const std::vector< std::size_t >&,
619 : : const inciter::FaceData& fd,
620 : : const tk::Fields& geoFace,
621 : : const tk::Fields& geoElem,
622 : : const std::vector< std::size_t >& /*ndofel*/,
623 : : const tk::Fields& U,
624 : : const tk::Fields& P,
625 : : const std::size_t nielem ) const
626 : : {
627 : : const auto ndof = g_inputdeck.get< tag::ndof >();
628 : : auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
629 : :
630 : : auto mindt = timeStepSizeMultiSpecies( m_mat_blk, fd.Esuf(), geoFace,
631 : : geoElem, nielem, nspec, U, P);
632 : :
633 : : //if (viscous)
634 : : // mindt = std::min(mindt, timeStepSizeViscousFV(geoElem, nielem, nspec, U));
635 : : //mindt = std::min(mindt, m_physics.dtRestriction(geoElem, nielem, {}));
636 : :
637 : : tk::real dgp = 0.0;
638 : : if (ndof == 4)
639 : : {
640 : : dgp = 1.0;
641 : : }
642 : : else if (ndof == 10)
643 : : {
644 : : dgp = 2.0;
645 : : }
646 : :
647 : : // Scale smallest dt with CFL coefficient and the CFL is scaled by (2*p+1)
648 : : // where p is the order of the DG polynomial by linear stability theory.
649 : : mindt /= (2.0*dgp + 1.0);
650 : : return mindt;
651 : : }
652 : :
653 : : //! Compute stiff terms for a single element. No-op until chem sources added
654 : : // //! \param[in] e Element number
655 : : // //! \param[in] geoElem Element geometry array
656 : : // //! \param[in] inpoel Element-node connectivity
657 : : // //! \param[in] coord Array of nodal coordinates
658 : : // //! \param[in] U Solution vector at recent time step
659 : : // //! \param[in] P Primitive vector at recent time step
660 : : // //! \param[in] ndofel Vector of local number of degrees of freedom
661 : : // //! \param[in,out] R Right-hand side vector computed
662 : : void stiff_rhs( std::size_t /*e*/,
663 : : const tk::Fields& /*geoElem*/,
664 : : const std::vector< std::size_t >& /*inpoel*/,
665 : : const tk::UnsMesh::Coords& /*coord*/,
666 : : const tk::Fields& /*U*/,
667 : : const tk::Fields& /*P*/,
668 : : const std::vector< std::size_t >& /*ndofel*/,
669 : : tk::Fields& /*R*/ ) const {}
670 : :
671 : : //! Extract the velocity field at cell nodes. Currently unused.
672 : : // //! \param[in] U Solution vector at recent time step
673 : : // //! \param[in] N Element node indices
674 : : //! \return Array of the four values of the velocity field
675 : : std::array< std::array< tk::real, 4 >, 3 >
676 : : velocity( const tk::Fields& /*U*/,
677 : : const std::array< std::vector< tk::real >, 3 >&,
678 : : const std::array< std::size_t, 4 >& /*N*/ ) const
679 : : {
680 : : std::array< std::array< tk::real, 4 >, 3 > v;
681 : : return v;
682 : : }
683 : :
684 : : //! Return a map that associates user-specified strings to functions
685 : : //! \return Map that associates user-specified strings to functions that
686 : : //! compute relevant quantities to be output to file
687 : : std::map< std::string, tk::GetVarFn > OutVarFn() const
688 : 352 : { return MultiSpeciesOutVarFn(); }
689 : :
690 : : //! Return analytic field names to be output to file
691 : : //! \return Vector of strings labelling analytic fields output in file
692 : : std::vector< std::string > analyticFieldNames() const {
693 : 0 : auto nspec = g_inputdeck.get< eq, tag::nspec >();
694 : :
695 : 0 : return MultiSpeciesFieldNames(nspec);
696 : : }
697 : :
698 : : //! Return time history field names to be output to file
699 : : //! \return Vector of strings labelling time history fields output in file
700 : : std::vector< std::string > histNames() const {
701 : 0 : return MultiSpeciesHistNames();
702 : : }
703 : :
704 : : //! Return surface field output going to file
705 : : std::vector< std::vector< tk::real > >
706 : : surfOutput( const std::map< int, std::vector< std::size_t > >&,
707 : : tk::Fields& ) const
708 : : {
709 : : std::vector< std::vector< tk::real > > s; // punt for now
710 : : return s;
711 : : }
712 : :
713 : : //! Return time history field output evaluated at time history points
714 : : //! \param[in] h History point data
715 : : //! \param[in] inpoel Element-node connectivity
716 : : //! \param[in] coord Array of nodal coordinates
717 : : //! \param[in] U Array of unknowns
718 : : // //! \param[in] P Array of primitive quantities
719 : : //! \return Vector of time history output of bulk flow quantities (density,
720 : : //! velocity, total energy, and pressure) evaluated at time history points
721 : : std::vector< std::vector< tk::real > >
722 : 0 : histOutput( const std::vector< HistData >& h,
723 : : const std::vector< std::size_t >& inpoel,
724 : : const tk::UnsMesh::Coords& coord,
725 : : const tk::Fields& U,
726 : : const tk::Fields& /*P*/ ) const
727 : : {
728 : 0 : const auto rdof = g_inputdeck.get< tag::rdof >();
729 : 0 : auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
730 : :
731 : : const auto& x = coord[0];
732 : : const auto& y = coord[1];
733 : : const auto& z = coord[2];
734 : :
735 : 0 : std::vector< std::vector< tk::real > > Up(h.size());
736 : :
737 : : std::size_t j = 0;
738 [ - - ]: 0 : for (const auto& p : h) {
739 : 0 : auto e = p.get< tag::elem >();
740 : 0 : auto chp = p.get< tag::coord >();
741 : :
742 : : // Evaluate inverse Jacobian
743 : 0 : std::array< std::array< tk::real, 3>, 4 > cp{{
744 : : {{ x[inpoel[4*e ]], y[inpoel[4*e ]], z[inpoel[4*e ]] }},
745 : : {{ x[inpoel[4*e+1]], y[inpoel[4*e+1]], z[inpoel[4*e+1]] }},
746 : : {{ x[inpoel[4*e+2]], y[inpoel[4*e+2]], z[inpoel[4*e+2]] }},
747 : : {{ x[inpoel[4*e+3]], y[inpoel[4*e+3]], z[inpoel[4*e+3]] }} }};
748 : 0 : auto J = tk::inverseJacobian( cp[0], cp[1], cp[2], cp[3] );
749 : :
750 : : // evaluate solution at history-point
751 : 0 : std::array< tk::real, 3 > dc{{chp[0]-cp[0][0], chp[1]-cp[0][1],
752 [ - - ]: 0 : chp[2]-cp[0][2]}};
753 [ - - ]: 0 : auto B = tk::eval_basis(rdof, tk::dot(J[0],dc), tk::dot(J[1],dc),
754 : : tk::dot(J[2],dc));
755 [ - - ]: 0 : auto uhp = eval_state(m_ncomp, rdof, rdof, e, U, B);
756 : :
757 : : // store solution in history output vector
758 [ - - ][ - - ]: 0 : Up[j].resize(6+nspec, 0.0);
759 [ - - ]: 0 : for (std::size_t k=0; k<nspec; ++k) {
760 : 0 : Up[j][0] += uhp[multispecies::densityIdx(nspec,k)];
761 : : }
762 [ - - ]: 0 : Up[j][1] = uhp[multispecies::momentumIdx(nspec,0)]/Up[j][0];
763 : 0 : Up[j][2] = uhp[multispecies::momentumIdx(nspec,1)]/Up[j][0];
764 [ - - ]: 0 : Up[j][3] = uhp[multispecies::momentumIdx(nspec,2)]/Up[j][0];
765 : 0 : Up[j][4] = uhp[multispecies::energyIdx(nspec,0)];
766 [ - - ]: 0 : Up[j][5] = m_mat_blk[0].compute< EOS::pressure >( Up[j][0], Up[j][1],
767 : : Up[j][2], Up[j][3], Up[j][4]);
768 [ - - ]: 0 : for (std::size_t k=0; k<nspec; ++k) {
769 : 0 : Up[j][6+k] = uhp[multispecies::densityIdx(nspec,k)]/Up[j][0];
770 : : }
771 [ - - ]: 0 : ++j;
772 : : }
773 : :
774 : 0 : return Up;
775 : : }
776 : :
777 : : //! Return names of integral variables to be output to diagnostics file
778 : : //! \return Vector of strings labelling integral variables output
779 : : std::vector< std::string > names() const
780 : : {
781 : 6 : auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
782 : 6 : return MultiSpeciesDiagNames(nspec);
783 : : }
784 : :
785 : : //! Return analytic solution (if defined by Problem) at xi, yi, zi, t
786 : : //! \param[in] xi X-coordinate at which to evaluate the analytic solution
787 : : //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
788 : : //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
789 : : //! \param[in] t Physical time at which to evaluate the analytic solution
790 : : //! \return Vector of analytic solution at given location and time
791 : : std::vector< tk::real >
792 : : analyticSolution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
793 : 0 : { return Problem::analyticSolution( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
794 : :
795 : : //! Return analytic solution for conserved variables
796 : : //! \param[in] xi X-coordinate at which to evaluate the analytic solution
797 : : //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
798 : : //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
799 : : //! \param[in] t Physical time at which to evaluate the analytic solution
800 : : //! \return Vector of analytic solution at given location and time
801 : : std::vector< tk::real >
802 : : solution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
803 : 227400 : { return Problem::initialize( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
804 : :
805 : : //! Return cell-averaged specific total energy for an element
806 : : //! \param[in] e Element id for which total energy is required
807 : : //! \param[in] unk Vector of conserved quantities
808 : : //! \return Cell-averaged specific total energy for given element
809 : : tk::real sp_totalenergy(std::size_t e, const tk::Fields& unk) const
810 : : {
811 : 227400 : const auto rdof = g_inputdeck.get< tag::rdof >();
812 : 227400 : auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
813 : :
814 : 227400 : return unk(e, multispecies::energyDofIdx(nspec,0,rdof,0));
815 : : }
816 : :
817 : : private:
818 : : //! Physics policy
819 : : const Physics m_physics;
820 : : //! Number of components in this PDE system
821 : : const ncomp_t m_ncomp;
822 : : //! Number of primitive quantities stored in this PDE system
823 : : const ncomp_t m_nprim;
824 : : //! Riemann solver
825 : : tk::RiemannFluxFn m_riemann;
826 : : //! BC configuration
827 : : BCStateFn m_bc;
828 : : //! EOS material block
829 : : std::vector< EOS > m_mat_blk;
830 : :
831 : : //! Evaluate conservative part of physical flux function for this PDE system
832 : : //! \param[in] ncomp Number of scalar components in this PDE system
833 : : //! \param[in] ugp Numerical solution at the Gauss point at which to
834 : : //! evaluate the flux
835 : : //! \return Flux vectors for all components in this PDE system
836 : : //! \note The function signature must follow tk::FluxFn
837 : : static tk::FluxFn::result_type
838 : 0 : flux( [[maybe_unused]] ncomp_t ncomp,
839 : : const std::vector< EOS >& mat_blk,
840 : : const std::vector< tk::real >& ugp,
841 : : const std::vector< std::array< tk::real, 3 > >& )
842 : : {
843 : : Assert( ugp.size() == ncomp, "Size mismatch" );
844 : :
845 : 0 : auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
846 : :
847 : 0 : std::vector< std::array< tk::real, 3 > > fl( ugp.size() );
848 : :
849 : 0 : tk::real rhob(0.0);
850 [ - - ]: 0 : for (std::size_t k=0; k<nspec; ++k)
851 : 0 : rhob += ugp[multispecies::densityIdx(nspec, k)];
852 : :
853 : 0 : std::array< tk::real, 3 > u{{
854 [ - - ]: 0 : ugp[multispecies::momentumIdx(nspec,1)] / rhob,
855 : 0 : ugp[multispecies::momentumIdx(nspec,2)] / rhob,
856 : 0 : ugp[multispecies::momentumIdx(nspec,3)] / rhob }};
857 : 0 : auto rhoE0 = ugp[multispecies::energyIdx(nspec,0)];
858 [ - - ]: 0 : auto p = mat_blk[0].compute< EOS::pressure >( rhob, u[0], u[1], u[2],
859 : : rhoE0 );
860 : :
861 : : // density flux
862 [ - - ]: 0 : for (std::size_t k=0; k<nspec; ++k) {
863 : : auto idx = multispecies::densityIdx(nspec, k);
864 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j) {
865 : 0 : fl[idx][j] = ugp[idx] * u[j];
866 : : }
867 : : }
868 : :
869 : : // momentum flux
870 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i) {
871 : : auto idx = multispecies::momentumIdx(nspec,i);
872 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j) {
873 [ - - ]: 0 : fl[idx][j] = ugp[idx] * u[j];
874 [ - - ]: 0 : if (i == j) fl[idx][j] += p;
875 : : }
876 : : }
877 : :
878 : : // energy flux
879 : : auto idx = multispecies::energyIdx(nspec,0);
880 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j) {
881 : 0 : fl[idx][j] = u[j] * (ugp[idx] + p);
882 : : }
883 : :
884 : 0 : return fl;
885 : : }
886 : :
887 : : //! \brief Boundary state function providing the left and right state of a
888 : : //! face at Dirichlet boundaries
889 : : //! \param[in] ncomp Number of scalar components in this PDE system
890 : : //! \param[in] mat_blk EOS material block
891 : : //! \param[in] ul Left (domain-internal) state
892 : : //! \param[in] x X-coordinate at which to compute the states
893 : : //! \param[in] y Y-coordinate at which to compute the states
894 : : //! \param[in] z Z-coordinate at which to compute the states
895 : : //! \param[in] t Physical time
896 : : //! \return Left and right states for all scalar components in this PDE
897 : : //! system
898 : : //! \note The function signature must follow tk::StateFn.
899 : : static tk::StateFn::result_type
900 : 2250 : dirichlet( ncomp_t ncomp,
901 : : const std::vector< EOS >& mat_blk,
902 : : const std::vector< tk::real >& ul, tk::real x, tk::real y,
903 : : tk::real z, tk::real t, const std::array< tk::real, 3 >& )
904 : : {
905 : 2250 : return {{ ul, Problem::initialize( ncomp, mat_blk, x, y, z, t ) }};
906 : : }
907 : :
908 : : // Other boundary condition types that do not depend on "Problem" should be
909 : : // added in BCFunctions.hpp
910 : : };
911 : :
912 : : } // dg::
913 : :
914 : : } // inciter::
915 : :
916 : : #endif // DGMultiSpecies_h
|