Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/PDE/CompFlow/DGCompFlow.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 discontinuous Galerkin
9 : : finite elements
10 : : \details This file implements calls to the physics operators governing
11 : : compressible single-material flow using discontinuous Galerkin
12 : : discretizations.
13 : : */
14 : : // *****************************************************************************
15 : : #ifndef DGCompFlow_h
16 : : #define DGCompFlow_h
17 : :
18 : : #include <cmath>
19 : : #include <algorithm>
20 : : #include <unordered_set>
21 : : #include <map>
22 : :
23 : : #include <brigand/algorithms/for_each.hpp>
24 : :
25 : : #include "Macro.hpp"
26 : : #include "Exception.hpp"
27 : : #include "Vector.hpp"
28 : : #include "ContainerUtil.hpp"
29 : : #include "UnsMesh.hpp"
30 : : #include "Inciter/InputDeck/InputDeck.hpp"
31 : : #include "Integrate/Basis.hpp"
32 : : #include "Integrate/Quadrature.hpp"
33 : : #include "Integrate/Initialize.hpp"
34 : : #include "Integrate/Mass.hpp"
35 : : #include "Integrate/Surface.hpp"
36 : : #include "Integrate/Boundary.hpp"
37 : : #include "Integrate/Volume.hpp"
38 : : #include "Integrate/Source.hpp"
39 : : #include "RiemannChoice.hpp"
40 : : #include "EoS/EOS.hpp"
41 : : #include "Reconstruction.hpp"
42 : : #include "Limiter.hpp"
43 : : #include "PrefIndicator.hpp"
44 : :
45 : : namespace inciter {
46 : :
47 : : extern ctr::InputDeck g_inputdeck;
48 : :
49 : : namespace dg {
50 : :
51 : : //! \brief CompFlow used polymorphically with tk::DGPDE
52 : : //! \details The template arguments specify policies and are used to configure
53 : : //! the behavior of the class. The policies are:
54 : : //! - Physics - physics configuration, see PDE/CompFlow/Physics.h
55 : : //! - Problem - problem configuration, see PDE/CompFlow/Problem.h
56 : : //! \note The default physics is Euler, set in inciter::deck::check_compflow()
57 : : template< class Physics, class Problem >
58 : : class CompFlow {
59 : :
60 : : private:
61 : : using eq = tag::compflow;
62 : :
63 : : public:
64 : : //! Constructor
65 : 178 : explicit CompFlow() :
66 : : m_physics(),
67 : : m_problem(),
68 : 178 : m_ncomp( g_inputdeck.get< tag::ncomp >() ),
69 : : m_riemann( compflowRiemannSolver(
70 : 178 : g_inputdeck.get< tag::flux >() ) )
71 : : {
72 : : // associate boundary condition configurations with state functions, the
73 : : // order in which the state functions listed matters, see ctr::bc::Keys
74 [ + - ][ + - ]: 2670 : brigand::for_each< ctr::bclist::Keys >( ConfigBC( m_bc,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + + ]
[ + + ][ - - ]
[ - - ]
75 : : // BC State functions
76 : : { dirichlet
77 : : , symmetry
78 : : , invalidBC // Outlet BC not implemented
79 : : , farfield
80 : : , extrapolate
81 : : , invalidBC // No slip wall BC not implemented
82 : : , symmetry }, // Slip equivalent to symmetry without mesh motion
83 : : // BC Gradient functions
84 : : { noOpGrad
85 : : , noOpGrad
86 : : , noOpGrad
87 : : , noOpGrad
88 : : , noOpGrad
89 : : , noOpGrad
90 : : , noOpGrad }
91 : : ) );
92 : :
93 : : // EoS initialization
94 : : const auto& matprop =
95 : 178 : g_inputdeck.get< tag::material >();
96 : : const auto& matidxmap =
97 : 178 : g_inputdeck.get< tag::matidxmap >();
98 : 178 : auto mateos = matprop[matidxmap.get< tag::eosidx >()[0]].get<tag::eos>();
99 [ + - ]: 178 : m_mat_blk.emplace_back(mateos, EqType::compflow, 0);
100 : :
101 : 178 : }
102 : :
103 : : //! Find the number of primitive quantities required for this PDE system
104 : : //! \return The number of primitive quantities required to be stored for
105 : : //! this PDE system
106 : 498 : std::size_t nprim() const
107 : : {
108 : : // compflow does not need/store any primitive quantities currently
109 : 498 : return 0;
110 : : }
111 : :
112 : : //! Find the number of materials set up for this PDE system
113 : : //! \return The number of materials set up for this PDE system
114 : 0 : std::size_t nmat() const
115 : : {
116 : : // compflow does not need nmat
117 : 0 : return 0;
118 : : }
119 : :
120 : : //! Assign number of DOFs per equation in the PDE system
121 : : //! \param[in,out] numEqDof Array storing number of Dofs for each PDE
122 : : //! equation
123 : 498 : void numEquationDofs(std::vector< std::size_t >& numEqDof) const
124 : : {
125 : : // all equation-dofs initialized to ndof
126 [ + + ]: 2988 : for (std::size_t i=0; i<m_ncomp; ++i) {
127 : 2490 : numEqDof.push_back(g_inputdeck.get< tag::ndof >());
128 : : }
129 : 498 : }
130 : :
131 : : //! Determine elements that lie inside the user-defined IC box
132 : : //! \param[in] geoElem Element geometry array
133 : : //! \param[in] nielem Number of internal elements
134 : : //! \param[in,out] inbox List of nodes at which box user ICs are set for
135 : : //! each IC box
136 : 498 : void IcBoxElems( const tk::Fields& geoElem,
137 : : std::size_t nielem,
138 : : std::vector< std::unordered_set< std::size_t > >& inbox ) const
139 : : {
140 : 498 : tk::BoxElems< eq >(geoElem, nielem, inbox);
141 : 498 : }
142 : :
143 : : //! Find how 'stiff equations', which we currently
144 : : //! have none for Compflow
145 : : //! \return number of stiff equations
146 : 1992 : std::size_t nstiffeq() const
147 : 1992 : { return 0; }
148 : :
149 : : //! Find how 'nonstiff equations', which we currently
150 : : //! don't use for Compflow
151 : : //! \return number of non-stiff equations
152 : 996 : std::size_t nnonstiffeq() const
153 : 996 : { return 0; }
154 : :
155 : : //! Locate the stiff equations. Unused for compflow.
156 : : //! \param[out] stiffEqIdx list
157 : 0 : void setStiffEqIdx( std::vector< std::size_t >& stiffEqIdx ) const
158 : : {
159 : 0 : stiffEqIdx.resize(0);
160 : 0 : }
161 : :
162 : : //! Locate the nonstiff equations. Unused for compflow.
163 : : //! \param[out] nonStiffEqIdx list
164 : 0 : void setNonStiffEqIdx( std::vector< std::size_t >& nonStiffEqIdx ) const
165 : : {
166 : 0 : nonStiffEqIdx.resize(0);
167 : 0 : }
168 : :
169 : : //! Initalize the compressible flow equations, prepare for time integration
170 : : //! \param[in] L Block diagonal mass matrix
171 : : //! \param[in] inpoel Element-node connectivity
172 : : //! \param[in] coord Array of nodal coordinates
173 : : //! \param[in] inbox List of elements at which box user ICs are set for
174 : : //! each IC box
175 : : //! \param[in,out] unk Array of unknowns
176 : : //! \param[in] t Physical time
177 : : //! \param[in] nielem Number of internal elements
178 : : void
179 : 506 : initialize( const tk::Fields& L,
180 : : const std::vector< std::size_t >& inpoel,
181 : : const tk::UnsMesh::Coords& coord,
182 : : const std::vector< std::unordered_set< std::size_t > >& inbox,
183 : : const std::unordered_map< std::size_t,
184 : : std::set< std::size_t > >&,
185 : : tk::Fields& unk,
186 : : tk::real t,
187 : : const std::size_t nielem ) const
188 : : {
189 [ + - ][ + - ]: 506 : tk::initialize( m_ncomp, m_mat_blk, L, inpoel, coord,
190 : : Problem::initialize, unk, t, nielem );
191 : :
192 : 506 : const auto rdof = g_inputdeck.get< tag::rdof >();
193 : 506 : const auto& ic = g_inputdeck.get< tag::ic >();
194 : 506 : const auto& icbox = ic.get< tag::box >();
195 : 506 : const auto& bgpreic = ic.get< tag::pressure >();
196 [ + - ]: 506 : auto c_v = getmatprop< tag::cv >();
197 : :
198 : : // Set initial conditions inside user-defined IC box
199 [ + - ]: 1012 : std::vector< tk::real > s(m_ncomp, 0.0);
200 [ + + ]: 107352 : for (std::size_t e=0; e<nielem; ++e) {
201 [ - + ]: 106846 : if (icbox.size() > 0) {
202 : 0 : std::size_t bcnt = 0;
203 [ - - ]: 0 : for (const auto& b : icbox) { // for all boxes
204 [ - - ][ - - ]: 0 : if (inbox.size() > bcnt && inbox[bcnt].find(e) != inbox[bcnt].end())
[ - - ][ - - ]
205 : : {
206 [ - - ]: 0 : std::vector< tk::real > box
207 : 0 : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
208 : 0 : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
209 : 0 : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
210 : 0 : auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
211 [ - - ]: 0 : for (std::size_t c=0; c<m_ncomp; ++c) {
212 : 0 : auto mark = c*rdof;
213 [ - - ]: 0 : s[c] = unk(e,mark);
214 : : // set high-order DOFs to zero
215 [ - - ]: 0 : for (std::size_t i=1; i<rdof; ++i)
216 [ - - ]: 0 : unk(e,mark+i) = 0.0;
217 : : }
218 [ - - ]: 0 : initializeBox<ctr::boxList>( m_mat_blk, 1.0, V_ex,
219 : : t, b, bgpreic, c_v, s );
220 : : // store box-initialization in solution vector
221 [ - - ]: 0 : for (std::size_t c=0; c<m_ncomp; ++c) {
222 : 0 : auto mark = c*rdof;
223 [ - - ]: 0 : unk(e,mark) = s[c];
224 : : }
225 : : }
226 : 0 : ++bcnt;
227 : : }
228 : : }
229 : : }
230 : 506 : }
231 : :
232 : : //! Compute density constraint for a given material
233 : : // //! \param[in] nelem Number of elements
234 : : // //! \param[in] unk Array of unknowns
235 : : //! \param[out] densityConstr Density Constraint: rho/(rho0*det(g))
236 : 874 : void computeDensityConstr( std::size_t /*nelem*/,
237 : : tk::Fields& /*unk*/,
238 : : std::vector< tk::real >& densityConstr) const
239 : : {
240 : 874 : densityConstr.resize(0);
241 : 874 : }
242 : :
243 : : //! Compute the left hand side block-diagonal mass matrix
244 : : //! \param[in] geoElem Element geometry array
245 : : //! \param[in,out] l Block diagonal mass matrix
246 : 506 : void lhs( const tk::Fields& geoElem, tk::Fields& l ) const {
247 : 506 : const auto ndof = g_inputdeck.get< tag::ndof >();
248 : 506 : tk::mass( m_ncomp, ndof, geoElem, l );
249 : 506 : }
250 : :
251 : : //! Update the interface cells to first order dofs
252 : : //! \details This function resets the high-order terms in interface cells,
253 : : //! and is currently not used in compflow.
254 : 24480 : void updateInterfaceCells( tk::Fields&,
255 : : std::size_t,
256 : : std::vector< std::size_t >&,
257 : 24480 : std::vector< std::size_t >& ) const {}
258 : :
259 : : //! Update the primitives for this PDE system
260 : : //! \details This function computes and stores the dofs for primitive
261 : : //! quantities, which is currently unused for compflow. But if a limiter
262 : : //! requires primitive variables for example, this would be the place to
263 : : //! add the computation of the primitive variables.
264 : 24978 : void updatePrimitives( const tk::Fields&,
265 : : const tk::Fields&,
266 : : const tk::Fields&,
267 : : tk::Fields&,
268 : : std::size_t,
269 : 24978 : const std::vector< std::size_t >& ) const {}
270 : :
271 : : //! Clean up the state of trace materials for this PDE system
272 : : //! \details This function cleans up the state of materials present in trace
273 : : //! quantities in each cell. This is unused for compflow.
274 : 24480 : void cleanTraceMaterial( tk::real,
275 : : const tk::Fields&,
276 : : tk::Fields&,
277 : : tk::Fields&,
278 : 24480 : std::size_t ) const {}
279 : :
280 : : //! Reconstruct second-order solution from first-order using least-squares
281 : : // //! \param[in] t Physical time
282 : : // //! \param[in] geoFace Face geometry array
283 : : // //! \param[in] geoElem Element geometry array
284 : : // //! \param[in] fd Face connectivity and boundary conditions object
285 : : // //! \param[in] inpoel Element-node connectivity
286 : : // //! \param[in] coord Array of nodal coordinates
287 : : // //! \param[in,out] U Solution vector at recent time step
288 : : // //! \param[in,out] P Primitive vector at recent time step
289 : 14160 : void reconstruct( tk::real,
290 : : const tk::Fields&,
291 : : const tk::Fields&,
292 : : const inciter::FaceData&,
293 : : const std::map< std::size_t, std::vector< std::size_t > >&,
294 : : const std::vector< std::size_t >&,
295 : : const tk::UnsMesh::Coords&,
296 : : tk::Fields&,
297 : : tk::Fields&,
298 : : const bool,
299 : : const std::vector< std::size_t >& ) const
300 : : {
301 : : // do reconstruction only if P0P1
302 [ + + ][ - + ]: 21210 : if (g_inputdeck.get< tag::rdof >() == 4 &&
303 [ - + ]: 7050 : g_inputdeck.get< tag::ndof >() == 1)
304 [ - - ][ - - ]: 0 : Throw("P0P1 not supported for CompFlow.");
[ - - ]
305 : 14160 : }
306 : :
307 : : //! Limit second-order solution
308 : : //! \param[in] t Physical time
309 : : //! \param[in] geoFace Face geometry array
310 : : //! \param[in] geoElem Element geometry array
311 : : //! \param[in] fd Face connectivity and boundary conditions object
312 : : //! \param[in] esup Elements surrounding points
313 : : //! \param[in] inpoel Element-node connectivity
314 : : //! \param[in] coord Array of nodal coordinates
315 : : //! \param[in] ndofel Vector of local number of degrees of freedome
316 : : //! \param[in] gid Local->global node id map
317 : : //! \param[in] bid Local chare-boundary node ids (value) associated to
318 : : //! global node ids (key)
319 : : //! \param[in] uNodalExtrm Chare-boundary nodal extrema for conservative
320 : : //! variables
321 : : //! \param[in] mtInv Inverse of Taylor mass matrix
322 : : //! \param[in,out] U Solution vector at recent time step
323 : : //! \param[in,out] shockmarker Vector of shock-marker values
324 : 14160 : void limit( [[maybe_unused]] tk::real t,
325 : : [[maybe_unused]] const bool pref,
326 : : [[maybe_unused]] const tk::Fields& geoFace,
327 : : const tk::Fields& geoElem,
328 : : const inciter::FaceData& fd,
329 : : const std::map< std::size_t, std::vector< std::size_t > >& esup,
330 : : const std::vector< std::size_t >& inpoel,
331 : : const tk::UnsMesh::Coords& coord,
332 : : const std::vector< std::size_t >& ndofel,
333 : : const std::vector< std::size_t >& gid,
334 : : const std::unordered_map< std::size_t, std::size_t >& bid,
335 : : const std::vector< std::vector<tk::real> >& uNodalExtrm,
336 : : const std::vector< std::vector<tk::real> >&,
337 : : const std::vector< std::vector<tk::real> >& mtInv,
338 : : tk::Fields& U,
339 : : tk::Fields&,
340 : : std::vector< std::size_t >& shockmarker) const
341 : : {
342 : 14160 : const auto limiter = g_inputdeck.get< tag::limiter >();
343 : 14160 : const auto rdof = g_inputdeck.get< tag::rdof >();
344 : 14160 : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
345 : :
346 [ - + ]: 14160 : if (limiter == ctr::LimiterType::WENOP1)
347 : 0 : WENO_P1( fd.Esuel(), U );
348 [ + + ]: 14160 : else if (limiter == ctr::LimiterType::SUPERBEEP1)
349 : 1650 : Superbee_P1( fd.Esuel(), inpoel, ndofel, coord, U );
350 [ + + ][ - + ]: 12510 : else if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 4)
351 [ - - ]: 0 : VertexBasedCompflow_P1( esup, inpoel, ndofel, fd.Esuel().size()/4,
352 : 0 : m_mat_blk, fd, geoFace, geoElem, coord, flux, solidx, U,
353 : : shockmarker);
354 [ + + ][ + - ]: 12510 : else if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 10)
355 [ + - ]: 5160 : VertexBasedCompflow_P2( esup, inpoel, ndofel, fd.Esuel().size()/4,
356 : 2580 : m_mat_blk, fd, geoFace, geoElem, coord, gid, bid,
357 : : uNodalExtrm, mtInv, flux, solidx, U, shockmarker);
358 : 14160 : }
359 : :
360 : : //! Update the conservative variable solution for this PDE system
361 : : //! \details This function computes the updated dofs for conservative
362 : : //! quantities based on the limited solution and is currently not used in
363 : : //! compflow.
364 : 14160 : void CPL( const tk::Fields&,
365 : : const tk::Fields&,
366 : : const std::vector< std::size_t >&,
367 : : const tk::UnsMesh::Coords&,
368 : : tk::Fields&,
369 : 14160 : std::size_t ) const {}
370 : :
371 : : //! Return cell-average deformation gradient tensor (no-op for compflow)
372 : : //! \details This function is a no-op in compflow.
373 : 0 : std::array< std::vector< tk::real >, 9 > cellAvgDeformGrad(
374 : : const tk::Fields&,
375 : : std::size_t ) const
376 : : {
377 : 0 : return {};
378 : : }
379 : :
380 : : //! Reset the high order solution for p-adaptive scheme
381 : : //! \param[in] fd Face connectivity and boundary conditions object
382 : : //! \param[in,out] unk Solution vector at recent time step
383 : : //! \param[in] ndofel Vector of local number of degrees of freedome
384 : : //! \details This function reset the high order coefficient for p-adaptive
385 : : //! solution polynomials.
386 : 1770 : void resetAdapSol( const inciter::FaceData& fd,
387 : : tk::Fields& unk,
388 : : tk::Fields&,
389 : : const std::vector< std::size_t >& ndofel ) const
390 : : {
391 : 1770 : const auto rdof = g_inputdeck.get< tag::rdof >();
392 : 1770 : const auto ncomp = unk.nprop() / rdof;
393 : :
394 [ + + ]: 414490 : for(std::size_t e=0; e<fd.Esuel().size()/4; e++)
395 : : {
396 [ + + ]: 412720 : if(ndofel[e] == 1)
397 : : {
398 [ + + ]: 1671966 : for (std::size_t c=0; c<ncomp; ++c)
399 : : {
400 : 1393305 : auto mark = c*rdof;
401 : 1393305 : unk(e, mark+1) = 0.0;
402 : 1393305 : unk(e, mark+2) = 0.0;
403 : 1393305 : unk(e, mark+3) = 0.0;
404 : : }
405 [ + + ]: 134059 : } else if(ndofel[e] == 4)
406 : : {
407 [ + + ]: 274422 : for (std::size_t c=0; c<ncomp; ++c)
408 : : {
409 : 228685 : auto mark = c*rdof;
410 : 228685 : unk(e, mark+4) = 0.0;
411 : 228685 : unk(e, mark+5) = 0.0;
412 : 228685 : unk(e, mark+6) = 0.0;
413 : 228685 : unk(e, mark+7) = 0.0;
414 : 228685 : unk(e, mark+8) = 0.0;
415 : 228685 : unk(e, mark+9) = 0.0;
416 : : }
417 : : }
418 : : }
419 : 1770 : }
420 : :
421 : : //! Compute right hand side
422 : : //! \param[in] t Physical time
423 : : //! \param[in] pref Indicator for p-adaptive algorithm
424 : : //! \param[in] geoFace Face geometry array
425 : : //! \param[in] geoElem Element geometry array
426 : : //! \param[in] fd Face connectivity and boundary conditions object
427 : : //! \param[in] inpoel Element-node connectivity
428 : : //! \param[in] boxelems Mesh node ids within user-defined IC boxes
429 : : //! \param[in] coord Array of nodal coordinates
430 : : //! \param[in] U Solution vector at recent time step
431 : : //! \param[in] P Primitive vector at recent time step
432 : : //! \param[in] ndofel Vector of local number of degrees of freedom
433 : : //! \param[in] dt Delta time
434 : : //! \param[in,out] R Right-hand side vector computed
435 : 24480 : void rhs( tk::real t,
436 : : const bool pref,
437 : : const tk::Fields& geoFace,
438 : : const tk::Fields& geoElem,
439 : : const inciter::FaceData& fd,
440 : : const std::vector< std::size_t >& inpoel,
441 : : const std::vector< std::unordered_set< std::size_t > >& boxelems,
442 : : const tk::UnsMesh::Coords& coord,
443 : : const tk::Fields& U,
444 : : const tk::Fields& P,
445 : : const std::vector< std::size_t >& ndofel,
446 : : const tk::real dt,
447 : : tk::Fields& R ) const
448 : : {
449 : 24480 : const auto ndof = g_inputdeck.get< tag::ndof >();
450 : 24480 : const auto rdof = g_inputdeck.get< tag::rdof >();
451 : :
452 : 24480 : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
453 : :
454 [ - + ][ - - ]: 24480 : Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
455 : : "vector and primitive vector at recent time step incorrect" );
456 [ - + ][ - - ]: 24480 : Assert( U.nunk() == R.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
457 : : "vector and right-hand side at recent time step incorrect" );
458 [ - + ][ - - ]: 24480 : Assert( U.nprop() == rdof*5, "Number of components in solution "
[ - - ][ - - ]
[ - - ]
459 : : "vector must equal "+ std::to_string(rdof*5) );
460 [ - + ][ - - ]: 24480 : Assert( P.nprop() == 0, "Number of components in primitive "
[ - - ][ - - ]
[ - - ]
461 : : "vector must equal "+ std::to_string(0) );
462 [ - + ][ - - ]: 24480 : Assert( R.nprop() == ndof*5, "Number of components in right-hand "
[ - - ][ - - ]
[ - - ]
463 : : "side vector must equal "+ std::to_string(ndof*5) );
464 [ - + ][ - - ]: 24480 : Assert( fd.Inpofa().size()/3 == fd.Esuf().size()/2,
[ - - ][ - - ]
465 : : "Mismatch in inpofa size" );
466 : :
467 : : // set rhs to zero
468 [ + - ]: 24480 : R.fill(0.0);
469 : :
470 : : // empty vector for non-conservative terms. This vector is unused for
471 : : // single-material hydrodynamics since, there are no non-conservative
472 : : // terms in the system of PDEs.
473 : 48960 : std::vector< std::vector < tk::real > > riemannDeriv;
474 : :
475 : : // configure a no-op lambda for prescribed velocity
476 : 40955568 : auto velfn = []( ncomp_t, tk::real, tk::real, tk::real, tk::real ){
477 : 40955568 : return tk::VelFn::result_type(); };
478 : :
479 : : // compute internal surface flux integrals
480 [ + - ]: 48960 : tk::surfInt( pref, 1, m_mat_blk, t, ndof, rdof, inpoel, solidx,
481 [ + - ]: 24480 : coord, fd, geoFace, geoElem, m_riemann, velfn, U, P, ndofel,
482 : : dt, R, riemannDeriv );
483 : :
484 : : // compute optional source term
485 [ + - ][ + - ]: 24480 : tk::srcInt( m_mat_blk, t, ndof, fd.Esuel().size()/4,
486 : : inpoel, coord, geoElem, Problem::src, ndofel, R );
487 : :
488 [ + + ]: 24480 : if(ndof > 1)
489 : : // compute volume integrals
490 [ + - ][ + - ]: 28320 : tk::volInt( 1, t, m_mat_blk, ndof, rdof,
[ + - ]
491 : 14160 : fd.Esuel().size()/4, inpoel, coord, geoElem, flux, velfn,
492 : : U, P, ndofel, R );
493 : :
494 : : // compute boundary surface flux integrals
495 [ + + ]: 195840 : for (const auto& b : m_bc)
496 [ + - ][ + - ]: 342720 : tk::bndSurfInt( pref, 1, m_mat_blk, ndof, rdof, std::get<0>(b),
497 : 171360 : fd, geoFace, geoElem, inpoel, coord, t, m_riemann,
498 : 171360 : velfn, std::get<1>(b), U, P, ndofel, R, riemannDeriv );
499 : :
500 : : // compute external (energy) sources
501 : 24480 : const auto& ic = g_inputdeck.get< tag::ic >();
502 : 24480 : const auto& icbox = ic.get< tag::box >();
503 : :
504 [ - + ][ - - ]: 24480 : if (!icbox.empty() && !boxelems.empty()) {
[ - + ]
505 : 0 : std::size_t bcnt = 0;
506 [ - - ]: 0 : for (const auto& b : icbox) { // for all boxes for this eq
507 [ - - ]: 0 : std::vector< tk::real > box
508 : 0 : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
509 : 0 : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
510 : 0 : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
511 : :
512 : 0 : const auto& initiate = b.template get< tag::initiate >();
513 [ - - ]: 0 : if (initiate == ctr::InitiateType::LINEAR) {
514 [ - - ]: 0 : boxSrc( t, inpoel, boxelems[bcnt], coord, geoElem, ndofel, R );
515 : : }
516 : 0 : ++bcnt;
517 : : }
518 : : }
519 : 24480 : }
520 : :
521 : : //! Evaluate the adaptive indicator and mark the ndof for each element
522 : : //! \param[in] nunk Number of unknowns
523 : : //! \param[in] coord Array of nodal coordinates
524 : : //! \param[in] inpoel Element-node connectivity
525 : : //! \param[in] fd Face connectivity and boundary conditions object
526 : : //! \param[in] unk Array of unknowns
527 : : //! \param[in] prim Array of primitive quantities
528 : : //! \param[in] indicator p-refinement indicator type
529 : : //! \param[in] ndof Number of degrees of freedom in the solution
530 : : //! \param[in] ndofmax Max number of degrees of freedom for p-refinement
531 : : //! \param[in] tolref Tolerance for p-refinement
532 : : //! \param[in,out] ndofel Vector of local number of degrees of freedome
533 : 1636 : void eval_ndof( std::size_t nunk,
534 : : const tk::UnsMesh::Coords& coord,
535 : : const std::vector< std::size_t >& inpoel,
536 : : const inciter::FaceData& fd,
537 : : const tk::Fields& unk,
538 : : [[maybe_unused]] const tk::Fields& prim,
539 : : inciter::ctr::PrefIndicatorType indicator,
540 : : std::size_t ndof,
541 : : std::size_t ndofmax,
542 : : tk::real tolref,
543 : : std::vector< std::size_t >& ndofel ) const
544 : : {
545 : 1636 : const auto& esuel = fd.Esuel();
546 : :
547 [ + - ]: 1636 : if(indicator == inciter::ctr::PrefIndicatorType::SPECTRAL_DECAY)
548 : 1636 : spectral_decay( 1, nunk, esuel, unk, ndof, ndofmax, tolref, ndofel );
549 [ - - ]: 0 : else if(indicator == inciter::ctr::PrefIndicatorType::NON_CONFORMITY)
550 : 0 : non_conformity( nunk, fd.Nbfac(), inpoel, coord, esuel, fd.Esuf(),
551 : : fd.Inpofa(), unk, ndof, ndofmax, ndofel );
552 : : else
553 [ - - ][ - - ]: 0 : Throw( "No such adaptive indicator type" );
[ - - ]
554 : 1636 : }
555 : :
556 : : //! Compute the minimum time step size
557 : : //! \param[in] coord Mesh node coordinates
558 : : //! \param[in] inpoel Mesh element connectivity
559 : : //! \param[in] fd Face connectivity and boundary conditions object
560 : : //! \param[in] geoFace Face geometry array
561 : : //! \param[in] geoElem Element geometry array
562 : : //! \param[in] ndofel Vector of local number of degrees of freedom
563 : : //! \param[in] U Solution vector at recent time step
564 : : //! \return Minimum time step size
565 : 2070 : tk::real dt( const std::array< std::vector< tk::real >, 3 >& coord,
566 : : const std::vector< std::size_t >& inpoel,
567 : : const inciter::FaceData& fd,
568 : : const tk::Fields& geoFace,
569 : : const tk::Fields& geoElem,
570 : : const std::vector< std::size_t >& ndofel,
571 : : const tk::Fields& U,
572 : : const tk::Fields&,
573 : : const std::size_t /*nielem*/ ) const
574 : : {
575 : 2070 : const auto rdof = g_inputdeck.get< tag::rdof >();
576 : :
577 : 2070 : const auto& esuf = fd.Esuf();
578 : 2070 : const auto& inpofa = fd.Inpofa();
579 : :
580 : : tk::real rho, u, v, w, rhoE, p, a, vn, dSV_l, dSV_r;
581 [ + - ]: 2070 : std::vector< tk::real > delt( U.nunk(), 0.0 );
582 : :
583 : 2070 : const auto& cx = coord[0];
584 : 2070 : const auto& cy = coord[1];
585 : 2070 : const auto& cz = coord[2];
586 : :
587 : : // compute internal surface maximum characteristic speed
588 [ + + ]: 1487410 : for (std::size_t f=0; f<esuf.size()/2; ++f)
589 : : {
590 : :
591 : 1485340 : std::size_t el = static_cast< std::size_t >(esuf[2*f]);
592 : 1485340 : auto er = esuf[2*f+1];
593 : :
594 : : // Number of quadrature points for face integration
595 : : std::size_t ng;
596 : :
597 [ + + ]: 1485340 : if(er > -1)
598 : : {
599 : 1101260 : auto eR = static_cast< std::size_t >( er );
600 : :
601 [ + - ]: 1101260 : auto ng_l = tk::NGfa(ndofel[el]);
602 [ + - ]: 1101260 : auto ng_r = tk::NGfa(ndofel[eR]);
603 : :
604 : : // When the number of gauss points for the left and right element are
605 : : // different, choose the larger ng
606 : 1101260 : ng = std::max( ng_l, ng_r );
607 : : }
608 : : else
609 : : {
610 [ + - ]: 384080 : ng = tk::NGfa(ndofel[el]);
611 : : }
612 : :
613 : : // arrays for quadrature points
614 : 2970680 : std::array< std::vector< tk::real >, 2 > coordgp;
615 : 2970680 : std::vector< tk::real > wgp;
616 : :
617 [ + - ]: 1485340 : coordgp[0].resize( ng );
618 [ + - ]: 1485340 : coordgp[1].resize( ng );
619 [ + - ]: 1485340 : wgp.resize( ng );
620 : :
621 : : // get quadrature point weights and coordinates for triangle
622 [ + - ]: 1485340 : tk::GaussQuadratureTri( ng, coordgp, wgp );
623 : :
624 : : // Extract the left element coordinates
625 : 14853400 : std::array< std::array< tk::real, 3>, 4 > coordel_l {{
626 : : {{ cx[inpoel[4*el ]], cy[inpoel[4*el ]], cz[inpoel[4*el ]] }},
627 : 4456020 : {{ cx[inpoel[4*el+1]], cy[inpoel[4*el+1]], cz[inpoel[4*el+1]] }},
628 : 4456020 : {{ cx[inpoel[4*el+2]], cy[inpoel[4*el+2]], cz[inpoel[4*el+2]] }},
629 : 4456020 : {{ cx[inpoel[4*el+3]], cy[inpoel[4*el+3]], cz[inpoel[4*el+3]] }} }};
630 : :
631 : : // Compute the determinant of Jacobian matrix
632 : : auto detT_l =
633 : 1485340 : tk::Jacobian(coordel_l[0], coordel_l[1], coordel_l[2], coordel_l[3]);
634 : :
635 : : // Extract the face coordinates
636 : 10397380 : std::array< std::array< tk::real, 3>, 3 > coordfa {{
637 : : {{ cx[ inpofa[3*f ] ], cy[ inpofa[3*f ] ], cz[ inpofa[3*f ] ] }},
638 : 4456020 : {{ cx[ inpofa[3*f+1] ], cy[ inpofa[3*f+1] ], cz[ inpofa[3*f+1] ] }},
639 : 4456020 : {{ cx[ inpofa[3*f+2] ], cy[ inpofa[3*f+2] ], cz[ inpofa[3*f+2] ] }}
640 : : }};
641 : :
642 : 1485340 : dSV_l = 0.0;
643 : 1485340 : dSV_r = 0.0;
644 : :
645 : : // Gaussian quadrature
646 [ + + ]: 5637109 : for (std::size_t igp=0; igp<ng; ++igp)
647 : : {
648 : : // Compute the coordinates of quadrature point at physical domain
649 [ + - ]: 4151769 : auto gp = tk::eval_gp( igp, coordfa, coordgp );
650 : :
651 : : // Compute the basis function for the left element
652 [ + - ]: 8303538 : auto B_l = tk::eval_basis( ndofel[el],
653 : 4151769 : tk::Jacobian(coordel_l[0], gp, coordel_l[2], coordel_l[3])/detT_l,
654 : 4151769 : tk::Jacobian(coordel_l[0], coordel_l[1], gp, coordel_l[3])/detT_l,
655 : 4151769 : tk::Jacobian(coordel_l[0], coordel_l[1], coordel_l[2], gp)/detT_l );
656 : :
657 [ + - ]: 4151769 : auto wt = wgp[igp] * geoFace(f,0);
658 : :
659 : 4151769 : std::array< std::vector< tk::real >, 2 > ugp;
660 : :
661 : : // left element
662 [ + + ]: 24910614 : for (ncomp_t c=0; c<5; ++c)
663 : : {
664 : 20758845 : auto mark = c*rdof;
665 [ + - ][ + - ]: 20758845 : ugp[0].push_back( U(el, mark) );
666 : :
667 [ + + ]: 20758845 : if(ndofel[el] > 1) //DG(P1)
668 [ + - ]: 34634370 : ugp[0][c] += U(el, mark+1) * B_l[1]
669 [ + - ]: 17317185 : + U(el, mark+2) * B_l[2]
670 [ + - ]: 17317185 : + U(el, mark+3) * B_l[3];
671 : :
672 [ + + ]: 20758845 : if(ndofel[el] > 4) //DG(P2)
673 [ + - ]: 20976480 : ugp[0][c] += U(el, mark+4) * B_l[4]
674 [ + - ]: 10488240 : + U(el, mark+5) * B_l[5]
675 [ + - ]: 10488240 : + U(el, mark+6) * B_l[6]
676 [ + - ]: 10488240 : + U(el, mark+7) * B_l[7]
677 [ + - ]: 10488240 : + U(el, mark+8) * B_l[8]
678 [ + - ]: 10488240 : + U(el, mark+9) * B_l[9];
679 : : }
680 : :
681 : 4151769 : rho = ugp[0][0];
682 : 4151769 : u = ugp[0][1]/rho;
683 : 4151769 : v = ugp[0][2]/rho;
684 : 4151769 : w = ugp[0][3]/rho;
685 : 4151769 : rhoE = ugp[0][4];
686 [ + - ]: 4151769 : p = m_mat_blk[0].compute< EOS::pressure >( rho, u, v, w, rhoE );
687 : :
688 [ + - ]: 4151769 : a = m_mat_blk[0].compute< EOS::soundspeed >( rho, p );
689 : :
690 [ + - ][ + - ]: 4151769 : vn = u*geoFace(f,1) + v*geoFace(f,2) + w*geoFace(f,3);
[ + - ]
691 : :
692 : 4151769 : dSV_l = wt * (std::fabs(vn) + a);
693 : :
694 : : // right element
695 [ + + ]: 4151769 : if (er > -1) {
696 : :
697 : : // nodal coordinates of the right element
698 : 3082564 : std::size_t eR = static_cast< std::size_t >( er );
699 : :
700 : : // Extract the left element coordinates
701 : 30825640 : std::array< std::array< tk::real, 3>, 4 > coordel_r {{
702 : : {{ cx[inpoel[4*eR ]], cy[inpoel[4*eR ]], cz[inpoel[4*eR ]] }},
703 : 9247692 : {{ cx[inpoel[4*eR+1]], cy[inpoel[4*eR+1]], cz[inpoel[4*eR+1]] }},
704 : 9247692 : {{ cx[inpoel[4*eR+2]], cy[inpoel[4*eR+2]], cz[inpoel[4*eR+2]] }},
705 : 9247692 : {{ cx[inpoel[4*eR+3]], cy[inpoel[4*eR+3]], cz[inpoel[4*eR+3]] }}
706 : : }};
707 : :
708 : : // Compute the determinant of Jacobian matrix
709 : : auto detT_r =
710 : 3082564 : tk::Jacobian(coordel_r[0],coordel_r[1],coordel_r[2],coordel_r[3]);
711 : :
712 : : // Compute the coordinates of quadrature point at physical domain
713 [ + - ]: 3082564 : gp = tk::eval_gp( igp, coordfa, coordgp );
714 : :
715 : : // Compute the basis function for the right element
716 [ + - ]: 3082564 : auto B_r = tk::eval_basis( ndofel[eR],
717 : 3082564 : tk::Jacobian(coordel_r[0],gp,coordel_r[2],coordel_r[3])/detT_r,
718 : 3082564 : tk::Jacobian(coordel_r[0],coordel_r[1],gp,coordel_r[3])/detT_r,
719 : 3082564 : tk::Jacobian(coordel_r[0],coordel_r[1],coordel_r[2],gp)/detT_r );
720 : :
721 [ + + ]: 18495384 : for (ncomp_t c=0; c<5; ++c)
722 : : {
723 : 15412820 : auto mark = c*rdof;
724 [ + - ][ + - ]: 15412820 : ugp[1].push_back( U(eR, mark) );
725 : :
726 [ + + ]: 15412820 : if(ndofel[eR] > 1) //DG(P1)
727 [ + - ]: 25661460 : ugp[1][c] += U(eR, mark+1) * B_r[1]
728 [ + - ]: 12830730 : + U(eR, mark+2) * B_r[2]
729 [ + - ]: 12830730 : + U(eR, mark+3) * B_r[3];
730 : :
731 [ + + ]: 15412820 : if(ndofel[eR] > 4) //DG(P2)
732 [ + - ]: 15728280 : ugp[1][c] += U(eR, mark+4) * B_r[4]
733 [ + - ]: 7864140 : + U(eR, mark+5) * B_r[5]
734 [ + - ]: 7864140 : + U(eR, mark+6) * B_r[6]
735 [ + - ]: 7864140 : + U(eR, mark+7) * B_r[7]
736 [ + - ]: 7864140 : + U(eR, mark+8) * B_r[8]
737 [ + - ]: 7864140 : + U(eR, mark+9) * B_r[9];
738 : : }
739 : :
740 : 3082564 : rho = ugp[1][0];
741 : 3082564 : u = ugp[1][1]/rho;
742 : 3082564 : v = ugp[1][2]/rho;
743 : 3082564 : w = ugp[1][3]/rho;
744 : 3082564 : rhoE = ugp[1][4];
745 [ + - ]: 3082564 : p = m_mat_blk[0].compute< EOS::pressure >( rho, u, v, w, rhoE );
746 [ + - ]: 3082564 : a = m_mat_blk[0].compute< EOS::soundspeed >( rho, p );
747 : :
748 [ + - ][ + - ]: 3082564 : vn = u*geoFace(f,1) + v*geoFace(f,2) + w*geoFace(f,3);
[ + - ]
749 : :
750 : 3082564 : dSV_r = wt * (std::fabs(vn) + a);
751 : 3082564 : delt[eR] += std::max( dSV_l, dSV_r );
752 : : }
753 : :
754 : 4151769 : delt[el] += std::max( dSV_l, dSV_r );
755 : : }
756 : : }
757 : :
758 : 2070 : tk::real mindt = std::numeric_limits< tk::real >::max();
759 : 2070 : tk::real dgp = 0.0;
760 : :
761 : : // compute allowable dt
762 [ + + ]: 618910 : for (std::size_t e=0; e<fd.Esuel().size()/4; ++e)
763 : : {
764 : 616840 : dgp = 0.0;
765 [ + + ]: 616840 : if (ndofel[e] == 4)
766 : : {
767 : 191457 : dgp = 1.0;
768 : : }
769 [ + + ]: 425383 : else if (ndofel[e] == 10)
770 : : {
771 : 146722 : dgp = 2.0;
772 : : }
773 : :
774 : : // Scale smallest dt with CFL coefficient and the CFL is scaled by (2*p+1)
775 : : // where p is the order of the DG polynomial by linear stability theory.
776 [ + - ]: 616840 : mindt = std::min( mindt, geoElem(e,0)/ (delt[e] * (2.0*dgp + 1.0)) );
777 : : }
778 : :
779 : 4140 : return mindt;
780 : : }
781 : :
782 : : //! Balances elastic energy after plastic update. Not implemented here.
783 : : // //! \param[in] e Element number
784 : : // //! \param[in] x_star Stiff variables before implicit update
785 : : // //! \param[in] x Stiff variables after implicit update
786 : : // //! \param[in] U Field of conserved variables
787 : 0 : void balance_plastic_energy( std::size_t /*e*/,
788 : : std::vector< tk::real > /*x_star*/,
789 : : std::vector< tk::real > /*x*/,
790 : 0 : tk::Fields& /*U*/ ) const {}
791 : :
792 : : //! Compute stiff terms for a single element, not implemented here
793 : : // //! \param[in] e Element number
794 : : // //! \param[in] geoElem Element geometry array
795 : : // //! \param[in] inpoel Element-node connectivity
796 : : // //! \param[in] coord Array of nodal coordinates
797 : : // //! \param[in] U Solution vector at recent time step
798 : : // //! \param[in] P Primitive vector at recent time step
799 : : // //! \param[in] ndofel Vector of local number of degrees of freedom
800 : : // //! \param[in,out] R Right-hand side vector computed
801 : 0 : void stiff_rhs( std::size_t /*e*/,
802 : : const tk::Fields& /*geoElem*/,
803 : : const std::vector< std::size_t >& /*inpoel*/,
804 : : const tk::UnsMesh::Coords& /*coord*/,
805 : : const tk::Fields& /*U*/,
806 : : const tk::Fields& /*P*/,
807 : : const std::vector< std::size_t >& /*ndofel*/,
808 : : tk::Fields& /*R*/ ) const
809 : 0 : {}
810 : :
811 : : //! Extract the velocity field at cell nodes. Currently unused.
812 : : //! \param[in] U Solution vector at recent time step
813 : : //! \param[in] N Element node indices
814 : : //! \return Array of the four values of the velocity field
815 : : std::array< std::array< tk::real, 4 >, 3 >
816 : : velocity( const tk::Fields& U,
817 : : const std::array< std::vector< tk::real >, 3 >&,
818 : : const std::array< std::size_t, 4 >& N ) const
819 : : {
820 : : std::array< std::array< tk::real, 4 >, 3 > v;
821 : : v[0] = U.extract( 1, N );
822 : : v[1] = U.extract( 2, N );
823 : : v[2] = U.extract( 3, N );
824 : : auto r = U.extract( 0, N );
825 : : std::transform( r.begin(), r.end(), v[0].begin(), v[0].begin(),
826 : : []( tk::real s, tk::real& d ){ return d /= s; } );
827 : : std::transform( r.begin(), r.end(), v[1].begin(), v[1].begin(),
828 : : []( tk::real s, tk::real& d ){ return d /= s; } );
829 : : std::transform( r.begin(), r.end(), v[2].begin(), v[2].begin(),
830 : : []( tk::real s, tk::real& d ){ return d /= s; } );
831 : : return v;
832 : : }
833 : :
834 : : //! Return a map that associates user-specified strings to functions
835 : : //! \return Map that associates user-specified strings to functions that
836 : : //! compute relevant quantities to be output to file
837 : 1748 : std::map< std::string, tk::GetVarFn > OutVarFn() const
838 : 1748 : { return CompFlowOutVarFn(); }
839 : :
840 : : //! Return analytic field names to be output to file
841 : : //! \return Vector of strings labelling analytic fields output in file
842 : 588 : std::vector< std::string > analyticFieldNames() const
843 : 588 : { return m_problem.analyticFieldNames( m_ncomp ); }
844 : :
845 : : //! Return time history field names to be output to file
846 : : //! \return Vector of strings labeling time history fields output in file
847 : 0 : std::vector< std::string > histNames() const
848 : 0 : { return CompFlowHistNames(); }
849 : :
850 : : //! Return surface field output going to file
851 : : std::vector< std::vector< tk::real > >
852 : 0 : surfOutput( const std::map< int, std::vector< std::size_t > >&,
853 : : tk::Fields& ) const
854 : : {
855 : 0 : std::vector< std::vector< tk::real > > s; // punt for now
856 : 0 : return s;
857 : : }
858 : :
859 : : //! Return time history field output evaluated at time history points
860 : : //! \param[in] h History point data
861 : : //! \param[in] inpoel Element-node connectivity
862 : : //! \param[in] coord Array of nodal coordinates
863 : : //! \param[in] U Array of unknowns
864 : : std::vector< std::vector< tk::real > >
865 : 0 : histOutput( const std::vector< HistData >& h,
866 : : const std::vector< std::size_t >& inpoel,
867 : : const tk::UnsMesh::Coords& coord,
868 : : const tk::Fields& U,
869 : : const tk::Fields& ) const
870 : : {
871 : 0 : const auto rdof = g_inputdeck.get< tag::rdof >();
872 : :
873 : 0 : const auto& x = coord[0];
874 : 0 : const auto& y = coord[1];
875 : 0 : const auto& z = coord[2];
876 : :
877 [ - - ]: 0 : std::vector< std::vector< tk::real > > Up(h.size());
878 : :
879 : 0 : std::size_t j = 0;
880 [ - - ]: 0 : for (const auto& p : h) {
881 : 0 : auto e = p.get< tag::elem >();
882 : 0 : auto chp = p.get< tag::coord >();
883 : :
884 : : // Evaluate inverse Jacobian
885 : 0 : std::array< std::array< tk::real, 3>, 4 > cp{{
886 : : {{ x[inpoel[4*e ]], y[inpoel[4*e ]], z[inpoel[4*e ]] }},
887 : 0 : {{ x[inpoel[4*e+1]], y[inpoel[4*e+1]], z[inpoel[4*e+1]] }},
888 : 0 : {{ x[inpoel[4*e+2]], y[inpoel[4*e+2]], z[inpoel[4*e+2]] }},
889 : 0 : {{ x[inpoel[4*e+3]], y[inpoel[4*e+3]], z[inpoel[4*e+3]] }} }};
890 : 0 : auto J = tk::inverseJacobian( cp[0], cp[1], cp[2], cp[3] );
891 : :
892 : : // evaluate solution at history-point
893 : 0 : std::array< tk::real, 3 > dc{{chp[0]-cp[0][0], chp[1]-cp[0][1],
894 : 0 : chp[2]-cp[0][2]}};
895 [ - - ]: 0 : auto B = tk::eval_basis(rdof, tk::dot(J[0],dc), tk::dot(J[1],dc),
896 : 0 : tk::dot(J[2],dc));
897 [ - - ]: 0 : auto uhp = eval_state(m_ncomp, rdof, rdof, e, U, B);
898 : :
899 : : // store solution in history output vector
900 [ - - ]: 0 : Up[j].resize(6, 0.0);
901 : 0 : Up[j][0] = uhp[0];
902 : 0 : Up[j][1] = uhp[1]/uhp[0];
903 : 0 : Up[j][2] = uhp[2]/uhp[0];
904 : 0 : Up[j][3] = uhp[3]/uhp[0];
905 : 0 : Up[j][4] = uhp[4]/uhp[0];
906 [ - - ]: 0 : Up[j][5] = m_mat_blk[0].compute< EOS::pressure >( uhp[0], uhp[1]/uhp[0],
907 : 0 : uhp[2]/uhp[0], uhp[3]/uhp[0], uhp[4] );
908 : 0 : ++j;
909 : : }
910 : :
911 : 0 : return Up;
912 : : }
913 : :
914 : : //! Return names of integral variables to be output to diagnostics file
915 : : //! \return Vector of strings labelling integral variables output
916 : 50 : std::vector< std::string > names() const
917 : 50 : { return m_problem.names( m_ncomp ); }
918 : :
919 : : //! Return analytic solution (if defined by Problem) at xi, yi, zi, t
920 : : //! \param[in] xi X-coordinate at which to evaluate the analytic solution
921 : : //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
922 : : //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
923 : : //! \param[in] t Physical time at which to evaluate the analytic solution
924 : : //! \return Vector of analytic solution at given location and time
925 : : std::vector< tk::real >
926 : 348546 : analyticSolution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
927 : 348546 : { return Problem::analyticSolution( m_ncomp, m_mat_blk, xi, yi,
928 : 348546 : zi, t ); }
929 : :
930 : : //! Return analytic solution for conserved variables
931 : : //! \param[in] xi X-coordinate at which to evaluate the analytic solution
932 : : //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
933 : : //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
934 : : //! \param[in] t Physical time at which to evaluate the analytic solution
935 : : //! \return Vector of analytic solution at given location and time
936 : : std::vector< tk::real >
937 : 2601398 : solution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
938 : 2601398 : { return Problem::initialize( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
939 : :
940 : : //! Return cell-averaged specific total energy for an element
941 : : //! \param[in] e Element id for which total energy is required
942 : : //! \param[in] unk Vector of conserved quantities
943 : : //! \return Cell-averaged specific total energy for given element
944 : 1146502 : tk::real sp_totalenergy(std::size_t e, const tk::Fields& unk) const
945 : : {
946 : 1146502 : const auto rdof = g_inputdeck.get< tag::rdof >();
947 : :
948 : 1146502 : return unk(e,4*rdof);
949 : : }
950 : :
951 : : private:
952 : : //! Physics policy
953 : : const Physics m_physics;
954 : : //! Problem policy
955 : : const Problem m_problem;
956 : : //! Number of components in this PDE system
957 : : const ncomp_t m_ncomp;
958 : : //! Riemann solver
959 : : tk::RiemannFluxFn m_riemann;
960 : : //! BC configuration
961 : : BCStateFn m_bc;
962 : : //! EOS material block
963 : : std::vector< EOS > m_mat_blk;
964 : :
965 : : //! Evaluate physical flux function for this PDE system
966 : : //! \param[in] ncomp Number of scalar components in this PDE system
967 : : //! \param[in] mat_blk EOS material block
968 : : //! \param[in] ugp Numerical solution at the Gauss point at which to
969 : : //! evaluate the flux
970 : : //! \return Flux vectors for all components in this PDE system
971 : : //! \note The function signature must follow tk::FluxFn
972 : : static tk::FluxFn::result_type
973 : 17110593 : flux( [[maybe_unused]] ncomp_t ncomp,
974 : : const std::vector< EOS >& mat_blk,
975 : : const std::vector< tk::real >& ugp,
976 : : const std::vector< std::array< tk::real, 3 > >& )
977 : : {
978 [ - + ][ - - ]: 17110593 : Assert( ugp.size() == ncomp, "Size mismatch" );
[ - - ][ - - ]
979 : :
980 : 17110593 : auto u = ugp[1] / ugp[0];
981 : 17110593 : auto v = ugp[2] / ugp[0];
982 : 17110593 : auto w = ugp[3] / ugp[0];
983 [ + - ]: 17110593 : auto p = mat_blk[0].compute< EOS::pressure >( ugp[0], u, v, w, ugp[4] );
984 : :
985 [ + - ]: 17110593 : std::vector< std::array< tk::real, 3 > > fl( ugp.size() );
986 : :
987 : 17110593 : fl[0][0] = ugp[1];
988 : 17110593 : fl[1][0] = ugp[1] * u + p;
989 : 17110593 : fl[2][0] = ugp[1] * v;
990 : 17110593 : fl[3][0] = ugp[1] * w;
991 : 17110593 : fl[4][0] = u * (ugp[4] + p);
992 : :
993 : 17110593 : fl[0][1] = ugp[2];
994 : 17110593 : fl[1][1] = ugp[2] * u;
995 : 17110593 : fl[2][1] = ugp[2] * v + p;
996 : 17110593 : fl[3][1] = ugp[2] * w;
997 : 17110593 : fl[4][1] = v * (ugp[4] + p);
998 : :
999 : 17110593 : fl[0][2] = ugp[3];
1000 : 17110593 : fl[1][2] = ugp[3] * u;
1001 : 17110593 : fl[2][2] = ugp[3] * v;
1002 : 17110593 : fl[3][2] = ugp[3] * w + p;
1003 : 17110593 : fl[4][2] = w * (ugp[4] + p);
1004 : :
1005 : 34221186 : return fl;
1006 : : }
1007 : :
1008 : : //! \brief Boundary state function providing the left and right state of a
1009 : : //! face at Dirichlet boundaries
1010 : : //! \param[in] ncomp Number of scalar components in this PDE system
1011 : : //! \param[in] mat_blk EOS material block
1012 : : //! \param[in] ul Left (domain-internal) state
1013 : : //! \param[in] x X-coordinate at which to compute the states
1014 : : //! \param[in] y Y-coordinate at which to compute the states
1015 : : //! \param[in] z Z-coordinate at which to compute the states
1016 : : //! \param[in] t Physical time
1017 : : //! \return Left and right states for all scalar components in this PDE
1018 : : //! system
1019 : : //! \note The function signature must follow tk::StateFn
1020 : : static tk::StateFn::result_type
1021 : 3462090 : dirichlet( ncomp_t ncomp,
1022 : : const std::vector< EOS >& mat_blk,
1023 : : const std::vector< tk::real >& ul, tk::real x, tk::real y,
1024 : : tk::real z, tk::real t, const std::array< tk::real, 3 >& )
1025 : : {
1026 : 3462090 : return {{ ul, Problem::initialize( ncomp, mat_blk, x, y, z, t ) }};
1027 : : }
1028 : :
1029 : : //! \brief Boundary state function providing the left and right state of a
1030 : : //! face at symmetry boundaries
1031 : : //! \param[in] ul Left (domain-internal) state
1032 : : //! \param[in] fn Unit face normal
1033 : : //! \return Left and right states for all scalar components in this PDE
1034 : : //! system
1035 : : //! \note The function signature must follow tk::StateFn
1036 : : static tk::StateFn::result_type
1037 : 2867445 : symmetry( ncomp_t, const std::vector< EOS >&,
1038 : : const std::vector< tk::real >& ul, tk::real, tk::real, tk::real,
1039 : : tk::real, const std::array< tk::real, 3 >& fn )
1040 : : {
1041 [ + - ]: 5734890 : std::vector< tk::real > ur(5);
1042 : : // Internal cell velocity components
1043 : 2867445 : auto v1l = ul[1]/ul[0];
1044 : 2867445 : auto v2l = ul[2]/ul[0];
1045 : 2867445 : auto v3l = ul[3]/ul[0];
1046 : : // Normal component of velocity
1047 : 2867445 : auto vnl = v1l*fn[0] + v2l*fn[1] + v3l*fn[2];
1048 : : // Ghost state velocity components
1049 : 2867445 : auto v1r = v1l - 2.0*vnl*fn[0];
1050 : 2867445 : auto v2r = v2l - 2.0*vnl*fn[1];
1051 : 2867445 : auto v3r = v3l - 2.0*vnl*fn[2];
1052 : : // Boundary condition
1053 : 2867445 : ur[0] = ul[0];
1054 : 2867445 : ur[1] = ur[0] * v1r;
1055 : 2867445 : ur[2] = ur[0] * v2r;
1056 : 2867445 : ur[3] = ur[0] * v3r;
1057 : 2867445 : ur[4] = ul[4];
1058 [ + - ]: 5734890 : return {{ std::move(ul), std::move(ur) }};
1059 : : }
1060 : :
1061 : : //! \brief Boundary state function providing the left and right state of a
1062 : : //! face at farfield boundaries
1063 : : //! \param[in] mat_blk EOS material block
1064 : : //! \param[in] ul Left (domain-internal) state
1065 : : //! \param[in] fn Unit face normal
1066 : : //! \return Left and right states for all scalar components in this PDE
1067 : : //! system
1068 : : //! \note The function signature must follow tk::StateFn
1069 : : static tk::StateFn::result_type
1070 : 40800 : farfield( ncomp_t, const std::vector< EOS >& mat_blk,
1071 : : const std::vector< tk::real >& ul, tk::real, tk::real, tk::real,
1072 : : tk::real, const std::array< tk::real, 3 >& fn )
1073 : : {
1074 : : // Primitive variables from farfield
1075 : 40800 : const auto& bc = g_inputdeck.get< tag::bc >()[0];
1076 : 40800 : auto frho = bc.get< tag::density >();
1077 : 40800 : auto fp = bc.get< tag::pressure >();
1078 : 40800 : const auto& fu = bc.get< tag::velocity >();
1079 : :
1080 : : // Speed of sound from farfield
1081 [ + - ]: 40800 : auto fa = mat_blk[0].compute< EOS::soundspeed >( frho, fp );
1082 : :
1083 : : // Normal component from farfield
1084 : 40800 : auto fvn = fu[0]*fn[0] + fu[1]*fn[1] + fu[2]*fn[2];
1085 : :
1086 : : // Mach number from farfield
1087 : 40800 : auto fM = fvn / fa;
1088 : :
1089 : : // Specific total energy from farfield
1090 [ + - ]: 40800 : auto frhoE = mat_blk[0].compute< EOS::totalenergy >( frho, fu[0], fu[1],
1091 : : fu[2], fp );
1092 : :
1093 : : // Pressure from internal cell
1094 [ + - ]: 81600 : auto p = mat_blk[0].compute< EOS::pressure >( ul[0], ul[1]/ul[0],
1095 : 40800 : ul[2]/ul[0], ul[3]/ul[0], ul[4] );
1096 : :
1097 [ + - ]: 81600 : auto ur = ul;
1098 : :
1099 [ - + ]: 40800 : if(fM <= -1) // Supersonic inflow
1100 : : {
1101 : : // For supersonic inflow, all the characteristics are from outside.
1102 : : // Therefore, we calculate the ghost cell state using the primitive
1103 : : // variables from outside.
1104 : 0 : ur[0] = frho;
1105 : 0 : ur[1] = frho * fu[0];
1106 : 0 : ur[2] = frho * fu[1];
1107 : 0 : ur[3] = frho * fu[2];
1108 : 0 : ur[4] = frhoE;
1109 [ + - ][ - + ]: 40800 : } else if(fM > -1 && fM < 0) // Subsonic inflow
1110 : : {
1111 : : // For subsonic inflow, there are 1 outgoing characteristcs and 4
1112 : : // incoming characteristic. Therefore, we calculate the ghost cell state
1113 : : // by taking pressure from the internal cell and other quantities from
1114 : : // the outside.
1115 : 0 : ur[0] = frho;
1116 : 0 : ur[1] = frho * fu[0];
1117 : 0 : ur[2] = frho * fu[1];
1118 : 0 : ur[3] = frho * fu[2];
1119 [ - - ]: 0 : ur[4] = mat_blk[0].compute< EOS::totalenergy >( frho, fu[0], fu[1],
1120 : : fu[2], p );
1121 [ + - ][ + - ]: 40800 : } else if(fM >= 0 && fM < 1) // Subsonic outflow
1122 : : {
1123 : : // For subsonic outflow, there are 1 incoming characteristcs and 4
1124 : : // outgoing characteristic. Therefore, we calculate the ghost cell state
1125 : : // by taking pressure from the outside and other quantities from the
1126 : : // internal cell.
1127 [ + - ]: 81600 : ur[4] = mat_blk[0].compute< EOS::totalenergy >( ul[0], ul[1]/ul[0],
1128 : 81600 : ul[2]/ul[0], ul[3]/ul[0], fp );
1129 : : }
1130 : : // Otherwise, for supersonic outflow, all the characteristics are from
1131 : : // internal cell. Therefore, we calculate the ghost cell state using the
1132 : : // conservative variables from outside.
1133 : :
1134 [ + - ][ + - ]: 81600 : return {{ ul, ur }};
1135 : : }
1136 : :
1137 : : //! \brief Boundary state function providing the left and right state of a
1138 : : //! face at extrapolation boundaries
1139 : : //! \param[in] ul Left (domain-internal) state
1140 : : //! \return Left and right states for all scalar components in this PDE
1141 : : //! system
1142 : : //! \note The function signature must follow tk::StateFn
1143 : : static tk::StateFn::result_type
1144 : 93360 : extrapolate( ncomp_t, const std::vector< EOS >&,
1145 : : const std::vector< tk::real >& ul, tk::real, tk::real,
1146 : : tk::real, tk::real, const std::array< tk::real, 3 >& )
1147 : : {
1148 : 93360 : return {{ ul, ul }};
1149 : : }
1150 : :
1151 : : //! \brief Boundary gradient function copying the left gradient to the right
1152 : : //! gradient at a face
1153 : : //! \param[in] dul Left (domain-internal) state
1154 : : //! \return Left and right states for all scalar components in this PDE
1155 : : //! system
1156 : : //! \note The function signature must follow tk::StateFn.
1157 : : static tk::StateFn::result_type
1158 : 0 : noOpGrad( ncomp_t,
1159 : : const std::vector< EOS >&,
1160 : : const std::vector< tk::real >& dul,
1161 : : tk::real, tk::real, tk::real, tk::real,
1162 : : const std::array< tk::real, 3 >& )
1163 : : {
1164 : 0 : return {{ dul, dul }};
1165 : : }
1166 : :
1167 : : //! Compute sources corresponding to a propagating front in user-defined box
1168 : : //! \param[in] t Physical time
1169 : : //! \param[in] inpoel Element point connectivity
1170 : : //! \param[in] boxelems Mesh node ids within user-defined box
1171 : : //! \param[in] coord Mesh node coordinates
1172 : : //! \param[in] geoElem Element geometry array
1173 : : //! \param[in] ndofel Vector of local number of degrees of freedome
1174 : : //! \param[in] R Right-hand side vector
1175 : : //! \details This function add the energy source corresponding to a planar
1176 : : //! wave-front propagating along the z-direction with a user-specified
1177 : : //! velocity, within a box initial condition, configured by the user.
1178 : : //! Example (SI) units of the quantities involved:
1179 : : //! * internal energy content (energy per unit volume): J/m^3
1180 : : //! * specific energy (internal energy per unit mass): J/kg
1181 : 0 : void boxSrc( tk::real t,
1182 : : const std::vector< std::size_t >& inpoel,
1183 : : const std::unordered_set< std::size_t >& boxelems,
1184 : : const tk::UnsMesh::Coords& coord,
1185 : : const tk::Fields& geoElem,
1186 : : const std::vector< std::size_t >& ndofel,
1187 : : tk::Fields& R ) const
1188 : : {
1189 : 0 : const auto ndof = g_inputdeck.get< tag::ndof >();
1190 : 0 : const auto& ic = g_inputdeck.get< tag::ic >();
1191 : 0 : const auto& icbox = ic.get< tag::box >();
1192 : :
1193 [ - - ]: 0 : for (const auto& b : icbox) { // for all boxes for this eq
1194 [ - - ]: 0 : std::vector< tk::real > box
1195 : 0 : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
1196 : 0 : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
1197 : 0 : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
1198 : :
1199 : 0 : auto boxenc = b.template get< tag::energy_content >();
1200 [ - - ][ - - ]: 0 : Assert( boxenc > 0.0, "Box energy content must be nonzero" );
[ - - ][ - - ]
1201 : :
1202 : 0 : auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
1203 : :
1204 : : // determine times at which sourcing is initialized and terminated
1205 : 0 : auto iv = b.template get< tag::front_speed >();
1206 : 0 : auto wFront = 0.1;
1207 : 0 : auto tInit = 0.0;
1208 : 0 : auto tFinal = tInit + (box[5] - box[4] - 2.0*wFront) / std::fabs(iv);
1209 : 0 : auto aBox = (box[1]-box[0]) * (box[3]-box[2]);
1210 : :
1211 : 0 : const auto& cx = coord[0];
1212 : 0 : const auto& cy = coord[1];
1213 : 0 : const auto& cz = coord[2];
1214 : :
1215 [ - - ][ - - ]: 0 : if (t >= tInit && t <= tFinal) {
1216 : : // The energy front is assumed to have a half-sine-wave shape. The
1217 : : // half wave-length is the width of the front. At t=0, the center of
1218 : : // this front (i.e. the peak of the partial-sine-wave) is at X_0 +
1219 : : // W_0. W_0 is calculated based on the width of the front and the
1220 : : // direction of propagation (which is assumed to be along the
1221 : : // z-direction). If the front propagation velocity is positive, it
1222 : : // is assumed that the initial position of the energy source is the
1223 : : // minimum z-coordinate of the box; whereas if this velocity is
1224 : : // negative, the initial position is the maximum z-coordinate of the
1225 : : // box.
1226 : :
1227 : : // Orientation of box
1228 : 0 : std::array< tk::real, 3 > b_orientn{{
1229 : 0 : b.template get< tag::orientation >()[0],
1230 : 0 : b.template get< tag::orientation >()[1],
1231 : 0 : b.template get< tag::orientation >()[2] }};
1232 : 0 : std::array< tk::real, 3 > b_centroid{{ 0.5*(box[0]+box[1]),
1233 : 0 : 0.5*(box[2]+box[3]), 0.5*(box[4]+box[5]) }};
1234 : : // Transform box to reference space
1235 : 0 : std::array< tk::real, 3 > b_min{{box[0], box[2], box[4]}};
1236 : 0 : std::array< tk::real, 3 > b_max{{box[1], box[3], box[5]}};
1237 : 0 : tk::movePoint(b_centroid, b_min);
1238 : 0 : tk::movePoint(b_centroid, b_max);
1239 : :
1240 : : // initial center of front
1241 : 0 : tk::real zInit(b_min[2]);
1242 [ - - ]: 0 : if (iv < 0.0) zInit = b_max[2];
1243 : : // current location of front
1244 : 0 : auto z0 = zInit + iv*t;
1245 : 0 : auto z1 = z0 + std::copysign(wFront, iv);
1246 : 0 : tk::real s0(z0), s1(z1);
1247 : : // if velocity of propagation is negative, initial position is z1
1248 [ - - ]: 0 : if (iv < 0.0) {
1249 : 0 : s0 = z1;
1250 : 0 : s1 = z0;
1251 : : }
1252 : : // Sine-wave (positive part of the wave) source term amplitude
1253 : 0 : auto pi = 4.0 * std::atan(1.0);
1254 : 0 : auto amplE = boxenc * V_ex * pi
1255 : 0 : / (aBox * wFront * 2.0 * (tFinal-tInit));
1256 : : //// Square wave (constant) source term amplitude
1257 : : //auto amplE = boxenc * V_ex
1258 : : // / (aBox * wFront * (tFinal-tInit));
1259 : :
1260 : : // add source
1261 [ - - ]: 0 : for (auto e : boxelems) {
1262 [ - - ][ - - ]: 0 : std::array< tk::real, 3 > node{{ geoElem(e,1), geoElem(e,2),
1263 [ - - ]: 0 : geoElem(e,3) }};
1264 : : // Transform node to reference space of box
1265 : 0 : tk::movePoint(b_centroid, node);
1266 : 0 : tk::rotatePoint({{-b_orientn[0], -b_orientn[1], -b_orientn[2]}},
1267 : : node);
1268 : :
1269 [ - - ][ - - ]: 0 : if (node[2] >= s0 && node[2] <= s1) {
[ - - ]
1270 [ - - ]: 0 : auto ng = tk::NGvol(ndofel[e]);
1271 : :
1272 : : // arrays for quadrature points
1273 : 0 : std::array< std::vector< tk::real >, 3 > coordgp;
1274 : 0 : std::vector< tk::real > wgp;
1275 : :
1276 [ - - ]: 0 : coordgp[0].resize( ng );
1277 [ - - ]: 0 : coordgp[1].resize( ng );
1278 [ - - ]: 0 : coordgp[2].resize( ng );
1279 [ - - ]: 0 : wgp.resize( ng );
1280 : :
1281 [ - - ]: 0 : tk::GaussQuadratureTet( ng, coordgp, wgp );
1282 : :
1283 : : // Extract the element coordinates
1284 : 0 : std::array< std::array< tk::real, 3>, 4 > coordel{{
1285 : : {{ cx[inpoel[4*e ]], cy[inpoel[4*e ]], cz[inpoel[4*e ]] }},
1286 : 0 : {{ cx[inpoel[4*e+1]], cy[inpoel[4*e+1]], cz[inpoel[4*e+1]] }},
1287 : 0 : {{ cx[inpoel[4*e+2]], cy[inpoel[4*e+2]], cz[inpoel[4*e+2]] }},
1288 : 0 : {{ cx[inpoel[4*e+3]], cy[inpoel[4*e+3]], cz[inpoel[4*e+3]] }}}};
1289 : :
1290 [ - - ]: 0 : for (std::size_t igp=0; igp<ng; ++igp) {
1291 : : // Compute the coordinates of quadrature point at physical
1292 : : // domain
1293 [ - - ]: 0 : auto gp = tk::eval_gp( igp, coordel, coordgp );
1294 : :
1295 : : // Transform quadrature point to reference space of box
1296 : 0 : tk::movePoint(b_centroid, gp);
1297 : 0 : tk::rotatePoint({{-b_orientn[0], -b_orientn[1], -b_orientn[2]}},
1298 : : gp);
1299 : :
1300 : : // Compute the basis function
1301 [ - - ]: 0 : auto B = tk::eval_basis( ndofel[e], coordgp[0][igp],
1302 : : coordgp[1][igp], coordgp[2][igp] );
1303 : :
1304 : : // Compute the source term variable
1305 [ - - ]: 0 : std::vector< tk::real > s(5, 0.0);
1306 : 0 : s[4] = amplE * std::sin(pi*(gp[2]-s0)/wFront);
1307 : :
1308 [ - - ]: 0 : auto wt = wgp[igp] * geoElem(e, 0);
1309 : :
1310 [ - - ]: 0 : tk::update_rhs( ndof, ndofel[e], wt, e, B, s, R );
1311 : : }
1312 : : }
1313 : : }
1314 : : }
1315 : : }
1316 : 0 : }
1317 : : };
1318 : :
1319 : : } // dg::
1320 : :
1321 : : } // inciter::
1322 : :
1323 : : #endif // DGCompFlow_h
|