Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/PDE/MultiMat/DGMultiMat.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-material flow using discontinuous Galerkin
9 : : finite elements
10 : : \details This file implements calls to the physics operators governing
11 : : compressible multi-material flow (with velocity equilibrium) using
12 : : discontinuous Galerkin discretizations.
13 : : */
14 : : // *****************************************************************************
15 : : #ifndef DGMultiMat_h
16 : : #define DGMultiMat_h
17 : :
18 : : #include <cmath>
19 : : #include <algorithm>
20 : : #include <unordered_set>
21 : : #include <map>
22 : : #include <array>
23 : :
24 : : #include "Macro.hpp"
25 : : #include "Exception.hpp"
26 : : #include "Vector.hpp"
27 : : #include "ContainerUtil.hpp"
28 : : #include "UnsMesh.hpp"
29 : : #include "Inciter/InputDeck/InputDeck.hpp"
30 : : #include "Integrate/Basis.hpp"
31 : : #include "Integrate/Quadrature.hpp"
32 : : #include "Integrate/Initialize.hpp"
33 : : #include "Integrate/Mass.hpp"
34 : : #include "Integrate/Surface.hpp"
35 : : #include "Integrate/Boundary.hpp"
36 : : #include "Integrate/Volume.hpp"
37 : : #include "Integrate/MultiMatTerms.hpp"
38 : : #include "Integrate/Source.hpp"
39 : : #include "Integrate/SolidTerms.hpp"
40 : : #include "RiemannChoice.hpp"
41 : : #include "MultiMat/MultiMatIndexing.hpp"
42 : : #include "Reconstruction.hpp"
43 : : #include "Limiter.hpp"
44 : : #include "Problem/FieldOutput.hpp"
45 : : #include "Problem/BoxInitialization.hpp"
46 : : #include "PrefIndicator.hpp"
47 : : #include "MultiMat/BCFunctions.hpp"
48 : : #include "MultiMat/MiscMultiMatFns.hpp"
49 : : #include "EoS/GetMatProp.hpp"
50 : :
51 : : namespace inciter {
52 : :
53 : : extern ctr::InputDeck g_inputdeck;
54 : :
55 : : namespace dg {
56 : :
57 : : //! \brief MultiMat used polymorphically with tk::DGPDE
58 : : //! \details The template arguments specify policies and are used to configure
59 : : //! the behavior of the class. The policies are:
60 : : //! - Physics - physics configuration, see PDE/MultiMat/Physics.h
61 : : //! - Problem - problem configuration, see PDE/MultiMat/Problem.h
62 : : //! \note The default physics is Euler, set in inciter::deck::check_multimat()
63 : : template< class Physics, class Problem >
64 : : class MultiMat {
65 : :
66 : : private:
67 : : using eq = tag::multimat;
68 : :
69 : : public:
70 : : //! Constructor
71 : 142 : explicit MultiMat() :
72 : 142 : m_ncomp( g_inputdeck.get< tag::ncomp >() ),
73 : : m_nprim(nprim()),
74 : : m_riemann( multimatRiemannSolver(
75 : 142 : g_inputdeck.get< tag::flux >() ) )
76 : : {
77 : : // associate boundary condition configurations with state functions
78 [ + - ][ + - ]: 2130 : brigand::for_each< ctr::bclist::Keys >( ConfigBC( m_bc,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + + ]
[ + + ][ - - ]
[ - - ]
79 : : // BC State functions
80 : : { dirichlet
81 : : , symmetry
82 : : , invalidBC // Outlet BC not implemented
83 : : , farfield
84 : : , extrapolate
85 : : , noslipwall
86 : : , symmetry }, // Slip equivalent to symmetry without mesh motion
87 : : // BC Gradient functions
88 : : { noOpGrad
89 : : , symmetryGrad
90 : : , noOpGrad
91 : : , noOpGrad
92 : : , noOpGrad
93 : : , noOpGrad
94 : : , symmetryGrad }
95 : : ) );
96 : :
97 : : // Inlet BC has a different structure than above BCs, so it must be
98 : : // handled differently than with ConfigBC
99 [ + - ][ + - ]: 142 : ConfigInletBC(m_bc, inlet, zeroGrad);
[ + - ]
100 : :
101 : : // Back pressure BC has a different structure than above BCs, so it must
102 : : // be handled differently than with ConfigBC
103 [ + - ][ + - ]: 142 : ConfigBackPressureBC(m_bc, back_pressure, noOpGrad);
[ + - ]
104 : :
105 : : // EoS initialization
106 [ + - ]: 142 : initializeMaterialEoS( m_mat_blk );
107 : 142 : }
108 : :
109 : : //! Find the number of primitive quantities required for this PDE system
110 : : //! \return The number of primitive quantities required to be stored for
111 : : //! this PDE system
112 : 211 : std::size_t nprim() const
113 : : {
114 : 211 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
115 : : const auto& solidx = inciter::g_inputdeck.get<
116 : 211 : tag::matidxmap, tag::solidx >();
117 : :
118 : : // individual material pressures and three velocity components
119 : 211 : std::size_t np(nmat+3);
120 : :
121 [ + + ]: 717 : for (std::size_t k=0; k<nmat; ++k) {
122 [ - + ]: 506 : if (solidx[k] > 0) {
123 : : // individual material Cauchy stress tensor components
124 : 0 : np += 6;
125 : : }
126 : : }
127 : :
128 : 211 : return np;
129 : : }
130 : :
131 : : //! Find the number of materials set up for this PDE system
132 : : //! \return The number of materials set up for this PDE system
133 : 0 : std::size_t nmat() const
134 : : {
135 : 0 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
136 : 0 : return nmat;
137 : : }
138 : :
139 : : //! Assign number of DOFs per equation in the PDE system
140 : : //! \param[in,out] numEqDof Array storing number of Dofs for each PDE
141 : : //! equation
142 : 69 : void numEquationDofs(std::vector< std::size_t >& numEqDof) const
143 : : {
144 : : // all equation-dofs initialized to ndofs first
145 [ + + ]: 705 : for (std::size_t i=0; i<m_ncomp; ++i) {
146 : 636 : numEqDof.push_back(g_inputdeck.get< tag::ndof >());
147 : : }
148 : :
149 : : // volume fractions are P0Pm (ndof = 1) for multi-material simulations
150 : 69 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
151 [ + - ]: 69 : if(nmat > 1)
152 [ + + ]: 212 : for (std::size_t k=0; k<nmat; ++k)
153 : 143 : numEqDof[volfracIdx(nmat, k)] = 1;
154 : 69 : }
155 : :
156 : : //! Determine elements that lie inside the user-defined IC box
157 : : //! \param[in] geoElem Element geometry array
158 : : //! \param[in] nielem Number of internal elements
159 : : //! \param[in,out] inbox List of nodes at which box user ICs are set for
160 : : //! each IC box
161 : 69 : void IcBoxElems( const tk::Fields& geoElem,
162 : : std::size_t nielem,
163 : : std::vector< std::unordered_set< std::size_t > >& inbox ) const
164 : : {
165 : 69 : tk::BoxElems< eq >(geoElem, nielem, inbox);
166 : 69 : }
167 : :
168 : : //! Find how many 'stiff equations', which are the inverse
169 : : //! deformation equations because of plasticity
170 : : //! \return number of stiff equations
171 : 414 : std::size_t nstiffeq() const
172 : : {
173 : 414 : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
174 : 414 : std::size_t nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
175 : 414 : return 9*numSolids(nmat, solidx);
176 : : }
177 : :
178 : : //! Find how many 'non-stiff equations', which are the inverse
179 : : //! deformation equations because of plasticity
180 : : //! \return number of stiff equations
181 : 138 : std::size_t nnonstiffeq() const
182 : : {
183 : 138 : return m_ncomp-nstiffeq();
184 : : }
185 : :
186 : : //! Locate the stiff equations.
187 : : //! \param[out] stiffEqIdx list with pointers to stiff equations
188 : 0 : void setStiffEqIdx( std::vector< std::size_t >& stiffEqIdx ) const
189 : : {
190 [ - - ][ - - ]: 0 : stiffEqIdx.resize(nstiffeq(), 0);
191 : 0 : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
192 : 0 : std::size_t nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
193 : 0 : std::size_t icnt = 0;
194 [ - - ]: 0 : for (std::size_t k=0; k<nmat; ++k)
195 [ - - ]: 0 : if (solidx[k] > 0)
196 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
197 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
198 : : {
199 : 0 : stiffEqIdx[icnt] =
200 : 0 : inciter::deformIdx(nmat, solidx[k], i, j);
201 : 0 : icnt++;
202 : : }
203 : 0 : }
204 : :
205 : : //! Locate the nonstiff equations.
206 : : //! \param[out] nonStiffEqIdx list with pointers to nonstiff equations
207 : 0 : void setNonStiffEqIdx( std::vector< std::size_t >& nonStiffEqIdx ) const
208 : : {
209 [ - - ][ - - ]: 0 : nonStiffEqIdx.resize(nnonstiffeq(), 0);
210 [ - - ]: 0 : for (std::size_t icomp=0; icomp<nnonstiffeq(); icomp++)
211 : 0 : nonStiffEqIdx[icomp] = icomp;
212 : 0 : }
213 : :
214 : : //! Initialize the compressible flow equations, prepare for time integration
215 : : //! \param[in] L Block diagonal mass matrix
216 : : //! \param[in] inpoel Element-node connectivity
217 : : //! \param[in] coord Array of nodal coordinates
218 : : //! \param[in] inbox List of elements at which box user ICs are set for
219 : : //! each IC box
220 : : //! \param[in] elemblkid Element ids associated with mesh block ids where
221 : : //! user ICs are set
222 : : //! \param[in,out] unk Array of unknowns
223 : : //! \param[in] t Physical time
224 : : //! \param[in] nielem Number of internal elements
225 : 69 : void initialize( const tk::Fields& L,
226 : : const std::vector< std::size_t >& inpoel,
227 : : const tk::UnsMesh::Coords& coord,
228 : : const std::vector< std::unordered_set< std::size_t > >& inbox,
229 : : const std::unordered_map< std::size_t, std::set< std::size_t > >&
230 : : elemblkid,
231 : : tk::Fields& unk,
232 : : tk::real t,
233 : : const std::size_t nielem ) const
234 : : {
235 [ + - ][ + - ]: 69 : tk::initialize( m_ncomp, m_mat_blk, L, inpoel, coord,
236 : : Problem::initialize, unk, t, nielem );
237 : :
238 : 69 : const auto rdof = g_inputdeck.get< tag::rdof >();
239 : 69 : const auto& ic = g_inputdeck.get< tag::ic >();
240 : 69 : const auto& icbox = ic.get< tag::box >();
241 : 69 : const auto& icmbk = ic.get< tag::meshblock >();
242 : :
243 : 69 : const auto& bgpre = ic.get< tag::pressure >();
244 : 69 : const auto& bgtemp = ic.get< tag::temperature >();
245 : :
246 : : // Set initial conditions inside user-defined IC boxes and mesh blocks
247 [ + - ]: 138 : std::vector< tk::real > s(m_ncomp, 0.0);
248 [ + + ]: 23411 : for (std::size_t e=0; e<nielem; ++e) {
249 : : // inside user-defined box
250 [ + + ]: 23342 : if (!icbox.empty()) {
251 : 896 : std::size_t bcnt = 0;
252 [ + + ]: 1792 : for (const auto& b : icbox) { // for all boxes
253 [ + - ][ + - ]: 896 : if (inbox.size() > bcnt && inbox[bcnt].find(e) != inbox[bcnt].end())
[ + + ][ + + ]
254 : : {
255 [ + - ]: 896 : std::vector< tk::real > box
256 : 448 : { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
257 : 448 : b.template get< tag::ymin >(), b.template get< tag::ymax >(),
258 : 448 : b.template get< tag::zmin >(), b.template get< tag::zmax >() };
259 : 448 : auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
260 [ + + ]: 4480 : for (std::size_t c=0; c<m_ncomp; ++c) {
261 : 4032 : auto mark = c*rdof;
262 [ + - ]: 4032 : s[c] = unk(e,mark);
263 : : // set high-order DOFs to zero
264 [ - + ]: 4032 : for (std::size_t i=1; i<rdof; ++i)
265 [ - - ]: 0 : unk(e,mark+i) = 0.0;
266 : : }
267 [ + - ]: 448 : initializeBox<ctr::boxList>( m_mat_blk, V_ex, t, b, bgpre,
268 : : bgtemp, s );
269 : : // store box-initialization in solution vector
270 [ + + ]: 4480 : for (std::size_t c=0; c<m_ncomp; ++c) {
271 : 4032 : auto mark = c*rdof;
272 [ + - ]: 4032 : unk(e,mark) = s[c];
273 : : }
274 : : }
275 : 896 : ++bcnt;
276 : : }
277 : : }
278 : :
279 : : // inside user-specified mesh blocks
280 [ - + ]: 23342 : if (!icmbk.empty()) {
281 [ - - ]: 0 : for (const auto& b : icmbk) { // for all blocks
282 : 0 : auto blid = b.get< tag::blockid >();
283 : 0 : auto V_ex = b.get< tag::volume >();
284 [ - - ][ - - ]: 0 : if (elemblkid.find(blid) != elemblkid.end()) {
285 [ - - ]: 0 : const auto& elset = tk::cref_find(elemblkid, blid);
286 [ - - ][ - - ]: 0 : if (elset.find(e) != elset.end()) {
287 [ - - ]: 0 : initializeBox<ctr::meshblockList>( m_mat_blk, V_ex, t, b,
288 : : bgpre, bgtemp, s );
289 : : // store initialization in solution vector
290 [ - - ]: 0 : for (std::size_t c=0; c<m_ncomp; ++c) {
291 : 0 : auto mark = c*rdof;
292 [ - - ]: 0 : unk(e,mark) = s[c];
293 : : }
294 : : }
295 : : }
296 : : }
297 : : }
298 : : }
299 : 69 : }
300 : :
301 : : //! Compute density constraint for a given material
302 : : //! \param[in] nelem Number of elements
303 : : //! \param[in] unk Array of unknowns
304 : : //! \param[out] densityConstr Density Constraint: rho/(rho0*det(g))
305 : 179 : void computeDensityConstr( std::size_t nelem,
306 : : tk::Fields& unk,
307 : : std::vector< tk::real >& densityConstr) const
308 : : {
309 : 179 : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
310 : 179 : std::size_t rdof = g_inputdeck.get< tag::rdof >();
311 : 179 : std::size_t nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
312 [ + + ]: 69861 : for (std::size_t e=0; e<nelem; ++e)
313 : 69682 : densityConstr[e] = 0.0;
314 [ + + ]: 552 : for (std::size_t imat=0; imat<nmat; ++imat)
315 [ - + ]: 373 : if (solidx[imat] > 0)
316 : : {
317 [ - - ]: 0 : for (std::size_t e=0; e<nelem; ++e)
318 : : {
319 : : // Retrieve unknowns
320 [ - - ]: 0 : tk::real arho = unk(e, densityDofIdx(nmat, imat, rdof, 0));
321 : : std::array< std::array< tk::real, 3 >, 3 > g;
322 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
323 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
324 [ - - ]: 0 : g[i][j] = unk(e, deformDofIdx(nmat, solidx[imat], i, j, rdof, 0));
325 : : // Compute determinant of g
326 : 0 : tk::real detg = tk::determinant(g);
327 : : // Compute constraint measure
328 [ - - ]: 0 : densityConstr[e] += arho/(m_mat_blk[imat].compute< EOS::rho0 >()*detg);
329 : : }
330 : : }
331 : : else
332 : : {
333 [ + + ]: 161595 : for (std::size_t e=0; e<nelem; ++e)
334 : : {
335 : : // Retrieve alpha and add it to the constraint measure
336 : 161222 : tk::real alpha = unk(e, volfracDofIdx(nmat, imat, rdof, 0));
337 : 161222 : densityConstr[e] += alpha;
338 : : }
339 : : }
340 : 179 : }
341 : :
342 : : //! Compute the left hand side block-diagonal mass matrix
343 : : //! \param[in] geoElem Element geometry array
344 : : //! \param[in,out] l Block diagonal mass matrix
345 : 69 : void lhs( const tk::Fields& geoElem, tk::Fields& l ) const {
346 : 69 : const auto ndof = g_inputdeck.get< tag::ndof >();
347 : : // Unlike Compflow and Transport, there is a weak reconstruction about
348 : : // conservative variable after limiting function which will require the
349 : : // size of left hand side vector to be rdof
350 : 69 : tk::mass( m_ncomp, ndof, geoElem, l );
351 : 69 : }
352 : :
353 : : //! Update the interface cells to first order dofs
354 : : //! \param[in] unk Array of unknowns
355 : : //! \param[in] nielem Number of internal elements
356 : : //! \param[in,out] ndofel Array of dofs
357 : : //! \param[in,out] interface Vector of interface marker
358 : : //! \details This function resets the high-order terms in interface cells.
359 : 6705 : void updateInterfaceCells( tk::Fields& unk,
360 : : std::size_t nielem,
361 : : std::vector< std::size_t >& ndofel,
362 : : std::vector< std::size_t >& interface ) const
363 : : {
364 : 6705 : auto intsharp =
365 : 6705 : g_inputdeck.get< tag::multimat, tag::intsharp >();
366 : : // If this cell is not material interface, return this function
367 [ + + ]: 6705 : if(not intsharp) return;
368 : :
369 : 375 : auto rdof = g_inputdeck.get< tag::rdof >();
370 : 375 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
371 : : const auto& solidx = g_inputdeck.get<
372 : 375 : tag::matidxmap, tag::solidx >();
373 : :
374 [ + + ]: 227775 : for (std::size_t e=0; e<nielem; ++e) {
375 [ + - ]: 454800 : std::vector< std::size_t > matInt(nmat, 0);
376 [ + - ]: 454800 : std::vector< tk::real > alAvg(nmat, 0.0);
377 [ + + ]: 682200 : for (std::size_t k=0; k<nmat; ++k)
378 [ + - ]: 454800 : alAvg[k] = unk(e, volfracDofIdx(nmat,k,rdof,0));
379 [ + - ]: 227400 : auto intInd = interfaceIndicator(nmat, alAvg, matInt);
380 : :
381 : : // interface cells cannot be high-order
382 [ + + ]: 227400 : if (intInd) {
383 : 10834 : interface[e] = 1;
384 [ + + ]: 32502 : for (std::size_t k=0; k<nmat; ++k) {
385 [ + - ]: 21668 : if (matInt[k]) {
386 [ + + ]: 86672 : for (std::size_t i=1; i<rdof; ++i) {
387 [ + - ]: 65004 : unk(e, densityDofIdx(nmat,k,rdof,i)) = 0.0;
388 [ + - ]: 65004 : unk(e, energyDofIdx(nmat,k,rdof,i)) = 0.0;
389 : : }
390 [ - + ]: 21668 : if (solidx[k] > 0) {
391 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
392 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
393 [ - - ]: 0 : for (std::size_t idof=1; idof<rdof; ++idof) {
394 [ - - ]: 0 : unk(e, deformDofIdx(nmat,solidx[k],i,j,rdof,idof)) = 0.0;
395 : : }
396 : : }
397 : : }
398 : : }
399 [ + + ]: 43336 : for (std::size_t idir=0; idir<3; ++idir) {
400 [ + + ]: 130008 : for (std::size_t i=1; i<rdof; ++i) {
401 [ + - ]: 97506 : unk(e, momentumDofIdx(nmat,idir,rdof,i)) = 0.0;
402 : : }
403 : : }
404 : : } else {
405 : : // If the cell is marked as interface cell in the previous timestep
406 : : // and does not marked as interface for the current timestep, DGP2
407 : : // will be applied for the current timestep in p-adaptive process
408 : : // Please note this block is added since the spectral decay indicator
409 : : // does not applied to P0 cells.
410 [ + + ]: 216566 : if (interface[e] == 1) {
411 [ + - ][ - + ]: 6 : if(ndofel[e] < 10 && rdof == 10) {
[ - + ]
412 : 0 : ndofel[e] = 10;
413 [ - - ]: 0 : for (std::size_t k=0; k<nmat; ++k) {
414 [ - - ]: 0 : for (std::size_t i=1; i<rdof; ++i) {
415 [ - - ]: 0 : unk(e, densityDofIdx(nmat,k,rdof,i)) = 0.0;
416 [ - - ]: 0 : unk(e, energyDofIdx(nmat,k,rdof,i)) = 0.0;
417 : : }
418 : : }
419 [ - - ]: 0 : for (std::size_t idir=0; idir<3; ++idir) {
420 [ - - ]: 0 : for (std::size_t i=1; i<rdof; ++i) {
421 [ - - ]: 0 : unk(e, momentumDofIdx(nmat,idir,rdof,i)) = 0.0;
422 : : }
423 : : }
424 : : }
425 : : }
426 : 216566 : interface[e] = 0;
427 : : }
428 : : }
429 : : }
430 : :
431 : : //! Update the primitives for this PDE system
432 : : //! \param[in] unk Array of unknowns
433 : : //! \param[in] L The left hand side block-diagonal mass matrix
434 : : //! \param[in] geoElem Element geometry array
435 : : //! \param[in,out] prim Array of primitives
436 : : //! \param[in] nielem Number of internal elements
437 : : //! \param[in] ndofel Array of dofs
438 : : //! \details This function computes and stores the dofs for primitive
439 : : //! quantities, which are required for obtaining reconstructed states used
440 : : //! in the Riemann solver. See /PDE/Riemann/AUSM.hpp, where the
441 : : //! normal velocity for advection is calculated from independently
442 : : //! reconstructed velocities.
443 : 6774 : void updatePrimitives( const tk::Fields& unk,
444 : : const tk::Fields& L,
445 : : const tk::Fields& geoElem,
446 : : tk::Fields& prim,
447 : : std::size_t nielem,
448 : : const std::vector< std::size_t >& ndofel ) const
449 : : {
450 : 6774 : const auto rdof = g_inputdeck.get< tag::rdof >();
451 : 6774 : const auto ndof = g_inputdeck.get< tag::ndof >();
452 : 6774 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
453 : 6774 : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
454 : :
455 [ - + ][ - - ]: 6774 : Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
456 : : "vector and primitive vector at recent time step incorrect" );
457 [ - + ][ - - ]: 6774 : Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
[ - - ][ - - ]
[ - - ]
458 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
459 [ - + ][ - - ]: 6774 : Assert( prim.nprop() == rdof*m_nprim, "Number of components in vector of "
[ - - ][ - - ]
[ - - ]
460 : : "primitive quantities must equal "+ std::to_string(rdof*m_nprim) );
461 : :
462 [ + + ]: 2527796 : for (std::size_t e=0; e<nielem; ++e)
463 : : {
464 [ + - ]: 5042044 : std::vector< tk::real > R(m_nprim*ndof, 0.0);
465 : :
466 [ + - ]: 2521022 : auto ng = tk::NGvol(ndof);
467 : :
468 : : // arrays for quadrature points
469 : 5042044 : std::array< std::vector< tk::real >, 3 > coordgp;
470 : 5042044 : std::vector< tk::real > wgp;
471 : :
472 [ + - ]: 2521022 : coordgp[0].resize( ng );
473 [ + - ]: 2521022 : coordgp[1].resize( ng );
474 [ + - ]: 2521022 : coordgp[2].resize( ng );
475 [ + - ]: 2521022 : wgp.resize( ng );
476 : :
477 [ + - ]: 2521022 : tk::GaussQuadratureTet( ng, coordgp, wgp );
478 : :
479 : : // Local degree of freedom
480 : 2521022 : auto dof_el = ndofel[e];
481 : :
482 : : // Loop over quadrature points in element e
483 [ + + ]: 7073484 : for (std::size_t igp=0; igp<ng; ++igp)
484 : : {
485 : : // Compute the basis function
486 [ + - ]: 9104924 : auto B =
487 : 4552462 : tk::eval_basis( dof_el, coordgp[0][igp], coordgp[1][igp], coordgp[2][igp] );
488 : :
489 [ + - ]: 4552462 : auto w = wgp[igp] * geoElem(e, 0);
490 : :
491 [ + - ]: 9104924 : auto state = tk::eval_state( m_ncomp, rdof, dof_el, e, unk, B );
492 : :
493 : : // bulk density at quadrature point
494 : 4552462 : tk::real rhob(0.0);
495 [ + + ]: 14757572 : for (std::size_t k=0; k<nmat; ++k)
496 : 10205110 : rhob += state[densityIdx(nmat, k)];
497 : :
498 : : // velocity vector at quadrature point
499 : : std::array< tk::real, 3 >
500 : 4552462 : vel{ state[momentumIdx(nmat, 0)]/rhob,
501 : 4552462 : state[momentumIdx(nmat, 1)]/rhob,
502 : 4552462 : state[momentumIdx(nmat, 2)]/rhob };
503 : :
504 [ + - ]: 9104924 : std::vector< tk::real > pri(m_nprim, 0.0);
505 : :
506 : : // Evaluate material pressure at quadrature point
507 [ + + ]: 14757572 : for(std::size_t imat = 0; imat < nmat; imat++)
508 : : {
509 : 10205110 : auto alphamat = state[volfracIdx(nmat, imat)];
510 : 10205110 : auto arhomat = state[densityIdx(nmat, imat)];
511 : 10205110 : auto arhoemat = state[energyIdx(nmat, imat)];
512 [ + - ]: 10205110 : auto gmat = getDeformGrad(nmat, imat, state);
513 : 10205110 : pri[pressureIdx(nmat,imat)] = m_mat_blk[imat].compute<
514 [ + - ]: 10205110 : EOS::pressure >( arhomat, vel[0], vel[1], vel[2], arhoemat,
515 : : alphamat, imat, gmat );
516 : :
517 [ + - ]: 10205110 : pri[pressureIdx(nmat,imat)] = constrain_pressure( m_mat_blk,
518 : : pri[pressureIdx(nmat,imat)], arhomat, alphamat, imat);
519 : :
520 [ - + ]: 10205110 : if (solidx[imat] > 0) {
521 [ - - ]: 0 : auto asigmat = m_mat_blk[imat].computeTensor< EOS::CauchyStress >(
522 : : alphamat, imat, gmat );
523 : :
524 : 0 : pri[stressIdx(nmat,solidx[imat],0)] = asigmat[0][0];
525 : 0 : pri[stressIdx(nmat,solidx[imat],1)] = asigmat[1][1];
526 : 0 : pri[stressIdx(nmat,solidx[imat],2)] = asigmat[2][2];
527 : 0 : pri[stressIdx(nmat,solidx[imat],3)] = asigmat[0][1];
528 : 0 : pri[stressIdx(nmat,solidx[imat],4)] = asigmat[0][2];
529 : 0 : pri[stressIdx(nmat,solidx[imat],5)] = asigmat[1][2];
530 : : }
531 : : }
532 : :
533 : : // Evaluate bulk velocity at quadrature point
534 [ + + ]: 18209848 : for (std::size_t idir=0; idir<3; ++idir) {
535 : 13657386 : pri[velocityIdx(nmat,idir)] = vel[idir];
536 : : }
537 : :
538 [ + + ]: 28414958 : for(std::size_t k = 0; k < m_nprim; k++)
539 : : {
540 : 23862496 : auto mark = k * ndof;
541 [ + + ]: 85814492 : for(std::size_t idof = 0; idof < dof_el; idof++)
542 : 61951996 : R[mark+idof] += w * pri[k] * B[idof];
543 : : }
544 : : }
545 : :
546 : : // Update the DG solution of primitive variables
547 [ + + ]: 16226318 : for(std::size_t k = 0; k < m_nprim; k++)
548 : : {
549 : 13705296 : auto mark = k * ndof;
550 : 13705296 : auto rmark = k * rdof;
551 [ + + ]: 35028492 : for(std::size_t idof = 0; idof < dof_el; idof++)
552 : : {
553 [ + - ][ + - ]: 21323196 : prim(e, rmark+idof) = R[mark+idof] / L(e, mark+idof);
554 [ + - ][ + + ]: 21323196 : if(fabs(prim(e, rmark+idof)) < 1e-16)
555 [ + - ]: 5292968 : prim(e, rmark+idof) = 0;
556 : : }
557 : : }
558 : : }
559 : 6774 : }
560 : :
561 : : //! Clean up the state of trace materials for this PDE system
562 : : //! \param[in] t Physical time
563 : : //! \param[in] geoElem Element geometry array
564 : : //! \param[in,out] unk Array of unknowns
565 : : //! \param[in,out] prim Array of primitives
566 : : //! \param[in] nielem Number of internal elements
567 : : //! \details This function cleans up the state of materials present in trace
568 : : //! quantities in each cell. Specifically, the state of materials with
569 : : //! very low volume-fractions in a cell is replaced by the state of the
570 : : //! material which is present in the largest quantity in that cell. This
571 : : //! becomes necessary when shocks pass through cells which contain a very
572 : : //! small amount of material. The state of that tiny material might
573 : : //! become unphysical and cause solution to diverge; thus requiring such
574 : : //! a "reset".
575 : 6705 : void cleanTraceMaterial( tk::real t,
576 : : const tk::Fields& geoElem,
577 : : tk::Fields& unk,
578 : : tk::Fields& prim,
579 : : std::size_t nielem ) const
580 : : {
581 : 6705 : [[maybe_unused]] const auto rdof = g_inputdeck.get< tag::rdof >();
582 : 6705 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
583 : :
584 [ - + ][ - - ]: 6705 : Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
585 : : "vector and primitive vector at recent time step incorrect" );
586 [ - + ][ - - ]: 6705 : Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
[ - - ][ - - ]
[ - - ]
587 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
588 [ - + ][ - - ]: 6705 : Assert( prim.nprop() == rdof*m_nprim, "Number of components in vector of "
[ - - ][ - - ]
[ - - ]
589 : : "primitive quantities must equal "+ std::to_string(rdof*m_nprim) );
590 : :
591 : 6705 : auto neg_density = cleanTraceMultiMat(t, nielem, m_mat_blk, geoElem, nmat,
592 : : unk, prim);
593 : :
594 [ - + ][ - - ]: 6705 : if (neg_density) Throw("Negative partial density.");
[ - - ][ - - ]
595 : 6705 : }
596 : :
597 : : //! Reconstruct second-order solution from first-order
598 : : //! \param[in] geoElem Element geometry array
599 : : //! \param[in] fd Face connectivity and boundary conditions object
600 : : //! \param[in] esup Elements-surrounding-nodes connectivity
601 : : //! \param[in] inpoel Element-node connectivity
602 : : //! \param[in] coord Array of nodal coordinates
603 : : //! \param[in,out] U Solution vector at recent time step
604 : : //! \param[in,out] P Vector of primitives at recent time step
605 : : //! \param[in] pref Indicator for p-adaptive algorithm
606 : : //! \param[in] ndofel Vector of local number of degrees of freedome
607 : 4080 : void reconstruct( tk::real,
608 : : const tk::Fields&,
609 : : const tk::Fields& geoElem,
610 : : const inciter::FaceData& fd,
611 : : const std::map< std::size_t, std::vector< std::size_t > >&
612 : : esup,
613 : : const std::vector< std::size_t >& inpoel,
614 : : const tk::UnsMesh::Coords& coord,
615 : : tk::Fields& U,
616 : : tk::Fields& P,
617 : : const bool pref,
618 : : const std::vector< std::size_t >& ndofel ) const
619 : : {
620 : 4080 : const auto rdof = g_inputdeck.get< tag::rdof >();
621 : 4080 : const auto ndof = g_inputdeck.get< tag::ndof >();
622 : :
623 : 4080 : bool is_p0p1(false);
624 [ + - ][ + + ]: 4080 : if (rdof == 4 && ndof == 1)
625 : 3300 : is_p0p1 = true;
626 : :
627 : 4080 : const auto nelem = fd.Esuel().size()/4;
628 : 4080 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
629 : :
630 [ - + ][ - - ]: 4080 : Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
[ - - ][ - - ]
[ - - ]
631 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
632 [ - + ][ - - ]: 4080 : Assert( P.nprop() == rdof*m_nprim, "Number of components in primitive "
[ - - ][ - - ]
[ - - ]
633 : : "vector must equal "+ std::to_string(rdof*m_nprim) );
634 : :
635 : : //----- reconstruction of conserved quantities -----
636 : : //--------------------------------------------------
637 : :
638 [ + + ]: 845460 : for (std::size_t e=0; e<nelem; ++e)
639 : : {
640 : : // 1. specify how many variables need to be reconstructed
641 : 1682760 : std::vector< std::size_t > vars;
642 : : // for p-adaptive DG
643 [ - + ]: 841380 : if (pref) {
644 : : // If DG is applied, reconstruct only volume fractions
645 [ - - ]: 0 : if(ndofel[e] > 1) {
646 [ - - ][ - - ]: 0 : for (std::size_t k=0; k<nmat; ++k) vars.push_back(volfracIdx(nmat, k));
647 : : }
648 : : else // If P0P1 is applied for this element
649 [ - - ][ - - ]: 0 : for (std::size_t c=0; c<m_ncomp; ++c) vars.push_back(c);
650 : : }
651 : : else {
652 : : // for P0P1, reconstruct all variables
653 [ + + ]: 841380 : if (is_p0p1)
654 [ + + ][ + - ]: 3411000 : for (std::size_t c=0; c<m_ncomp; ++c) vars.push_back(c);
655 : : // for high-order DG, reconstruct only volume fractions
656 [ + - ]: 500280 : else if (ndof > 1)
657 [ + + ][ + - ]: 1500840 : for (std::size_t k=0; k<nmat; ++k) vars.push_back(volfracIdx(nmat, k));
658 : : }
659 : :
660 : : // 2. solve 3x3 least-squares system
661 : : // Reconstruct second-order dofs of volume-fractions in Taylor space
662 : : // using nodal-stencils, for a good interface-normal estimate
663 [ + - ]: 841380 : tk::recoLeastSqExtStencil( rdof, e, esup, inpoel, geoElem, U, vars );
664 : :
665 : : // 3. transform reconstructed derivatives to Dubiner dofs
666 [ + - ]: 841380 : tk::transform_P0P1( rdof, e, inpoel, coord, U, vars );
667 : : }
668 : :
669 : : //----- reconstruction of primitive quantities -----
670 : : //--------------------------------------------------
671 : : // For multimat, conserved and primitive quantities are reconstructed
672 : : // separately.
673 : :
674 [ + + ]: 845460 : for (std::size_t e=0; e<nelem; ++e)
675 : : {
676 : : // There are two conditions that requires the reconstruction of the
677 : : // primitive variables:
678 : : // 1. p-adaptive is triggered and P0P1 scheme is applied to specific
679 : : // elements
680 : : // 2. p-adaptive is not triggered and P0P1 scheme is applied to the
681 : : // whole computation domain
682 [ - + ][ - - ]: 841380 : if ((pref && ndofel[e] == 1) || (!pref && is_p0p1)) {
[ + - ][ + + ]
[ + + ]
683 : 682200 : std::vector< std::size_t > vars;
684 [ + + ][ + - ]: 2046600 : for (std::size_t c=0; c<m_nprim; ++c) vars.push_back(c);
685 : :
686 : : // 1.
687 : : // Reconstruct second-order dofs of volume-fractions in Taylor space
688 : : // using nodal-stencils, for a good interface-normal estimate
689 [ + - ]: 341100 : tk::recoLeastSqExtStencil( rdof, e, esup, inpoel, geoElem, P, vars );
690 : :
691 : : // 2.
692 [ + - ]: 341100 : tk::transform_P0P1(rdof, e, inpoel, coord, P, vars);
693 : : }
694 : : }
695 : :
696 : 4080 : }
697 : :
698 : : //! Limit second-order solution, and primitive quantities separately
699 : : //! \param[in] t Physical time
700 : : //! \param[in] pref Indicator for p-adaptive algorithm
701 : : //! \param[in] geoFace Face geometry array
702 : : //! \param[in] geoElem Element geometry array
703 : : //! \param[in] fd Face connectivity and boundary conditions object
704 : : //! \param[in] esup Elements-surrounding-nodes connectivity
705 : : //! \param[in] inpoel Element-node connectivity
706 : : //! \param[in] coord Array of nodal coordinates
707 : : //! \param[in] ndofel Vector of local number of degrees of freedome
708 : : //! \param[in] gid Local->global node id map
709 : : //! \param[in] bid Local chare-boundary node ids (value) associated to
710 : : //! global node ids (key)
711 : : //! \param[in] uNodalExtrm Chare-boundary nodal extrema for conservative
712 : : //! variables
713 : : //! \param[in] pNodalExtrm Chare-boundary nodal extrema for primitive
714 : : //! variables
715 : : //! \param[in] mtInv Inverse of Taylor mass matrix
716 : : //! \param[in,out] U Solution vector at recent time step
717 : : //! \param[in,out] P Vector of primitives at recent time step
718 : : //! \param[in,out] shockmarker Vector of shock-marker values
719 : 4080 : void limit( [[maybe_unused]] tk::real t,
720 : : const bool pref,
721 : : const tk::Fields& geoFace,
722 : : const tk::Fields& geoElem,
723 : : const inciter::FaceData& fd,
724 : : const std::map< std::size_t, std::vector< std::size_t > >& esup,
725 : : const std::vector< std::size_t >& inpoel,
726 : : const tk::UnsMesh::Coords& coord,
727 : : const std::vector< std::size_t >& ndofel,
728 : : const std::vector< std::size_t >& gid,
729 : : const std::unordered_map< std::size_t, std::size_t >& bid,
730 : : const std::vector< std::vector<tk::real> >& uNodalExtrm,
731 : : const std::vector< std::vector<tk::real> >& pNodalExtrm,
732 : : const std::vector< std::vector<tk::real> >& mtInv,
733 : : tk::Fields& U,
734 : : tk::Fields& P,
735 : : std::vector< std::size_t >& shockmarker ) const
736 : : {
737 [ - + ][ - - ]: 4080 : Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
738 : : "vector and primitive vector at recent time step incorrect" );
739 : :
740 : 4080 : const auto limiter = g_inputdeck.get< tag::limiter >();
741 : 4080 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
742 : 4080 : const auto rdof = g_inputdeck.get< tag::rdof >();
743 : : const auto& solidx = g_inputdeck.get<
744 : 4080 : tag::matidxmap, tag::solidx >();
745 : :
746 : : // limit vectors of conserved and primitive quantities
747 [ - + ]: 4080 : if (limiter == ctr::LimiterType::SUPERBEEP1)
748 : : {
749 : 0 : SuperbeeMultiMat_P1( fd.Esuel(), inpoel, ndofel,
750 : : coord, solidx, U, P, nmat );
751 : : }
752 [ + - ][ + - ]: 4080 : else if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 4)
753 : : {
754 [ + - ]: 8160 : VertexBasedMultiMat_P1( esup, inpoel, ndofel, fd.Esuel().size()/4,
755 : 4080 : m_mat_blk, fd, geoFace, geoElem, coord, flux, solidx, U, P,
756 : : nmat, shockmarker );
757 : : }
758 [ - - ][ - - ]: 0 : else if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 10)
759 : : {
760 [ - - ]: 0 : VertexBasedMultiMat_P2( pref, esup, inpoel, ndofel, fd.Esuel().size()/4,
761 : 0 : m_mat_blk, fd, geoFace, geoElem, coord, gid, bid,
762 : : uNodalExtrm, pNodalExtrm, mtInv, flux, solidx, U, P, nmat,
763 : : shockmarker );
764 : : }
765 [ - - ]: 0 : else if (limiter != ctr::LimiterType::NOLIMITER)
766 : : {
767 [ - - ][ - - ]: 0 : Throw("Limiter type not configured for multimat.");
[ - - ]
768 : : }
769 : 4080 : }
770 : :
771 : : //! Apply CPL to the conservative variable solution for this PDE system
772 : : //! \param[in] prim Array of primitive variables
773 : : //! \param[in] geoElem Element geometry array
774 : : //! \param[in] inpoel Element-node connectivity
775 : : //! \param[in] coord Array of nodal coordinates
776 : : //! \param[in,out] unk Array of conservative variables
777 : : //! \param[in] nielem Number of internal elements
778 : : //! \details This function applies CPL to obtain consistent dofs for
779 : : //! conservative quantities based on the limited primitive quantities.
780 : : //! See Pandare et al. (2023). On the Design of Stable,
781 : : //! Consistent, and Conservative High-Order Methods for Multi-Material
782 : : //! Hydrodynamics. J Comp Phys, 112313.
783 : 30 : void CPL( const tk::Fields& prim,
784 : : const tk::Fields& geoElem,
785 : : const std::vector< std::size_t >& inpoel,
786 : : const tk::UnsMesh::Coords& coord,
787 : : tk::Fields& unk,
788 : : std::size_t nielem ) const
789 : : {
790 : 30 : [[maybe_unused]] const auto rdof = g_inputdeck.get< tag::rdof >();
791 : 30 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
792 : :
793 [ - + ][ - - ]: 30 : Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
794 : : "vector and primitive vector at recent time step incorrect" );
795 [ - + ][ - - ]: 30 : Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
[ - - ][ - - ]
[ - - ]
796 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
797 [ - + ][ - - ]: 30 : Assert( prim.nprop() == rdof*m_nprim, "Number of components in vector of "
[ - - ][ - - ]
[ - - ]
798 : : "primitive quantities must equal "+ std::to_string(rdof*m_nprim) );
799 : :
800 : 30 : correctLimConservMultiMat(nielem, m_mat_blk, nmat, inpoel,
801 : : coord, geoElem, prim, unk);
802 : 30 : }
803 : :
804 : : //! Return cell-average deformation gradient tensor
805 : : //! \param[in] unk Solution vector at recent time step
806 : : //! \param[in] nielem Number of internal elements
807 : : //! \details This function returns the bulk cell-average inverse
808 : : //! deformation gradient tensor
809 : 0 : std::array< std::vector< tk::real >, 9 > cellAvgDeformGrad(
810 : : const tk::Fields& unk,
811 : : std::size_t nielem ) const
812 : : {
813 : 0 : const auto rdof = g_inputdeck.get< tag::rdof >();
814 : 0 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
815 : 0 : const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
816 : :
817 : 0 : std::array< std::vector< tk::real >, 9 > gb;
818 [ - - ][ - - ]: 0 : if (inciter::haveSolid(nmat, solidx)) {
819 [ - - ]: 0 : for (auto& gij : gb)
820 [ - - ]: 0 : gij.resize(nielem, 0.0);
821 [ - - ]: 0 : for (std::size_t e=0; e<nielem; ++e) {
822 [ - - ]: 0 : for (std::size_t k=0; k<nmat; ++k) {
823 [ - - ]: 0 : if (solidx[k] > 0) {
824 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
825 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
826 [ - - ]: 0 : gb[3*i+j][e] += unk(e, volfracDofIdx(nmat,k,rdof,0)) *
827 [ - - ]: 0 : unk(e,deformDofIdx(nmat,solidx[k],i,j,rdof,0));
828 : : }
829 : : }
830 : : }
831 : : }
832 : :
833 : 0 : return gb;
834 : : }
835 : :
836 : :
837 : : //! Reset the high order solution for p-adaptive scheme
838 : : //! \param[in] fd Face connectivity and boundary conditions object
839 : : //! \param[in,out] unk Solution vector at recent time step
840 : : //! \param[in,out] prim Primitive vector at recent time step
841 : : //! \param[in] ndofel Vector of local number of degrees of freedome
842 : : //! \details This function reset the high order coefficient for p-adaptive
843 : : //! solution polynomials. Unlike compflow class, the high order of fv
844 : : //! solution will not be reset since p0p1 is the base scheme for
845 : : //! multi-material p-adaptive DG method.
846 : 0 : void resetAdapSol( const inciter::FaceData& fd,
847 : : tk::Fields& unk,
848 : : tk::Fields& prim,
849 : : const std::vector< std::size_t >& ndofel ) const
850 : : {
851 : 0 : const auto rdof = g_inputdeck.get< tag::rdof >();
852 : 0 : const auto ncomp = unk.nprop() / rdof;
853 : 0 : const auto nprim = prim.nprop() / rdof;
854 : :
855 [ - - ]: 0 : for(std::size_t e = 0; e < fd.Esuel().size()/4; e++)
856 : : {
857 [ - - ]: 0 : if(ndofel[e] < 10)
858 : : {
859 [ - - ]: 0 : for (std::size_t c=0; c<ncomp; ++c)
860 : : {
861 : 0 : auto mark = c*rdof;
862 : 0 : unk(e, mark+4) = 0.0;
863 : 0 : unk(e, mark+5) = 0.0;
864 : 0 : unk(e, mark+6) = 0.0;
865 : 0 : unk(e, mark+7) = 0.0;
866 : 0 : unk(e, mark+8) = 0.0;
867 : 0 : unk(e, mark+9) = 0.0;
868 : : }
869 [ - - ]: 0 : for (std::size_t c=0; c<nprim; ++c)
870 : : {
871 : 0 : auto mark = c*rdof;
872 : 0 : prim(e, mark+4) = 0.0;
873 : 0 : prim(e, mark+5) = 0.0;
874 : 0 : prim(e, mark+6) = 0.0;
875 : 0 : prim(e, mark+7) = 0.0;
876 : 0 : prim(e, mark+8) = 0.0;
877 : 0 : prim(e, mark+9) = 0.0;
878 : : }
879 : : }
880 : : }
881 : 0 : }
882 : :
883 : : //! Compute right hand side
884 : : //! \param[in] t Physical time
885 : : //! \param[in] pref Indicator for p-adaptive algorithm
886 : : //! \param[in] geoFace Face geometry array
887 : : //! \param[in] geoElem Element geometry array
888 : : //! \param[in] fd Face connectivity and boundary conditions object
889 : : //! \param[in] inpoel Element-node connectivity
890 : : //! \param[in] coord Array of nodal coordinates
891 : : //! \param[in] U Solution vector at recent time step
892 : : //! \param[in] P Primitive vector at recent time step
893 : : //! \param[in] ndofel Vector of local number of degrees of freedom
894 : : //! \param[in] dt Delta time
895 : : //! \param[in,out] R Right-hand side vector computed
896 : 6705 : void rhs( tk::real t,
897 : : const bool pref,
898 : : const tk::Fields& geoFace,
899 : : const tk::Fields& geoElem,
900 : : const inciter::FaceData& fd,
901 : : const std::vector< std::size_t >& inpoel,
902 : : const std::vector< std::unordered_set< std::size_t > >&,
903 : : const tk::UnsMesh::Coords& coord,
904 : : const tk::Fields& U,
905 : : const tk::Fields& P,
906 : : const std::vector< std::size_t >& ndofel,
907 : : const tk::real dt,
908 : : tk::Fields& R ) const
909 : : {
910 : 6705 : const auto ndof = g_inputdeck.get< tag::ndof >();
911 : 6705 : const auto rdof = g_inputdeck.get< tag::rdof >();
912 : 6705 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
913 : 6705 : const auto intsharp =
914 : 6705 : g_inputdeck.get< tag::multimat, tag::intsharp >();
915 : : const auto& solidx = inciter::g_inputdeck.get<
916 : 6705 : tag::matidxmap, tag::solidx >();
917 [ + - ]: 6705 : auto nsld = numSolids(nmat, solidx);
918 : :
919 : 6705 : const auto nelem = fd.Esuel().size()/4;
920 : :
921 [ - + ][ - - ]: 6705 : Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
922 : : "vector and primitive vector at recent time step incorrect" );
923 [ - + ][ - - ]: 6705 : Assert( U.nunk() == R.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
924 : : "vector and right-hand side at recent time step incorrect" );
925 [ - + ][ - - ]: 6705 : Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
[ - - ][ - - ]
[ - - ]
926 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
927 [ - + ][ - - ]: 6705 : Assert( P.nprop() == rdof*m_nprim, "Number of components in primitive "
[ - - ][ - - ]
[ - - ]
928 : : "vector must equal "+ std::to_string(rdof*m_nprim) );
929 [ - + ][ - - ]: 6705 : Assert( R.nprop() == ndof*m_ncomp, "Number of components in right-hand "
[ - - ][ - - ]
[ - - ]
930 : : "side vector must equal "+ std::to_string(ndof*m_ncomp) );
931 [ - + ][ - - ]: 6705 : Assert( fd.Inpofa().size()/3 == fd.Esuf().size()/2,
[ - - ][ - - ]
932 : : "Mismatch in inpofa size" );
933 : :
934 : : // set rhs to zero
935 [ + - ]: 6705 : R.fill(0.0);
936 : :
937 : : // Allocate space for Riemann derivatives used in non-conservative terms.
938 : : // The following Riemann derivatives are stored, in order:
939 : : // 1) 3*nmat terms: derivatives of partial pressure of each material,
940 : : // for the energy equations.
941 : : // 2) ndof terms: derivatives of Riemann velocity times the basis
942 : : // function, for the volume fraction equations.
943 : : // 3) nmat*3*3*9 terms: 3 derivatives of u_l*g_ij for each material, for
944 : : // the deformation gradient equations.
945 : : // 4) 3*nsld terms: 3 derivatives of \alpha \sigma_ij for each solid
946 : : // material, for the energy equations.
947 : : // 5) 27*nsld terms: all combinations of d(g_il)/d(x_j) - d(g_ij)/d(x_l)
948 : : // for each solid material, for the deformation equations.
949 : : std::vector< std::vector< tk::real > >
950 [ + - ][ + - ]: 20115 : riemannDeriv(3*nmat+ndof+3*nsld+27*nsld, std::vector<tk::real>(U.nunk(),0.0));
951 : :
952 : : // configure a no-op lambda for prescribed velocity
953 : 10787925 : auto velfn = []( ncomp_t, tk::real, tk::real, tk::real, tk::real ){
954 : 10787925 : return tk::VelFn::result_type(); };
955 : :
956 : : // compute internal surface flux integrals
957 [ + - ]: 13410 : tk::surfInt( pref, nmat, m_mat_blk, t, ndof, rdof, inpoel, solidx,
958 [ + - ]: 6705 : coord, fd, geoFace, geoElem, m_riemann, velfn, U, P, ndofel,
959 : : dt, R, riemannDeriv, intsharp );
960 : :
961 : : // compute optional source term
962 [ + - ][ + - ]: 6705 : tk::srcInt( m_mat_blk, t, ndof, fd.Esuel().size()/4, inpoel,
963 : : coord, geoElem, Problem::src, ndofel, R, nmat );
964 : :
965 [ + + ]: 6705 : if(ndof > 1)
966 : : // compute volume integrals
967 [ + - ][ + - ]: 780 : tk::volInt( nmat, t, m_mat_blk, ndof, rdof, nelem,
[ + - ]
968 : : inpoel, coord, geoElem, flux, velfn, U, P, ndofel, R,
969 : : intsharp );
970 : :
971 : : // compute boundary surface flux integrals
972 [ + + ]: 60345 : for (const auto& b : m_bc)
973 [ + - ][ + - ]: 107280 : tk::bndSurfInt( pref, nmat, m_mat_blk, ndof, rdof,
974 : 53640 : std::get<0>(b), fd, geoFace, geoElem, inpoel, coord, t,
975 : 107280 : m_riemann, velfn, std::get<1>(b), U, P, ndofel, R,
976 : : riemannDeriv, intsharp );
977 : :
978 [ - + ][ - - ]: 6705 : Assert( riemannDeriv.size() == 3*nmat+ndof+3*nsld+27*nsld, "Size of "
[ - - ][ - - ]
979 : : "Riemann derivative vector incorrect" );
980 : :
981 : : // get derivatives from riemannDeriv
982 [ + + ]: 58230 : for (std::size_t k=0; k<riemannDeriv.size(); ++k)
983 : : {
984 [ - + ][ - - ]: 51525 : Assert( riemannDeriv[k].size() == U.nunk(), "Riemann derivative vector "
[ - - ][ - - ]
985 : : "for non-conservative terms has incorrect size" );
986 [ + + ]: 33037725 : for (std::size_t e=0; e<U.nunk(); ++e)
987 [ + - ]: 32986200 : riemannDeriv[k][e] /= geoElem(e, 0);
988 : : }
989 : :
990 : : // compute volume integrals of non-conservative terms
991 [ + - ]: 6705 : tk::nonConservativeInt( pref, nmat, m_mat_blk, ndof, rdof, nelem,
992 : : inpoel, coord, geoElem, U, P, riemannDeriv,
993 : : ndofel, R, intsharp );
994 : :
995 : : // Compute integrals for inverse deformation correction in solid materials
996 [ + - ][ - + ]: 6705 : if (inciter::haveSolid(nmat, solidx) &&
[ - - ][ - + ]
997 : 0 : g_inputdeck.get< tag::multimat, tag::rho0constraint >())
998 [ - - ]: 0 : tk::solidTermsVolInt( nmat, m_mat_blk, ndof, rdof, nelem,
999 : : inpoel, coord, geoElem, U, P, ndofel,
1000 : : dt, R);
1001 : :
1002 : : // compute finite pressure relaxation terms
1003 [ + + ]: 6705 : if (g_inputdeck.get< tag::multimat, tag::prelax >())
1004 : : {
1005 : 375 : const auto ct = g_inputdeck.get< tag::multimat,
1006 : 375 : tag::prelax_timescale >();
1007 [ + - ]: 375 : tk::pressureRelaxationInt( pref, nmat, m_mat_blk, ndof,
1008 : : rdof, nelem, inpoel, coord, geoElem, U, P,
1009 : : ndofel, ct, R, intsharp );
1010 : : }
1011 : 6705 : }
1012 : :
1013 : : //! Evaluate the adaptive indicator and mark the ndof for each element
1014 : : //! \param[in] nunk Number of unknowns
1015 : : //! \param[in] coord Array of nodal coordinates
1016 : : //! \param[in] inpoel Element-node connectivity
1017 : : //! \param[in] fd Face connectivity and boundary conditions object
1018 : : //! \param[in] unk Array of unknowns
1019 : : //! \param[in] prim Array of primitive quantities
1020 : : //! \param[in] indicator p-refinement indicator type
1021 : : //! \param[in] ndof Number of degrees of freedom in the solution
1022 : : //! \param[in] ndofmax Max number of degrees of freedom for p-refinement
1023 : : //! \param[in] tolref Tolerance for p-refinement
1024 : : //! \param[in,out] ndofel Vector of local number of degrees of freedome
1025 : 0 : void eval_ndof( std::size_t nunk,
1026 : : [[maybe_unused]] const tk::UnsMesh::Coords& coord,
1027 : : [[maybe_unused]] const std::vector< std::size_t >& inpoel,
1028 : : const inciter::FaceData& fd,
1029 : : const tk::Fields& unk,
1030 : : [[maybe_unused]] const tk::Fields& prim,
1031 : : inciter::ctr::PrefIndicatorType indicator,
1032 : : std::size_t ndof,
1033 : : std::size_t ndofmax,
1034 : : tk::real tolref,
1035 : : std::vector< std::size_t >& ndofel ) const
1036 : : {
1037 : 0 : const auto& esuel = fd.Esuel();
1038 : 0 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1039 : :
1040 [ - - ]: 0 : if(indicator == inciter::ctr::PrefIndicatorType::SPECTRAL_DECAY)
1041 : 0 : spectral_decay(nmat, nunk, esuel, unk, ndof, ndofmax, tolref, ndofel);
1042 : : else
1043 [ - - ][ - - ]: 0 : Throw( "No such adaptive indicator type" );
[ - - ]
1044 : 0 : }
1045 : :
1046 : : //! Compute the minimum time step size
1047 : : //! \param[in] fd Face connectivity and boundary conditions object
1048 : : //! \param[in] geoFace Face geometry array
1049 : : //! \param[in] geoElem Element geometry array
1050 : : // //! \param[in] ndofel Vector of local number of degrees of freedom
1051 : : //! \param[in] U Solution vector at recent time step
1052 : : //! \param[in] P Vector of primitive quantities at recent time step
1053 : : //! \param[in] nielem Number of internal elements
1054 : : //! \return Minimum time step size
1055 : : //! \details The allowable dt is calculated by looking at the maximum
1056 : : //! wave-speed in elements surrounding each face, times the area of that
1057 : : //! face. Once the maximum of this quantity over the mesh is determined,
1058 : : //! the volume of each cell is divided by this quantity. A minimum of this
1059 : : //! ratio is found over the entire mesh, which gives the allowable dt.
1060 : 760 : tk::real dt( const std::array< std::vector< tk::real >, 3 >&,
1061 : : const std::vector< std::size_t >&,
1062 : : const inciter::FaceData& fd,
1063 : : const tk::Fields& geoFace,
1064 : : const tk::Fields& geoElem,
1065 : : const std::vector< std::size_t >& /*ndofel*/,
1066 : : const tk::Fields& U,
1067 : : const tk::Fields& P,
1068 : : const std::size_t nielem ) const
1069 : : {
1070 : 760 : const auto ndof = g_inputdeck.get< tag::ndof >();
1071 : 760 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1072 : :
1073 : 760 : auto mindt = timeStepSizeMultiMat( m_mat_blk, fd.Esuf(), geoFace, geoElem,
1074 : : nielem, nmat, U, P);
1075 : :
1076 : 760 : tk::real dgp = 0.0;
1077 [ + + ]: 760 : if (ndof == 4)
1078 : : {
1079 : 260 : dgp = 1.0;
1080 : : }
1081 [ - + ]: 500 : else if (ndof == 10)
1082 : : {
1083 : 0 : dgp = 2.0;
1084 : : }
1085 : :
1086 : : // Scale smallest dt with CFL coefficient and the CFL is scaled by (2*p+1)
1087 : : // where p is the order of the DG polynomial by linear stability theory.
1088 : 760 : mindt /= (2.0*dgp + 1.0);
1089 : 760 : return mindt;
1090 : : }
1091 : :
1092 : : //! Balances elastic energy after plastic update
1093 : : //! \details Since we perform an implicit update for the
1094 : : //! deformation based on plastic work, we perform an update
1095 : : //! on the total energy based on that change in elastic energy.
1096 : : //! We use a Taylor-Quinney expression, see:
1097 : : //! Bever, Michael Berliner, David Lewis Holt, and Alan Lee
1098 : : //! Titchener. "The stored energy of cold work." Progress in
1099 : : //! materials science 17 (1973): 5-177.
1100 : : //! \param[in] e Element number
1101 : : //! \param[in] x_star Stiff variables before implicit update
1102 : : //! \param[in] x Stiff variables after implicit update
1103 : : //! \param[in] U Field of conserved variables
1104 : 0 : void balance_plastic_energy( std::size_t e,
1105 : : std::vector< tk::real > x_star,
1106 : : std::vector< tk::real > x,
1107 : : tk::Fields& U ) const
1108 : : {
1109 : 0 : const auto ndof = g_inputdeck.get< tag::ndof >();
1110 : 0 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1111 : : const auto& solidx = inciter::g_inputdeck.get<
1112 : 0 : tag::matidxmap, tag::solidx >();
1113 : :
1114 : : // compute correction
1115 : : // Loop through materials
1116 : 0 : std::size_t ksld = 0;
1117 [ - - ]: 0 : for (std::size_t k=0; k<nmat; ++k)
1118 : : {
1119 : 0 : tk::real alpha = U(e, inciter::volfracDofIdx(nmat, k, ndof, 0));
1120 [ - - ]: 0 : if (solidx[k] > 0)
1121 : : {
1122 : 0 : tk::real dpsi = 0.0;
1123 [ - - ]: 0 : for (std::size_t idof=0; idof<ndof; ++idof) {
1124 : : std::array< std::array< tk::real, 3 >, 3 > g;
1125 : : std::array< std::array< tk::real, 3 >, 3 > g_star;
1126 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1127 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j) {
1128 : 0 : std::size_t dofId = solidTensorIdx(ksld,i,j)*ndof+idof;
1129 : 0 : g[i][j] = x[dofId];
1130 : 0 : g_star[i][j] = x_star[dofId];
1131 : : }
1132 : : std::array< std::array< tk::real, 3 >, 3 > devH;
1133 : : // Coded in for now
1134 [ - - ]: 0 : tk::real mu = getmatprop< tag::mu >(k);
1135 : : // 1. Compute Psi
1136 : : // Compute deviatoric part of Hencky tensor
1137 [ - - ]: 0 : devH = tk::getDevHencky(g);
1138 : : // Compute elastic energy
1139 : 0 : tk::real psi = 0.0;
1140 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1141 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1142 : 0 : psi += mu*devH[i][j]*devH[i][j];
1143 : : // 2. Compute Psi_star
1144 : : // Compute deviatoric part of Hencky tensor
1145 [ - - ]: 0 : devH = tk::getDevHencky(g_star);
1146 : : // Compute elastic energy
1147 : 0 : tk::real psi_star = 0.0;
1148 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1149 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1150 : 0 : psi_star += mu*devH[i][j]*devH[i][j];
1151 : : // Compute difference
1152 : 0 : dpsi += psi - psi_star;
1153 : : }
1154 : 0 : tk::real a_min = 1.0e-04, a_max = 2.0e-01;
1155 : 0 : auto smoothstep = [&](tk::real a){
1156 : 0 : tk::real t = std::clamp((a-a_min)/(a_max-a_min), 0.0, 1.0);
1157 : 0 : return t*t*(3.0-2.0*t);
1158 : : };
1159 [ - - ]: 0 : tk::real a_tilde = smoothstep(alpha);
1160 : 0 : tk::real beta = 1.0;
1161 : 0 : const tk::real dE_vol = alpha * a_tilde * beta * (-dpsi);
1162 [ - - ]: 0 : for (std::size_t idof=0; idof<ndof; ++idof)
1163 : : // Should have B[idof] here for it to work for high order
1164 : : // Currently, only useful for ndof=1
1165 [ - - ]: 0 : U(e, energyDofIdx(nmat,k,ndof,idof)) += dE_vol;
1166 : 0 : ksld++;
1167 : : }
1168 : : }
1169 : 0 : }
1170 : :
1171 : :
1172 : : //! Compute stiff terms for a single element
1173 : : //! \param[in] e Element number
1174 : : //! \param[in] geoElem Element geometry array
1175 : : //! \param[in] inpoel Element-node connectivity
1176 : : //! \param[in] coord Array of nodal coordinates
1177 : : //! \param[in] U Solution vector at recent time step
1178 : : //! \param[in] P Primitive vector at recent time step
1179 : : //! \param[in] ndofel Vector of local number of degrees of freedom
1180 : : //! \param[in,out] R Right-hand side vector computed
1181 : 0 : void stiff_rhs( std::size_t e,
1182 : : const tk::Fields& geoElem,
1183 : : const std::vector< std::size_t >& inpoel,
1184 : : const tk::UnsMesh::Coords& coord,
1185 : : const tk::Fields& U,
1186 : : const tk::Fields& P,
1187 : : const std::vector< std::size_t >& ndofel,
1188 : : tk::Fields& R ) const
1189 : : {
1190 : 0 : const auto ndof = g_inputdeck.get< tag::ndof >();
1191 : 0 : const auto rdof = g_inputdeck.get< tag::rdof >();
1192 : 0 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1193 : 0 : const auto intsharp =
1194 : 0 : g_inputdeck.get< tag::multimat, tag::intsharp >();
1195 : : const auto& solidx = inciter::g_inputdeck.get<
1196 : 0 : tag::matidxmap, tag::solidx >();
1197 : :
1198 [ - - ][ - - ]: 0 : Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
[ - - ][ - - ]
1199 : : "vector and primitive vector at recent time step incorrect" );
1200 [ - - ][ - - ]: 0 : Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
[ - - ][ - - ]
[ - - ]
1201 : : "vector must equal "+ std::to_string(rdof*m_ncomp) );
1202 [ - - ][ - - ]: 0 : Assert( P.nprop() == rdof*m_nprim, "Number of components in primitive "
[ - - ][ - - ]
[ - - ]
1203 : : "vector must equal "+ std::to_string(rdof*m_nprim) );
1204 [ - - ][ - - ]: 0 : Assert( R.nprop() == ndof*nstiffeq(), "Number of components in "
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ]
1205 : : "right-hand side must equal "+ std::to_string(ndof*nstiffeq()) );
1206 : :
1207 : : // set rhs to zero for element e
1208 [ - - ][ - - ]: 0 : for (std::size_t i=0; i<ndof*nstiffeq(); ++i)
1209 [ - - ]: 0 : R(e, i) = 0.0;
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 : auto ncomp = U.nprop()/rdof;
1216 : 0 : auto nprim = P.nprop()/rdof;
1217 : :
1218 [ - - ]: 0 : auto ng = tk::NGvol(ndofel[e]);
1219 : :
1220 : : // arrays for quadrature points
1221 : 0 : std::array< std::vector< tk::real >, 3 > coordgp;
1222 : 0 : std::vector< tk::real > wgp;
1223 : :
1224 [ - - ]: 0 : coordgp[0].resize( ng );
1225 [ - - ]: 0 : coordgp[1].resize( ng );
1226 [ - - ]: 0 : coordgp[2].resize( ng );
1227 [ - - ]: 0 : wgp.resize( ng );
1228 : :
1229 [ - - ]: 0 : tk::GaussQuadratureTet( ng, coordgp, wgp );
1230 : :
1231 : : // Extract the element coordinates
1232 : 0 : std::array< std::array< tk::real, 3>, 4 > coordel {{
1233 : : {{ cx[ inpoel[4*e ] ], cy[ inpoel[4*e ] ], cz[ inpoel[4*e ] ] }},
1234 : 0 : {{ cx[ inpoel[4*e+1] ], cy[ inpoel[4*e+1] ], cz[ inpoel[4*e+1] ] }},
1235 : 0 : {{ cx[ inpoel[4*e+2] ], cy[ inpoel[4*e+2] ], cz[ inpoel[4*e+2] ] }},
1236 : 0 : {{ cx[ inpoel[4*e+3] ], cy[ inpoel[4*e+3] ], cz[ inpoel[4*e+3] ] }}
1237 : : }};
1238 : :
1239 : : // Gaussian quadrature
1240 [ - - ]: 0 : for (std::size_t igp=0; igp<ng; ++igp)
1241 : : {
1242 : : // Compute the coordinates of quadrature point at physical domain
1243 [ - - ]: 0 : auto gp = tk::eval_gp( igp, coordel, coordgp );
1244 : :
1245 : : // Compute the basis function
1246 [ - - ]: 0 : auto B = tk::eval_basis( ndofel[e], coordgp[0][igp], coordgp[1][igp],
1247 : : coordgp[2][igp] );
1248 : :
1249 [ - - ]: 0 : auto state = tk::evalPolynomialSol(m_mat_blk, intsharp, ncomp, nprim,
1250 : : rdof, nmat, e, ndofel[e], inpoel, coord, geoElem, gp, B, U, P);
1251 : :
1252 : : // compute source
1253 : : // Loop through materials
1254 : 0 : std::size_t ksld = 0;
1255 [ - - ]: 0 : for (std::size_t k=0; k<nmat; ++k)
1256 : : {
1257 : 0 : tk::real alpha = state[inciter::volfracIdx(nmat, k)];
1258 [ - - ]: 0 : if (solidx[k] > 0)
1259 : : {
1260 : : std::array< std::array< tk::real, 3 >, 3 > g;
1261 : : // Compute the source terms
1262 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1263 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1264 : 0 : g[i][j] = state[inciter::deformIdx(nmat,solidx[k],i,j)];
1265 : :
1266 : : // Compute Lp
1267 : : // Reference: Ortega, A. L., Lombardini, M., Pullin, D. I., &
1268 : : // Meiron, D. I. (2014). Numerical simulation of elastic–plastic
1269 : : // solid mechanics using an Eulerian stretch tensor approach and
1270 : : // HLLD Riemann solver. Journal of Computational Physics, 257,
1271 : : // 414-441
1272 : : std::array< std::array< tk::real, 3 >, 3 > Lp;
1273 : :
1274 : : // 1. Compute dev(sigma)
1275 [ - - ]: 0 : auto sigma_dev = m_mat_blk[k].computeTensor< EOS::CauchyStress >(
1276 : : alpha, k, g );
1277 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1278 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1279 : 0 : sigma_dev[i][j] /= alpha;
1280 : 0 : tk::real sigma_trace =
1281 : 0 : sigma_dev[0][0]+sigma_dev[1][1]+sigma_dev[2][2];
1282 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1283 : 0 : sigma_dev[i][i] -= sigma_trace/3.0;
1284 : :
1285 : : // 2. Compute g*dev(sigma), symmetrized
1286 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1287 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1288 : : {
1289 : 0 : tk::real sum1 = 0.0;
1290 : 0 : tk::real sum2 = 0.0;
1291 [ - - ]: 0 : for (std::size_t l=0; l<3; ++l) {
1292 : 0 : sum1 += g[i][l]*sigma_dev[l][j];
1293 : 0 : sum2 += sigma_dev[i][l]*g[l][j];
1294 : : }
1295 : 0 : Lp[i][j] = 0.5*(sum1+sum2);
1296 : : }
1297 : :
1298 : : // 3. Divide by 2*mu*tau
1299 : : // 'Perfect' plasticity
1300 [ - - ]: 0 : std::vector< tk::real > s(9*ndof, 0.0);
1301 [ - - ]: 0 : tk::real yield_stress = getmatprop< tag::yield_stress >(k);
1302 : 0 : tk::real equiv_stress = 0.0;
1303 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1304 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1305 : 0 : equiv_stress += sigma_dev[i][j]*sigma_dev[i][j];
1306 : 0 : equiv_stress = std::sqrt(3.0*equiv_stress/2.0);
1307 : 0 : tk::real rel_factor = 0.0;
1308 : 0 : tk::real phi = std::max(0.0, equiv_stress-yield_stress);
1309 [ - - ]: 0 : tk::real rel_time = getmatprop< tag::plasticity_reltime >(k);
1310 [ - - ]: 0 : if (phi > 0.0) {
1311 : 0 : rel_factor = std::pow((phi/yield_stress),2.0)/rel_time;
1312 : : // Scale rel_factor by alpha
1313 : 0 : tk::real a_min = 1.0e-04, a_max = 2.0e-01;
1314 : 0 : auto smoothstep = [&](tk::real a){
1315 : 0 : tk::real t = std::clamp((a-a_min)/(a_max-a_min), 0.0, 1.0);
1316 : 0 : return t*t*(3.0-2.0*t);
1317 : : };
1318 : 0 : tk::real a_tilde = smoothstep(alpha);
1319 : 0 : rel_factor *= a_tilde;
1320 : : }
1321 [ - - ]: 0 : tk::real mu = getmatprop< tag::mu >(k);
1322 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1323 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1324 : 0 : Lp[i][j] *= rel_factor/(2.0*mu);
1325 : :
1326 : : // Compute the source terms
1327 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1328 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1329 [ - - ]: 0 : for (std::size_t idof=0; idof<ndof; ++idof)
1330 : : {
1331 : 0 : s[(i*3+j)*ndof+idof] = B[idof] * Lp[i][j];
1332 : : }
1333 : :
1334 [ - - ]: 0 : auto wt = wgp[igp] * geoElem(e, 0);
1335 : :
1336 : : // Contribute to the right-hand-side
1337 [ - - ]: 0 : for (std::size_t i=0; i<3; ++i)
1338 [ - - ]: 0 : for (std::size_t j=0; j<3; ++j)
1339 [ - - ]: 0 : for (std::size_t idof=0; idof<ndof; ++idof)
1340 : : {
1341 : 0 : std::size_t srcId = (i*3+j)*ndof+idof;
1342 : 0 : std::size_t dofId = solidTensorIdx(ksld,i,j)*ndof+idof;
1343 [ - - ]: 0 : R(e, dofId) += wt * s[srcId];
1344 : : }
1345 : :
1346 : 0 : ksld++;
1347 : : }
1348 : : }
1349 : :
1350 : : }
1351 : 0 : }
1352 : :
1353 : : //! Extract the velocity field at cell nodes. Currently unused.
1354 : : //! \param[in] U Solution vector at recent time step
1355 : : //! \param[in] N Element node indices
1356 : : //! \return Array of the four values of the velocity field
1357 : : std::array< std::array< tk::real, 4 >, 3 >
1358 : : velocity( const tk::Fields& U,
1359 : : const std::array< std::vector< tk::real >, 3 >&,
1360 : : const std::array< std::size_t, 4 >& N ) const
1361 : : {
1362 : : const auto rdof = g_inputdeck.get< tag::rdof >();
1363 : : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1364 : :
1365 : : std::array< std::array< tk::real, 4 >, 3 > v;
1366 : : v[0] = U.extract( momentumDofIdx(nmat, 0, rdof, 0), N );
1367 : : v[1] = U.extract( momentumDofIdx(nmat, 1, rdof, 0), N );
1368 : : v[2] = U.extract( momentumDofIdx(nmat, 2, rdof, 0), N );
1369 : :
1370 : : std::vector< std::array< tk::real, 4 > > ar;
1371 : : ar.resize(nmat);
1372 : : for (std::size_t k=0; k<nmat; ++k)
1373 : : ar[k] = U.extract( densityDofIdx(nmat, k, rdof, 0), N );
1374 : :
1375 : : std::array< tk::real, 4 > r{{ 0.0, 0.0, 0.0, 0.0 }};
1376 : : for (std::size_t i=0; i<r.size(); ++i) {
1377 : : for (std::size_t k=0; k<nmat; ++k)
1378 : : r[i] += ar[k][i];
1379 : : }
1380 : :
1381 : : std::transform( r.begin(), r.end(), v[0].begin(), v[0].begin(),
1382 : : []( tk::real s, tk::real& d ){ return d /= s; } );
1383 : : std::transform( r.begin(), r.end(), v[1].begin(), v[1].begin(),
1384 : : []( tk::real s, tk::real& d ){ return d /= s; } );
1385 : : std::transform( r.begin(), r.end(), v[2].begin(), v[2].begin(),
1386 : : []( tk::real s, tk::real& d ){ return d /= s; } );
1387 : : return v;
1388 : : }
1389 : :
1390 : : //! Return a map that associates user-specified strings to functions
1391 : : //! \return Map that associates user-specified strings to functions that
1392 : : //! compute relevant quantities to be output to file
1393 : 358 : std::map< std::string, tk::GetVarFn > OutVarFn() const
1394 : 358 : { return MultiMatOutVarFn(); }
1395 : :
1396 : : //! Return analytic field names to be output to file
1397 : : //! \return Vector of strings labelling analytic fields output in file
1398 : 0 : std::vector< std::string > analyticFieldNames() const {
1399 : 0 : auto nmat = g_inputdeck.get< eq, tag::nmat >();
1400 : :
1401 : 0 : return MultiMatFieldNames(nmat);
1402 : : }
1403 : :
1404 : : //! Return time history field names to be output to file
1405 : : //! \return Vector of strings labelling time history fields output in file
1406 : 0 : std::vector< std::string > histNames() const {
1407 : 0 : return MultiMatHistNames();
1408 : : }
1409 : :
1410 : : //! Return surface field output going to file
1411 : : std::vector< std::vector< tk::real > >
1412 : 0 : surfOutput( const std::map< int, std::vector< std::size_t > >&,
1413 : : tk::Fields& ) const
1414 : : {
1415 : 0 : std::vector< std::vector< tk::real > > s; // punt for now
1416 : 0 : return s;
1417 : : }
1418 : :
1419 : : //! Return time history field output evaluated at time history points
1420 : : //! \param[in] h History point data
1421 : : //! \param[in] inpoel Element-node connectivity
1422 : : //! \param[in] coord Array of nodal coordinates
1423 : : //! \param[in] U Array of unknowns
1424 : : //! \param[in] P Array of primitive quantities
1425 : : //! \return Vector of time history output of bulk flow quantities (density,
1426 : : //! velocity, total energy, and pressure) evaluated at time history points
1427 : : std::vector< std::vector< tk::real > >
1428 : 0 : histOutput( const std::vector< HistData >& h,
1429 : : const std::vector< std::size_t >& inpoel,
1430 : : const tk::UnsMesh::Coords& coord,
1431 : : const tk::Fields& U,
1432 : : const tk::Fields& P ) const
1433 : : {
1434 : 0 : const auto rdof = g_inputdeck.get< tag::rdof >();
1435 : 0 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1436 : :
1437 : 0 : const auto& x = coord[0];
1438 : 0 : const auto& y = coord[1];
1439 : 0 : const auto& z = coord[2];
1440 : :
1441 [ - - ]: 0 : std::vector< std::vector< tk::real > > Up(h.size());
1442 : :
1443 : 0 : std::size_t j = 0;
1444 [ - - ]: 0 : for (const auto& p : h) {
1445 : 0 : auto e = p.get< tag::elem >();
1446 : 0 : auto chp = p.get< tag::coord >();
1447 : :
1448 : : // Evaluate inverse Jacobian
1449 : 0 : std::array< std::array< tk::real, 3>, 4 > cp{{
1450 : : {{ x[inpoel[4*e ]], y[inpoel[4*e ]], z[inpoel[4*e ]] }},
1451 : 0 : {{ x[inpoel[4*e+1]], y[inpoel[4*e+1]], z[inpoel[4*e+1]] }},
1452 : 0 : {{ x[inpoel[4*e+2]], y[inpoel[4*e+2]], z[inpoel[4*e+2]] }},
1453 : 0 : {{ x[inpoel[4*e+3]], y[inpoel[4*e+3]], z[inpoel[4*e+3]] }} }};
1454 : 0 : auto J = tk::inverseJacobian( cp[0], cp[1], cp[2], cp[3] );
1455 : :
1456 : : // evaluate solution at history-point
1457 : 0 : std::array< tk::real, 3 > dc{{chp[0]-cp[0][0], chp[1]-cp[0][1],
1458 : 0 : chp[2]-cp[0][2]}};
1459 [ - - ]: 0 : auto B = tk::eval_basis(rdof, tk::dot(J[0],dc), tk::dot(J[1],dc),
1460 : 0 : tk::dot(J[2],dc));
1461 [ - - ]: 0 : auto uhp = eval_state(m_ncomp, rdof, rdof, e, U, B);
1462 [ - - ]: 0 : auto php = eval_state(m_nprim, rdof, rdof, e, P, B);
1463 : :
1464 : : // store solution in history output vector
1465 [ - - ]: 0 : Up[j].resize(6, 0.0);
1466 [ - - ]: 0 : for (std::size_t k=0; k<nmat; ++k) {
1467 : 0 : Up[j][0] += uhp[densityIdx(nmat,k)];
1468 : 0 : Up[j][4] += uhp[energyIdx(nmat,k)];
1469 : 0 : Up[j][5] += php[pressureIdx(nmat,k)];
1470 : : }
1471 : 0 : Up[j][1] = php[velocityIdx(nmat,0)];
1472 : 0 : Up[j][2] = php[velocityIdx(nmat,1)];
1473 : 0 : Up[j][3] = php[velocityIdx(nmat,2)];
1474 : 0 : ++j;
1475 : : }
1476 : :
1477 : 0 : return Up;
1478 : : }
1479 : :
1480 : : //! Return names of integral variables to be output to diagnostics file
1481 : : //! \return Vector of strings labelling integral variables output
1482 : 13 : std::vector< std::string > names() const
1483 : : {
1484 : 13 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1485 : 13 : return MultiMatDiagNames(nmat);
1486 : : }
1487 : :
1488 : : //! Return analytic solution (if defined by Problem) at xi, yi, zi, t
1489 : : //! \param[in] xi X-coordinate at which to evaluate the analytic solution
1490 : : //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
1491 : : //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
1492 : : //! \param[in] t Physical time at which to evaluate the analytic solution
1493 : : //! \return Vector of analytic solution at given location and time
1494 : : std::vector< tk::real >
1495 : 0 : analyticSolution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
1496 : 0 : { return Problem::analyticSolution( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
1497 : :
1498 : : //! Return analytic solution for conserved variables
1499 : : //! \param[in] xi X-coordinate at which to evaluate the analytic solution
1500 : : //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
1501 : : //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
1502 : : //! \param[in] t Physical time at which to evaluate the analytic solution
1503 : : //! \return Vector of analytic solution at given location and time
1504 : : std::vector< tk::real >
1505 : 1358616 : solution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
1506 : 1358616 : { return Problem::initialize( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
1507 : :
1508 : : //! Return cell-averaged specific total energy for an element
1509 : : //! \param[in] e Element id for which total energy is required
1510 : : //! \param[in] unk Vector of conserved quantities
1511 : : //! \return Cell-averaged specific total energy for given element
1512 : 858336 : tk::real sp_totalenergy(std::size_t e, const tk::Fields& unk) const
1513 : : {
1514 : 858336 : const auto rdof = g_inputdeck.get< tag::rdof >();
1515 : 858336 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1516 : :
1517 : 858336 : tk::real sp_te(0.0);
1518 : : // sum each material total energy
1519 [ + + ]: 2965588 : for (std::size_t k=0; k<nmat; ++k) {
1520 : 2107252 : sp_te += unk(e, energyDofIdx(nmat,k,rdof,0));
1521 : : }
1522 : 858336 : return sp_te;
1523 : : }
1524 : :
1525 : : private:
1526 : : //! Number of components in this PDE system
1527 : : const ncomp_t m_ncomp;
1528 : : //! Number of primitive quantities stored in this PDE system
1529 : : const ncomp_t m_nprim;
1530 : : //! Riemann solver
1531 : : tk::RiemannFluxFn m_riemann;
1532 : : //! BC configuration
1533 : : BCStateFn m_bc;
1534 : : //! EOS material block
1535 : : std::vector< EOS > m_mat_blk;
1536 : :
1537 : : //! Evaluate conservative part of physical flux function for this PDE system
1538 : : //! \param[in] ncomp Number of scalar components in this PDE system
1539 : : //! \param[in] ugp Numerical solution at the Gauss point at which to
1540 : : //! evaluate the flux
1541 : : //! \return Flux vectors for all components in this PDE system
1542 : : //! \note The function signature must follow tk::FluxFn
1543 : : static tk::FluxFn::result_type
1544 : 7374000 : flux( ncomp_t ncomp,
1545 : : const std::vector< EOS >& mat_blk,
1546 : : const std::vector< tk::real >& ugp,
1547 : : const std::vector< std::array< tk::real, 3 > >& )
1548 : : {
1549 : 7374000 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1550 : :
1551 : 7374000 : return tk::fluxTerms(ncomp, nmat, mat_blk, ugp);
1552 : : }
1553 : :
1554 : : //! \brief Boundary state function providing the left and right state of a
1555 : : //! face at Dirichlet boundaries
1556 : : //! \param[in] ncomp Number of scalar components in this PDE system
1557 : : //! \param[in] mat_blk EOS material block
1558 : : //! \param[in] ul Left (domain-internal) state
1559 : : //! \param[in] x X-coordinate at which to compute the states
1560 : : //! \param[in] y Y-coordinate at which to compute the states
1561 : : //! \param[in] z Z-coordinate at which to compute the states
1562 : : //! \param[in] t Physical time
1563 : : //! \return Left and right states for all scalar components in this PDE
1564 : : //! system
1565 : : //! \note The function signature must follow tk::StateFn. For multimat, the
1566 : : //! left or right state is the vector of conserved quantities, followed by
1567 : : //! the vector of primitive quantities appended to it.
1568 : : static tk::StateFn::result_type
1569 : 48000 : dirichlet( ncomp_t ncomp,
1570 : : const std::vector< EOS >& mat_blk,
1571 : : const std::vector< tk::real >& ul, tk::real x, tk::real y,
1572 : : tk::real z, tk::real t, const std::array< tk::real, 3 >& )
1573 : : {
1574 : 48000 : auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
1575 : : const auto& solidx = g_inputdeck.get<
1576 : 48000 : tag::matidxmap, tag::solidx >();
1577 : :
1578 [ + - ]: 48000 : [[maybe_unused]] auto nsld = numSolids(nmat, solidx);
1579 : :
1580 [ + - ]: 96000 : auto ur = Problem::initialize( ncomp, mat_blk, x, y, z, t );
1581 [ - + ][ - - ]: 48000 : Assert( ur.size() == ncomp, "Incorrect size for boundary state vector" );
[ - - ][ - - ]
1582 : :
1583 [ + - ]: 48000 : ur.resize(ul.size());
1584 : :
1585 : 48000 : tk::real rho(0.0);
1586 [ + + ]: 192000 : for (std::size_t k=0; k<nmat; ++k)
1587 : 144000 : rho += ur[densityIdx(nmat, k)];
1588 : :
1589 : : // get primitives in boundary state
1590 : :
1591 : : // velocity
1592 : 48000 : ur[ncomp+velocityIdx(nmat, 0)] = ur[momentumIdx(nmat, 0)] / rho;
1593 : 48000 : ur[ncomp+velocityIdx(nmat, 1)] = ur[momentumIdx(nmat, 1)] / rho;
1594 : 48000 : ur[ncomp+velocityIdx(nmat, 2)] = ur[momentumIdx(nmat, 2)] / rho;
1595 : :
1596 : : // material pressures
1597 [ + + ]: 192000 : for (std::size_t k=0; k<nmat; ++k)
1598 : : {
1599 [ + - ]: 144000 : auto gk = getDeformGrad(nmat, k, ur);
1600 [ + - ]: 288000 : ur[ncomp+pressureIdx(nmat, k)] = mat_blk[k].compute< EOS::pressure >(
1601 : 144000 : ur[densityIdx(nmat, k)], ur[ncomp+velocityIdx(nmat, 0)],
1602 : 144000 : ur[ncomp+velocityIdx(nmat, 1)], ur[ncomp+velocityIdx(nmat, 2)],
1603 : 144000 : ur[energyIdx(nmat, k)], ur[volfracIdx(nmat, k)], k, gk );
1604 : : }
1605 : :
1606 [ - + ][ - - ]: 48000 : Assert( ur.size() == ncomp+nmat+3+nsld*6, "Incorrect size for appended "
[ - - ][ - - ]
1607 : : "boundary state vector" );
1608 : :
1609 [ + - ]: 96000 : return {{ std::move(ul), std::move(ur) }};
1610 : : }
1611 : :
1612 : : // Other boundary condition types that do not depend on "Problem" should be
1613 : : // added in BCFunctions.hpp
1614 : : };
1615 : :
1616 : : } // dg::
1617 : :
1618 : : } // inciter::
1619 : :
1620 : : #endif // DGMultiMat_h
|